]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/global/OnDependency.java
Initial import.
[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
16import org.apache.tools.ant.BuildException;\r
17import org.apache.tools.ant.Task;\r
18import org.apache.tools.ant.taskdefs.Sequential;\r
19\r
20import java.io.File;\r
21import java.util.Iterator;\r
22\r
23/**\r
24 Class OnDepdendency is used to check the timestamp between source files and\r
25 target files, which can be used to determine if the target files are needed to\r
26 be re-generated from source files.\r
27 **/\r
28public class OnDependency extends Task {\r
29 ///\r
30 /// source files list\r
31 ///\r
32 private DpFileList sources = null;\r
33 ///\r
34 /// target files list\r
35 ///\r
36 private DpFileList targets = null;\r
37 ///\r
38 /// tasks to be performed to generate target files\r
39 ///\r
40 private Sequential task = null;\r
41\r
42 ///\r
43 /// An empty constructor for an ANT task can avoid some potential issues\r
44 ///\r
45 public OnDependency(){\r
46 }\r
47\r
48 /**\r
49 Standard execute method of ANT task\r
50 **/\r
51 public void execute() {\r
52 if (isOutOfDate() && task != null) {\r
53 task.perform();\r
54 }\r
55 }\r
56\r
57 ///\r
58 /// check if the target files are outofdate\r
59 ///\r
60 private boolean isOutOfDate() {\r
61 ///\r
62 /// if no source files specified, take it as a fresh start\r
63 ///\r
64 if (sources.nameList.size() == 0) {\r
65 return true;\r
66 }\r
67\r
68 Iterator dstIt = targets.nameList.iterator();\r
69 while (dstIt.hasNext()) {\r
70 String dstFileName = (String)dstIt.next();\r
71 File dstFile = new File(dstFileName);\r
72 if (!dstFile.exists()) {\r
73 return true;\r
74 }\r
75\r
76 long dstTimeStamp = dstFile.lastModified();\r
77 Iterator srcIt = sources.nameList.iterator();\r
78 while (srcIt.hasNext()) {\r
79 String srcFileName = (String)srcIt.next();\r
80 File srcFile = new File(srcFileName);\r
81 if (!srcFile.exists()) {\r
82 throw new BuildException(srcFileName + " doesn't exist !!!");\r
83 }\r
84\r
85 if (dstTimeStamp < srcFile.lastModified()) {\r
86 return true;\r
87 }\r
88 }\r
89 }\r
90\r
91 return false;\r
92 }\r
93\r
94 /**\r
95 Add method of ANT task for nested element with Sequential type\r
96\r
97 @param task Sequential object which contains tasks for generating target files\r
98 **/\r
99 public void addSequential(Sequential task) {\r
100 this.task = task;\r
101 }\r
102\r
103 /**\r
104 Add method of ANT task for nested element with DpFileList type\r
105\r
106 @param sources DpFileList object which contains the list of source files\r
107 **/\r
108 public void addSourcefiles(DpFileList sources) {\r
109 this.sources = sources;\r
110 }\r
111\r
112 /**\r
113 Add method of ANT task for nested element with DpFileList type\r
114\r
115 @param targets DpFileList object which contains the list of target files\r
116 **/\r
117 public void addTargetfiles(DpFileList targets) {\r
118 this.targets = targets;\r
119 }\r
120}\r
121\r