]>
Commit | Line | Data |
---|---|---|
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 |
196ad8d7 | 17 | import java.util.Iterator;\r |
196ad8d7 | 18 | \r |
878ddf1f | 19 | import org.apache.tools.ant.BuildException;\r |
20 | import org.apache.tools.ant.Task;\r | |
21 | import org.apache.tools.ant.taskdefs.Sequential;\r | |
93f5dd0a | 22 | import org.tianocore.common.logger.EdkLog;\r |
4b134847 | 23 | import org.tianocore.common.cache.FileTimeStamp;\r |
878ddf1f | 24 | \r |
878ddf1f | 25 | /**\r |
26 | Class OnDepdendency is used to check the timestamp between source files and\r | |
27 | target files, which can be used to determine if the target files are needed to\r | |
28 | be re-generated from source files.\r | |
29 | **/\r | |
30 | public class OnDependency extends Task {\r | |
4b134847 | 31 | //\r |
32 | // source files list\r | |
33 | //\r | |
878ddf1f | 34 | private DpFileList sources = null;\r |
4b134847 | 35 | \r |
36 | //\r | |
37 | // target files list\r | |
38 | //\r | |
878ddf1f | 39 | private DpFileList targets = null;\r |
4b134847 | 40 | \r |
41 | //\r | |
42 | // tasks to be performed to generate target files\r | |
43 | //\r | |
878ddf1f | 44 | private Sequential task = null;\r |
45 | \r | |
4b134847 | 46 | /**\r |
47 | An empty constructor for an ANT task can avoid some potential issues\r | |
48 | **/\r | |
878ddf1f | 49 | public OnDependency(){\r |
50 | }\r | |
51 | \r | |
52 | /**\r | |
53 | Standard execute method of ANT task\r | |
54 | **/\r | |
93f5dd0a | 55 | public void execute() throws BuildException {\r |
878ddf1f | 56 | if (isOutOfDate() && task != null) {\r |
57 | task.perform();\r | |
58 | }\r | |
4b134847 | 59 | \r |
60 | //\r | |
61 | // Update the time stamp of target files since they are just re-generated\r | |
62 | // \r | |
63 | for (Iterator dstIt = targets.nameList.iterator(); dstIt.hasNext();) {\r | |
64 | FileTimeStamp.update((String)dstIt.next());\r | |
65 | }\r | |
878ddf1f | 66 | }\r |
67 | \r | |
4b134847 | 68 | //\r |
69 | // check if the target files are outofdate\r | |
70 | //\r | |
878ddf1f | 71 | private boolean isOutOfDate() {\r |
72 | ///\r | |
73 | /// if no source files specified, take it as a fresh start\r | |
74 | ///\r | |
75 | if (sources.nameList.size() == 0) {\r | |
93f5dd0a | 76 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "No source file spcified!");\r |
878ddf1f | 77 | return true;\r |
78 | }\r | |
79 | \r | |
34f40a4a | 80 | if (targets.nameList.size() == 0) {\r |
81 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "No target file found!");\r | |
82 | return true;\r | |
83 | }\r | |
84 | \r | |
878ddf1f | 85 | Iterator dstIt = targets.nameList.iterator();\r |
86 | while (dstIt.hasNext()) {\r | |
87 | String dstFileName = (String)dstIt.next();\r | |
88 | File dstFile = new File(dstFileName);\r | |
89 | if (!dstFile.exists()) {\r | |
93f5dd0a | 90 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "Target file [" + dstFileName + "] doesn't exist!");\r |
878ddf1f | 91 | return true;\r |
92 | }\r | |
93 | \r | |
4b134847 | 94 | long dstTimeStamp = FileTimeStamp.get(dstFileName);\r |
878ddf1f | 95 | Iterator srcIt = sources.nameList.iterator();\r |
96 | while (srcIt.hasNext()) {\r | |
97 | String srcFileName = (String)srcIt.next();\r | |
4b134847 | 98 | long srcTimeStamp = FileTimeStamp.get(srcFileName);\r |
99 | \r | |
100 | if (srcTimeStamp == 0) {\r | |
101 | //\r | |
102 | // time stamp 0 means that the file doesn't exist\r | |
103 | // \r | |
104 | throw new BuildException("Source File name: " + srcFileName + " doesn't exist!!!");\r | |
878ddf1f | 105 | }\r |
106 | \r | |
196ad8d7 | 107 | if (dstTimeStamp < srcTimeStamp) {\r |
93f5dd0a | 108 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "Source file [" + srcFileName + "] has been changed since last build!");\r |
878ddf1f | 109 | return true;\r |
110 | }\r | |
111 | }\r | |
112 | }\r | |
113 | \r | |
34f40a4a | 114 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "Target files are up-to-date!");\r |
878ddf1f | 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 |