aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--anttasks/src/anttasks.properties40
-rw-r--r--anttasks/src/com/android/ant/ComputeDependencyTask.java19
-rw-r--r--anttasks/src/com/android/ant/ComputeProjectClasspathTask.java4
-rw-r--r--anttasks/src/com/android/ant/DependencyHelper.java26
-rw-r--r--anttasks/src/com/android/ant/GetLibraryListTask.java99
-rw-r--r--anttasks/src/com/android/ant/GetLibraryPathTask.java208
-rw-r--r--anttasks/src/com/android/ant/GetProjectPathsTask.java (renamed from anttasks/src/com/android/ant/GetProjectPropertyTask.java)16
-rw-r--r--anttasks/src/com/android/ant/TaskHelper.java12
-rw-r--r--files/ant/build.xml31
9 files changed, 301 insertions, 154 deletions
diff --git a/anttasks/src/anttasks.properties b/anttasks/src/anttasks.properties
index e0854f4..04047e5 100644
--- a/anttasks/src/anttasks.properties
+++ b/anttasks/src/anttasks.properties
@@ -1,20 +1,20 @@
-checkenv: com.android.ant.CheckEnvTask
-gettype: com.android.ant.GetTypeTask
-gettarget: com.android.ant.GetTargetTask
-getproperty: com.android.ant.GetProjectPropertyTask
-getlibs: com.android.ant.GetLibraryListTask
-dependency: com.android.ant.ComputeDependencyTask
-testedprojectclasspath: com.android.ant.ComputeProjectClasspathTask
-getemmafilter: com.android.ant.GetEmmaFilterTask
-mergemanifest: com.android.ant.ManifestMergerTask
-aapt: com.android.ant.AaptExecTask
-aidl: com.android.ant.AidlExecTask
-renderscript: com.android.ant.RenderScriptTask
-buildconfig: com.android.ant.BuildConfigTask
-dex: com.android.ant.DexExecTask
-apkbuilder: com.android.ant.ApkBuilderTask
-signapk: com.android.ant.SignApkTask
-zipalign: com.android.ant.ZipAlignTask
-xpath: com.android.ant.XPathTask
-if: com.android.ant.IfElseTask
-propertybyreplace: com.android.ant.PropertyByReplaceTask
+checkenv: com.android.ant.CheckEnvTask
+gettype: com.android.ant.GetTypeTask
+gettarget: com.android.ant.GetTargetTask
+getprojectpaths: com.android.ant.GetProjectPathsTask
+getlibpath: com.android.ant.GetLibraryPathTask
+dependency: com.android.ant.ComputeDependencyTask
+testedprojectclasspath: com.android.ant.ComputeProjectClasspathTask
+getemmafilter: com.android.ant.GetEmmaFilterTask
+mergemanifest: com.android.ant.ManifestMergerTask
+aapt: com.android.ant.AaptExecTask
+aidl: com.android.ant.AidlExecTask
+renderscript: com.android.ant.RenderScriptTask
+buildconfig: com.android.ant.BuildConfigTask
+dex: com.android.ant.DexExecTask
+apkbuilder: com.android.ant.ApkBuilderTask
+signapk: com.android.ant.SignApkTask
+zipalign: com.android.ant.ZipAlignTask
+xpath: com.android.ant.XPathTask
+if: com.android.ant.IfElseTask
+propertybyreplace: com.android.ant.PropertyByReplaceTask
diff --git a/anttasks/src/com/android/ant/ComputeDependencyTask.java b/anttasks/src/com/android/ant/ComputeDependencyTask.java
index fda4e17..e4699a8 100644
--- a/anttasks/src/com/android/ant/ComputeDependencyTask.java
+++ b/anttasks/src/com/android/ant/ComputeDependencyTask.java
@@ -16,7 +16,7 @@
package com.android.ant;
-import com.android.ant.DependencyHelper.LibraryProcessorFor3rdPartyJars;
+import com.android.ant.DependencyHelper.JarProcessor;
import com.android.io.FileWrapper;
import com.android.sdklib.SdkConstants;
import com.android.sdklib.internal.project.IPropertySource;
@@ -51,7 +51,7 @@ import java.util.List;
* <code>verbose</code>: whether the build is verbose.
*
*/
-public class ComputeDependencyTask extends GetLibraryListTask {
+public class ComputeDependencyTask extends GetLibraryPathTask {
private String mLibraryManifestFilePathOut;
private String mLibraryResFolderPathOut;
@@ -90,14 +90,6 @@ public class ComputeDependencyTask extends GetLibraryListTask {
mTargetApi = targetApi;
}
- /**
- * 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 (mLibraryManifestFilePathOut == null) {
@@ -134,11 +126,12 @@ public class ComputeDependencyTask extends GetLibraryListTask {
final Path binAidlFolderPath = new Path(antProject);
final StringBuilder packageStrBuilder = new StringBuilder();
- LibraryProcessorFor3rdPartyJars processor = new LibraryProcessorFor3rdPartyJars() {
+ // custom jar processor doing a bit more than just collecting the jar files
+ JarProcessor processor = new JarProcessor() {
@Override
- public void processLibrary(String libRootPath) {
+ public void processLibrary(String libRootPath, IPropertySource properties) {
// let the super class handle the jar files
- super.processLibrary(libRootPath);
+ super.processLibrary(libRootPath, properties);
// get the AndroidManifest.xml path.
// FIXME: support renamed location.
diff --git a/anttasks/src/com/android/ant/ComputeProjectClasspathTask.java b/anttasks/src/com/android/ant/ComputeProjectClasspathTask.java
index 4a89ec2..d4a0380 100644
--- a/anttasks/src/com/android/ant/ComputeProjectClasspathTask.java
+++ b/anttasks/src/com/android/ant/ComputeProjectClasspathTask.java
@@ -16,7 +16,7 @@
package com.android.ant;
-import com.android.ant.DependencyHelper.LibraryProcessorFor3rdPartyJars;
+import com.android.ant.DependencyHelper.JarProcessor;
import com.android.sdklib.SdkConstants;
import org.apache.tools.ant.BuildException;
@@ -53,7 +53,7 @@ public class ComputeProjectClasspathTask extends Task {
DependencyHelper helper = new DependencyHelper(new File(mProjectLocation),
false /*verbose*/);
- LibraryProcessorFor3rdPartyJars processor = new LibraryProcessorFor3rdPartyJars();
+ JarProcessor processor = new JarProcessor();
helper.processLibraries(processor);
List<File> jars = processor.getJars();
diff --git a/anttasks/src/com/android/ant/DependencyHelper.java b/anttasks/src/com/android/ant/DependencyHelper.java
index 0019b8b..aab7614 100644
--- a/anttasks/src/com/android/ant/DependencyHelper.java
+++ b/anttasks/src/com/android/ant/DependencyHelper.java
@@ -16,6 +16,7 @@
package com.android.ant;
+import com.android.annotations.Nullable;
import com.android.io.FolderWrapper;
import com.android.sdklib.SdkConstants;
import com.android.sdklib.build.JarListSanitizer;
@@ -54,10 +55,26 @@ public class DependencyHelper {
}
/**
- * Basic implementation of {@link LibraryProcessor} that builds a list of sanitized list
+ * Advanced version of the {@link LibraryProcessor} that provides the library properties
+ * to the processor.
+ */
+ public static abstract class AdvancedLibraryProcessor implements LibraryProcessor {
+
+ public abstract void processLibrary(String libRootPath, IPropertySource properties);
+
+ @Override
+ public final void processLibrary(String libRootPath) {
+ ProjectProperties properties = TaskHelper.getProperties(libRootPath);
+
+ processLibrary(libRootPath, properties);
+ }
+ }
+
+ /**
+ * Implementation of {@link AdvancedLibraryProcessor} that builds a list of sanitized list
* of 3rd party jar files from all the Library Projects.
*/
- public static class LibraryProcessorFor3rdPartyJars implements LibraryProcessor {
+ public static class JarProcessor extends AdvancedLibraryProcessor {
private final List<File> mJars = new ArrayList<File>();
@@ -77,7 +94,7 @@ public class DependencyHelper {
}
@Override
- public void processLibrary(String libRootPath) {
+ public void processLibrary(String libRootPath, IPropertySource properties) {
// get the library output
// FIXME: support renamed folder.
mJars.add(new File(libRootPath + "/" + SdkConstants.FD_OUTPUT +
@@ -95,6 +112,7 @@ public class DependencyHelper {
}
}
+
public static List<File> sanitizePaths(File projectFolder, IPropertySource properties,
List<File> paths) {
// first get the non-files.
@@ -178,7 +196,7 @@ public class DependencyHelper {
return mProperties.getProperty(name);
}
- public void processLibraries(LibraryProcessor processor) {
+ public void processLibraries(@Nullable LibraryProcessor processor) {
// use that same order to process the libraries.
for (File library : mLibraries) {
// get the root path.
diff --git a/anttasks/src/com/android/ant/GetLibraryListTask.java b/anttasks/src/com/android/ant/GetLibraryListTask.java
deleted file mode 100644
index 97d1773..0000000
--- a/anttasks/src/com/android/ant/GetLibraryListTask.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.ant;
-
-import com.android.ant.DependencyHelper.LibraryProcessor;
-import com.android.sdklib.internal.project.IPropertySource;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.types.Path;
-import org.apache.tools.ant.types.Path.PathElement;
-
-import java.io.File;
-import java.util.List;
-
-/**
- * Task to get the list of Library Project for the current project.
- *
- */
-public class GetLibraryListTask extends Task {
-
- private String mLibraryFolderPathOut;
-
-
- public void setLibraryFolderPathOut(String libraryFolderPathOut) {
- mLibraryFolderPathOut = libraryFolderPathOut;
- }
-
- @Override
- public void execute() throws BuildException {
- execute(null);
- }
-
- public void execute(LibraryProcessor processor) throws BuildException {
-
- if (mLibraryFolderPathOut == null) {
- throw new BuildException("Missing attribute libraryFolderPathOut");
- }
-
- final Project antProject = getProject();
-
- DependencyHelper helper = new DependencyHelper(antProject.getBaseDir(),
- new IPropertySource() {
- @Override
- public String getProperty(String name) {
- return antProject.getProperty(name);
- }
-
- @Override
- public void debugPrint() {
- }
- },
- true /*verbose*/);
-
- System.out.println("Library dependencies:");
-
- if (helper.getLibraryCount() > 0) {
- System.out.println("\n------------------\nOrdered libraries:");
-
- helper.processLibraries(processor);
-
- // Create a Path object of all the libraries in reverse order.
- // This is important so that compilation of libraries happens
- // in the reverse order.
- Path rootPath = new Path(antProject);
-
- List<File> libraries = helper.getLibraries();
-
- for (int i = libraries.size() - 1 ; i >= 0; i--) {
- File library = libraries.get(i);
- PathElement element = rootPath.createPathElement();
- element.setPath(library.getAbsolutePath());
- }
-
- antProject.addReference(mLibraryFolderPathOut, rootPath);
- } else {
- System.out.println("No Libraries");
- }
- }
-
- protected String getLibraryFolderPathOut() {
- return mLibraryFolderPathOut;
- }
-}
diff --git a/anttasks/src/com/android/ant/GetLibraryPathTask.java b/anttasks/src/com/android/ant/GetLibraryPathTask.java
new file mode 100644
index 0000000..a79f6e3
--- /dev/null
+++ b/anttasks/src/com/android/ant/GetLibraryPathTask.java
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ant;
+
+import com.android.annotations.NonNull;
+import com.android.annotations.Nullable;
+import com.android.ant.DependencyHelper.AdvancedLibraryProcessor;
+import com.android.ant.DependencyHelper.LibraryProcessor;
+import com.android.sdklib.internal.project.IPropertySource;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Path.PathElement;
+
+import java.io.File;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Task to get the list of Library Project paths for either the current project or any given
+ * project.
+ *
+ */
+public class GetLibraryPathTask extends Task {
+
+ private String mProjectPath;
+ private String mLibraryFolderPathOut;
+ private String mLeaf;
+ private boolean mVerbose = false;
+
+ private static class LeafProcessor extends AdvancedLibraryProcessor {
+ private final static Pattern PH = Pattern.compile("^\\@\\{(.*)\\}$");
+
+ private Path mPath;
+ private final String[] mLeafSegments;
+
+ LeafProcessor(Project antProject, String leaf) {
+ mPath = new Path(antProject);
+ mLeafSegments = leaf.split("/");
+ }
+
+ @Override
+ public void processLibrary(String libRootPath, IPropertySource properties) {
+ StringBuilder sb = new StringBuilder(libRootPath);
+ for (String segment : mLeafSegments) {
+ sb.append('/');
+
+ Matcher m = PH.matcher(segment);
+ if (m.matches()) {
+ String value = properties.getProperty(m.group(1));
+ if (value == null) {
+ value = TaskHelper.getDefault(m.group(1));
+ }
+ if (value == null) {
+ throw new BuildException(
+ "Failed to resolve '" + m.group(1) + "' for project "
+ + libRootPath);
+ }
+ sb.append(value);
+ } else {
+ sb.append(segment);
+ }
+ }
+
+ PathElement element = mPath.createPathElement();
+ element.setPath(sb.toString());
+ }
+
+ public Path getPath() {
+ return mPath;
+ }
+ }
+
+ public void setProjectPath(String projectPath) {
+ mProjectPath = projectPath;
+ }
+
+ public void setLibraryFolderPathOut(String libraryFolderPathOut) {
+ mLibraryFolderPathOut = libraryFolderPathOut;
+ }
+
+ protected String getLibraryFolderPathOut() {
+ return mLibraryFolderPathOut;
+ }
+
+ public void setLeaf(String leaf) {
+ mLeaf = leaf;
+ }
+
+ /**
+ * Sets the value of the "verbose" attribute.
+ * @param verbose the value.
+ */
+ public void setVerbose(boolean verbose) {
+ mVerbose = verbose;
+ }
+
+ protected boolean getVerbose() {
+ return mVerbose;
+ }
+
+ @Override
+ public void execute() throws BuildException {
+ if (mLibraryFolderPathOut == null) {
+ throw new BuildException("Missing attribute libraryFolderPathOut");
+ }
+
+ LibraryProcessor processor = null;
+
+ if (mLeaf != null) {
+ // we need a custom processor
+ processor = new LeafProcessor(getProject(), mLeaf);
+ }
+
+ if (mProjectPath == null) {
+ execute(processor);
+ } else {
+ DependencyHelper helper = new DependencyHelper(new File(mProjectPath), mVerbose);
+
+ execute(helper, processor);
+ }
+ }
+
+ /**
+ * Executes the processor on the current project.
+ * @param processor
+ * @throws BuildException
+ */
+ protected void execute(@Nullable LibraryProcessor processor) throws BuildException {
+ final Project antProject = getProject();
+
+ DependencyHelper helper = new DependencyHelper(antProject.getBaseDir(),
+ new IPropertySource() {
+ @Override
+ public String getProperty(String name) {
+ return antProject.getProperty(name);
+ }
+
+ @Override
+ public void debugPrint() {
+ }
+ },
+ mVerbose);
+
+ execute(helper, processor);
+ }
+
+ /**
+ * Executes the processor using a given DependencyHelper.
+ * @param helper
+ * @param processor
+ * @throws BuildException
+ */
+ private void execute(@NonNull DependencyHelper helper, @Nullable LibraryProcessor processor)
+ throws BuildException {
+
+ final Project antProject = getProject();
+
+ System.out.println("Library dependencies:");
+
+ if (helper.getLibraryCount() > 0) {
+ System.out.println("\n------------------\nOrdered libraries:");
+
+ helper.processLibraries(processor);
+
+ if (mLibraryFolderPathOut != null) {
+ if (mLeaf == null) {
+ // Create a Path object of all the libraries in reverse order.
+ // This is important so that compilation of libraries happens
+ // in the reverse order.
+ Path rootPath = new Path(antProject);
+
+ List<File> libraries = helper.getLibraries();
+
+ for (int i = libraries.size() - 1 ; i >= 0; i--) {
+ File library = libraries.get(i);
+ PathElement element = rootPath.createPathElement();
+ element.setPath(library.getAbsolutePath());
+ }
+
+ antProject.addReference(mLibraryFolderPathOut, rootPath);
+ } else {
+ antProject.addReference(mLibraryFolderPathOut,
+ ((LeafProcessor) processor).getPath());
+ }
+ }
+ } else {
+ System.out.println("No Libraries");
+ }
+ }
+}
diff --git a/anttasks/src/com/android/ant/GetProjectPropertyTask.java b/anttasks/src/com/android/ant/GetProjectPathsTask.java
index 1713cb7..42494ab 100644
--- a/anttasks/src/com/android/ant/GetProjectPropertyTask.java
+++ b/anttasks/src/com/android/ant/GetProjectPathsTask.java
@@ -16,7 +16,6 @@
package com.android.ant;
-import com.android.sdklib.SdkConstants;
import com.android.sdklib.internal.project.ProjectProperties;
import org.apache.tools.ant.BuildException;
@@ -24,7 +23,7 @@ import org.apache.tools.ant.Task;
import java.io.File;
-public class GetProjectPropertyTask extends Task {
+public class GetProjectPathsTask extends Task {
private String mProjectPath;
private String mBinName;
@@ -34,11 +33,11 @@ public class GetProjectPropertyTask extends Task {
mProjectPath = projectPath;
}
- public void setBin(String binName) {
+ public void setBinOut(String binName) {
mBinName = binName;
}
- public void setSrc(String srcName) {
+ public void setSrcOut(String srcName) {
mSrcName = srcName;
}
@@ -51,20 +50,19 @@ public class GetProjectPropertyTask extends Task {
ProjectProperties props = TaskHelper.getProperties(mProjectPath);
if (mBinName != null) {
- handleProp(props, "out.dir", mBinName, SdkConstants.FD_OUTPUT);
+ handleProp(props, "out.dir", mBinName);
}
if (mSrcName != null) {
- handleProp(props, "source.dir", mSrcName, SdkConstants.FD_SOURCES);
+ handleProp(props, "source.dir", mSrcName);
}
}
- private void handleProp(ProjectProperties props, String inName, String outName,
- String defaultValue) {
+ private void handleProp(ProjectProperties props, String inName, String outName) {
String value = props.getProperty(inName);
if (value == null) {
- value = defaultValue;
+ value = TaskHelper.getDefault(inName);
}
getProject().setProperty(outName, new File(mProjectPath, value).getAbsolutePath());
diff --git a/anttasks/src/com/android/ant/TaskHelper.java b/anttasks/src/com/android/ant/TaskHelper.java
index 8a9128c..7afa920 100644
--- a/anttasks/src/com/android/ant/TaskHelper.java
+++ b/anttasks/src/com/android/ant/TaskHelper.java
@@ -30,10 +30,22 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
final class TaskHelper {
+ private static Map<String, String> DEFAULT_ATTR_VALUES = new HashMap<String, String>();
+ static {
+ DEFAULT_ATTR_VALUES.put("source.dir", SdkConstants.FD_SOURCES);
+ DEFAULT_ATTR_VALUES.put("out.dir", SdkConstants.FD_OUTPUT);
+ }
+
+ static String getDefault(String name) {
+ return DEFAULT_ATTR_VALUES.get(name);
+ }
+
static File getSdkLocation(Project antProject) {
// get the SDK location
String sdkOsPath = antProject.getProperty(ProjectProperties.PROPERTY_SDK);
diff --git a/files/ant/build.xml b/files/ant/build.xml
index eb8b3d5..e842433 100644
--- a/files/ant/build.xml
+++ b/files/ant/build.xml
@@ -473,7 +473,7 @@
<if>
<condition><not><isset property="dont.do.deps" /></not></condition>
<then>
- <getlibs libraryFolderPathOut="project.library.folder.path" />
+ <getlibpath libraryFolderPathOut="project.library.folder.path" />
<if>
<condition>
<isreference refid="project.library.folder.path" />
@@ -570,6 +570,7 @@
antfile="build.xml">
<target name="nodeps" />
<target name="${project.libraries.target}" />
+ <property name="emma.coverage.absolute.file" location="${out.absolute.dir}/coverage.em" />
</subant>
</then>
</if>
@@ -706,13 +707,17 @@
libraryPackagesRefId="project.library.packages"
filterOut="emma.default.filter"/>
+ <!-- define where the .em file is going. This may have been
+ setup already if this is a library -->
+ <property name="emma.coverage.absolute.file" location="${out.absolute.dir}/coverage.em" />
+
<!-- It only instruments class files, not any external libs -->
<emma enabled="true">
<instr verbosity="${verbosity}"
mode="overwrite"
instrpath="${out.absolute.dir}/classes"
outdir="${out.absolute.dir}/classes"
- metadatafile="${out.absolute.dir}/coverage.em">
+ metadatafile="${emma.coverage.absolute.file}">
<filter excludes="${emma.default.filter}" />
<filter value="${emma.filter}" />
</instr>
@@ -1187,15 +1192,26 @@
<xpath input="${tested.project.absolute.dir}/AndroidManifest.xml"
expression="/manifest/@package" output="tested.project.app.package" />
- <getproperty projectPath="${tested.project.absolute.dir}"
- bin="tested.project.out.absolute.dir"
- src="tested.project.source.absolute.dir" />
+ <if condition="${emma.enabled}">
+ <then>
+ <getprojectpaths projectPath="${tested.project.absolute.dir}"
+ binOut="tested.project.out.absolute.dir"
+ srcOut="tested.project.source.absolute.dir" />
+ </then>
+ </if>
+
</then>
<else>
<!-- this is a test app, the tested package is the app's own package -->
<property name="tested.project.app.package" value="${project.app.package}" />
- <property name="tested.project.out.absolute.dir" value="${out.absolute.dir}" />
- <property name="tested.project.source.absolute.dir" value="${source.absolute.dir}" />
+
+ <if condition="${emma.enabled}">
+ <then>
+ <property name="tested.project.out.absolute.dir" value="${out.absolute.dir}" />
+ <property name="tested.project.source.absolute.dir" value="${source.absolute.dir}" />
+ </then>
+ </if>
+
</else>
</if>
@@ -1220,6 +1236,7 @@
<arg value="${out.absolute.dir}/coverage.ec" />
</exec>
<echo level="info">Extracting coverage report...</echo>
+
<emma>
<report sourcepath="${tested.project.source.absolute.dir}"
verbosity="${verbosity}">