]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Source/GenBuild/org/tianocore/build/global/OnDependency.java
Fixed an issue which will cause dependency check failure
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / OnDependency.java
... / ...
CommitLineData
1/** @file\r
2This file is to define OnDependency class.\r
3\r
4Copyright (c) 2006, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13--*/\r
14package org.tianocore.build.global;\r
15\r
16import java.io.File;\r
17import java.util.HashMap;\r
18import java.util.Iterator;\r
19import java.util.Map;\r
20\r
21import org.apache.tools.ant.BuildException;\r
22import org.apache.tools.ant.Task;\r
23import org.apache.tools.ant.taskdefs.Sequential;\r
24import org.tianocore.common.logger.EdkLog;\r
25\r
26/**\r
27 Class OnDepdendency is used to check the timestamp between source files and\r
28 target files, which can be used to determine if the target files are needed to\r
29 be re-generated from source files.\r
30 **/\r
31public class OnDependency extends Task {\r
32 ///\r
33 /// cache the modified timestamp of files accessed, to speed up the depencey check\r
34 /// \r
35 private Map<String, Long> timeStampCache = new HashMap<String, Long>();\r
36 ///\r
37 /// source files list\r
38 ///\r
39 private DpFileList sources = null;\r
40 ///\r
41 /// target files list\r
42 ///\r
43 private DpFileList targets = null;\r
44 ///\r
45 /// tasks to be performed to generate target files\r
46 ///\r
47 private Sequential task = null;\r
48\r
49 ///\r
50 /// An empty constructor for an ANT task can avoid some potential issues\r
51 ///\r
52 public OnDependency(){\r
53 }\r
54\r
55 /**\r
56 Standard execute method of ANT task\r
57 **/\r
58 public void execute() throws BuildException {\r
59 if (isOutOfDate() && task != null) {\r
60 task.perform();\r
61 }\r
62 }\r
63\r
64 ///\r
65 /// check if the target files are outofdate\r
66 ///\r
67 private boolean isOutOfDate() {\r
68 ///\r
69 /// if no source files specified, take it as a fresh start\r
70 ///\r
71 if (sources.nameList.size() == 0) {\r
72 EdkLog.log(this, EdkLog.EDK_VERBOSE, "No source file spcified!");\r
73 return true;\r
74 }\r
75\r
76 if (targets.nameList.size() == 0) {\r
77 EdkLog.log(this, EdkLog.EDK_VERBOSE, "No target file found!");\r
78 return true;\r
79 }\r
80\r
81 Iterator dstIt = targets.nameList.iterator();\r
82 while (dstIt.hasNext()) {\r
83 String dstFileName = (String)dstIt.next();\r
84 File dstFile = new File(dstFileName);\r
85 if (!dstFile.exists()) {\r
86 EdkLog.log(this, EdkLog.EDK_VERBOSE, "Target file [" + dstFileName + "] doesn't exist!");\r
87 return true;\r
88 }\r
89\r
90 long dstTimeStamp = dstFile.lastModified();\r
91 Iterator srcIt = sources.nameList.iterator();\r
92 while (srcIt.hasNext()) {\r
93 String srcFileName = (String)srcIt.next();\r
94 long srcTimeStamp;\r
95\r
96 if (timeStampCache.containsKey(srcFileName)) {\r
97 srcTimeStamp = ((Long)timeStampCache.get(srcFileName)).longValue();\r
98 } else {\r
99 File srcFile = new File(srcFileName);\r
100 if (!srcFile.exists()) {\r
101 throw new BuildException("Source File name: " + srcFileName + " doesn't exist!!!");\r
102 }\r
103 srcTimeStamp = srcFile.lastModified();\r
104 timeStampCache.put(srcFileName, new Long(srcTimeStamp));\r
105 }\r
106\r
107 if (dstTimeStamp < srcTimeStamp) {\r
108 EdkLog.log(this, EdkLog.EDK_VERBOSE, "Source file [" + srcFileName + "] has been changed since last build!");\r
109 return true;\r
110 }\r
111 }\r
112 }\r
113\r
114 EdkLog.log(this, EdkLog.EDK_VERBOSE, "Target files are up-to-date!");\r
115 return false;\r
116 }\r
117\r
118 /**\r
119 Add method of ANT task for nested element with Sequential type\r
120\r
121 @param task Sequential object which contains tasks for generating target files\r
122 **/\r
123 public void addSequential(Sequential task) {\r
124 this.task = task;\r
125 }\r
126\r
127 /**\r
128 Add method of ANT task for nested element with DpFileList type\r
129\r
130 @param sources DpFileList object which contains the list of source files\r
131 **/\r
132 public void addSourcefiles(DpFileList sources) {\r
133 this.sources = sources;\r
134 }\r
135\r
136 /**\r
137 Add method of ANT task for nested element with DpFileList type\r
138\r
139 @param targets DpFileList object which contains the list of target files\r
140 **/\r
141 public void addTargetfiles(DpFileList targets) {\r
142 this.targets = targets;\r
143 }\r
144}\r
145\r