Fixed EDKT102;
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / OnDependency.java
index 936dac8..ba388a1 100644 (file)
@@ -13,19 +13,25 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 --*/\r
 package org.tianocore.build.global;\r
 \r
 --*/\r
 package org.tianocore.build.global;\r
 \r
+import java.io.File;\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.Map;\r
+\r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Task;\r
 import org.apache.tools.ant.taskdefs.Sequential;\r
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Task;\r
 import org.apache.tools.ant.taskdefs.Sequential;\r
 \r
-import java.io.File;\r
-import java.util.Iterator;\r
-\r
 /**\r
  Class OnDepdendency is used to check the timestamp between source files and\r
  target files, which can be used to determine if the target files are needed to\r
  be re-generated from source files.\r
  **/\r
 public class OnDependency extends Task {\r
 /**\r
  Class OnDepdendency is used to check the timestamp between source files and\r
  target files, which can be used to determine if the target files are needed to\r
  be re-generated from source files.\r
  **/\r
 public class OnDependency extends Task {\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
     /// source files list\r
     ///\r
     ///\r
     /// source files list\r
     ///\r
@@ -77,12 +83,20 @@ public class OnDependency extends Task {
             Iterator srcIt = sources.nameList.iterator();\r
             while (srcIt.hasNext()) {\r
                 String srcFileName = (String)srcIt.next();\r
             Iterator srcIt = sources.nameList.iterator();\r
             while (srcIt.hasNext()) {\r
                 String srcFileName = (String)srcIt.next();\r
-                File srcFile = new File(srcFileName);\r
-                if (!srcFile.exists()) {\r
-                    throw new BuildException(srcFileName + " doesn't exist !!!");\r
+                long srcTimeStamp;\r
+\r
+                if (timeStampCache.containsKey(srcFileName)) {\r
+                    srcTimeStamp = ((Long)timeStampCache.get(srcFileName)).longValue();\r
+                } else {\r
+                    File srcFile = new File(srcFileName);\r
+                    if (!srcFile.exists()) {\r
+                        throw new BuildException(srcFileName + " doesn't exist !!!");\r
+                    }\r
+                    srcTimeStamp = srcFile.lastModified();\r
+                    timeStampCache.put(srcFileName, new Long(srcTimeStamp));\r
                 }\r
 \r
                 }\r
 \r
-                if (dstTimeStamp < srcFile.lastModified()) {\r
+                if (dstTimeStamp < srcTimeStamp) {\r
                     return true;\r
                 }\r
             }\r
                     return true;\r
                 }\r
             }\r