aboutsummaryrefslogtreecommitdiffstats
path: root/anttasks
diff options
context:
space:
mode:
authorJosiah Gaskin <josiahgaskin@google.com>2011-08-17 11:58:44 -0700
committerJosiah Gaskin <josiahgaskin@google.com>2011-08-18 14:35:42 -0700
commit48902aa6250561146066fc9d56e95c5c2a930e3c (patch)
tree35a7aac6b5dbc03a9b1b4e573c138f9ed3ac184f /anttasks
parentd02592f8bfaf1de01a8d03ee6fb4b2576045c07d (diff)
downloadsdk-48902aa6250561146066fc9d56e95c5c2a930e3c.zip
sdk-48902aa6250561146066fc9d56e95c5c2a930e3c.tar.gz
sdk-48902aa6250561146066fc9d56e95c5c2a930e3c.tar.bz2
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
Diffstat (limited to 'anttasks')
-rw-r--r--anttasks/src/com/android/ant/BaseTask.java20
-rw-r--r--anttasks/src/com/android/ant/DependencyGraph.java34
2 files changed, 47 insertions, 7 deletions
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<String> 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>();
+ 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<File> mTargets = Collections.emptySet();
private Set<File> mPrereqs = mTargets;
- private ArrayList<File> mWatchPaths;
+ private final ArrayList<File> mWatchPaths;
public DependencyGraph(String dependencyFilePath, ArrayList<File> 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<String> 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<String> 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);
+ }
}