From 48902aa6250561146066fc9d56e95c5c2a930e3c Mon Sep 17 00:00:00 2001 From: Josiah Gaskin Date: Wed, 17 Aug 2011 11:58:44 -0700 Subject: Added extension specification to dependency check This change adds a parameter 'touchedextensions' that can be qualified with a colon-separated list of extension to consider during checks to see if prerequisite files have been modified. if this parameter is not set, files of all extensions will be checked to see if they have been modified. Change-Id: I9bd7e20b6e5341b3a0f3698ffdc2de10d286921c --- anttasks/src/com/android/ant/BaseTask.java | 20 ++++++++++++- anttasks/src/com/android/ant/DependencyGraph.java | 34 +++++++++++++++++++---- 2 files changed, 47 insertions(+), 7 deletions(-) (limited to 'anttasks') diff --git a/anttasks/src/com/android/ant/BaseTask.java b/anttasks/src/com/android/ant/BaseTask.java index 00b7fcb..0ff7bf1 100644 --- a/anttasks/src/com/android/ant/BaseTask.java +++ b/anttasks/src/com/android/ant/BaseTask.java @@ -21,6 +21,8 @@ import org.apache.tools.ant.Task; import java.io.File; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; /** * A base class for the ant task that contains logic for handling dependency files @@ -41,6 +43,22 @@ public abstract class BaseTask extends Task { protected abstract String getExecTaskName(); + private Set mRestrictTouchedExtensionsTo; + + /** + * Sets the value of the "restricttouchedextensionsto" attribute. + * @param touchedExtensions the extensions to check to see if they have been modified. + * values should be separated by a colon (:). If left blank or not set, all extensions + * will be checked. + */ + public void setRestrictTouchedExtensionsTo(String restrictTouchedExtensionsTo) { + mRestrictTouchedExtensionsTo = new HashSet(); + String[] extensions = restrictTouchedExtensionsTo.split(":"); + for (String s : extensions) { + mRestrictTouchedExtensionsTo.add(s); + } + } + @Override public void execute() throws BuildException { @@ -84,6 +102,6 @@ public abstract class BaseTask extends Task { } assert mDependencies != null : "Dependencies have not been initialized"; - return mDependencies.dependenciesHaveChanged(); + return mDependencies.dependenciesHaveChanged(mRestrictTouchedExtensionsTo); } } diff --git a/anttasks/src/com/android/ant/DependencyGraph.java b/anttasks/src/com/android/ant/DependencyGraph.java index 5939a92..4c85860 100644 --- a/anttasks/src/com/android/ant/DependencyGraph.java +++ b/anttasks/src/com/android/ant/DependencyGraph.java @@ -36,7 +36,7 @@ public class DependencyGraph { // Files that we know about from the dependency file private Set mTargets = Collections.emptySet(); private Set mPrereqs = mTargets; - private ArrayList mWatchPaths; + private final ArrayList mWatchPaths; public DependencyGraph(String dependencyFilePath, ArrayList watchPaths) { mWatchPaths = watchPaths; @@ -45,15 +45,18 @@ public class DependencyGraph { /** * Check all the dependencies to see if anything has changed. + * @param extensionsToCheck a set of extensions. Only files with an extension in this set will + * be considered for a modification check. All deleted/created files will still be + * checked. If this is null, all files will be checked for modification date * @return true if new prerequisites have appeared, target files are missing or if * prerequisite files have been modified since the last target generation. */ - public boolean dependenciesHaveChanged() { + public boolean dependenciesHaveChanged(Set extensionsToCheck) { boolean noFile = (mTargets.size() == 0); boolean missingPrereq = missingPrereqFile(); boolean newPrereq = newPrereqFile(); boolean missingTarget = missingTargetFile(); - boolean modPrereq = modifiedPrereq(); + boolean modPrereq = modifiedPrereq(extensionsToCheck); if (noFile) { System.out.println("No Dependency File Found"); @@ -206,7 +209,7 @@ public class DependencyGraph { * @return true if the latest prerequisite modification is after the oldest * target modification. */ - private boolean modifiedPrereq() { + private boolean modifiedPrereq(Set extensionsToCheck) { // Find the oldest target long oldestTarget = Long.MAX_VALUE; for (File target : mTargets) { @@ -218,8 +221,12 @@ public class DependencyGraph { // Find the newest prerequisite long newestPrereq = 0; for (File prereq : mPrereqs) { - if (prereq.lastModified() > newestPrereq) { - newestPrereq = prereq.lastModified(); + // If we have a list of extensions that we need to restrict ourselves to, only + // consider this file if it has that extension. + if (extensionsToCheck == null || extensionsToCheck.contains(getExtension(prereq))) { + if (prereq.lastModified() > newestPrereq) { + newestPrereq = prereq.lastModified(); + } } } @@ -251,4 +258,19 @@ public class DependencyGraph { } return null; } + + /** + * Gets the extension (if present) on a file by looking at the filename + * @param file the file to get the extension of + * @return the extension if present, or the empty string if the filename doesn't have + * and extension. + */ + private static String getExtension(File file) { + String filename = file.getName(); + if (filename.lastIndexOf('.') == -1) { + return ""; + } + // Don't include the leading '.' in the extension + return filename.substring(filename.lastIndexOf('.') + 1); + } } -- cgit v1.1