+++ /dev/null
-/** @file\r
-This file is to define OnDependency class.\r
-\r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
---*/\r
-package org.tianocore.build.global;\r
-\r
-import java.io.File;\r
-import java.util.Iterator;\r
-\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.tools.ant.Task;\r
-import org.apache.tools.ant.taskdefs.Sequential;\r
-import org.tianocore.common.logger.EdkLog;\r
-import org.tianocore.common.cache.FileTimeStamp;\r
-\r
-/**\r
- Class OnDepdendency is used to check the timestamp between source files and\r
- target files, which can be used to determine if the target files are needed to\r
- be re-generated from source files.\r
- **/\r
-public class OnDependency extends Task {\r
- //\r
- // source files list\r
- //\r
- private DpFileList sources = null;\r
-\r
- //\r
- // target files list\r
- //\r
- private DpFileList targets = null;\r
-\r
- //\r
- // tasks to be performed to generate target files\r
- //\r
- private Sequential task = null;\r
-\r
- /**\r
- An empty constructor for an ANT task can avoid some potential issues\r
- **/\r
- public OnDependency(){\r
- }\r
-\r
- /**\r
- Standard execute method of ANT task\r
- **/\r
- public void execute() throws BuildException {\r
- if (isOutOfDate() && task != null) {\r
- task.perform();\r
- }\r
-\r
- //\r
- // Update the time stamp of target files since they are just re-generated\r
- // \r
- for (Iterator dstIt = targets.nameList.iterator(); dstIt.hasNext();) {\r
- FileTimeStamp.update((String)dstIt.next());\r
- }\r
- }\r
-\r
- //\r
- // check if the target files are outofdate\r
- //\r
- private boolean isOutOfDate() {\r
- ///\r
- /// if no source files specified, take it as a fresh start\r
- ///\r
- if (sources.nameList.size() == 0) {\r
- EdkLog.log(this, EdkLog.EDK_VERBOSE, "No source file spcified!");\r
- return true;\r
- }\r
-\r
- if (targets.nameList.size() == 0) {\r
- EdkLog.log(this, EdkLog.EDK_VERBOSE, "No target file found!");\r
- return true;\r
- }\r
-\r
- Iterator dstIt = targets.nameList.iterator();\r
- while (dstIt.hasNext()) {\r
- String dstFileName = (String)dstIt.next();\r
- File dstFile = new File(dstFileName);\r
- if (!dstFile.exists()) {\r
- EdkLog.log(this, EdkLog.EDK_VERBOSE, "Target file [" + dstFileName + "] doesn't exist!");\r
- return true;\r
- }\r
-\r
- long dstTimeStamp = FileTimeStamp.get(dstFileName);\r
- Iterator srcIt = sources.nameList.iterator();\r
- while (srcIt.hasNext()) {\r
- String srcFileName = (String)srcIt.next();\r
- long srcTimeStamp = FileTimeStamp.get(srcFileName);\r
-\r
- if (srcTimeStamp == 0) {\r
- //\r
- // time stamp 0 means that the file doesn't exist\r
- // \r
- throw new BuildException("Source File name: " + srcFileName + " doesn't exist!!!");\r
- }\r
-\r
- if (dstTimeStamp < srcTimeStamp) {\r
- EdkLog.log(this, EdkLog.EDK_VERBOSE, "Source file [" + srcFileName + "] has been changed since last build!");\r
- return true;\r
- }\r
- }\r
- }\r
-\r
- EdkLog.log(this, EdkLog.EDK_VERBOSE, "Target files are up-to-date!");\r
- return false;\r
- }\r
-\r
- /**\r
- Add method of ANT task for nested element with Sequential type\r
-\r
- @param task Sequential object which contains tasks for generating target files\r
- **/\r
- public void addSequential(Sequential task) {\r
- this.task = task;\r
- }\r
-\r
- /**\r
- Add method of ANT task for nested element with DpFileList type\r
-\r
- @param sources DpFileList object which contains the list of source files\r
- **/\r
- public void addSourcefiles(DpFileList sources) {\r
- this.sources = sources;\r
- }\r
-\r
- /**\r
- Add method of ANT task for nested element with DpFileList type\r
-\r
- @param targets DpFileList object which contains the list of target files\r
- **/\r
- public void addTargetfiles(DpFileList targets) {\r
- this.targets = targets;\r
- }\r
-}\r
-\r