diff options
author | Xavier Ducrohet <xav@android.com> | 2012-04-13 12:19:36 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2012-04-16 12:55:07 -0700 |
commit | 47f429464374712e770b8e9b703790faa75dff19 (patch) | |
tree | db4b3f5e929076c17e2f712337a59b79751dc995 /anttasks/src/com | |
parent | 1daa8f999d87443d14f698ca8ccc103e3309fa3e (diff) | |
download | sdk-47f429464374712e770b8e9b703790faa75dff19.zip sdk-47f429464374712e770b8e9b703790faa75dff19.tar.gz sdk-47f429464374712e770b8e9b703790faa75dff19.tar.bz2 |
Properly exclude some classes in code coverage.
Using a custom task to create the filter based on the
app packages for the main project and its library projects and
the list of class to exclude.
Change-Id: Id37862bf53656bd17991b5c307d772ed2019650b
Diffstat (limited to 'anttasks/src/com')
-rw-r--r-- | anttasks/src/com/android/ant/GetEmmaFilterTask.java | 95 |
1 files changed, 95 insertions, 0 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()); + } +} |