]>
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
;
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
{
32 /// cache the modified timestamp of files accessed, to speed up the depencey check
34 private static Map
<String
, Long
> timeStampCache
= new HashMap
<String
, Long
>();
38 private DpFileList sources
= null;
42 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() {
58 if (isOutOfDate() && task
!= null) {
64 /// check if the target files are outofdate
66 private boolean isOutOfDate() {
68 /// if no source files specified, take it as a fresh start
70 if (sources
.nameList
.size() == 0) {
74 Iterator dstIt
= targets
.nameList
.iterator();
75 while (dstIt
.hasNext()) {
76 String dstFileName
= (String
)dstIt
.next();
77 File dstFile
= new File(dstFileName
);
78 if (!dstFile
.exists()) {
82 long dstTimeStamp
= dstFile
.lastModified();
83 Iterator srcIt
= sources
.nameList
.iterator();
84 while (srcIt
.hasNext()) {
85 String srcFileName
= (String
)srcIt
.next();
88 if (timeStampCache
.containsKey(srcFileName
)) {
89 srcTimeStamp
= ((Long
)timeStampCache
.get(srcFileName
)).longValue();
91 File srcFile
= new File(srcFileName
);
92 if (!srcFile
.exists()) {
93 throw new BuildException("Source File name: " + srcFileName
+ " doesn't exist!!!");
95 srcTimeStamp
= srcFile
.lastModified();
96 timeStampCache
.put(srcFileName
, new Long(srcTimeStamp
));
99 if (dstTimeStamp
< srcTimeStamp
) {
109 Add method of ANT task for nested element with Sequential type
111 @param task Sequential object which contains tasks for generating target files
113 public void addSequential(Sequential task
) {
118 Add method of ANT task for nested element with DpFileList type
120 @param sources DpFileList object which contains the list of source files
122 public void addSourcefiles(DpFileList sources
) {
123 this.sources
= sources
;
127 Add method of ANT task for nested element with DpFileList type
129 @param targets DpFileList object which contains the list of target files
131 public void addTargetfiles(DpFileList targets
) {
132 this.targets
= targets
;