Merge "Added more instrumentation option"
diff --git a/builder-model/src/main/java/com/android/builder/model/ProductFlavor.java b/builder-model/src/main/java/com/android/builder/model/ProductFlavor.java
index f1a6d16..f1a5c73 100644
--- a/builder-model/src/main/java/com/android/builder/model/ProductFlavor.java
+++ b/builder-model/src/main/java/com/android/builder/model/ProductFlavor.java
@@ -107,4 +107,20 @@
*/
@Nullable
String getTestInstrumentationRunner();
+
+ /**
+ * Returns the handlingProfile value. This is only the value set on this product flavor.
+ *
+ * @return the handlingProfile value.
+ */
+ @Nullable
+ Boolean getTestHandleProfiling();
+
+ /**
+ * Returns the functionalTest value. This is only the value set on this product flavor.
+ *
+ * @return the functionalTest value.
+ */
+ @Nullable
+ Boolean getTestFunctionalTest();
}
diff --git a/builder/src/main/java/com/android/builder/AndroidBuilder.java b/builder/src/main/java/com/android/builder/AndroidBuilder.java
index 34c0dd4..e6b78a3 100644
--- a/builder/src/main/java/com/android/builder/AndroidBuilder.java
+++ b/builder/src/main/java/com/android/builder/AndroidBuilder.java
@@ -80,7 +80,7 @@
* then build steps can be done with
* {@link #generateBuildConfig(String, boolean, java.util.List, String)}
* {@link #processManifest(java.io.File, java.util.List, java.util.List, String, int, String, int, int, String)}
- * {@link #processTestManifest(String, int, int, String, String, java.util.List, String)}
+ * {@link #processTestManifest(String, int, int, String, String, Boolean, Boolean, java.util.List, String)}
* {@link #processResources(java.io.File, java.io.File, java.io.File, java.util.List, String, String, String, String, String, com.android.builder.VariantConfiguration.Type, boolean, com.android.builder.model.AaptOptions)}
* {@link #compileAllAidlFiles(java.util.List, java.io.File, java.util.List, com.android.builder.compiling.DependencyFileProcessor)}
* {@link #convertByteCode(Iterable, Iterable, File, String, DexOptions, boolean)}
@@ -316,6 +316,8 @@
* @param targetSdkVersion the targetSdkVersion of the test application
* @param testedPackageName the package name of the tested application
* @param instrumentationRunner the name of the instrumentation runner
+ * @param handleProfiling whether or not the Instrumentation object will turn profiling on and off
+ * @param functionalTest whether or not the Instrumentation class should run as a functional test
* @param libraries the library dependency graph
* @param outManifestLocation the output location for the merged manifest
*
@@ -324,6 +326,8 @@
* @see com.android.builder.VariantConfiguration#getMinSdkVersion()
* @see com.android.builder.VariantConfiguration#getTestedPackageName()
* @see com.android.builder.VariantConfiguration#getInstrumentationRunner()
+ * @see com.android.builder.VariantConfiguration#getHandleProfiling()
+ * @see com.android.builder.VariantConfiguration#getFunctionalTest()
* @see com.android.builder.VariantConfiguration#getDirectLibraries()
*/
public void processTestManifest(
@@ -332,11 +336,15 @@
int targetSdkVersion,
@NonNull String testedPackageName,
@NonNull String instrumentationRunner,
+ @NonNull Boolean handleProfiling,
+ @NonNull Boolean functionalTest,
@NonNull List<? extends ManifestDependency> libraries,
@NonNull String outManifestLocation) {
checkNotNull(testPackageName, "testPackageName cannot be null.");
checkNotNull(testedPackageName, "testedPackageName cannot be null.");
checkNotNull(instrumentationRunner, "instrumentationRunner cannot be null.");
+ checkNotNull(handleProfiling, "handleProfiling cannot be null.");
+ checkNotNull(functionalTest, "functionalTest cannot be null.");
checkNotNull(libraries, "libraries cannot be null.");
checkNotNull(outManifestLocation, "outManifestLocation cannot be null.");
@@ -351,6 +359,8 @@
targetSdkVersion,
testedPackageName,
instrumentationRunner,
+ handleProfiling,
+ functionalTest,
generatedTestManifest.getAbsolutePath());
mergeLibraryManifests(
@@ -368,6 +378,8 @@
targetSdkVersion,
testedPackageName,
instrumentationRunner,
+ handleProfiling,
+ functionalTest,
outManifestLocation);
}
}
@@ -378,6 +390,8 @@
int targetSdkVersion,
String testedPackageName,
String instrumentationRunner,
+ Boolean handleProfiling,
+ Boolean functionalTest,
String outManifestLocation) {
TestManifestGenerator generator = new TestManifestGenerator(
outManifestLocation,
@@ -385,7 +399,9 @@
minSdkVersion,
targetSdkVersion,
testedPackageName,
- instrumentationRunner);
+ instrumentationRunner,
+ handleProfiling,
+ functionalTest);
try {
generator.generate();
} catch (IOException e) {
diff --git a/builder/src/main/java/com/android/builder/DefaultProductFlavor.java b/builder/src/main/java/com/android/builder/DefaultProductFlavor.java
index 6541dde..844485f 100644
--- a/builder/src/main/java/com/android/builder/DefaultProductFlavor.java
+++ b/builder/src/main/java/com/android/builder/DefaultProductFlavor.java
@@ -41,6 +41,8 @@
private String mPackageName = null;
private String mTestPackageName = null;
private String mTestInstrumentationRunner = null;
+ private Boolean mTestHandleProfiling = null;
+ private Boolean mTestFunctionalTest = null;
private SigningConfig mSigningConfig = null;
/**
@@ -169,6 +171,30 @@
return mTestInstrumentationRunner;
}
+ @Override
+ @Nullable
+ public Boolean getTestHandleProfiling() {
+ return mTestHandleProfiling;
+ }
+
+ @NonNull
+ public ProductFlavor setTestHandleProfiling(boolean handleProfiling) {
+ mTestHandleProfiling = handleProfiling;
+ return this;
+ }
+
+ @Override
+ @Nullable
+ public Boolean getTestFunctionalTest() {
+ return mTestFunctionalTest;
+ }
+
+ @NonNull
+ public ProductFlavor setTestFunctionalTest(boolean functionalTest) {
+ mTestFunctionalTest = functionalTest;
+ return this;
+ }
+
@Nullable
public SigningConfig getSigningConfig() {
return mSigningConfig;
@@ -203,6 +229,12 @@
flavor.mTestInstrumentationRunner = chooseString(mTestInstrumentationRunner,
base.mTestInstrumentationRunner);
+ flavor.mTestHandleProfiling = chooseBoolean(mTestHandleProfiling,
+ base.mTestHandleProfiling);
+
+ flavor.mTestFunctionalTest = chooseBoolean(mTestFunctionalTest,
+ base.mTestFunctionalTest);
+
flavor.mSigningConfig =
mSigningConfig != null ? mSigningConfig : base.mSigningConfig;
@@ -218,6 +250,10 @@
return overlay != null ? overlay : base;
}
+ private Boolean chooseBoolean(Boolean overlay, Boolean base) {
+ return overlay != null ? overlay : base;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -239,6 +275,14 @@
!mTestInstrumentationRunner.equals(that.mTestInstrumentationRunner) :
that.mTestInstrumentationRunner != null)
return false;
+ if (mTestHandleProfiling != null ?
+ !mTestHandleProfiling.equals(that.mTestHandleProfiling) :
+ that.mTestHandleProfiling != null)
+ return false;
+ if (mTestFunctionalTest != null ?
+ !mTestFunctionalTest.equals(that.mTestFunctionalTest) :
+ that.mTestFunctionalTest != null)
+ return false;
if (mTestPackageName != null ?
!mTestPackageName.equals(that.mTestPackageName) : that.mTestPackageName != null)
return false;
@@ -265,6 +309,10 @@
result = 31 * result + (mTestPackageName != null ? mTestPackageName.hashCode() : 0);
result = 31 * result + (mTestInstrumentationRunner != null ?
mTestInstrumentationRunner.hashCode() : 0);
+ result = 31 * result + (mTestHandleProfiling != null ?
+ mTestHandleProfiling.hashCode() : 0);
+ result = 31 * result + (mTestFunctionalTest != null ?
+ mTestFunctionalTest.hashCode() : 0);
result = 31 * result + (mSigningConfig != null ? mSigningConfig.hashCode() : 0);
return result;
}
@@ -282,6 +330,8 @@
.add("packageName", mPackageName)
.add("testPackageName", mTestPackageName)
.add("testInstrumentationRunner", mTestInstrumentationRunner)
+ .add("testHandleProfiling", mTestHandleProfiling)
+ .add("testFunctionalTest", mTestFunctionalTest)
.add("signingConfig", mSigningConfig)
.toString();
}
diff --git a/builder/src/main/java/com/android/builder/VariantConfiguration.java b/builder/src/main/java/com/android/builder/VariantConfiguration.java
index 5b1b5e5..10994db 100644
--- a/builder/src/main/java/com/android/builder/VariantConfiguration.java
+++ b/builder/src/main/java/com/android/builder/VariantConfiguration.java
@@ -457,6 +457,8 @@
}
private final static String DEFAULT_TEST_RUNNER = "android.test.InstrumentationTestRunner";
+ private final static Boolean DEFAULT_HANDLE_PROFILING = false;
+ private final static Boolean DEFAULT_FUNCTIONAL_TEST = false;
/**
* Returns the instrumentationRunner to use to test this variant, or if the
@@ -475,6 +477,38 @@
}
/**
+ * Returns handleProfiling value to use to test this variant, or if the
+ * variant is a test, the one to use to test the tested variant.
+ * @return the handleProfiling value
+ */
+ @Override
+ @NonNull
+ public Boolean getHandleProfiling() {
+ VariantConfiguration config = this;
+ if (mType == Type.TEST) {
+ config = getTestedConfig();
+ }
+ Boolean handleProfiling = config.mMergedFlavor.getTestHandleProfiling();
+ return handleProfiling != null ? handleProfiling : DEFAULT_HANDLE_PROFILING;
+ }
+
+ /**
+ * Returns functionalTest value to use to test this variant, or if the
+ * variant is a test, the one to use to test the tested variant.
+ * @return the functionalTest value
+ */
+ @Override
+ @NonNull
+ public Boolean getFunctionalTest() {
+ VariantConfiguration config = this;
+ if (mType == Type.TEST) {
+ config = getTestedConfig();
+ }
+ Boolean functionalTest = config.mMergedFlavor.getTestFunctionalTest();
+ return functionalTest != null ? functionalTest : DEFAULT_FUNCTIONAL_TEST;
+ }
+
+ /**
* Reads the package name from the manifest. This is unmodified by the build type.
*/
@Nullable
diff --git a/builder/src/main/java/com/android/builder/internal/TestManifestGenerator.java b/builder/src/main/java/com/android/builder/internal/TestManifestGenerator.java
index 69fa7b5..9e443a7 100644
--- a/builder/src/main/java/com/android/builder/internal/TestManifestGenerator.java
+++ b/builder/src/main/java/com/android/builder/internal/TestManifestGenerator.java
@@ -33,6 +33,8 @@
private final static String PH_TARGET_SDK_VERSION = "#TARGETSDKVERSION#";
private final static String PH_TESTED_PACKAGE = "#TESTEDPACKAGE#";
private final static String PH_TEST_RUNNER = "#TESTRUNNER#";
+ private final static String PH_HANDLE_PROFILING = "#HANDLEPROFILING#";
+ private final static String PH_FUNCTIONAL_TEST = "#FUNCTIONALTEST#";
private final String mOutputFile;
private final String mPackageName;
@@ -40,19 +42,25 @@
private final int mTargetSdkVersion;
private final String mTestedPackageName;
private final String mTestRunnerName;
+ private final boolean mHandleProfiling;
+ private final boolean mFunctionalTest;
public TestManifestGenerator(@NonNull String outputFile,
@NonNull String packageName,
int minSdkVersion,
int targetSdkVersion,
@NonNull String testedPackageName,
- @NonNull String testRunnerName) {
+ @NonNull String testRunnerName,
+ @NonNull Boolean handleProfiling,
+ @NonNull Boolean functionalTest) {
mOutputFile = outputFile;
mPackageName = packageName;
mMinSdkVersion = minSdkVersion;
mTargetSdkVersion = targetSdkVersion != -1 ? targetSdkVersion : minSdkVersion;
mTestedPackageName = testedPackageName;
mTestRunnerName = testRunnerName;
+ mHandleProfiling = handleProfiling;
+ mFunctionalTest = functionalTest;
}
public void generate() throws IOException {
@@ -62,6 +70,8 @@
map.put(PH_TARGET_SDK_VERSION, Integer.toString(mTargetSdkVersion));
map.put(PH_TESTED_PACKAGE, mTestedPackageName);
map.put(PH_TEST_RUNNER, mTestRunnerName);
+ map.put(PH_HANDLE_PROFILING, Boolean.toString(mHandleProfiling));
+ map.put(PH_FUNCTIONAL_TEST, Boolean.toString(mFunctionalTest));
TemplateProcessor processor = new TemplateProcessor(
TestManifestGenerator.class.getResourceAsStream(TEMPLATE),
diff --git a/builder/src/main/java/com/android/builder/testing/TestData.java b/builder/src/main/java/com/android/builder/testing/TestData.java
index 2495659..0bc7b61 100644
--- a/builder/src/main/java/com/android/builder/testing/TestData.java
+++ b/builder/src/main/java/com/android/builder/testing/TestData.java
@@ -44,6 +44,12 @@
@NonNull
String getInstrumentationRunner();
+ @NonNull
+ Boolean getHandleProfiling();
+
+ @NonNull
+ Boolean getFunctionalTest();
+
int getMinSdkVersion();
@Nullable
diff --git a/builder/src/main/resources/com/android/builder/internal/AndroidManifest.template b/builder/src/main/resources/com/android/builder/internal/AndroidManifest.template
index 257e79d..ed50233 100644
--- a/builder/src/main/resources/com/android/builder/internal/AndroidManifest.template
+++ b/builder/src/main/resources/com/android/builder/internal/AndroidManifest.template
@@ -10,5 +10,7 @@
<instrumentation android:name="#TESTRUNNER#"
android:targetPackage="#TESTEDPACKAGE#"
+ android:handleProfiling="#HANDLEPROFILING#"
+ android:functionalTest="#FUNCTIONALTEST#"
android:label="Tests for #TESTEDPACKAGE#"/>
</manifest>
diff --git a/builder/src/test/java/com/android/builder/DefaultProductFlavorTest.java b/builder/src/test/java/com/android/builder/DefaultProductFlavorTest.java
index 1e09828..f618085 100644
--- a/builder/src/test/java/com/android/builder/DefaultProductFlavorTest.java
+++ b/builder/src/test/java/com/android/builder/DefaultProductFlavorTest.java
@@ -39,6 +39,8 @@
mCustom.setPackageName("com.forty.two");
mCustom.setTestPackageName("com.forty.two.test");
mCustom.setTestInstrumentationRunner("com.forty.two.test.Runner");
+ mCustom.setTestHandleProfiling(true);
+ mCustom.setTestFunctionalTest(true);
}
public void testMergeOnDefault() {
@@ -52,6 +54,8 @@
assertEquals("com.forty.two", flavor.getPackageName());
assertEquals("com.forty.two.test", flavor.getTestPackageName());
assertEquals("com.forty.two.test.Runner", flavor.getTestInstrumentationRunner());
+ assertEquals(Boolean.TRUE, flavor.getTestHandleProfiling());
+ assertEquals(Boolean.TRUE, flavor.getTestFunctionalTest());
}
public void testMergeOnCustom() {
@@ -65,6 +69,8 @@
assertEquals("com.forty.two", flavor.getPackageName());
assertEquals("com.forty.two.test", flavor.getTestPackageName());
assertEquals("com.forty.two.test.Runner", flavor.getTestInstrumentationRunner());
+ assertEquals(Boolean.TRUE, flavor.getTestHandleProfiling());
+ assertEquals(Boolean.TRUE, flavor.getTestFunctionalTest());
}
public void testMergeDefaultOnDefault() {
@@ -78,5 +84,7 @@
assertNull(flavor.getPackageName());
assertNull(flavor.getTestPackageName());
assertNull(flavor.getTestInstrumentationRunner());
+ assertNull(flavor.getTestHandleProfiling());
+ assertNull(flavor.getTestFunctionalTest());
}
}
diff --git a/gradle-model/src/test/java/com/android/build/gradle/model/AndroidProjectTest.java b/gradle-model/src/test/java/com/android/build/gradle/model/AndroidProjectTest.java
index 375e6fd..a666eab 100644
--- a/gradle-model/src/test/java/com/android/build/gradle/model/AndroidProjectTest.java
+++ b/gradle-model/src/test/java/com/android/build/gradle/model/AndroidProjectTest.java
@@ -198,6 +198,9 @@
.setVersionName("2.0")
.setMinSdkVersion(16)
.setTargetSdkVersion(16)
+ .setTestInstrumentationRunner("android.test.InstrumentationTestRunner")
+ .setTestHandleProfiling(Boolean.FALSE)
+ .setTestFunctionalTest(null)
.test();
ArtifactInfo debugMainInfo = debugVariant.getMainArtifactInfo();
@@ -528,6 +531,8 @@
private int renderscriptTargetApi = -1;
private String testPackageName = null;
private String testInstrumentationRunner = null;
+ private Boolean testHandleProfiling = null;
+ private Boolean testFunctionalTest = null;
ProductFlavorTester(@NonNull ProductFlavor productFlavor, @NonNull String name) {
this.productFlavor = productFlavor;
@@ -544,36 +549,46 @@
return this;
}
- ProductFlavorTester setVersionName(String versionName) {
+ ProductFlavorTester setVersionName(String versionName) {
this.versionName = versionName;
return this;
}
- ProductFlavorTester setMinSdkVersion(int minSdkVersion) {
+ ProductFlavorTester setMinSdkVersion(int minSdkVersion) {
this.minSdkVersion = minSdkVersion;
return this;
}
- ProductFlavorTester setTargetSdkVersion(int targetSdkVersion) {
+ ProductFlavorTester setTargetSdkVersion(int targetSdkVersion) {
this.targetSdkVersion = targetSdkVersion;
return this;
}
- ProductFlavorTester setRenderscriptTargetApi(int renderscriptTargetApi) {
+ ProductFlavorTester setRenderscriptTargetApi(int renderscriptTargetApi) {
this.renderscriptTargetApi = renderscriptTargetApi;
return this;
}
- ProductFlavorTester setTestPackageName(String testPackageName) {
+ ProductFlavorTester setTestPackageName(String testPackageName) {
this.testPackageName = testPackageName;
return this;
}
- ProductFlavorTester setTestInstrumentationRunner(String testInstrumentationRunner) {
+ ProductFlavorTester setTestInstrumentationRunner(String testInstrumentationRunner) {
this.testInstrumentationRunner = testInstrumentationRunner;
return this;
}
+ ProductFlavorTester setTestHandleProfiling(Boolean testHandleProfiling) {
+ this.testHandleProfiling = testHandleProfiling;
+ return this;
+ }
+
+ ProductFlavorTester setTestFunctionalTest(Boolean testFunctionalTest) {
+ this.testFunctionalTest = testFunctionalTest;
+ return this;
+ }
+
void test() {
assertEquals(name + ":packageName", packageName, productFlavor.getPackageName());
assertEquals(name + ":VersionCode", versionCode, productFlavor.getVersionCode());
@@ -587,6 +602,10 @@
testPackageName, productFlavor.getTestPackageName());
assertEquals(name + ":testInstrumentationRunner",
testInstrumentationRunner, productFlavor.getTestInstrumentationRunner());
+ assertEquals(name + ":testHandleProfiling",
+ testHandleProfiling, productFlavor.getTestHandleProfiling());
+ assertEquals(name + ":testFunctionalTest",
+ testFunctionalTest, productFlavor.getTestFunctionalTest());
}
}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy b/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy
index 000b418..0df2a27 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy
@@ -410,6 +410,12 @@
processTestManifestTask.conventionMapping.instrumentationRunner = {
config.instrumentationRunner
}
+ processTestManifestTask.conventionMapping.handleProfiling = {
+ config.handleProfiling
+ }
+ processTestManifestTask.conventionMapping.functionalTest = {
+ config.functionalTest
+ }
processTestManifestTask.conventionMapping.libraries = {
getManifestDependencies(config.directLibraries)
}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/model/ProductFlavorImpl.java b/gradle/src/main/groovy/com/android/build/gradle/internal/model/ProductFlavorImpl.java
index 0e3be19..dbd30d6 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/internal/model/ProductFlavorImpl.java
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/model/ProductFlavorImpl.java
@@ -41,6 +41,8 @@
private String mPackageName = null;
private String mTestPackageName = null;
private String mTestInstrumentationRunner = null;
+ private Boolean mTestHandleProfiling = null;
+ private Boolean mTestFunctionalTest = null;
@NonNull
@@ -59,6 +61,8 @@
clonedFlavor.mTestPackageName = productFlavor.getTestPackageName();
clonedFlavor.mTestInstrumentationRunner = productFlavor.getTestInstrumentationRunner();
+ clonedFlavor.mTestHandleProfiling = productFlavor.getTestHandleProfiling();
+ clonedFlavor.mTestFunctionalTest = productFlavor.getTestFunctionalTest();
return clonedFlavor;
}
@@ -116,6 +120,18 @@
return mTestInstrumentationRunner;
}
+ @Nullable
+ @Override
+ public Boolean getTestHandleProfiling() {
+ return mTestHandleProfiling;
+ }
+
+ @Nullable
+ @Override
+ public Boolean getTestFunctionalTest() {
+ return mTestFunctionalTest;
+ }
+
@Override
public String toString() {
return "ProductFlavorImpl{" +
@@ -128,6 +144,8 @@
", mPackageName='" + mPackageName + '\'' +
", mTestPackageName='" + mTestPackageName + '\'' +
", mTestInstrumentationRunner='" + mTestInstrumentationRunner + '\'' +
+ ", mTestHandleProfiling='" + mTestHandleProfiling + '\'' +
+ ", mTestFunctionalTest='" + mTestFunctionalTest + '\'' +
'}';
}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/tasks/ProcessTestManifest.groovy b/gradle/src/main/groovy/com/android/build/gradle/tasks/ProcessTestManifest.groovy
index 10fc11f..6a24155 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/tasks/ProcessTestManifest.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/tasks/ProcessTestManifest.groovy
@@ -41,6 +41,12 @@
@Input
String instrumentationRunner
+ @Input
+ Boolean handleProfiling;
+
+ @Input
+ Boolean functionalTest;
+
@Nested
List<ManifestDependencyImpl> libraries
@@ -52,6 +58,8 @@
getTargetSdkVersion(),
getTestedPackageName(),
getInstrumentationRunner(),
+ getHandleProfiling(),
+ getFunctionalTest(),
getLibraries(),
getManifestOutputFile().absolutePath)
}
diff --git a/tests/basic/build.gradle b/tests/basic/build.gradle
index 6857ff1..0a0bfdd 100644
--- a/tests/basic/build.gradle
+++ b/tests/basic/build.gradle
@@ -40,6 +40,9 @@
minSdkVersion 16
targetSdkVersion 16
+ testInstrumentationRunner "android.test.InstrumentationTestRunner"
+ testHandleProfiling false
+
buildConfig "private final static boolean DEFAULT = true;", \
"private final static String FOO = \"foo\";"
}