]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/global/OnDependency.java
1) Changed ToolArg class to abstract generic arguments of a tool
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / OnDependency.java
CommitLineData
878ddf1f 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
196ad8d7 16import java.io.File;\r
17import java.util.HashMap;\r
18import java.util.Iterator;\r
19import java.util.Map;\r
20\r
878ddf1f 21import org.apache.tools.ant.BuildException;\r
22import org.apache.tools.ant.Task;\r
23import org.apache.tools.ant.taskdefs.Sequential;\r
93f5dd0a 24import org.tianocore.common.logger.EdkLog;\r
878ddf1f 25\r
878ddf1f 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
196ad8d7 32 ///\r
33 /// cache the modified timestamp of files accessed, to speed up the depencey check\r
34 /// \r
19bf6b15 35 private Map<String, Long> timeStampCache = new HashMap<String, Long>();\r
878ddf1f 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
93f5dd0a 58 public void execute() throws BuildException {\r
878ddf1f 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
93f5dd0a 72 EdkLog.log(this, EdkLog.EDK_VERBOSE, "No source file spcified!");\r
878ddf1f 73 return true;\r
74 }\r
75\r
76 Iterator dstIt = targets.nameList.iterator();\r
77 while (dstIt.hasNext()) {\r
78 String dstFileName = (String)dstIt.next();\r
79 File dstFile = new File(dstFileName);\r
80 if (!dstFile.exists()) {\r
93f5dd0a 81 EdkLog.log(this, EdkLog.EDK_VERBOSE, "Target file [" + dstFileName + "] doesn't exist!");\r
878ddf1f 82 return true;\r
83 }\r
84\r
85 long dstTimeStamp = dstFile.lastModified();\r
86 Iterator srcIt = sources.nameList.iterator();\r
87 while (srcIt.hasNext()) {\r
88 String srcFileName = (String)srcIt.next();\r
196ad8d7 89 long srcTimeStamp;\r
90\r
91 if (timeStampCache.containsKey(srcFileName)) {\r
92 srcTimeStamp = ((Long)timeStampCache.get(srcFileName)).longValue();\r
93 } else {\r
94 File srcFile = new File(srcFileName);\r
95 if (!srcFile.exists()) {\r
391dbbb1 96 throw new BuildException("Source File name: " + srcFileName + " doesn't exist!!!");\r
196ad8d7 97 }\r
98 srcTimeStamp = srcFile.lastModified();\r
99 timeStampCache.put(srcFileName, new Long(srcTimeStamp));\r
878ddf1f 100 }\r
101\r
196ad8d7 102 if (dstTimeStamp < srcTimeStamp) {\r
93f5dd0a 103 EdkLog.log(this, EdkLog.EDK_VERBOSE, "Source file [" + srcFileName + "] has been changed since last build!");\r
878ddf1f 104 return true;\r
105 }\r
106 }\r
107 }\r
108\r
109 return false;\r
110 }\r
111\r
112 /**\r
113 Add method of ANT task for nested element with Sequential type\r
114\r
115 @param task Sequential object which contains tasks for generating target files\r
116 **/\r
117 public void addSequential(Sequential task) {\r
118 this.task = task;\r
119 }\r
120\r
121 /**\r
122 Add method of ANT task for nested element with DpFileList type\r
123\r
124 @param sources DpFileList object which contains the list of source files\r
125 **/\r
126 public void addSourcefiles(DpFileList sources) {\r
127 this.sources = sources;\r
128 }\r
129\r
130 /**\r
131 Add method of ANT task for nested element with DpFileList type\r
132\r
133 @param targets DpFileList object which contains the list of target files\r
134 **/\r
135 public void addTargetfiles(DpFileList targets) {\r
136 this.targets = targets;\r
137 }\r
138}\r
139\r