]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/GenBuild/org/tianocore/build/global/OnDependency.java
2 This file is to define OnDependency class.
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
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.
14 package org
.tianocore
.build
.global
;
17 import java
.util
.Iterator
;
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
;
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.
30 public class OnDependency
extends Task
{
34 private DpFileList sources
= null;
39 private DpFileList targets
= null;
42 // tasks to be performed to generate target files
44 private Sequential task
= null;
47 An empty constructor for an ANT task can avoid some potential issues
49 public OnDependency(){
53 Standard execute method of ANT task
55 public void execute() throws BuildException
{
56 if (isOutOfDate() && task
!= null) {
61 // Update the time stamp of target files since they are just re-generated
63 for (Iterator dstIt
= targets
.nameList
.iterator(); dstIt
.hasNext();) {
64 FileTimeStamp
.update((String
)dstIt
.next());
69 // check if the target files are outofdate
71 private boolean isOutOfDate() {
73 /// if no source files specified, take it as a fresh start
75 if (sources
.nameList
.size() == 0) {
76 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "No source file spcified!");
80 if (targets
.nameList
.size() == 0) {
81 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "No target file found!");
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!");
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
);
100 if (srcTimeStamp
== 0) {
102 // time stamp 0 means that the file doesn't exist
104 throw new BuildException("Source File name: " + srcFileName
+ " doesn't exist!!!");
107 if (dstTimeStamp
< srcTimeStamp
) {
108 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "Source file [" + srcFileName
+ "] has been changed since last build!");
114 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "Target files are up-to-date!");
119 Add method of ANT task for nested element with Sequential type
121 @param task Sequential object which contains tasks for generating target files
123 public void addSequential(Sequential task
) {
128 Add method of ANT task for nested element with DpFileList type
130 @param sources DpFileList object which contains the list of source files
132 public void addSourcefiles(DpFileList sources
) {
133 this.sources
= sources
;
137 Add method of ANT task for nested element with DpFileList type
139 @param targets DpFileList object which contains the list of target files
141 public void addTargetfiles(DpFileList targets
) {
142 this.targets
= targets
;