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