aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--anttasks/src/com/android/ant/GetEmmaFilterTask.java95
-rw-r--r--files/ant/build.xml13
2 files changed, 107 insertions, 1 deletions
diff --git a/anttasks/src/com/android/ant/GetEmmaFilterTask.java b/anttasks/src/com/android/ant/GetEmmaFilterTask.java
new file mode 100644
index 0000000..f449f8d
--- /dev/null
+++ b/anttasks/src/com/android/ant/GetEmmaFilterTask.java
@@ -0,0 +1,95 @@
+/*
+ * 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 org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+/**
+ * Task building an emma filter to remove all build-only classes.
+ *
+ * Currently ignore:
+ * app.package.R
+ * app.package.R$*
+ * app.package.Manifest
+ * app.package.BuildConfig
+ *
+ */
+public class GetEmmaFilterTask extends Task {
+
+ private static final String[] FILTER_CLASSES = new String[] {
+ "R", "R$*", "Manifest", "BuildConfig"
+ };
+
+ private String mAppPackage;
+ private String mLibraryPackagesRefId;
+ private String mFilterOut;
+
+
+ public void setAppPackage(String appPackage) {
+ mAppPackage = appPackage;
+ }
+
+ public void setLibraryPackagesRefId(String libraryPackagesRefId) {
+ mLibraryPackagesRefId = libraryPackagesRefId;
+ }
+
+ public void setFilterOut(String filterOut) {
+ mFilterOut = filterOut;
+ }
+
+ @Override
+ public void execute() throws BuildException {
+ if (mAppPackage == null) {
+ throw new BuildException("Missing attribute appPackage");
+ }
+ if (mLibraryPackagesRefId == null) {
+ throw new BuildException("Missing attribute libraryPackagesRefId");
+ }
+ if (mFilterOut == null) {
+ throw new BuildException("Missing attribute filterOut");
+ }
+
+ StringBuilder sb = new StringBuilder();
+
+ String libraryPackagesValue = getProject().getProperty(mLibraryPackagesRefId);
+
+ if (libraryPackagesValue != null && libraryPackagesValue.length() > 0) {
+ // split the app packages.
+ String[] libPackages = libraryPackagesValue.split(";");
+
+ for (String libPackage : libPackages) {
+ if (libPackage.length() > 0) {
+ for (String filterClass : FILTER_CLASSES) {
+ sb.append(libPackage).append('.').append(filterClass).append(',');
+ }
+ }
+ }
+ }
+
+ // add the app package:
+ final int count = FILTER_CLASSES.length;
+ for (int i = 0 ; i < count ; i++) {
+ sb.append(mAppPackage).append('.').append(FILTER_CLASSES[i]);
+ if (i < count - 1) {
+ sb.append(',');
+ }
+ }
+
+ getProject().setProperty(mFilterOut, sb.toString());
+ }
+}
diff --git a/files/ant/build.xml b/files/ant/build.xml
index 856a501..db47263 100644
--- a/files/ant/build.xml
+++ b/files/ant/build.xml
@@ -96,6 +96,10 @@
classname="com.android.ant.ComputeProjectClasspathTask"
classpathref="android.antlibs" />
+ <taskdef name="getemmafilter"
+ classname="com.android.ant.GetEmmaFilterTask"
+ classpathref="android.antlibs" />
+
<taskdef name="aapt"
classname="com.android.ant.AaptExecTask"
classpathref="android.antlibs" />
@@ -730,13 +734,20 @@
<if condition="${build.is.instrumented}">
<then>
<echo level="info">Instrumenting classes from ${out.absolute.dir}/classes...</echo>
+
+ <!-- build the filter to remove R, Manifest, BuildConfig -->
+ <getemmafilter
+ appPackage="${project.app.package}"
+ libraryPackagesRefId="project.library.packages"
+ filterOut="emma.default.filter"/>
+
<!-- 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">
- <filter excludes="${project.app.package}.R,${project.app.package}.R$$*,${project.app.package}.BuildConfig" />
+ <filter excludes="${emma.default.filter}" />
<filter value="${emma.filter}" />
</instr>
</emma>