aboutsummaryrefslogtreecommitdiff
path: root/gradle/src
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-10-04 16:07:22 -0700
committerXavier Ducrohet <xav@android.com>2012-10-04 16:39:59 -0700
commitd14ea2c706561925d45feb30a1b57732bcefc383 (patch)
tree656bf1405b3abe7026c0b5abe07c48a14cda391e /gradle/src
parent8428cf7c046c051ff7c60cee614c31691d664463 (diff)
downloadbuild-d14ea2c706561925d45feb30a1b57732bcefc383.tar.gz
Use custom SourceSet instead of default Java ones.
Fixed a couple of path-related issue to make it work on Windows. Replaced "customized" test app with "migrated" that uses the folder structure of older projects and reconfigure it through the source sets. Change-Id: Ibb1e81ef7272c3ca8e766c17b5a105d69be98c51
Diffstat (limited to 'gradle/src')
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/AndroidSourceDirectory.java31
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/AndroidSourceFile.java33
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/AndroidSourceSet.groovy111
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/AppExtension.groovy7
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy44
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/BaseExtension.groovy55
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy93
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/InstallTask.groovy2
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/LibraryExtension.groovy5
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/LibraryPlugin.groovy55
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/PackageApplicationTask.groovy5
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/ProcessManifestTask.groovy2
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/RunTestsTask.groovy2
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/UninstallTask.groovy2
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/ZipAlignTask.groovy2
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/internal/AndroidSourceSet.groovy81
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/internal/AndroidSourceSetFactory.groovy37
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/internal/ApplicationVariant.groovy10
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/internal/BuildTypeData.groovy10
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceDirectory.java57
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceFile.java57
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceSet.java257
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/internal/ProductFlavorData.groovy20
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/internal/ProductionAppVariant.groovy2
-rw-r--r--gradle/src/main/groovy/com/android/build/gradle/internal/SourceVariant.groovy2
25 files changed, 786 insertions, 196 deletions
diff --git a/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceDirectory.java b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceDirectory.java
new file mode 100644
index 0000000..6d80f7b
--- /dev/null
+++ b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceDirectory.java
@@ -0,0 +1,31 @@
+/*
+ * 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.build.gradle;
+
+import org.gradle.tooling.model.SourceDirectory;
+
+/**
+ */
+public interface AndroidSourceDirectory extends SourceDirectory {
+
+ /**
+ * A concise name for the source directory (typically used to identify it in a collection).
+ */
+ String getName();
+
+ AndroidSourceDirectory srcDir(java.lang.Object o);
+}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceFile.java b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceFile.java
new file mode 100644
index 0000000..cc33c7f
--- /dev/null
+++ b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceFile.java
@@ -0,0 +1,33 @@
+/*
+ * 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.build.gradle;
+
+import java.io.File;
+
+/**
+ */
+public interface AndroidSourceFile {
+
+ /**
+ * A concise name for the source directory (typically used to identify it in a collection).
+ */
+ String getName();
+
+ File getFile();
+
+ AndroidSourceFile srcFile(java.lang.Object o);
+}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceSet.groovy b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceSet.groovy
new file mode 100644
index 0000000..d337ec7
--- /dev/null
+++ b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceSet.groovy
@@ -0,0 +1,111 @@
+/*
+ * 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.build.gradle
+
+import org.gradle.api.file.SourceDirectorySet
+
+/**
+ */
+public interface AndroidSourceSet {
+
+ /**
+ * Returns the name of this source set.
+ *
+ * @return The name. Never returns null.
+ */
+ String getName();
+
+ /**
+ * Returns the Java javaResources which are to be copied into the javaResources output directory.
+ *
+ * @return the javaResources. Never returns null.
+ */
+ SourceDirectorySet getJavaResources();
+
+ /**
+ * Configures the Java javaResources for this set.
+ *
+ * <p>The given closure is used to configure the {@link SourceDirectorySet} which contains the javaResources.
+ *
+ * @param configureClosure The closure to use to configure the javaResources.
+ * @return this
+ */
+ AndroidSourceSet javaResources(Closure configureClosure);
+
+ /**
+ * Returns the Java source which is to be compiled by the Java compiler into the class output directory.
+ *
+ * @return the Java source. Never returns null.
+ */
+ SourceDirectorySet getJava();
+
+ /**
+ * Configures the Java source for this set.
+ *
+ * <p>The given closure is used to configure the {@link SourceDirectorySet} which contains the Java source.
+ *
+ * @param configureClosure The closure to use to configure the Java source.
+ * @return this
+ */
+ AndroidSourceSet java(Closure configureClosure);
+
+ /**
+ * All Java source files for this source set. This includes, for example, source which is directly compiled, and
+ * source which is indirectly compiled through joint compilation.
+ *
+ * @return the Java source. Never returns null.
+ */
+ SourceDirectorySet getAllJava();
+
+ /**
+ * All source files for this source set.
+ *
+ * @return the source. Never returns null.
+ */
+ SourceDirectorySet getAllSource();
+
+ /**
+ * Returns the name of the compile configuration for this source set.
+ * @return The configuration name
+ */
+ String getCompileConfigurationName();
+
+ /**
+ * Returns the name of the runtime configuration for this source set.
+ * @return The runtime configuration name
+ */
+ String getPackageConfigurationName();
+
+ AndroidSourceFile getManifest();
+ AndroidSourceSet manifest(Closure configureClosure);
+
+ AndroidSourceDirectory getResources();
+ AndroidSourceSet resources(Closure configureClosure);
+
+ AndroidSourceDirectory getAssets();
+ AndroidSourceSet assets(Closure configureClosure);
+
+ AndroidSourceDirectory getAidl();
+ AndroidSourceSet aidl(Closure configureClosure);
+
+ AndroidSourceDirectory getRenderscript();
+ AndroidSourceSet renderscript(Closure configureClosure);
+
+ AndroidSourceDirectory getJni();
+ AndroidSourceSet jni(Closure configureClosure);
+
+}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/AppExtension.groovy b/gradle/src/main/groovy/com/android/build/gradle/AppExtension.groovy
index a51d33c..1c61f34 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/AppExtension.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/AppExtension.groovy
@@ -19,6 +19,7 @@ import com.android.build.gradle.internal.BuildTypeDsl
import com.android.build.gradle.internal.ProductFlavorDsl
import org.gradle.api.Action
import org.gradle.api.NamedDomainObjectContainer
+import org.gradle.api.internal.project.ProjectInternal
class AppExtension extends BaseExtension {
final NamedDomainObjectContainer<ProductFlavorDsl> productFlavors
@@ -28,8 +29,10 @@ class AppExtension extends BaseExtension {
String testBuildType = "debug"
- AppExtension(NamedDomainObjectContainer<BuildTypeDsl> buildTypes,
- NamedDomainObjectContainer<ProductFlavorDsl> productFlavors) {
+ AppExtension(ProjectInternal project,
+ NamedDomainObjectContainer<BuildTypeDsl> buildTypes,
+ NamedDomainObjectContainer<ProductFlavorDsl> productFlavors) {
+ super(project)
this.buildTypes = buildTypes
this.productFlavors = productFlavors
}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy b/gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy
index 15729c4..3d49b75 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy
@@ -25,9 +25,9 @@ import com.android.builder.BuildType
import com.android.builder.VariantConfiguration
import com.google.common.collect.ArrayListMultimap
import com.google.common.collect.ListMultimap
-
import org.gradle.api.Project
import org.gradle.api.Task
+import org.gradle.api.internal.project.ProjectInternal
import org.gradle.api.plugins.BasePlugin
class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradle.api.Plugin<Project> {
@@ -44,8 +44,8 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
def productFlavorContainer = project.container(ProductFlavorDsl)
extension = project.extensions.create('android', AppExtension,
- buildTypeContainer, productFlavorContainer)
- setDefaultConfig(extension.defaultConfig)
+ (ProjectInternal) project, buildTypeContainer, productFlavorContainer)
+ setDefaultConfig(extension.defaultConfig, extension.sourceSetsContainer)
buildTypeContainer.whenObjectAdded { BuildType buildType ->
addBuildType(buildType)
@@ -79,12 +79,7 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
throw new RuntimeException("BuildType names cannot collide with ProductFlavor names")
}
- def sourceSet = project.sourceSets.add(buildType.name)
-
- // TODO remove when moving to custom source sets
- project.tasks.remove(project.tasks.getByName("${buildType.name}Classes"))
- project.tasks.remove(project.tasks.getByName("compile${buildType.name.capitalize()}Java"))
- project.tasks.remove(project.tasks.getByName("process${buildType.name.capitalize()}Resources"))
+ def sourceSet = extension.sourceSetsContainer.create(buildType.name)
BuildTypeData buildTypeData = new BuildTypeData(buildType, sourceSet, project)
project.tasks.assemble.dependsOn buildTypeData.assembleTask
@@ -100,17 +95,9 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
throw new RuntimeException("ProductFlavor names cannot collide with BuildType names")
}
- def mainSourceSet = project.sourceSets.add(productFlavor.name)
+ def mainSourceSet = extension.sourceSetsContainer.create(productFlavor.name)
String testName = "test${productFlavor.name.capitalize()}"
- def testSourceSet = project.sourceSets.add(testName)
-
- // TODO remove when moving to custom source sets
- project.tasks.remove(project.tasks.getByName("${productFlavor.name}Classes"))
- project.tasks.remove(project.tasks.getByName("compile${productFlavor.name.capitalize()}Java"))
- project.tasks.remove(project.tasks.getByName("process${productFlavor.name.capitalize()}Resources"))
- project.tasks.remove(project.tasks.getByName("${testName}Classes"))
- project.tasks.remove(project.tasks.getByName("compile${testName.capitalize()}Java"))
- project.tasks.remove(project.tasks.getByName("process${testName.capitalize()}Resources"))
+ def testSourceSet = extension.sourceSetsContainer.create(testName)
ProductFlavorData productFlavorData = new ProductFlavorData(
productFlavor, mainSourceSet, testSourceSet, project)
@@ -192,8 +179,8 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
for (BuildTypeData buildTypeData : buildTypes.values()) {
def variantConfig = new VariantConfiguration(
- defaultConfigData.productFlavor, defaultConfigData.androidSourceSet,
- buildTypeData.buildType, buildTypeData.androidSourceSet)
+ defaultConfigData.productFlavor, defaultConfigData.sourceSet,
+ buildTypeData.buildType, buildTypeData.sourceSet)
ProductionAppVariant productionAppVariant = addVariant(variantConfig,
buildTypeData.assembleTask)
@@ -206,7 +193,7 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
assert testedVariant != null
def testVariantConfig = new VariantConfiguration(
- defaultConfigData.productFlavor, defaultConfigData.androidTestSourceSet,
+ defaultConfigData.productFlavor, defaultConfigData.testSourceSet,
testData.buildType, null,
VariantConfiguration.Type.TEST, testedVariant.config)
@@ -237,11 +224,11 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
for (BuildTypeData buildTypeData : buildTypes.values()) {
def variantConfig = new VariantConfiguration(
- extension.defaultConfig, getDefaultConfigData().androidSourceSet,
- buildTypeData.buildType, buildTypeData.androidSourceSet)
+ extension.defaultConfig, getDefaultConfigData().sourceSet,
+ buildTypeData.buildType, buildTypeData.sourceSet)
for (ProductFlavorData data : flavorDataList) {
- variantConfig.addProductFlavor(data.productFlavor, data.androidSourceSet)
+ variantConfig.addProductFlavor(data.productFlavor, data.sourceSet)
}
ProductionAppVariant productionAppVariant = addVariant(variantConfig, null)
@@ -263,12 +250,12 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
assert testedVariant != null
def testVariantConfig = new VariantConfiguration(
- extension.defaultConfig, getDefaultConfigData().androidTestSourceSet,
+ extension.defaultConfig, getDefaultConfigData().testSourceSet,
testData.buildType, null,
VariantConfiguration.Type.TEST, testedVariant.config)
for (ProductFlavorData data : flavorDataList) {
- testVariantConfig.addProductFlavor(data.productFlavor, data.androidTestSourceSet)
+ testVariantConfig.addProductFlavor(data.productFlavor, data.testSourceSet)
}
// TODO: add actual dependencies
@@ -314,6 +301,9 @@ class AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradl
// Add a task to generate resource source files
def processResources = createProcessResTask(variant, processManifestTask, crunchTask)
+ // Add a task to process the java resources
+ createProcessJavaResTask(variant)
+
def compileAidl = createAidlTask(variant)
// TODO - move this
compileAidl.dependsOn prepareDependenciesTask
diff --git a/gradle/src/main/groovy/com/android/build/gradle/BaseExtension.groovy b/gradle/src/main/groovy/com/android/build/gradle/BaseExtension.groovy
index dc78958..cd045df 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/BaseExtension.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/BaseExtension.groovy
@@ -16,9 +16,14 @@
package com.android.build.gradle
import com.android.build.gradle.internal.AaptOptionsImpl
+import com.android.build.gradle.internal.AndroidSourceSetFactory
import com.android.build.gradle.internal.DexOptionsImpl
import com.android.build.gradle.internal.ProductFlavorDsl
import org.gradle.api.Action
+import org.gradle.api.NamedDomainObjectContainer
+import org.gradle.api.artifacts.Configuration
+import org.gradle.api.artifacts.ConfigurationContainer
+import org.gradle.api.internal.project.ProjectInternal
/**
* Base android extension for all android plugins.
@@ -31,7 +36,53 @@ class BaseExtension {
final AaptOptionsImpl aaptOptions = new AaptOptionsImpl()
final DexOptionsImpl dexOptions = new DexOptionsImpl()
- BaseExtension() {
+ /**
+ * The source sets container.
+ */
+ final NamedDomainObjectContainer<AndroidSourceSet> sourceSetsContainer
+
+ BaseExtension(ProjectInternal project) {
+ sourceSetsContainer = project.container(AndroidSourceSet,
+ new AndroidSourceSetFactory(project.fileResolver))
+
+ sourceSetsContainer.whenObjectAdded { AndroidSourceSet sourceSet ->
+ ConfigurationContainer configurations = project.getConfigurations();
+
+ Configuration compileConfiguration = configurations.findByName(
+ sourceSet.getCompileConfigurationName());
+ if (compileConfiguration == null) {
+ compileConfiguration = configurations.add(sourceSet.getCompileConfigurationName());
+ }
+ compileConfiguration.setVisible(false);
+ compileConfiguration.setDescription(
+ String.format("Classpath for compiling the %s sources.", sourceSet.getName()));
+
+ Configuration packageConfiguration = configurations.findByName(
+ sourceSet.getPackageConfigurationName());
+ if (packageConfiguration == null) {
+ packageConfiguration = configurations.add(sourceSet.getPackageConfigurationName());
+ }
+ packageConfiguration.setVisible(false);
+ packageConfiguration.extendsFrom(compileConfiguration);
+ packageConfiguration.setDescription(
+ String.format("Classpath packaged with the compiled %s classes.",
+ sourceSet.getName()));
+
+ sourceSet.getJava().srcDir(String.format("src/%s/java", sourceSet.getName()));
+ sourceSet.getJavaResources().srcDir(
+ String.format("src/%s/resources", sourceSet.getName()));
+ sourceSet.getResources().srcDir(String.format("src/%s/res", sourceSet.getName()));
+ sourceSet.getAssets().srcDir(String.format("src/%s/assets", sourceSet.getName()));
+ sourceSet.getManifest().srcFile(
+ String.format("src/%s/AndroidManifest.xml", sourceSet.getName()));
+ sourceSet.getAidl().srcDir(String.format("src/%s/aidl", sourceSet.getName()));
+ sourceSet.getRenderscript().srcDir(String.format("src/%s/rs", sourceSet.getName()));
+ sourceSet.getJni().srcDir(String.format("src/%s/jni", sourceSet.getName()));
+ }
+ }
+
+ void sourceSets(Action<NamedDomainObjectContainer<AndroidSourceSet>> action) {
+ action.execute(sourceSetsContainer)
}
void defaultConfig(Action<ProductFlavorDsl> action) {
@@ -45,4 +96,6 @@ class BaseExtension {
void dexOptions(Action<DexOptionsImpl> action) {
action.execute(dexOptions)
}
+
+
}
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 fa7503f..a07766b 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy
@@ -17,7 +17,6 @@ package com.android.build.gradle
import com.android.SdkConstants
import com.android.build.gradle.internal.AndroidDependencyImpl
-import com.android.build.gradle.internal.AndroidSourceSet
import com.android.build.gradle.internal.ApplicationVariant
import com.android.build.gradle.internal.ProductFlavorData
import com.android.build.gradle.internal.ProductionAppVariant
@@ -28,10 +27,12 @@ import com.android.builder.DefaultSdkParser
import com.android.builder.JarDependency
import com.android.builder.ProductFlavor
import com.android.builder.SdkParser
+import com.android.builder.SourceProvider
import com.android.builder.VariantConfiguration
import com.android.utils.ILogger
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
+import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
@@ -40,9 +41,11 @@ import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.ResolvedArtifact
import org.gradle.api.artifacts.result.ResolvedDependencyResult
import org.gradle.api.artifacts.result.ResolvedModuleVersionResult
+import org.gradle.api.internal.plugins.ProcessResources
import org.gradle.api.logging.LogLevel
import org.gradle.api.plugins.JavaBasePlugin
-import org.gradle.api.tasks.SourceSet
+import org.gradle.api.plugins.JavaPluginConvention
+import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.compile.JavaCompile
/**
@@ -60,8 +63,8 @@ abstract class BasePlugin {
private LoggerWrapper loggerWrapper
private ProductFlavorData defaultConfigData
- protected SourceSet mainSourceSet
- protected SourceSet testSourceSet
+ protected AndroidSourceSet mainSourceSet
+ protected AndroidSourceSet testSourceSet
protected Task uninstallAll
protected Task assembleTest
@@ -72,17 +75,6 @@ abstract class BasePlugin {
this.project = project
project.apply plugin: JavaBasePlugin
- mainSourceSet = project.sourceSets.add("main")
- testSourceSet = project.sourceSets.add("test")
-
- // TODO remove when moving to custom source sets
- project.tasks.remove(project.tasks.getByName("classes"))
- project.tasks.remove(project.tasks.getByName("compileJava"))
- project.tasks.remove(project.tasks.getByName("processResources"))
- project.tasks.remove(project.tasks.getByName("testClasses"))
- project.tasks.remove(project.tasks.getByName("compileTestJava"))
- project.tasks.remove(project.tasks.getByName("processTestResources"))
-
project.tasks.assemble.description =
"Assembles all variants of all applications and secondary packages."
@@ -93,7 +85,11 @@ abstract class BasePlugin {
uninstallAll.group = INSTALL_GROUP
}
- protected setDefaultConfig(ProductFlavor defaultConfig) {
+ protected setDefaultConfig(ProductFlavor defaultConfig,
+ NamedDomainObjectContainer<AndroidSourceSet> sourceSets) {
+ mainSourceSet = sourceSets.create("main")
+ testSourceSet = sourceSets.create("test")
+
defaultConfigData = new ProductFlavorData(defaultConfig, mainSourceSet,
testSourceSet, project)
}
@@ -167,7 +163,7 @@ abstract class BasePlugin {
protected String getRuntimeJars(ApplicationVariant variant) {
AndroidBuilder androidBuilder = getAndroidBuilder(variant)
- return androidBuilder.runtimeClasspath.join(":")
+ return androidBuilder.runtimeClasspath.join(File.pathSeparator)
}
protected ProcessManifestTask createProcessManifestTask(ApplicationVariant variant,
@@ -255,6 +251,31 @@ abstract class BasePlugin {
return processResources
}
+ protected void createProcessJavaResTask(ApplicationVariant variant) {
+ VariantConfiguration config = variant.config
+
+ Copy processResources = project.getTasks().add("process${variant.name}JavaRes",
+ ProcessResources.class);
+
+ // set the input
+ processResources.from(((AndroidSourceSet) config.defaultSourceSet).javaResources)
+
+ if (config.getType() != VariantConfiguration.Type.TEST) {
+ processResources.from(((AndroidSourceSet) config.buildTypeSourceSet).javaResources)
+ }
+ if (config.hasFlavors()) {
+ for (SourceProvider flavorSourceSet : config.flavorSourceSets) {
+ processResources.from(((AndroidSourceSet) flavorSourceSet).javaResources)
+ }
+ }
+
+ processResources.conventionMapping.destinationDir = {
+ project.file("$project.buildDir/javaResources/$variant.dirName")
+ }
+
+ variant.processJavaResources = processResources
+ }
+
protected CompileAidlTask createAidlTask(ApplicationVariant variant) {
VariantConfiguration config = variant.config
@@ -265,13 +286,13 @@ abstract class BasePlugin {
compileTask.configObjects = variant.configObjects
List<Object> sourceList = new ArrayList<Object>();
- sourceList.add(config.defaultSourceSet.aidlSource)
+ sourceList.add(config.defaultSourceSet.aidlDir)
if (config.getType() != VariantConfiguration.Type.TEST) {
- sourceList.add(config.buildTypeSourceSet.aidlSource)
+ sourceList.add(config.buildTypeSourceSet.aidlDir)
}
if (config.hasFlavors()) {
- for (com.android.builder.SourceSet flavorSourceSet : config.flavorSourceSets) {
- sourceList.add(flavorSourceSet.aidlSource)
+ for (SourceProvider flavorSourceSet : config.flavorSourceSets) {
+ sourceList.add(flavorSourceSet.aidlDir)
}
}
@@ -296,14 +317,14 @@ abstract class BasePlugin {
VariantConfiguration config = variant.config
List<Object> sourceList = new ArrayList<Object>();
- sourceList.add(((AndroidSourceSet) config.defaultSourceSet).sourceSet.java)
+ sourceList.add(((AndroidSourceSet) config.defaultSourceSet).java)
sourceList.add({ processResources.sourceOutputDir })
if (config.getType() != VariantConfiguration.Type.TEST) {
- sourceList.add(((AndroidSourceSet) config.buildTypeSourceSet).sourceSet.java)
+ sourceList.add(((AndroidSourceSet) config.buildTypeSourceSet).java)
}
if (config.hasFlavors()) {
- for (com.android.builder.SourceSet flavorSourceSet : config.flavorSourceSets) {
- sourceList.add(((AndroidSourceSet) flavorSourceSet).sourceSet.java)
+ for (SourceProvider flavorSourceSet : config.flavorSourceSets) {
+ sourceList.add(((AndroidSourceSet) flavorSourceSet).java)
}
}
compileTask.source = sourceList.toArray()
@@ -324,6 +345,20 @@ abstract class BasePlugin {
compileTask.conventionMapping.dependencyCacheDir = {
project.file("$project.buildDir/dependency-cache/$variant.dirName")
}
+
+ // set source/target compatibility
+ // TODO: fix?
+ JavaPluginConvention convention = project.convention.getPlugin(JavaPluginConvention.class);
+
+ compileTask.conventionMapping.sourceCompatibility = {
+ convention.sourceCompatibility.toString()
+ }
+ compileTask.conventionMapping.targetCompatibility = {
+ convention.targetCompatibility.toString()
+ }
+
+ // setup the bootclasspath just before the task actually runs since this will
+ // force the sdk to be parsed.
compileTask.doFirst {
compileTask.options.bootClasspath = getRuntimeJars(variant)
}
@@ -356,6 +391,9 @@ abstract class BasePlugin {
// Add a task to generate resource source files
def processResources = createProcessResTask(variant, processManifestTask, crunchTask)
+ // process java resources
+ createProcessJavaResTask(variant)
+
def compileAidl = createAidlTask(variant)
// Add a task to compile the test application
@@ -415,7 +453,7 @@ abstract class BasePlugin {
// Add a task to generate application package
def packageApp = project.tasks.add("package${variant.name}", PackageApplicationTask)
- packageApp.dependsOn variant.resourcePackage, dexTask
+ packageApp.dependsOn variant.resourcePackage, dexTask, variant.processJavaResources
packageApp.plugin = this
packageApp.variant = variant
packageApp.configObjects = variant.configObjects
@@ -431,6 +469,9 @@ abstract class BasePlugin {
}
packageApp.conventionMapping.resourceFile = { variant.resourcePackage.singleFile }
packageApp.conventionMapping.dexFile = { dexTask.outputFile }
+ packageApp.conventionMapping.javaResourceDir = {
+ variant.processJavaResources.destinationDir
+ }
def appTask = packageApp
diff --git a/gradle/src/main/groovy/com/android/build/gradle/InstallTask.groovy b/gradle/src/main/groovy/com/android/build/gradle/InstallTask.groovy
index 29ddb8a..e7def37 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/InstallTask.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/InstallTask.groovy
@@ -33,7 +33,7 @@ class InstallTask extends DefaultTask {
@TaskAction
void generate() {
project.exec {
- executable = new File(getSdkDir(), "platform-tools/adb")
+ executable = new File(getSdkDir(), "platform-tools${File.separator}adb")
args 'install'
args '-r'
args getPackageFile()
diff --git a/gradle/src/main/groovy/com/android/build/gradle/LibraryExtension.groovy b/gradle/src/main/groovy/com/android/build/gradle/LibraryExtension.groovy
index 73927e3..668a9eb 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/LibraryExtension.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/LibraryExtension.groovy
@@ -18,14 +18,15 @@ package com.android.build.gradle
import com.android.build.gradle.internal.BuildTypeDsl
import com.android.builder.BuildType
import org.gradle.api.Action
+import org.gradle.api.internal.project.ProjectInternal
class LibraryExtension extends BaseExtension {
final BuildTypeDsl debug = new BuildTypeDsl(BuildType.DEBUG)
final BuildTypeDsl release = new BuildTypeDsl(BuildType.RELEASE)
- LibraryExtension() {
- super()
+ LibraryExtension(ProjectInternal project) {
+ super(project)
}
void debug(Action<BuildTypeDsl> action) {
diff --git a/gradle/src/main/groovy/com/android/build/gradle/LibraryPlugin.groovy b/gradle/src/main/groovy/com/android/build/gradle/LibraryPlugin.groovy
index ae9d0bc..5f256a2 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/LibraryPlugin.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/LibraryPlugin.groovy
@@ -21,15 +21,15 @@ import com.android.build.gradle.internal.ProductionAppVariant
import com.android.build.gradle.internal.TestAppVariant
import com.android.builder.AndroidDependency
import com.android.builder.BuildType
-
+import com.android.builder.BundleDependency
import com.android.builder.VariantConfiguration
import org.gradle.api.Plugin
import org.gradle.api.Project
+import org.gradle.api.internal.project.ProjectInternal
import org.gradle.api.plugins.MavenPlugin
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.bundling.Zip
-import com.android.builder.BundleDependency
class LibraryPlugin extends BasePlugin implements Plugin<Project> {
@@ -43,21 +43,14 @@ class LibraryPlugin extends BasePlugin implements Plugin<Project> {
void apply(Project project) {
super.apply(project)
- extension = project.extensions.create('android', LibraryExtension)
- setDefaultConfig(extension.defaultConfig)
+ extension = project.extensions.create('android', LibraryExtension,
+ (ProjectInternal) project)
+ setDefaultConfig(extension.defaultConfig, extension.sourceSetsContainer)
// 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)
-
- // TODO remove when moving to custom source sets
- project.tasks.remove(project.tasks.getByName("debugClasses"))
- project.tasks.remove(project.tasks.getByName("compileDebugJava"))
- project.tasks.remove(project.tasks.getByName("processDebugResources"))
- project.tasks.remove(project.tasks.getByName("releaseClasses"))
- project.tasks.remove(project.tasks.getByName("compileReleaseJava"))
- project.tasks.remove(project.tasks.getByName("processReleaseResources"))
+ def debugSourceSet = extension.sourceSetsContainer.create(BuildType.DEBUG)
+ def releaseSourceSet = extension.sourceSetsContainer.create(BuildType.RELEASE)
debugBuildTypeData = new BuildTypeData(extension.debug, debugSourceSet, project)
releaseBuildTypeData = new BuildTypeData(extension.release, releaseSourceSet, project)
@@ -74,15 +67,15 @@ class LibraryPlugin extends BasePlugin implements Plugin<Project> {
void createConfigurations() {
def debugConfig = project.configurations.add(BuildType.DEBUG)
def releaseConfig = project.configurations.add(BuildType.RELEASE)
- debugConfig.extendsFrom(project.configurations.runtime)
- releaseConfig.extendsFrom(project.configurations.runtime)
+ debugConfig.extendsFrom(project.configurations["package"])
+ releaseConfig.extendsFrom(project.configurations["package"])
project.configurations["default"].extendsFrom(releaseConfig)
// Adjust the pom scope mappings
// TODO - this should be part of JavaBase plugin. Fix this in Gradle
project.plugins.withType(MavenPlugin) {
project.conf2ScopeMappings.addMapping(300, project.configurations.compile, "runtime")
- project.conf2ScopeMappings.addMapping(300, project.configurations.runtime, "runtime")
+ project.conf2ScopeMappings.addMapping(300, project.configurations["package"], "runtime")
project.conf2ScopeMappings.addMapping(300, releaseConfig, "runtime")
}
}
@@ -97,8 +90,8 @@ class LibraryPlugin extends BasePlugin implements Plugin<Project> {
ProductFlavorData defaultConfigData = getDefaultConfigData();
def variantConfig = new VariantConfiguration(
- defaultConfigData.productFlavor, defaultConfigData.androidSourceSet,
- buildTypeData.buildType, buildTypeData.androidSourceSet,
+ defaultConfigData.productFlavor, defaultConfigData.sourceSet,
+ buildTypeData.buildType, buildTypeData.sourceSet,
VariantConfiguration.Type.LIBRARY)
ProductionAppVariant variant = new ProductionAppVariant(variantConfig)
@@ -117,6 +110,9 @@ class LibraryPlugin extends BasePlugin implements Plugin<Project> {
def processResources = createProcessResTask(variant, processManifestTask,
null /*crunchTask*/)
+ // process java resources
+ createProcessJavaResTask(variant)
+
def compileAidl = createAidlTask(variant)
// TODO - move this
compileAidl.dependsOn prepareDependenciesTask
@@ -126,11 +122,10 @@ class LibraryPlugin extends BasePlugin implements Plugin<Project> {
compileAidl)
// jar the classes.
- Jar jar = project.tasks.add("package${buildTypeData.buildType.name}Jar", Jar);
+ Jar jar = project.tasks.add("package${buildTypeData.buildType.name.capitalize()}Jar", Jar);
+ jar.dependsOn variant.compileTask, variant.processJavaResources
jar.from(variant.compileTask.outputs);
- // TODO: replace with proper ProcessResources task with properly configured SourceDirectorySet
- jar.from(defaultConfigData.androidSourceSet.javaResources);
- jar.from(buildTypeData.androidSourceSet.javaResources);
+ jar.from(variant.processJavaResources.destinationDir)
jar.destinationDir = project.file("$project.buildDir/$DIR_BUNDLES/${variant.dirName}")
jar.archiveName = "classes.jar"
@@ -138,22 +133,22 @@ class LibraryPlugin extends BasePlugin implements Plugin<Project> {
jar.exclude(packageName + "/R.class")
jar.exclude(packageName + "/R\$*.class")
- // package the resources into the bundle folder
+ // package the android resources into the bundle folder
Copy packageRes = project.tasks.add("package${variant.name}Res", Copy)
// packageRes from 3 sources. the order is important to make sure the override works well.
// TODO: fix the case of values -- need to merge the XML!
- packageRes.from(defaultConfigData.androidSourceSet.androidResources,
- buildTypeData.androidSourceSet.androidResources)
+ packageRes.from(defaultConfigData.sourceSet.resources.directory,
+ buildTypeData.sourceSet.resources.directory)
packageRes.into(project.file("$project.buildDir/$DIR_BUNDLES/${variant.dirName}/res"))
// package the aidl files into the bundle folder
Copy packageAidl = project.tasks.add("package${variant.name}Aidl", Copy)
// packageAidl from 3 sources. the order is important to make sure the override works well.
- packageAidl.from(defaultConfigData.androidSourceSet.aidlSource,
- buildTypeData.androidSourceSet.aidlSource)
+ packageAidl.from(defaultConfigData.sourceSet.aidl.directory,
+ buildTypeData.sourceSet.aidl.directory)
packageAidl.into(project.file("$project.buildDir/$DIR_BUNDLES/${variant.dirName}/aidl"))
- // package the resources into the bundle folder
+ // package the R symbol test file into the bundle folder
Copy packageSymbol = project.tasks.add("package${variant.name}Symbols", Copy)
packageSymbol.dependsOn processResources
packageSymbol.from(processResources.textSymbolDir)
@@ -191,7 +186,7 @@ class LibraryPlugin extends BasePlugin implements Plugin<Project> {
ProductFlavorData defaultConfigData = getDefaultConfigData();
def testVariantConfig = new VariantConfiguration(
- defaultConfigData.productFlavor, defaultConfigData.androidTestSourceSet,
+ defaultConfigData.productFlavor, defaultConfigData.testSourceSet,
debugBuildTypeData.buildType, null,
VariantConfiguration.Type.TEST, testedVariant.config)
// TODO: add actual dependencies
diff --git a/gradle/src/main/groovy/com/android/build/gradle/PackageApplicationTask.groovy b/gradle/src/main/groovy/com/android/build/gradle/PackageApplicationTask.groovy
index 72b5a30..8da0129 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/PackageApplicationTask.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/PackageApplicationTask.groovy
@@ -16,6 +16,7 @@
package com.android.build.gradle
import com.android.builder.packaging.DuplicateFileException
+import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
@@ -32,6 +33,9 @@ class PackageApplicationTask extends BaseTask {
@InputFile
File dexFile
+ @Input
+ File javaResourceDir
+
@InputDirectory @Optional
File jniDir
@@ -42,6 +46,7 @@ class PackageApplicationTask extends BaseTask {
getBuilder().packageApk(
getResourceFile().absolutePath,
getDexFile().absolutePath,
+ getJavaResourceDir()?.absolutePath,
getJniDir()?.absolutePath,
getOutputFile().absolutePath)
} catch (DuplicateFileException e) {
diff --git a/gradle/src/main/groovy/com/android/build/gradle/ProcessManifestTask.groovy b/gradle/src/main/groovy/com/android/build/gradle/ProcessManifestTask.groovy
index 5a1fd5f..c361d53 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/ProcessManifestTask.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/ProcessManifestTask.groovy
@@ -15,9 +15,9 @@
*/
package com.android.build.gradle
+import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
-import org.gradle.api.tasks.InputFiles
/**
*/
diff --git a/gradle/src/main/groovy/com/android/build/gradle/RunTestsTask.groovy b/gradle/src/main/groovy/com/android/build/gradle/RunTestsTask.groovy
index c413f51..5d07dac 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/RunTestsTask.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/RunTestsTask.groovy
@@ -32,7 +32,7 @@ class RunTestsTask extends BaseTask {
logger.info("Running tests with command: " + command)
project.exec {
- executable = new File(getSdkDir(), "platform-tools/adb")
+ executable = new File(getSdkDir(), "platform-tools${File.separator}adb")
args command
}
}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/UninstallTask.groovy b/gradle/src/main/groovy/com/android/build/gradle/UninstallTask.groovy
index a21b419..234601c 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/UninstallTask.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/UninstallTask.groovy
@@ -27,7 +27,7 @@ class UninstallTask extends BaseTask {
String packageName = variant.package
logger.info("Uninstalling app: " + packageName)
project.exec {
- executable = new File(getSdkDir(), "platform-tools/adb")
+ executable = new File(getSdkDir(), "platform-tools${File.separator}adb")
args "uninstall"
args packageName
}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/ZipAlignTask.groovy b/gradle/src/main/groovy/com/android/build/gradle/ZipAlignTask.groovy
index 37f3f6f..81a09f0 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/ZipAlignTask.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/ZipAlignTask.groovy
@@ -34,7 +34,7 @@ class ZipAlignTask extends DefaultTask {
@TaskAction
void generate() {
project.exec {
- executable = new File(getSdkDir(), "tools/zipalign")
+ executable = new File(getSdkDir(), "tools${File.separator}zipalign")
args '-f', '4'
args getInputFile()
args getOutputFile()
diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/AndroidSourceSet.groovy b/gradle/src/main/groovy/com/android/build/gradle/internal/AndroidSourceSet.groovy
deleted file mode 100644
index 70b4976..0000000
--- a/gradle/src/main/groovy/com/android/build/gradle/internal/AndroidSourceSet.groovy
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.build.gradle.internal
-
-import org.gradle.api.Project
-import org.gradle.api.tasks.SourceSet
-
-/**
- * Implementation of the AndroidBuilder SourceSet on top of a gradle SourceSet
- */
-public class AndroidSourceSet implements com.android.builder.SourceSet {
-
- final SourceSet sourceSet
- private final String name
- private final Project project
-
- public AndroidSourceSet(SourceSet sourceSet, Project project) {
- this.sourceSet = sourceSet
- this.name = sourceSet.name
- this.project = project
- }
-
- @Override
- Set<File> getJavaResources() {
- return sourceSet.resources.srcDirs
- }
-
- @Override
- Iterable<File> getCompileClasspath() {
- return sourceSet.compileClasspath
- }
-
- @Override
- File getAndroidResources() {
- // FIXME: make this configurable by the SourceSet
- return project.file("src/$name/res")
- }
-
- @Override
- File getAndroidAssets() {
- // FIXME: make this configurable by the SourceSet
- return project.file("src/$name/assets")
- }
-
- @Override
- File getAndroidManifest() {
- // FIXME: make this configurable by the SourceSet
- return project.file("src/$name/AndroidManifest.xml")
- }
-
- @Override
- File getAidlSource() {
- // FIXME: make this configurable by the SourceSet
- return project.file("src/$name/aidl")
- }
-
- @Override
- File getRenderscriptSource() {
- // FIXME: make this configurable by the SourceSet
- return project.file("src/$name/rs")
- }
-
- @Override
- File getNativeSource() {
- // FIXME: make this configurable by the SourceSet
- return project.file("src/$name/jni")
- }
-}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/AndroidSourceSetFactory.groovy b/gradle/src/main/groovy/com/android/build/gradle/internal/AndroidSourceSetFactory.groovy
new file mode 100644
index 0000000..062b646
--- /dev/null
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/AndroidSourceSetFactory.groovy
@@ -0,0 +1,37 @@
+/*
+ * 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.build.gradle.internal
+
+import com.android.build.gradle.AndroidSourceSet
+import org.gradle.api.NamedDomainObjectFactory
+import org.gradle.api.internal.file.FileResolver
+
+/**
+ */
+public class AndroidSourceSetFactory implements NamedDomainObjectFactory<AndroidSourceSet> {
+
+ final FileResolver fileResolver
+
+ public AndroidSourceSetFactory(FileResolver fileResolver) {
+ this.fileResolver = fileResolver
+ }
+
+ @Override
+ AndroidSourceSet create(String name) {
+ return new DefaultAndroidSourceSet(name, fileResolver)
+ }
+}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/ApplicationVariant.groovy b/gradle/src/main/groovy/com/android/build/gradle/internal/ApplicationVariant.groovy
index b4a6908..826f206 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/internal/ApplicationVariant.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/ApplicationVariant.groovy
@@ -15,13 +15,14 @@
*/
package com.android.build.gradle.internal
+import com.android.build.gradle.BasePlugin
import com.android.builder.AndroidBuilder
import com.android.builder.ProductFlavor
import com.android.builder.VariantConfiguration
import org.gradle.api.Task
import org.gradle.api.file.FileCollection
+import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.compile.JavaCompile
-import com.android.build.gradle.BasePlugin
/**
* Represents something that can be packaged into an APK and installed.
@@ -29,9 +30,12 @@ import com.android.build.gradle.BasePlugin
public abstract class ApplicationVariant {
final VariantConfiguration config
+ Iterable<Object> configObjects
+
FileCollection resourcePackage
JavaCompile compileTask
- Iterable<Object> configObjects
+ Copy processJavaResources
+
Task assembleTask
Task installTask
Task uninstallTask
@@ -52,6 +56,8 @@ public abstract class ApplicationVariant {
return config.buildConfigLines
}
+ abstract String getName()
+
abstract String getDescription()
abstract String getDirName()
diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/BuildTypeData.groovy b/gradle/src/main/groovy/com/android/build/gradle/internal/BuildTypeData.groovy
index 65799e6..679b5e3 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/internal/BuildTypeData.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/BuildTypeData.groovy
@@ -15,23 +15,21 @@
*/
package com.android.build.gradle.internal
+import com.android.build.gradle.AndroidSourceSet
import com.android.builder.BuildType
import org.gradle.api.Project
import org.gradle.api.Task
-import org.gradle.api.tasks.SourceSet
class BuildTypeData {
final BuildType buildType
- final SourceSet mainSource
- final AndroidSourceSet androidSourceSet
+ final AndroidSourceSet sourceSet
final Task assembleTask
- BuildTypeData(BuildType buildType, SourceSet mainSource, Project project) {
+ BuildTypeData(BuildType buildType, AndroidSourceSet sourceSet, Project project) {
this.buildType = buildType
- this.mainSource = mainSource
- androidSourceSet = new AndroidSourceSet(mainSource, project)
+ this.sourceSet = sourceSet
assembleTask = project.tasks.add("assemble${buildType.name.capitalize()}")
assembleTask.description = "Assembles all ${buildType.name.capitalize()} builds"
diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceDirectory.java b/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceDirectory.java
new file mode 100644
index 0000000..4ab3322
--- /dev/null
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceDirectory.java
@@ -0,0 +1,57 @@
+/*
+ * 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.build.gradle.internal;
+
+import com.android.build.gradle.AndroidSourceDirectory;
+import org.gradle.api.internal.file.FileResolver;
+
+import java.io.File;
+
+/**
+ */
+public class DefaultAndroidSourceDirectory implements AndroidSourceDirectory {
+
+ private final String name;
+ private final FileResolver fileResolver;
+ private Object source;
+
+ DefaultAndroidSourceDirectory(String name, FileResolver fileResolver) {
+ this.name = name;
+ this.fileResolver = fileResolver;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public AndroidSourceDirectory srcDir(Object o) {
+ source = o;
+ return this;
+ }
+
+ @Override
+ public File getDirectory() {
+ return fileResolver.resolve(source);
+ }
+
+ @Override
+ public String toString() {
+ return source.toString();
+ }
+}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceFile.java b/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceFile.java
new file mode 100644
index 0000000..8080a25
--- /dev/null
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceFile.java
@@ -0,0 +1,57 @@
+/*
+ * 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.build.gradle.internal;
+
+import com.android.build.gradle.AndroidSourceFile;
+import org.gradle.api.internal.file.FileResolver;
+
+import java.io.File;
+
+/**
+ */
+public class DefaultAndroidSourceFile implements AndroidSourceFile {
+
+ private final String name;
+ private final FileResolver fileResolver;
+ private Object source;
+
+ DefaultAndroidSourceFile(String name, FileResolver fileResolver) {
+ this.name = name;
+ this.fileResolver = fileResolver;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public AndroidSourceFile srcFile(Object o) {
+ source = o;
+ return this;
+ }
+
+ @Override
+ public File getFile() {
+ return fileResolver.resolve(source);
+ }
+
+ @Override
+ public String toString() {
+ return source.toString();
+ }
+}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceSet.java b/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceSet.java
new file mode 100644
index 0000000..7c7b26d
--- /dev/null
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceSet.java
@@ -0,0 +1,257 @@
+/*
+ * 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.build.gradle.internal;
+
+import com.android.build.gradle.AndroidSourceDirectory;
+import com.android.build.gradle.AndroidSourceFile;
+import com.android.build.gradle.AndroidSourceSet;
+import com.android.builder.SourceProvider;
+import groovy.lang.Closure;
+import org.gradle.api.file.FileTreeElement;
+import org.gradle.api.file.SourceDirectorySet;
+import org.gradle.api.internal.file.DefaultSourceDirectorySet;
+import org.gradle.api.internal.file.FileResolver;
+import org.gradle.api.specs.Spec;
+import org.gradle.api.tasks.SourceSet;
+import org.gradle.util.ConfigureUtil;
+import org.gradle.util.GUtil;
+
+import java.io.File;
+
+/**
+ */
+public class DefaultAndroidSourceSet implements AndroidSourceSet, SourceProvider {
+ private final String name;
+ private final SourceDirectorySet javaSource;
+ private final SourceDirectorySet allJavaSource;
+ private final SourceDirectorySet javaResources;
+ private final AndroidSourceFile manifest;
+ private final AndroidSourceDirectory assets;
+ private final AndroidSourceDirectory resources;
+ private final AndroidSourceDirectory aidl;
+ private final AndroidSourceDirectory renderscript;
+ private final AndroidSourceDirectory jni;
+ private final String displayName;
+ private final SourceDirectorySet allSource;
+
+ public DefaultAndroidSourceSet(String name, FileResolver fileResolver) {
+ this.name = name;
+ displayName = GUtil.toWords(this.name);
+
+ String javaSrcDisplayName = String.format("%s Java source", displayName);
+
+ javaSource = new DefaultSourceDirectorySet(javaSrcDisplayName, fileResolver);
+ javaSource.getFilter().include("**/*.java");
+
+ allJavaSource = new DefaultSourceDirectorySet(javaSrcDisplayName, fileResolver);
+ allJavaSource.getFilter().include("**/*.java");
+ allJavaSource.source(javaSource);
+
+ String javaResourcesDisplayName = String.format("%s Java resources", displayName);
+ javaResources = new DefaultSourceDirectorySet(javaResourcesDisplayName, fileResolver);
+ javaResources.getFilter().exclude(new Spec<FileTreeElement>() {
+ public boolean isSatisfiedBy(FileTreeElement element) {
+ return javaSource.contains(element.getFile());
+ }
+ });
+
+ String allSourceDisplayName = String.format("%s source", displayName);
+ allSource = new DefaultSourceDirectorySet(allSourceDisplayName, fileResolver);
+ allSource.source(javaResources);
+ allSource.source(javaSource);
+
+ String manifestDisplayName = String.format("%s manifest", displayName);
+ manifest = new DefaultAndroidSourceFile(manifestDisplayName, fileResolver);
+
+ String assetsDisplayName = String.format("%s assets", displayName);
+ assets = new DefaultAndroidSourceDirectory(assetsDisplayName, fileResolver);
+
+ String resourcesDisplayName = String.format("%s resources", displayName);
+ resources = new DefaultAndroidSourceDirectory(resourcesDisplayName, fileResolver);
+
+ String aidlDisplayName = String.format("%s aidl", displayName);
+ aidl = new DefaultAndroidSourceDirectory(aidlDisplayName, fileResolver);
+
+ String renderscriptDisplayName = String.format("%s renderscript", displayName);
+ renderscript = new DefaultAndroidSourceDirectory(renderscriptDisplayName, fileResolver);
+
+ String jniDisplayName = String.format("%s jni", displayName);
+ jni = new DefaultAndroidSourceDirectory(jniDisplayName, fileResolver);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("source set %s", getDisplayName());
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ @Override
+ public String getCompileConfigurationName() {
+ if (name.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
+ return "compile";
+ } else {
+ return String.format("%sCompile", name);
+ }
+ }
+
+ @Override
+ public String getPackageConfigurationName() {
+ if (name.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
+ return "package";
+ } else {
+ return String.format("%sPackage", name);
+ }
+ }
+
+ @Override
+ public AndroidSourceFile getManifest() {
+ return manifest;
+ }
+
+ @Override
+ public AndroidSourceSet manifest(Closure configureClosure) {
+ ConfigureUtil.configure(configureClosure, getManifest());
+ return this;
+ }
+
+ @Override
+ public AndroidSourceDirectory getResources() {
+ return resources;
+ }
+
+ @Override
+ public AndroidSourceSet resources(Closure configureClosure) {
+ ConfigureUtil.configure(configureClosure, getResources());
+ return this;
+ }
+
+ @Override
+ public AndroidSourceDirectory getAssets() {
+ return assets;
+ }
+
+ @Override
+ public AndroidSourceSet assets(Closure configureClosure) {
+ ConfigureUtil.configure(configureClosure, getAssets());
+ return this;
+ }
+
+ @Override
+ public AndroidSourceDirectory getAidl() {
+ return aidl;
+ }
+
+ @Override
+ public AndroidSourceSet aidl(Closure configureClosure) {
+ ConfigureUtil.configure(configureClosure, getAidl());
+ return this;
+ }
+
+ @Override
+ public AndroidSourceDirectory getRenderscript() {
+ return renderscript;
+ }
+
+ @Override
+ public AndroidSourceSet renderscript(Closure configureClosure) {
+ ConfigureUtil.configure(configureClosure, getRenderscript());
+ return this;
+ }
+
+ @Override
+ public AndroidSourceDirectory getJni() {
+ return jni;
+ }
+
+ @Override
+ public AndroidSourceSet jni(Closure configureClosure) {
+ ConfigureUtil.configure(configureClosure, getJni());
+ return this;
+ }
+
+ @Override
+ public SourceDirectorySet getJava() {
+ return javaSource;
+ }
+
+ @Override
+ public AndroidSourceSet java(Closure configureClosure) {
+ ConfigureUtil.configure(configureClosure, getJava());
+ return this;
+ }
+
+ @Override
+ public SourceDirectorySet getAllJava() {
+ return allJavaSource;
+ }
+
+ @Override
+ public SourceDirectorySet getJavaResources() {
+ return javaResources;
+ }
+
+ @Override
+ public AndroidSourceSet javaResources(Closure configureClosure) {
+ ConfigureUtil.configure(configureClosure, getJavaResources());
+ return this;
+ }
+
+ @Override
+ public SourceDirectorySet getAllSource() {
+ return allSource;
+ }
+
+ // --- SourceProvider
+
+ @Override
+ public File getManifestFile() {
+ return getManifest().getFile();
+ }
+
+ @Override
+ public File getAidlDir() {
+ return getAidl().getDirectory();
+ }
+
+ @Override
+ public File getRenderscriptDir() {
+ return getRenderscript().getDirectory();
+ }
+
+ @Override
+ public File getJniDir() {
+ return getJni().getDirectory();
+ }
+
+ @Override
+ public File getResourcesDir() {
+ return getResources().getDirectory();
+ }
+
+ @Override
+ public File getAssetsDir() {
+ return getAssets().getDirectory();
+ }
+}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/ProductFlavorData.groovy b/gradle/src/main/groovy/com/android/build/gradle/internal/ProductFlavorData.groovy
index 4d9e76a..68f59ff 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/internal/ProductFlavorData.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/ProductFlavorData.groovy
@@ -15,30 +15,26 @@
*/
package com.android.build.gradle.internal
+import com.android.build.gradle.AndroidSourceSet
import org.gradle.api.Project
import org.gradle.api.Task
-import org.gradle.api.tasks.SourceSet
class ProductFlavorData {
final ProductFlavorDsl productFlavor
- final SourceSet mainSource
- final AndroidSourceSet androidSourceSet
+ final AndroidSourceSet sourceSet
- final SourceSet testSource
- final AndroidSourceSet androidTestSourceSet
+ final AndroidSourceSet testSourceSet
Task assembleTask
- ProductFlavorData(ProductFlavorDsl productFlavor, SourceSet mainSource, SourceSet testSource,
- Project project) {
+ ProductFlavorData(ProductFlavorDsl productFlavor,
+ AndroidSourceSet sourceSet, AndroidSourceSet testSourceSet,
+ Project project) {
this.productFlavor = productFlavor
- this.mainSource = mainSource
- androidSourceSet = new AndroidSourceSet(mainSource, project)
-
- this.testSource = testSource
- androidTestSourceSet = new AndroidSourceSet(testSource, project)
+ this.sourceSet = sourceSet
+ this.testSourceSet = testSourceSet
}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/ProductionAppVariant.groovy b/gradle/src/main/groovy/com/android/build/gradle/internal/ProductionAppVariant.groovy
index 1f23999..6e6e8b7 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/internal/ProductionAppVariant.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/ProductionAppVariant.groovy
@@ -15,9 +15,9 @@
*/
package com.android.build.gradle.internal
+import com.android.build.gradle.BasePlugin
import com.android.builder.AndroidBuilder
import com.android.builder.VariantConfiguration
-import com.android.build.gradle.BasePlugin
class ProductionAppVariant extends ApplicationVariant {
final String name
diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/SourceVariant.groovy b/gradle/src/main/groovy/com/android/build/gradle/internal/SourceVariant.groovy
index 9d2e82d..89d74c4 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/internal/SourceVariant.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/SourceVariant.groovy
@@ -16,7 +16,7 @@
package com.android.build.gradle.internal
/**
- * Represents something that contains source and resources.
+ * Represents something that contains source and javaResources.
*/
public interface SourceVariant {
String getName()