fbffb3bcb77490e55b1fe4c029339029c42e46aa
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
.HashMap
;
18 import java
.util
.Iterator
;
21 import org
.apache
.tools
.ant
.BuildException
;
22 import org
.apache
.tools
.ant
.Task
;
23 import org
.apache
.tools
.ant
.taskdefs
.Sequential
;
24 import org
.tianocore
.common
.logger
.EdkLog
;
25 import org
.tianocore
.common
.cache
.FileTimeStamp
;
28 Class OnDepdendency is used to check the timestamp between source files and
29 target files, which can be used to determine if the target files are needed to
30 be re-generated from source files.
32 public class OnDependency
extends Task
{
36 private DpFileList sources
= null;
41 private DpFileList targets
= null;
44 // tasks to be performed to generate target files
46 private Sequential task
= null;
49 An empty constructor for an ANT task can avoid some potential issues
51 public OnDependency(){
55 Standard execute method of ANT task
57 public void execute() throws BuildException
{
58 if (isOutOfDate() && task
!= null) {
63 // Update the time stamp of target files since they are just re-generated
65 for (Iterator dstIt
= targets
.nameList
.iterator(); dstIt
.hasNext();) {
66 FileTimeStamp
.update((String
)dstIt
.next());
71 // check if the target files are outofdate
73 private boolean isOutOfDate() {
75 /// if no source files specified, take it as a fresh start
77 if (sources
.nameList
.size() == 0) {
78 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "No source file spcified!");
82 if (targets
.nameList
.size() == 0) {
83 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "No target file found!");
87 Iterator dstIt
= targets
.nameList
.iterator();
88 while (dstIt
.hasNext()) {
89 String dstFileName
= (String
)dstIt
.next();
90 File dstFile
= new File(dstFileName
);
91 if (!dstFile
.exists()) {
92 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "Target file [" + dstFileName
+ "] doesn't exist!");
96 long dstTimeStamp
= FileTimeStamp
.get(dstFileName
);
97 Iterator srcIt
= sources
.nameList
.iterator();
98 while (srcIt
.hasNext()) {
99 String srcFileName
= (String
)srcIt
.next();
100 long srcTimeStamp
= FileTimeStamp
.get(srcFileName
);
102 if (srcTimeStamp
== 0) {
104 // time stamp 0 means that the file doesn't exist
106 throw new BuildException("Source File name: " + srcFileName
+ " doesn't exist!!!");
109 if (dstTimeStamp
< srcTimeStamp
) {
110 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "Source file [" + srcFileName
+ "] has been changed since last build!");
116 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "Target files are up-to-date!");
121 Add method of ANT task for nested element with Sequential type
123 @param task Sequential object which contains tasks for generating target files
125 public void addSequential(Sequential task
) {
130 Add method of ANT task for nested element with DpFileList type
132 @param sources DpFileList object which contains the list of source files
134 public void addSourcefiles(DpFileList sources
) {
135 this.sources
= sources
;
139 Add method of ANT task for nested element with DpFileList type
141 @param targets DpFileList object which contains the list of target files
143 public void addTargetfiles(DpFileList targets
) {
144 this.targets
= targets
;