Change tests to be instrumentationTests everywhere.
Xavier Ducrohet [Tue, 19 Feb 2013 00:55:29 +0000 (16:55 -0800)]
This is to not collide with jUnit 'tests'. The idea is
to allow regular jUnit tests in the same project, alongside
instrumentation (and ui automator) tests.

Change-Id: I8db8527f82f16860a83c1d2def996e8074282c5d

builder/src/main/java/com/android/builder/AndroidBuilder.java
builder/src/main/java/com/android/builder/BuilderConstants.java
builder/src/main/java/com/android/builder/DefaultSdkParser.java
changelog.txt
gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy
gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy
gradle/src/main/groovy/com/android/build/gradle/ReportingPlugin.groovy
tests/multiproject/build.gradle

index f4ff2d2..52cc42a 100644 (file)
@@ -479,8 +479,6 @@ public class AndroidBuilder {
     /**
      * Process the resources and generate R.java and/or the packaged resources.
      *
-     * TODO support 2+ assets folders.
-     *
      * @param manifestFile the location of the manifest file
      * @param resFolder the merged res folder
      * @param assetsDir the merged asset folder
index 9e90aed..5daca96 100644 (file)
@@ -34,6 +34,18 @@ public class BuilderConstants {
     public final static String DEBUG = "debug";
     public final static String RELEASE = "release";
 
-    public final static String TEST = "test";
     public final static String LINT = "lint";
+
+    public final static String REPORTS = "reports";
+
+    public final static String INSTRUMENTATION_TEST = "instrumentTest";
+    public final static String INSTRUMENTATION_TESTS = "instrumentTests";
+    public final static String INSTRUMENTATION_RESULTS = INSTRUMENTATION_TEST + "-results";
+
+    public final static String UI_TEST = "uiTest";
+    public final static String UI_TESTS = "uiTests";
+    public final static String UI_RESULTS = UI_TEST + "-results";
+
+    public final static String FLAVORS = "flavors";
+    public final static String FLAVORS_ALL = "all";
 }
index 14ede6d..0345d51 100644 (file)
@@ -9,18 +9,20 @@
       * PNG crunch is now done incrementally and in parallel.
    - Support for multi asset folders.
    - Support for asset folders in Library Projects.
-   - API to manipulate Build Variants.
    - Support for versionName suffix provided by the BuildType.
    - Testing
-      * Instrumentation tests now started from "deviceCheck" instead of "check"
-      * Instrumentation tests now run on all connected devices in parallel.
-      * Instrumentation tests now break the build if any test fails.
-      * Instrumentation tests now generate an HTML report for each flavor/project, but also aggregated.
+      * Default sourceset for tests now src/instrumentTest (instrumentTest<Name> for flavors)
+      * Instrumentation tests now:
+          - started from "deviceCheck" instead of "check"
+          - run on all connected devices in parallel.
+          - break the build if any test fails.
+          - generate an HTML report for each flavor/project, but also aggregated.
       * New plugin 'android-reporting' to aggregate android test results across projects. See 'flavorlib' sample.
    - Improved DSL:
       * replaced android.target with android.compileSdkVersion to make it less confusing with targetSdkVersion
       * signing information now a SigningConfig object reusable across BuildType and ProductFlavor
       * ability to relocate a full sourceSet. See 'migrated' sample.
+      * API to manipulate Build Variants.
 * Fixes:
    - Default Java compile target set to 1.6.
    - Fix generation of R classes in case libraries share same package name as the app project.
index b8eb23d..6c133e9 100644 (file)
@@ -15,7 +15,6 @@
  */
 
 package com.android.build.gradle
-
 import com.android.build.gradle.internal.BuildTypeData
 import com.android.build.gradle.internal.DefaultBuildVariant
 import com.android.build.gradle.internal.ProductFlavorData
@@ -34,7 +33,6 @@ import com.android.build.gradle.internal.test.PluginHolder
 import com.android.build.gradle.internal.test.report.ReportType
 import com.android.builder.AndroidDependency
 import com.android.builder.BuildType
-import com.android.builder.BuilderConstants
 import com.android.builder.JarDependency
 import com.android.builder.VariantConfiguration
 import com.android.builder.signing.SigningConfig
@@ -49,6 +47,16 @@ import org.gradle.internal.reflect.Instantiator
 
 import javax.inject.Inject
 
+import static com.android.builder.BuilderConstants.DEBUG
+import static com.android.builder.BuilderConstants.FLAVORS_ALL
+import static com.android.builder.BuilderConstants.LINT
+import static com.android.builder.BuilderConstants.RELEASE
+import static com.android.builder.BuilderConstants.REPORTS
+import static com.android.builder.BuilderConstants.INSTRUMENTATION_RESULTS
+import static com.android.builder.BuilderConstants.INSTRUMENTATION_TEST
+import static com.android.builder.BuilderConstants.INSTRUMENTATION_TESTS
+import static com.android.builder.BuilderConstants.UI_TEST
+
 /**
  * Gradle plugin class for 'application' projects.
  */
@@ -94,7 +102,7 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
         }
 
         buildTypeContainer.whenObjectAdded { BuildType buildType ->
-            ((BuildTypeDsl)buildType).init(signingConfigContainer.getByName(BuilderConstants.DEBUG))
+            ((BuildTypeDsl)buildType).init(signingConfigContainer.getByName(DEBUG))
             addBuildType(buildType)
         }
 
@@ -103,9 +111,9 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
         }
 
         // create default Objects, signingConfig first as its used by the BuildTypes.
-        signingConfigContainer.create(BuilderConstants.DEBUG)
-        buildTypeContainer.create(BuilderConstants.DEBUG)
-        buildTypeContainer.create(BuilderConstants.RELEASE)
+        signingConfigContainer.create(DEBUG)
+        buildTypeContainer.create(DEBUG)
+        buildTypeContainer.create(RELEASE)
 
         // map whenObjectRemoved on the containers to throw an exception.
         signingConfigContainer.whenObjectRemoved {
@@ -155,7 +163,7 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
         }
 
         def mainSourceSet = extension.sourceSetsContainer.create(productFlavor.name)
-        String testName = "${BuilderConstants.TEST}${productFlavor.name.capitalize()}"
+        String testName = "${INSTRUMENTATION_TEST}${productFlavor.name.capitalize()}"
         def testSourceSet = extension.sourceSetsContainer.create(testName)
 
         ProductFlavorData<GroupableProductFlavor> productFlavorData =
@@ -166,13 +174,18 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
     }
 
     private static void checkName(String name, String displayName) {
-        if (name.startsWith(BuilderConstants.TEST)) {
+        if (name.startsWith(INSTRUMENTATION_TEST)) {
+            throw new RuntimeException(
+                    "${displayName} names cannot start with '${INSTRUMENTATION_TEST}'")
+        }
+
+        if (name.startsWith(UI_TEST)) {
             throw new RuntimeException(
-                    "${displayName} names cannot start with '${BuilderConstants.TEST}'")
+                    "${displayName} names cannot start with '${UI_TEST}'")
         }
 
-        if (BuilderConstants.LINT.equals(name)) {
-            throw new RuntimeException("${displayName} names cannot be ${BuilderConstants.LINT}")
+        if (LINT.equals(name)) {
+            throw new RuntimeException("${displayName} names cannot be ${LINT}")
         }
     }
 
@@ -205,15 +218,16 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
 
             testTask.conventionMapping.resultsDir = {
                 String rootLocation = extension.testOptions.resultsDir != null ?
-                    extension.testOptions.resultsDir : "$project.buildDir/test-results"
+                    extension.testOptions.resultsDir : "$project.buildDir/$INSTRUMENTATION_RESULTS"
 
-                project.file("$rootLocation/all")
+                project.file("$rootLocation/$FLAVORS_ALL")
             }
             testTask.conventionMapping.reportsDir = {
                 String rootLocation = extension.testOptions.reportDir != null ?
-                    extension.testOptions.reportDir : "$project.buildDir/reports/tests"
+                    extension.testOptions.reportDir :
+                    "$project.buildDir/$REPORTS/$INSTRUMENTATION_TESTS"
 
-                project.file("$rootLocation/all")
+                project.file("$rootLocation/$FLAVORS_ALL")
             }
 
             // check whether we have multi flavor builds
index e489559..888eea0 100644 (file)
@@ -49,7 +49,6 @@ import com.android.build.gradle.tasks.RenderscriptCompile
 import com.android.build.gradle.tasks.ZipAlign
 import com.android.builder.AndroidBuilder
 import com.android.builder.AndroidDependency
-import com.android.builder.BuilderConstants
 import com.android.builder.DefaultSdkParser
 import com.android.builder.JarDependency
 import com.android.builder.ManifestDependency
@@ -82,6 +81,13 @@ import org.gradle.api.tasks.compile.JavaCompile
 import org.gradle.internal.reflect.Instantiator
 import org.gradle.tooling.BuildException
 import org.gradle.util.GUtil
+
+import static com.android.builder.BuilderConstants.EXT_LIB_ARCHIVE
+import static com.android.builder.BuilderConstants.FLAVORS
+import static com.android.builder.BuilderConstants.REPORTS
+import static com.android.builder.BuilderConstants.INSTRUMENTATION_RESULTS
+import static com.android.builder.BuilderConstants.INSTRUMENTATION_TEST
+import static com.android.builder.BuilderConstants.INSTRUMENTATION_TESTS
 /**
  * Base class for all Android plugins
  */
@@ -180,7 +186,7 @@ public abstract class BasePlugin {
     protected setDefaultConfig(ProductFlavor defaultConfig,
                                NamedDomainObjectContainer<AndroidSourceSet> sourceSets) {
         mainSourceSet = sourceSets.create(defaultConfig.name)
-        testSourceSet = sourceSets.create(BuilderConstants.TEST)
+        testSourceSet = sourceSets.create(INSTRUMENTATION_TEST)
 
         defaultConfigData = new ProductFlavorData<ProductFlavor>(defaultConfig, mainSourceSet,
                 testSourceSet, project, ConfigurationDependencies.ConfigType.DEFAULT)
@@ -702,15 +708,25 @@ public abstract class BasePlugin {
 
         testFlavorTask.conventionMapping.resultsDir = {
             String rootLocation = extension.testOptions.resultsDir != null ?
-                extension.testOptions.resultsDir : "$project.buildDir/test-results"
+                extension.testOptions.resultsDir : "$project.buildDir/$INSTRUMENTATION_RESULTS"
+
+            String flavorFolder = variant.flavorDirName
+            if (!flavorFolder.isEmpty()) {
+                flavorFolder = "$FLAVORS/" + flavorFolder
+            }
 
-            project.file("$rootLocation/flavors/$variant.flavorDirName")
+            project.file("$rootLocation/$flavorFolder")
         }
         testFlavorTask.conventionMapping.reportsDir = {
             String rootLocation = extension.testOptions.reportDir != null ?
-                extension.testOptions.reportDir : "$project.buildDir/reports/tests"
+                extension.testOptions.reportDir : "$project.buildDir/$REPORTS/$INSTRUMENTATION_TESTS"
+
+            String flavorFolder = variant.flavorDirName
+            if (!flavorFolder.isEmpty()) {
+                flavorFolder = "$FLAVORS/" + flavorFolder
+            }
 
-            project.file("$rootLocation/flavors/$variant.flavorDirName")
+            project.file("$rootLocation/$flavorFolder")
         }
         variant.testFlavorTask = testFlavorTask
 
@@ -1019,7 +1035,7 @@ public abstract class BasePlugin {
 
             def moduleArtifacts = artifacts[id]
             moduleArtifacts?.each { artifact ->
-                if (artifact.type == BuilderConstants.EXT_LIB_ARCHIVE) {
+                if (artifact.type == EXT_LIB_ARCHIVE) {
                     def explodedDir = project.file(
                             "$project.buildDir/exploded-bundles/$artifact.file.name")
                     AndroidDependencyImpl adep = new AndroidDependencyImpl(
index 22ca9be..30964bb 100644 (file)
@@ -22,6 +22,10 @@ import com.android.build.gradle.internal.test.report.ReportType
 import org.gradle.api.Project
 import org.gradle.api.plugins.JavaBasePlugin
 import org.gradle.api.tasks.TaskCollection
+
+import static com.android.builder.BuilderConstants.REPORTS
+import static com.android.builder.BuilderConstants.INSTRUMENTATION_RESULTS
+import static com.android.builder.BuilderConstants.INSTRUMENTATION_TESTS
 /**
  * Gradle plugin class for 'reporting' projects.
  *
@@ -48,13 +52,13 @@ class ReportingPlugin implements org.gradle.api.Plugin<Project> {
 
         mergeReportsTask.conventionMapping.resultsDir = {
             String location = extension.resultsDir != null ?
-                extension.resultsDir : "$project.buildDir/test-results"
+                extension.resultsDir : "$project.buildDir/$INSTRUMENTATION_RESULTS"
 
             project.file(location)
         }
         mergeReportsTask.conventionMapping.reportsDir = {
             String location = extension.reportDir != null ?
-                extension.reportDir : "$project.buildDir/reports/tests"
+                extension.reportDir : "$project.buildDir/$REPORTS/$INSTRUMENTATION_TESTS"
 
             project.file(location)
         }
index 157183f..e224b4f 100644 (file)
@@ -14,3 +14,5 @@ allprojects {
         mavenCentral()
     }
 }
+
+apply plugin: 'android-reporting'
\ No newline at end of file