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