]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/Common/org/tianocore/common/cache/FileTimeStamp.java
1) Add FileTimeStamp class to centralize the cache mechanism for file time stamp...
[mirror_edk2.git] / Tools / Source / Common / org / tianocore / common / cache / FileTimeStamp.java
diff --git a/Tools/Source/Common/org/tianocore/common/cache/FileTimeStamp.java b/Tools/Source/Common/org/tianocore/common/cache/FileTimeStamp.java
new file mode 100644 (file)
index 0000000..968d31f
--- /dev/null
@@ -0,0 +1,83 @@
+/** @file\r
+This file is to define the FileTimeStamp class for speeding up the dependency check.\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+package org.tianocore.common.cache;\r
+\r
+import java.io.File;\r
+import java.util.Map;\r
+import java.util.TreeMap;\r
+import java.util.HashMap;\r
+\r
+/**\r
+   FileTimeStamp class is used to cache the time stamp of accessing file, which\r
+   will speed up the dependency check for build\r
+ **/\r
+public class FileTimeStamp {\r
+    //\r
+    // cache the modified timestamp of files accessed, to speed up the depencey check\r
+    // \r
+    private static Map<String, Long> timeStampCache = new HashMap<String, Long>();\r
+\r
+    /**\r
+       Get the time stamp of given file. It will try the cache first and then\r
+       get from file system if no time stamp of the file is cached.\r
+\r
+       @param file      File name\r
+       \r
+       @return long     The time stamp of the file\r
+     **/\r
+    synchronized public static long get(String file) {\r
+        long timeStamp = 0;\r
+\r
+        Long value = timeStampCache.get(file);\r
+        if (value != null) {\r
+            timeStamp = value.longValue();\r
+        } else {\r
+            timeStamp = new File(file).lastModified();\r
+            timeStampCache.put(file, new Long(timeStamp));\r
+        }\r
+\r
+        return timeStamp;\r
+    }\r
+\r
+    /**\r
+       Force update the time stamp for the given file\r
+\r
+       @param file          File name\r
+       @param timeStamp     The time stamp of the file\r
+     **/\r
+    synchronized public static void update(String file, long timeStamp) {\r
+        timeStampCache.put(file, new Long(timeStamp));\r
+    }\r
+\r
+    /**\r
+       Force update the time stamp for the given file\r
+\r
+       @param file          File name\r
+     **/\r
+    synchronized public static void update(String file) {\r
+        long timeStamp = new File(file).lastModified();\r
+        timeStampCache.put(file, new Long(timeStamp));\r
+    }\r
+\r
+    /**\r
+       Check if the time stamp of given file has been cached for not\r
+\r
+       @param file      The file name\r
+       \r
+       @return boolean\r
+     **/\r
+    synchronized public static boolean containsKey(String file) {\r
+        return timeStampCache.containsKey(file);\r
+    }\r
+}\r