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