aboutsummaryrefslogtreecommitdiffstats
path: root/anttasks
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-03-07 19:56:17 -0800
committerXavier Ducrohet <xav@android.com>2012-03-07 20:25:29 -0800
commita08befd52438d523cb2cd41b53f961785d3872fd (patch)
tree782b1febe0eb57200ef9af545380848ade67da4a /anttasks
parent7d2737e54866f33553ee85c546dcea197bffd130 (diff)
downloadsdk-a08befd52438d523cb2cd41b53f961785d3872fd.zip
sdk-a08befd52438d523cb2cd41b53f961785d3872fd.tar.gz
sdk-a08befd52438d523cb2cd41b53f961785d3872fd.tar.bz2
Ant build now sanitize jar files in setup task.
Previously the list of jar files was sanitized (to remove duplicates) in the dex task, but this meant the full list (with duplicates) was passed to proguard when building in release mode. This changeset move the sanitization of the jar files in the Setup Task so that the script later only deals with a sanitized list. The means the content of libs/*.jar for the current project must be looked at in the task instead of later in the XML script. Change-Id: Ib5253b80ee7c1ded004bcdad6184e0900b7a7543
Diffstat (limited to 'anttasks')
-rw-r--r--anttasks/src/com/android/ant/ApkBuilderTask.java9
-rw-r--r--anttasks/src/com/android/ant/DexExecTask.java48
-rw-r--r--anttasks/src/com/android/ant/NewSetupTask.java103
3 files changed, 102 insertions, 58 deletions
diff --git a/anttasks/src/com/android/ant/ApkBuilderTask.java b/anttasks/src/com/android/ant/ApkBuilderTask.java
index 14b0678..8997ad1 100644
--- a/anttasks/src/com/android/ant/ApkBuilderTask.java
+++ b/anttasks/src/com/android/ant/ApkBuilderTask.java
@@ -342,16 +342,25 @@ public class ApkBuilderTask extends SingleDependencyTask {
// add the content of the zip files.
for (File f : zipFiles) {
+ if (mVerbose) {
+ System.out.println("Zip Input: " + f.getAbsolutePath());
+ }
apkBuilder.addZipFile(f);
}
// now go through the list of file to directly add the to the list.
for (File f : sourceFolderList) {
+ if (mVerbose) {
+ System.out.println("Source Folder Input: " + f.getAbsolutePath());
+ }
apkBuilder.addSourceFolder(f);
}
// now go through the list of jar files.
for (File f : jarFileList) {
+ if (mVerbose) {
+ System.out.println("Jar Input: " + f.getAbsolutePath());
+ }
apkBuilder.addResourcesFromJar(f);
}
diff --git a/anttasks/src/com/android/ant/DexExecTask.java b/anttasks/src/com/android/ant/DexExecTask.java
index 085e924..a2b2b07 100644
--- a/anttasks/src/com/android/ant/DexExecTask.java
+++ b/anttasks/src/com/android/ant/DexExecTask.java
@@ -16,10 +16,6 @@
package com.android.ant;
-import com.android.sdklib.build.JarListSanitizer;
-import com.android.sdklib.build.JarListSanitizer.DifferentLibException;
-import com.android.sdklib.build.JarListSanitizer.Sha1Exception;
-
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.ExecTask;
import org.apache.tools.ant.types.FileSet;
@@ -165,12 +161,11 @@ public class DexExecTask extends SingleDependencyTask {
task.createArg().setValue("--output");
task.createArg().setValue(mOutput);
-
- paths = sanitizePaths(paths);
-
for (File f : paths) {
String absPath = f.getAbsolutePath();
- System.out.println("Input: " + absPath);
+ if (mVerbose) {
+ System.out.println("Input: " + absPath);
+ }
task.createArg().setValue(absPath);
}
@@ -185,41 +180,4 @@ public class DexExecTask extends SingleDependencyTask {
protected String getExecTaskName() {
return "dx";
}
-
- // private helper methods.
-
- private List<File> sanitizePaths(List<File> paths) {
- // first get the non-files.
- List<File> results = new ArrayList<File>();
- for (int i = 0 ; i < paths.size() ;) {
- File f = paths.get(i);
- // TEMP WORKAROUND: ignore classes.jar as all the output of libraries are
- // called the same (in Ant) but are not actually the same jar file.
- // TODO: Be aware of library output vs. regular jar dependency.
- if (f.isFile() && f.getName().equals("classes.jar") == false) {
- i++;
- } else {
- results.add(f);
- paths.remove(i);
- }
- }
-
- File outputFile = new File(mOutput);
- JarListSanitizer sanitizer = new JarListSanitizer(outputFile.getParentFile());
-
- try {
- results.addAll(sanitizer.sanitize(paths));
- } catch (DifferentLibException e) {
- String[] details = e.getDetails();
- for (String s : details) {
- System.err.println(s);
- }
- throw new BuildException(e.getMessage(), e);
- } catch (Sha1Exception e) {
- throw new BuildException(
- "Failed to compute sha1 for " + e.getJarFile().getAbsolutePath(), e);
- }
-
- return results;
- }
}
diff --git a/anttasks/src/com/android/ant/NewSetupTask.java b/anttasks/src/com/android/ant/NewSetupTask.java
index 1f29d17..f2f365a 100644
--- a/anttasks/src/com/android/ant/NewSetupTask.java
+++ b/anttasks/src/com/android/ant/NewSetupTask.java
@@ -24,6 +24,9 @@ import com.android.sdklib.IAndroidTarget.IOptionalLibrary;
import com.android.sdklib.ISdkLog;
import com.android.sdklib.SdkConstants;
import com.android.sdklib.SdkManager;
+import com.android.sdklib.build.JarListSanitizer;
+import com.android.sdklib.build.JarListSanitizer.DifferentLibException;
+import com.android.sdklib.build.JarListSanitizer.Sha1Exception;
import com.android.sdklib.internal.project.ProjectProperties;
import com.android.sdklib.internal.project.ProjectProperties.PropertyType;
import com.android.sdklib.xml.AndroidManifest;
@@ -83,6 +86,7 @@ public class NewSetupTask extends Task {
private String mProjectLibrariesJarsOut;
private String mProjectLibrariesLibsOut;
private String mTargetApiOut;
+ private boolean mVerbose = false;
public void setProjectTypeOut(String projectTypeOut) {
mProjectTypeOut = projectTypeOut;
@@ -132,6 +136,14 @@ public class NewSetupTask extends Task {
mTargetApiOut = targetApiOut;
}
+ /**
+ * Sets the value of the "verbose" attribute.
+ * @param verbose the value.
+ */
+ public void setVerbose(boolean verbose) {
+ mVerbose = verbose;
+ }
+
@Override
public void execute() throws BuildException {
if (mProjectTypeOut == null) {
@@ -440,9 +452,12 @@ public class NewSetupTask extends Task {
Path rootPath = new Path(antProject);
Path resPath = new Path(antProject);
Path libsPath = new Path(antProject);
- Path jarsPath = new Path(antProject);
StringBuilder packageStrBuilder = new StringBuilder();
+ // list of all the jars that are on the classpath. This will receive the
+ // project's libs/*.jar files, the Library Projects output and their own libs/*.jar
+ List<File> jars = new ArrayList<File>();
+
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
@@ -477,17 +492,15 @@ public class NewSetupTask extends Task {
// get the jars from it too.
// 1. the library code jar
- element = jarsPath.createPathElement();
- element.setPath(libRootPath + "/" + SdkConstants.FD_OUTPUT +
- "/" + SdkConstants.FN_CLASSES_JAR);
+ jars.add(new File(libRootPath + "/" + SdkConstants.FD_OUTPUT +
+ "/" + SdkConstants.FN_CLASSES_JAR));
// 2. the 3rd party jar files
File libsFolder = new File(library, SdkConstants.FD_NATIVE_LIBS);
File[] jarFiles = libsFolder.listFiles(filter);
if (jarFiles != null) {
for (File jarFile : jarFiles) {
- element = jarsPath.createPathElement();
- element.setPath(jarFile.getAbsolutePath());
+ jars.add(jarFile);
}
}
@@ -516,29 +529,28 @@ public class NewSetupTask extends Task {
PathElement element = rootPath.createPathElement();
element.setPath(library.getAbsolutePath());
}
+ System.out.println();
} else {
System.out.println("No library dependencies.\n");
}
- System.out.println("------------------\n");
+ System.out.println("------------------");
- boolean hasLibraries = jarsPath.list().length > 0;
+ boolean hasLibraries = jars.size() > 0;
if (androidTarget.getVersion().getApiLevel() <= 15) {
System.out.println("API<=15: Adding annotations.jar to the classpath.\n");
- PathElement element = jarsPath.createPathElement();
- element.setPath(sdkLocation + "/" + SdkConstants.FD_TOOLS +
+ jars.add(new File(sdkLocation + "/" + SdkConstants.FD_TOOLS +
"/" + SdkConstants.FD_SUPPORT +
- "/" + SdkConstants.FN_ANNOTATIONS_JAR);
+ "/" + SdkConstants.FN_ANNOTATIONS_JAR));
- System.out.println("------------------\n");
+ System.out.println("------------------");
}
// even with no libraries, always setup these so that various tasks in Ant don't complain
// (the task themselves can handle a ref to an empty Path)
- antProject.addReference(mProjectLibrariesJarsOut, jarsPath);
antProject.addReference(mProjectLibrariesLibsOut, libsPath);
// the rest is done only if there's a library.
@@ -547,6 +559,36 @@ public class NewSetupTask extends Task {
antProject.addReference(mProjectLibrariesResOut, resPath);
antProject.setProperty(mProjectLibrariesPackageOut, packageStrBuilder.toString());
}
+
+ // add the project's own content of libs/*.jar
+ File libsFolder = new File(SdkConstants.FD_NATIVE_LIBS);
+ File[] jarFiles = libsFolder.listFiles(filter);
+ if (jarFiles != null) {
+ for (File jarFile : jarFiles) {
+ jars.add(jarFile);
+ }
+ }
+
+ // now sanitize the path to remove dups
+ jars = sanitizePaths(antProject, jars);
+
+ // and create a Path object for them
+ Path jarsPath = new Path(antProject);
+ if (mVerbose) {
+ System.out.println("Sanitized jar list:");
+ }
+ for (File f : jars) {
+ if (mVerbose) {
+ System.out.println("- " + f.getAbsolutePath());
+ }
+ PathElement element = jarsPath.createPathElement();
+ element.setPath(f.getAbsolutePath());
+ }
+ antProject.addReference(mProjectLibrariesJarsOut, jarsPath);
+
+ if (mVerbose) {
+ System.out.println();
+ }
}
/**
@@ -683,4 +725,39 @@ public class NewSetupTask extends Task {
}
return new DeweyDecimal(sb.toString());
}
+
+ private List<File> sanitizePaths(Project antProject, List<File> paths) {
+ // first get the non-files.
+ List<File> results = new ArrayList<File>();
+ for (int i = 0 ; i < paths.size() ;) {
+ File f = paths.get(i);
+ // TEMP WORKAROUND: ignore classes.jar as all the output of libraries are
+ // called the same (in Ant) but are not actually the same jar file.
+ // TODO: Be aware of library output vs. regular jar dependency.
+ if (f.isFile() && f.getName().equals(SdkConstants.FN_CLASSES_JAR) == false) {
+ i++;
+ } else {
+ results.add(f);
+ paths.remove(i);
+ }
+ }
+
+ File outputFile = new File(antProject.getProperty("out.absolute.dir"));
+ JarListSanitizer sanitizer = new JarListSanitizer(outputFile);
+
+ try {
+ results.addAll(sanitizer.sanitize(paths));
+ } catch (DifferentLibException e) {
+ String[] details = e.getDetails();
+ for (String s : details) {
+ System.err.println(s);
+ }
+ throw new BuildException(e.getMessage(), e);
+ } catch (Sha1Exception e) {
+ throw new BuildException(
+ "Failed to compute sha1 for " + e.getJarFile().getAbsolutePath(), e);
+ }
+
+ return results;
+ }
}