]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/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
.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
;
27 Class OnDepdendency is used to check the timestamp between source files and
28 target files, which can be used to determine if the target files are needed to
29 be re-generated from source files.
31 public class OnDependency
extends Task
{
33 /// cache the modified timestamp of files accessed, to speed up the depencey check
35 private Map
<String
, Long
> timeStampCache
= new HashMap
<String
, Long
>();
39 private DpFileList sources
= null;
43 private DpFileList targets
= null;
45 /// tasks to be performed to generate target files
47 private Sequential task
= null;
50 /// An empty constructor for an ANT task can avoid some potential issues
52 public OnDependency(){
56 Standard execute method of ANT task
58 public void execute() throws BuildException
{
59 if (isOutOfDate() && task
!= null) {
65 /// check if the target files are outofdate
67 private boolean isOutOfDate() {
69 /// if no source files specified, take it as a fresh start
71 if (sources
.nameList
.size() == 0) {
72 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "No source file spcified!");
76 Iterator dstIt
= targets
.nameList
.iterator();
77 while (dstIt
.hasNext()) {
78 String dstFileName
= (String
)dstIt
.next();
79 File dstFile
= new File(dstFileName
);
80 if (!dstFile
.exists()) {
81 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "Target file [" + dstFileName
+ "] doesn't exist!");
85 long dstTimeStamp
= dstFile
.lastModified();
86 Iterator srcIt
= sources
.nameList
.iterator();
87 while (srcIt
.hasNext()) {
88 String srcFileName
= (String
)srcIt
.next();
91 if (timeStampCache
.containsKey(srcFileName
)) {
92 srcTimeStamp
= ((Long
)timeStampCache
.get(srcFileName
)).longValue();
94 File srcFile
= new File(srcFileName
);
95 if (!srcFile
.exists()) {
96 throw new BuildException("Source File name: " + srcFileName
+ " doesn't exist!!!");
98 srcTimeStamp
= srcFile
.lastModified();
99 timeStampCache
.put(srcFileName
, new Long(srcTimeStamp
));
102 if (dstTimeStamp
< srcTimeStamp
) {
103 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "Source file [" + srcFileName
+ "] has been changed since last build!");
113 Add method of ANT task for nested element with Sequential type
115 @param task Sequential object which contains tasks for generating target files
117 public void addSequential(Sequential task
) {
122 Add method of ANT task for nested element with DpFileList type
124 @param sources DpFileList object which contains the list of source files
126 public void addSourcefiles(DpFileList sources
) {
127 this.sources
= sources
;
131 Add method of ANT task for nested element with DpFileList type
133 @param targets DpFileList object which contains the list of target files
135 public void addTargetfiles(DpFileList targets
) {
136 this.targets
= targets
;