Refactoring to prepare for building libraries.
Xavier Ducrohet [Tue, 28 Aug 2012 22:07:56 +0000 (15:07 -0700)]
Change-Id: Ic8f0055a5433871da26859abfda85908b09b182f

gradle/src/main/groovy/com/android/build/gradle/AndroidBasePlugin.groovy
gradle/src/main/groovy/com/android/build/gradle/AndroidExtension.groovy
gradle/src/main/groovy/com/android/build/gradle/AndroidLibraryExtension.groovy
gradle/src/main/groovy/com/android/build/gradle/AndroidLibraryPlugin.groovy
gradle/src/main/groovy/com/android/build/gradle/AndroidPlugin.groovy
gradle/src/main/groovy/com/android/build/gradle/BaseAndroidExtension.groovy
gradle/src/main/groovy/com/android/build/gradle/internal/ApplicationVariant.groovy
gradle/src/main/groovy/com/android/build/gradle/internal/ProductionAppVariant.groovy
gradle/src/main/groovy/com/android/build/gradle/internal/TestAppVariant.groovy

index 87edf73..d0f49ed 100644 (file)
  */
 package com.android.build.gradle
 
+import com.android.build.gradle.internal.AndroidSourceSet
 import com.android.build.gradle.internal.ApplicationVariant
 import com.android.build.gradle.internal.ProductFlavorData
 import com.android.builder.AndroidBuilder
 import com.android.builder.DefaultSdkParser
 import com.android.builder.ProductFlavor
 import com.android.builder.SdkParser
+import com.android.builder.VariantConfiguration
 import com.android.utils.ILogger
 import org.gradle.api.Project
 import org.gradle.api.logging.LogLevel
 import org.gradle.api.plugins.JavaBasePlugin
 import org.gradle.api.tasks.SourceSet
+import org.gradle.api.tasks.compile.Compile
 
 /**
  * Base class for all Android plugins
@@ -52,7 +55,8 @@ abstract class AndroidBasePlugin {
         mainSourceSet = project.sourceSets.add("main")
         testSourceSet = project.sourceSets.add("test")
 
-        project.tasks.assemble.description = "Assembles all variants of all applications and secondary packages."
+        project.tasks.assemble.description =
+            "Assembles all variants of all applications and secondary packages."
     }
 
     protected setDefaultConfig(ProductFlavor defaultConfig) {
@@ -112,11 +116,13 @@ abstract class AndroidBasePlugin {
         }
 
         if (sdkDir == null) {
-            throw new RuntimeException("SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.")
+            throw new RuntimeException(
+                    "SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.")
         }
 
         if (!sdkDir.directory) {
-            throw new RuntimeException("The SDK directory '$sdkDir' specified in local.properties does not exist.")
+            throw new RuntimeException(
+                    "The SDK directory '$sdkDir' specified in local.properties does not exist.")
         }
     }
 
@@ -125,4 +131,113 @@ abstract class AndroidBasePlugin {
 
         return androidBuilder.runtimeClasspath.join(":")
     }
+
+    protected ProcessManifest createProcessManifestTask(ApplicationVariant variant) {
+        def processManifestTask = project.tasks.add("process${variant.name}Manifest",
+                ProcessManifest)
+        processManifestTask.plugin = this
+        processManifestTask.variant = variant
+        processManifestTask.conventionMapping.mergedManifest = {
+            project.file("$project.buildDir/manifests/$variant.dirName/AndroidManifest.xml")
+        }
+        return processManifestTask
+    }
+
+    protected CrunchResources createCrunchResTask(ApplicationVariant variant) {
+        def crunchTask = project.tasks.add("crunch${variant.name}Res", CrunchResources)
+        crunchTask.plugin = this
+        crunchTask.variant = variant
+        crunchTask.conventionMapping.outputDir = {
+            project.file("$project.buildDir/res/$variant.dirName")
+        }
+        return crunchTask
+    }
+
+    protected GenerateBuildConfigTask createBuildConfigTask(ApplicationVariant variant,
+                                                            ProcessManifest processManifestTask) {
+        def generateBuildConfigTask = project.tasks.add(
+                "generate${variant.name}BuildConfig", GenerateBuildConfigTask)
+        if (processManifestTask != null) {
+            // This is in case the manifest is generated
+            generateBuildConfigTask.dependsOn processManifestTask
+        }
+        generateBuildConfigTask.plugin = this
+        generateBuildConfigTask.variant = variant
+        generateBuildConfigTask.conventionMapping.sourceOutputDir = {
+            project.file("$project.buildDir/source/${variant.dirName}")
+        }
+        return generateBuildConfigTask
+    }
+
+    protected ProcessResources createProcessResTask(ApplicationVariant variant,
+                                                    ProcessManifest processManifestTask,
+                                                    CrunchResources crunchTask) {
+        def processResources = project.tasks.add("process${variant.name}Res", ProcessResources)
+        processResources.dependsOn processManifestTask, crunchTask
+        processResources.plugin = this
+        processResources.variant = variant
+        processResources.conventionMapping.manifestFile = { processManifestTask.mergedManifest }
+        processResources.conventionMapping.crunchDir = { crunchTask.outputDir }
+        // TODO: unify with generateBuilderConfig somehow?
+        processResources.conventionMapping.sourceOutputDir = {
+            project.file("$project.buildDir/source/$variant.dirName")
+        }
+        processResources.conventionMapping.packageFile = {
+            project.file(
+                    "$project.buildDir/libs/${project.archivesBaseName}-${variant.baseName}.ap_")
+        }
+        if (variant.runProguard) {
+            processResources.conventionMapping.proguardFile = {
+                project.file("$project.buildDir/proguard/${variant.dirName}/rules.txt")
+            }
+        }
+        processResources.aaptOptions = extension.aaptOptions
+        return processResources
+    }
+
+    protected void createCompileTask(ApplicationVariant variant,
+                                     ApplicationVariant testedVariant,
+                                     ProcessResources processResources,
+                                     GenerateBuildConfigTask generateBuildConfigTask) {
+        def compileTask = project.tasks.add("compile${variant.name}", Compile)
+        compileTask.dependsOn processResources, generateBuildConfigTask
+
+        VariantConfiguration config = variant.config
+
+        List<Object> sourceList = new ArrayList<Object>();
+        sourceList.add(((AndroidSourceSet) config.defaultSourceSet).sourceSet.java)
+        sourceList.add({ processResources.sourceOutputDir })
+        if (config.getType() != VariantConfiguration.Type.TEST) {
+            sourceList.add(((AndroidSourceSet) config.buildTypeSourceSet).sourceSet.java)
+        }
+        if (config.hasFlavors()) {
+            for (com.android.builder.SourceSet flavorSourceSet : config.flavorSourceSets) {
+                sourceList.add(((AndroidSourceSet) flavorSourceSet).sourceSet.java)
+            }
+        }
+        compileTask.source = sourceList.toArray()
+        // TODO: support classpath per flavor
+        if (testedVariant != null) {
+            compileTask.classpath =
+                ((AndroidSourceSet) config.defaultSourceSet).sourceSet.compileClasspath +
+                        testedVariant.runtimeClasspath
+        } else {
+            compileTask.classpath =
+                ((AndroidSourceSet) config.defaultSourceSet).sourceSet.compileClasspath
+        }
+        compileTask.conventionMapping.destinationDir = {
+            project.file("$project.buildDir/classes/$variant.dirName")
+        }
+        compileTask.doFirst {
+            compileTask.options.bootClasspath = getRuntimeJars(variant)
+        }
+
+        // Wire up the outputs
+        // TODO: remove the classpath once the jar deps are set in the Variantconfig, so that we can pre-dex
+        variant.runtimeClasspath = compileTask.outputs.files + compileTask.classpath
+        variant.resourcePackage = project.files({processResources.packageFile}) {
+            builtBy processResources
+        }
+        variant.compileTask = compileTask
+    }
 }
index 4ba6a48..3b7ccc7 100644 (file)
@@ -24,6 +24,8 @@ import org.gradle.api.NamedDomainObjectContainer
 
 class AndroidExtension extends BaseAndroidExtension {
     final NamedDomainObjectContainer<ProductFlavor> productFlavors
+    final NamedDomainObjectContainer<BuildType> buildTypes
+
 
     String testBuildType = "debug"
 
@@ -32,10 +34,15 @@ class AndroidExtension extends BaseAndroidExtension {
 
     AndroidExtension(NamedDomainObjectContainer<BuildType> buildTypes,
                      NamedDomainObjectContainer<ProductFlavor> productFlavors) {
-        super(buildTypes)
+        super()
+        this.buildTypes = buildTypes
         this.productFlavors = productFlavors
     }
 
+    void buildTypes(Action<? super NamedDomainObjectContainer<BuildType>> action) {
+        action.execute(buildTypes)
+    }
+
     void productFlavors(Action<? super NamedDomainObjectContainer<ProductFlavor>> action) {
         action.execute(productFlavors)
     }
index 58682eb..5ac9ea1 100644 (file)
 package com.android.build.gradle
 
 import com.android.builder.BuildType
-import org.gradle.api.NamedDomainObjectContainer
+import org.gradle.api.Action
 
 class AndroidLibraryExtension extends BaseAndroidExtension {
 
-    AndroidLibraryExtension(NamedDomainObjectContainer<BuildType> buildTypes) {
-        super(buildTypes)
+    final BuildType debug = new BuildType(BuildType.DEBUG)
+    final BuildType release = new BuildType(BuildType.RELEASE)
+
+    AndroidLibraryExtension() {
+        super()
+    }
+
+    void debug(Action<BuildType> action) {
+        action.execute(debug);
+    }
+
+    void release(Action<BuildType> action) {
+        action.execute(release);
     }
 }
index f7aff52..fb65ecc 100644 (file)
@@ -18,35 +18,65 @@ package com.android.build.gradle
 import com.android.builder.BuildType
 import org.gradle.api.Plugin
 import org.gradle.api.Project
+import com.android.build.gradle.internal.BuildTypeData
+import com.android.builder.VariantConfiguration
+import com.android.build.gradle.internal.ProductionAppVariant
+import com.android.build.gradle.internal.ProductFlavorData
 
 class AndroidLibraryPlugin extends AndroidBasePlugin implements Plugin<Project> {
 
     AndroidLibraryExtension extension
+    BuildTypeData debugBuildTypeData
+    BuildTypeData releaseBuildTypeData
 
     @Override
     void apply(Project project) {
         super.apply(project)
 
-        def buildTypes = project.container(BuildType)
-
-        extension = project.extensions.create('android', AndroidLibraryExtension, buildTypes)
+        extension = project.extensions.create('android', AndroidLibraryExtension)
         setDefaultConfig(extension.defaultConfig)
 
-        buildTypes.whenObjectAdded { BuildType buildType ->
-            addBuildType(buildType)
-        }
-        buildTypes.whenObjectRemoved {
-            throw new UnsupportedOperationException("Removing build types is not implemented yet.")
+        // create the source sets for the build type.
+        // the ones for the main product flavors are handled by the base plugin.
+        def debugSourceSet = project.sourceSets.add(BuildType.DEBUG)
+        def releaseSourceSet = project.sourceSets.add(BuildType.RELEASE)
+
+        debugBuildTypeData = new BuildTypeData(extension.debug, debugSourceSet, project)
+        releaseBuildTypeData = new BuildTypeData(extension.release, releaseSourceSet, project)
+
+        project.afterEvaluate {
+            createAndroidTasks()
         }
+    }
 
-        buildTypes.create(BuildType.DEBUG)
-        buildTypes.create(BuildType.RELEASE)
+    void createAndroidTasks() {
+        createLibraryTasks()
     }
 
-    void addBuildType(BuildType buildType) {
-        def assemble = project.tasks.add("assemble${buildType.name.capitalize()}")
+    void createLibraryTasks() {
+        ProductFlavorData defaultConfigData = getDefaultConfigData();
+
+        def variantConfig = new VariantConfiguration(
+                defaultConfigData.productFlavor, defaultConfigData.androidSourceSet,
+                debugBuildTypeData.buildType, debugBuildTypeData.androidSourceSet,
+                VariantConfiguration.Type.LIBRARY)
+
+        ProductionAppVariant variant = new ProductionAppVariant(variantConfig)
+
+        // Add a task to process the manifest(s)
+        ProcessManifest processManifestTask = createProcessManifestTask(variant)
+
+        // Add a task to crunch resource files
+        def crunchTask = createCrunchResTask(variant)
+
+        // Add a task to create the BuildConfig class
+        def generateBuildConfigTask = createBuildConfigTask(variant, null)
+
+        // Add a task to generate resource source files
+        def processResources = createProcessResTask(variant, processManifestTask, crunchTask)
 
-        project.tasks.assemble.dependsOn assemble
+        // Add a compile task
+        createCompileTask(variant, null/*testedVariant*/, processResources, generateBuildConfigTask)
     }
 
     @Override
index 99782b8..78830cb 100644 (file)
@@ -15,7 +15,6 @@
  */
 package com.android.build.gradle
 
-import com.android.build.gradle.internal.AndroidSourceSet
 import com.android.build.gradle.internal.ApplicationVariant
 import com.android.build.gradle.internal.BuildTypeData
 import com.android.build.gradle.internal.ProductFlavorData
@@ -27,7 +26,6 @@ import com.android.builder.VariantConfiguration
 import org.gradle.api.Plugin
 import org.gradle.api.Project
 import org.gradle.api.Task
-import org.gradle.api.tasks.compile.Compile
 import org.gradle.internal.reflect.Instantiator
 
 class AndroidPlugin extends AndroidBasePlugin implements Plugin<Project> {
@@ -254,66 +252,19 @@ class AndroidPlugin extends AndroidBasePlugin implements Plugin<Project> {
         def variant = new ProductionAppVariant(variantConfig)
 
         // Add a task to process the manifest(s)
-        def processManifestTask = project.tasks.add("process${variant.name}Manifest", ProcessManifest)
-        processManifestTask.plugin = this
-        processManifestTask.variant = variant
-        processManifestTask.conventionMapping.mergedManifest = { project.file("$project.buildDir/manifests/$variant.dirName/AndroidManifest.xml") }
+        ProcessManifest processManifestTask = createProcessManifestTask(variant)
 
         // Add a task to crunch resource files
-        def crunchTask = project.tasks.add("crunchAndroid${variant.name}Res", CrunchResources)
-        crunchTask.plugin = this
-        crunchTask.variant = variant
-        crunchTask.conventionMapping.outputDir = { project.file("$project.buildDir/resources/$variant.dirName/res") }
+        def crunchTask = createCrunchResTask(variant)
 
         // Add a task to create the BuildConfig class
-        def generateBuildConfigTask = project.tasks.add("generate${variant.name}BuildConfig", GenerateBuildConfigTask)
-        generateBuildConfigTask.plugin = this
-        generateBuildConfigTask.variant = variant
-        generateBuildConfigTask.conventionMapping.sourceOutputDir = { project.file("$project.buildDir/source/${variant.dirName}") }
+        def generateBuildConfigTask = createBuildConfigTask(variant, null)
 
         // Add a task to generate resource source files
-        def processResources = project.tasks.add("processAndroid${variant.name}Res", ProcessResources)
-        processResources.dependsOn processManifestTask, crunchTask
-        processResources.plugin = this
-        processResources.variant = variant
-        processResources.conventionMapping.manifestFile = { processManifestTask.mergedManifest }
-        processResources.conventionMapping.crunchDir = { crunchTask.outputDir }
-        // TODO: unify with generateBuilderConfig somehow?
-        processResources.conventionMapping.sourceOutputDir = { project.file("$project.buildDir/source/$variant.dirName") }
-        processResources.conventionMapping.packageFile = { project.file("$project.buildDir/libs/${project.archivesBaseName}-${variant.baseName}.ap_") }
-        if (variantConfig.buildType.runProguard) {
-            processResources.conventionMapping.proguardFile = { project.file("$project.buildDir/proguard/${variant.dirName}/rules.txt") }
-        }
-        processResources.aaptOptions = extension.aaptOptions
+        def processResources = createProcessResTask(variant, processManifestTask, crunchTask)
 
         // Add a compile task
-        def compileTaskName = "compile${variant.name}"
-        def compileTask = project.tasks.add(compileTaskName, Compile)
-        compileTask.dependsOn processResources, generateBuildConfigTask
-        if (variantConfig.hasFlavors()) {
-            compileTask.source(
-                    ((AndroidSourceSet)variantConfig.defaultSourceSet).sourceSet.java,
-                    ((AndroidSourceSet)variantConfig.buildTypeSourceSet).sourceSet.java,
-                    ((AndroidSourceSet)variantConfig.firstFlavorSourceSet).sourceSet.java,
-                    { processResources.sourceOutputDir })
-        } else {
-            compileTask.source(
-                    ((AndroidSourceSet)variantConfig.defaultSourceSet).sourceSet.java,
-                    ((AndroidSourceSet)variantConfig.buildTypeSourceSet).sourceSet.java,
-                    { processResources.sourceOutputDir })
-        }
-        // TODO: support classpath per flavor
-        compileTask.classpath = ((AndroidSourceSet)variantConfig.defaultSourceSet).sourceSet.compileClasspath
-        compileTask.conventionMapping.destinationDir = { project.file("$project.buildDir/classes/$variant.dirName") }
-        compileTask.doFirst {
-            compileTask.options.bootClasspath = getRuntimeJars(variant)
-        }
-
-        // Wire up the outputs
-        // TODO: remove the classpath once the jar deps are set in the Variantconfig, so that we can pre-dex
-        variant.runtimeClasspath = compileTask.outputs.files + compileTask.classpath
-        variant.resourcePackage = project.files({processResources.packageFile}) { builtBy processResources }
-        variant.compileTask = compileTask
+        createCompileTask(variant, null/*testedVariant*/, processResources, generateBuildConfigTask)
 
         Task returnTask = addPackageTasks(variant, assembleTask, isTestApk)
         if (returnTask != null) {
@@ -330,60 +281,19 @@ class AndroidPlugin extends AndroidBasePlugin implements Plugin<Project> {
         def variant = new TestAppVariant(variantConfig, testedVariantConfig)
 
         // Add a task to process the manifest
-        def processManifestTask = project.tasks.add("process${variant.name}Manifest", ProcessManifest)
-        processManifestTask.plugin = this
-        processManifestTask.variant = variant
-        processManifestTask.conventionMapping.mergedManifest = { project.file("$project.buildDir/manifests/$variant.dirName/AndroidManifest.xml") }
+        def processManifestTask = createProcessManifestTask(variant)
 
         // Add a task to crunch resource files
-        def crunchTask = project.tasks.add("crunchAndroid${variant.name}Res", CrunchResources)
-        crunchTask.plugin = this
-        crunchTask.variant = variant
-        crunchTask.conventionMapping.outputDir = { project.file("$project.buildDir/resources/$variant.dirName/res") }
+        def crunchTask = createCrunchResTask(variant)
 
         // Add a task to create the BuildConfig class
-        def generateBuildConfigTask = project.tasks.add("generate${variant.name}BuildConfig", GenerateBuildConfigTask)
-        generateBuildConfigTask.dependsOn processManifestTask // this is because the manifest can be generated.
-        generateBuildConfigTask.plugin = this
-        generateBuildConfigTask.variant = variant
-        generateBuildConfigTask.conventionMapping.sourceOutputDir = { project.file("$project.buildDir/source/${variant.dirName}") }
+        def generateBuildConfigTask = createBuildConfigTask(variant, processManifestTask)
 
         // Add a task to generate resource source files
-        def processResources = project.tasks.add("processAndroid${variant.name}Res", ProcessResources)
-        processResources.dependsOn processManifestTask, crunchTask
-        processResources.plugin = this
-        processResources.variant = variant
-        processResources.conventionMapping.manifestFile = { processManifestTask.mergedManifest }
-        processResources.conventionMapping.crunchDir = { crunchTask.outputDir }
-        // TODO: unify with generateBuilderConfig somehow?
-        processResources.conventionMapping.sourceOutputDir = { project.file("$project.buildDir/source/$variant.dirName") }
-        processResources.conventionMapping.packageFile = { project.file("$project.buildDir/libs/${project.archivesBaseName}-${variant.baseName}.ap_") }
-        processResources.aaptOptions = extension.aaptOptions
+        def processResources = createProcessResTask(variant, processManifestTask, crunchTask)
 
         // Add a task to compile the test application
-        def testCompile = project.tasks.add("compile${variant.name}", Compile)
-        testCompile.dependsOn processResources, generateBuildConfigTask
-        if (variantConfig.hasFlavors()) {
-            testCompile.source(
-                    ((AndroidSourceSet)variantConfig.defaultSourceSet).sourceSet.java,
-                    ((AndroidSourceSet)variantConfig.firstFlavorSourceSet).sourceSet.java,
-                    { processResources.sourceOutputDir })
-        } else {
-            testCompile.source(
-                    ((AndroidSourceSet)variantConfig.defaultSourceSet).sourceSet.java,
-                    { processResources.sourceOutputDir })
-        }
-
-        testCompile.classpath = ((AndroidSourceSet)variantConfig.defaultSourceSet).sourceSet.compileClasspath + testedVariant.runtimeClasspath
-
-        testCompile.conventionMapping.destinationDir = { project.file("$project.buildDir/classes/$variant.dirName") }
-        testCompile.doFirst {
-            testCompile.options.bootClasspath = getRuntimeJars(variant)
-        }
-
-        variant.runtimeClasspath = testCompile.outputs.files
-        variant.resourcePackage = project.files({processResources.packageFile}) { builtBy processResources }
-        variant.compileTask = testCompile
+        createCompileTask(variant, testedVariant, processResources, generateBuildConfigTask)
 
         Task assembleTask = addPackageTasks(variant, null, true /*isTestApk*/)
 
index c3a5587..d314ab6 100644 (file)
  */
 package com.android.build.gradle
 
-import com.android.builder.BuildType
-import org.gradle.api.Action
-import org.gradle.api.NamedDomainObjectContainer
 import com.android.builder.ProductFlavor
+import org.gradle.api.Action
 
 /**
  * Base android extension for all android plugins.
@@ -28,14 +26,7 @@ class BaseAndroidExtension {
     String target
     final ProductFlavor defaultConfig = new ProductFlavor("main");
 
-    final NamedDomainObjectContainer<BuildType> buildTypes
-
-    BaseAndroidExtension(NamedDomainObjectContainer<BuildType> buildTypes) {
-        this.buildTypes = buildTypes
-    }
-
-    void buildTypes(Action<? super NamedDomainObjectContainer<BuildType>> action) {
-        action.execute(buildTypes)
+    BaseAndroidExtension() {
     }
 
     void defaultConfig(Action<ProductFlavor> action) {
index 3b03549..99d37df 100644 (file)
@@ -19,6 +19,7 @@ import com.android.build.gradle.AndroidBasePlugin
 import com.android.builder.AndroidBuilder
 import org.gradle.api.file.FileCollection
 import org.gradle.api.tasks.compile.Compile
+import com.android.builder.VariantConfiguration
 
 /**
  * Represents something that can be packaged into an APK and installed.
@@ -32,10 +33,14 @@ public interface ApplicationVariant {
 
     String getBaseName()
 
+    VariantConfiguration getConfig()
+
     boolean getZipAlign()
 
     boolean isSigned()
 
+    boolean getRunProguard()
+
     FileCollection getRuntimeClasspath()
 
     FileCollection getResourcePackage()
index 9c29b5f..0471452 100644 (file)
@@ -24,54 +24,59 @@ import org.gradle.api.tasks.compile.Compile
 
 class ProductionAppVariant implements ApplicationVariant {
     final String name
-    final VariantConfiguration variant
+    final VariantConfiguration config
     FileCollection runtimeClasspath
     FileCollection resourcePackage
     Compile compileTask
     Task assembleTask
 
-    ProductionAppVariant(VariantConfiguration variant) {
-        this.variant = variant
-        if (variant.hasFlavors()) {
-            this.name = "${variant.firstFlavor.name.capitalize()}${variant.buildType.name.capitalize()}"
+    ProductionAppVariant(VariantConfiguration config) {
+        this.config = config
+        if (config.hasFlavors()) {
+            this.name = "${config.firstFlavor.name.capitalize()}${config.buildType.name.capitalize()}"
         } else {
-            this.name = "${variant.buildType.name.capitalize()}"
+            this.name = "${config.buildType.name.capitalize()}"
         }
     }
 
     String getDescription() {
-        if (variant.hasFlavors()) {
-            return "${variant.buildType.name.capitalize()} build for flavor ${variant.firstFlavor.name.capitalize()}"
+        if (config.hasFlavors()) {
+            return "${config.buildType.name.capitalize()} build for flavor ${config.firstFlavor.name.capitalize()}"
         } else {
-            return "${variant.buildType.name.capitalize()} build"
+            return "${config.buildType.name.capitalize()} build"
         }
     }
 
     String getDirName() {
-        if (variant.hasFlavors()) {
-            return "$variant.firstFlavor.name/$variant.buildType.name"
+        if (config.hasFlavors()) {
+            return "$config.firstFlavor.name/$config.buildType.name"
         } else {
-            return "$variant.buildType.name"
+            return "$config.buildType.name"
         }
     }
 
     String getBaseName() {
-        if (variant.hasFlavors()) {
-            return "$variant.firstFlavor.name-$variant.buildType.name"
+        if (config.hasFlavors()) {
+            return "$config.firstFlavor.name-$config.buildType.name"
         } else {
-            return "$variant.buildType.name"
+            return "$config.buildType.name"
         }
     }
 
     @Override
     boolean getZipAlign() {
-        return variant.buildType.zipAlign
+        return config.buildType.zipAlign
     }
 
     @Override
     boolean isSigned() {
-        return variant.buildType.debugSigned ||
-                variant.mergedFlavor.isSigningReady()
+        return config.buildType.debugSigned ||
+                config.mergedFlavor.isSigningReady()
+    }
+
+    @Override
+    boolean getRunProguard() {
+        return config.buildType.runProguard
     }
 
     @Override
@@ -80,7 +85,7 @@ class ProductionAppVariant implements ApplicationVariant {
     }
 
     String getPackage() {
-        return variant.getPackageName(null)
+        return config.getPackageName(null)
     }
 
     @Override
@@ -91,7 +96,7 @@ class ProductionAppVariant implements ApplicationVariant {
                 androidBasePlugin.verbose)
 
         androidBuilder.setTarget(androidBasePlugin.target)
-        androidBuilder.setBuildVariant(variant, null /*testedVariant*/)
+        androidBuilder.setBuildVariant(config, null /*testedConfig*/)
 
         return androidBuilder
     }
index eabf665..774c8ac 100644 (file)
@@ -23,17 +23,17 @@ import com.android.builder.VariantConfiguration
 
 class TestAppVariant implements ApplicationVariant {
     final String name
-    final VariantConfiguration variant
-    final VariantConfiguration testedVariant
+    final VariantConfiguration config
+    final VariantConfiguration testedConfig
     FileCollection runtimeClasspath
     FileCollection resourcePackage
     Compile compileTask
 
-    TestAppVariant(VariantConfiguration variant, VariantConfiguration testedVariant) {
-        this.variant = variant
-        this.testedVariant = testedVariant
-        if (variant.hasFlavors()) {
-            this.name = "${variant.firstFlavor.name.capitalize()}Test"
+    TestAppVariant(VariantConfiguration config, VariantConfiguration testedConfig) {
+        this.config = config
+        this.testedConfig = testedConfig
+        if (config.hasFlavors()) {
+            this.name = "${config.firstFlavor.name.capitalize()}Test"
         } else {
             this.name = "Test"
         }
@@ -41,24 +41,24 @@ class TestAppVariant implements ApplicationVariant {
 
     @Override
     String getDescription() {
-        if (variant.hasFlavors()) {
-            return "Test build for the ${variant.firstFlavor.name.capitalize()}${variant.buildType.name.capitalize()} build"
+        if (config.hasFlavors()) {
+            return "Test build for the ${config.firstFlavor.name.capitalize()}${config.buildType.name.capitalize()} build"
         } else {
-            return "Test for the ${variant.buildType.name.capitalize()} build"
+            return "Test for the ${config.buildType.name.capitalize()} build"
         }
     }
 
     String getDirName() {
-        if (variant.hasFlavors()) {
-            return "$variant.firstFlavor.name/test"
+        if (config.hasFlavors()) {
+            return "$config.firstFlavor.name/test"
         } else {
             return "test"
         }
     }
 
     String getBaseName() {
-        if (variant.hasFlavors()) {
-            return "$variant.firstFlavor.name-test"
+        if (config.hasFlavors()) {
+            return "$config.firstFlavor.name-test"
         } else {
             return "test"
         }
@@ -75,16 +75,21 @@ class TestAppVariant implements ApplicationVariant {
     }
 
     @Override
+    boolean getRunProguard() {
+        return false
+    }
+
+    @Override
     List<String> getRunCommand() {
         String[] args = [ "shell", "am", "instrument", "-w",
-                variant.getPackageName(testedVariant) + "/" + testedVariant.instrumentationRunner]
+                config.getPackageName(testedConfig) + "/" + testedConfig.instrumentationRunner]
 
         return Arrays.asList(args)
     }
 
     @Override
     String getPackage() {
-        return variant.getPackageName(testedVariant)
+        return config.getPackageName(testedConfig)
     }
 
     @Override
@@ -95,9 +100,8 @@ class TestAppVariant implements ApplicationVariant {
                 androidBasePlugin.verbose)
 
         androidBuilder.setTarget(androidBasePlugin.target)
-        androidBuilder.setBuildVariant(variant, testedVariant)
+        androidBuilder.setBuildVariant(config, testedConfig)
 
         return androidBuilder
     }
-
 }