diff options
author | Xavier Ducrohet <xav@android.com> | 2012-06-15 16:15:06 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2012-06-15 16:26:31 -0700 |
commit | aaeb6a3d58ce5dccc91360bb429b5e37af650619 (patch) | |
tree | da6b77dd015773a6c9d4da12d3c07c93d15acc4d /anttasks/src | |
parent | fcb82e3185d657e3b5440295478cdc58afd168c3 (diff) | |
download | sdk-aaeb6a3d58ce5dccc91360bb429b5e37af650619.zip sdk-aaeb6a3d58ce5dccc91360bb429b5e37af650619.tar.gz sdk-aaeb6a3d58ce5dccc91360bb429b5e37af650619.tar.bz2 |
Fix issue where libraries were not getting instrumented.
They actually were instrumented but the emma output file was not
passed to the report task.
After trying to make each library generate its own .em file and
passing to the report task, I gave up due to FileSet (and the
report task) being stupid.
So the main fix is having the libraries contribute to the main coverage.em
file (since it's build using the merge option) which location is passed
to the library project.
The changes to the custom task was to support querying the libraries for
a path with a given leaf (from the lib root folder) but this is not
used at the moment. The other tasks are slightly cleaned up due to
this though and are getting prepared to support customized folder
names in folder.
Change-Id: Ife59a2971ce6f2acf01b923abe90dea8adee462a
Diffstat (limited to 'anttasks/src')
-rw-r--r-- | anttasks/src/anttasks.properties | 40 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/ComputeDependencyTask.java | 19 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/ComputeProjectClasspathTask.java | 4 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/DependencyHelper.java | 26 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/GetLibraryListTask.java | 99 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/GetLibraryPathTask.java | 208 | ||||
-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.java | 12 |
8 files changed, 277 insertions, 147 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); |