Add getSourceSets on extension object.
Change-Id: Ifed369c3e397c031326c10778d17241eb3f6cccf
diff --git a/builder/src/main/java/com/android/builder/VariantConfiguration.java b/builder/src/main/java/com/android/builder/VariantConfiguration.java
index ac88e7c..e54e31a 100644
--- a/builder/src/main/java/com/android/builder/VariantConfiguration.java
+++ b/builder/src/main/java/com/android/builder/VariantConfiguration.java
@@ -543,7 +543,7 @@
for (int n = mFlatLibraries.size() - 1 ; n >= 0 ; n--) {
AndroidDependency dependency = mFlatLibraries.get(n);
File resFolder = dependency.getResFolder();
- if (resFolder != null) {
+ if (resFolder.isDirectory()) {
ResourceSet resourceSet = new ResourceSet(dependency.getFolder().getName());
resourceSet.addSource(resFolder);
resourceSets.add(resourceSet);
@@ -599,7 +599,7 @@
for (int n = mFlatLibraries.size() - 1 ; n >= 0 ; n--) {
AndroidDependency dependency = mFlatLibraries.get(n);
File assetFolder = dependency.getAssetsFolder();
- if (assetFolder != null) {
+ if (assetFolder.isDirectory()) {
AssetSet assetSet = new AssetSet(dependency.getFolder().getName());
assetSet.addSource(assetFolder);
assetSets.add(assetSet);
@@ -643,7 +643,7 @@
for (AndroidDependency lib : mFlatLibraries) {
File rsLib = lib.getRenderscriptFolder();
- if (rsLib != null && rsLib.isDirectory()) {
+ if (rsLib.isDirectory()) {
list.add(rsLib);
}
}
@@ -683,7 +683,7 @@
for (AndroidDependency lib : mFlatLibraries) {
File aidlLib = lib.getAidlFolder();
- if (aidlLib != null && aidlLib.isDirectory()) {
+ if (aidlLib.isDirectory()) {
list.add(aidlLib);
}
}
diff --git a/changelog.txt b/changelog.txt
index 91db840..55048fc 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -4,6 +4,7 @@
- Fix support for subfolders in assets/
- Fix cases where Android Libraries have local Jars dependencies
- Fix renaming of package through DSL to ensure resources are compiled in the new namespace
+ - Fix DSL to add getSourceSets on the "android" extension.
0.3
diff --git a/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceDirectorySet.java b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceDirectorySet.java
index 1109707..12b6f7b 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceDirectorySet.java
+++ b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceDirectorySet.java
@@ -16,6 +16,8 @@
package com.android.build.gradle;
+import com.android.annotations.NonNull;
+
import java.io.File;
import java.util.Set;
@@ -27,6 +29,7 @@
/**
* A concise name for the source directory (typically used to identify it in a collection).
*/
+ @NonNull
String getName();
/**
@@ -34,8 +37,9 @@
*
* @param srcDir The source directory. This is evaluated as for
* {@link org.gradle.api.Project#file(Object)}
- * @return the AndroidSourceDirectorySet object
+ * @return this
*/
+ @NonNull
AndroidSourceDirectorySet srcDir(Object srcDir);
/**
@@ -43,8 +47,9 @@
*
* @param srcDirs The source directories. These are evaluated as for
* {@link org.gradle.api.Project#files(Object...)}
- * @return the AndroidSourceDirectorySet object
+ * @return this
*/
+ @NonNull
AndroidSourceDirectorySet srcDirs(Object... srcDirs);
/**
@@ -52,13 +57,15 @@
*
* @param srcDirs The source directories. These are evaluated as for
* {@link org.gradle.api.Project#files(Object...)}
- * @return
+ * @return this
*/
+ @NonNull
AndroidSourceDirectorySet setSrcDirs(Iterable<?> srcDirs);
/**
* Returns the resolved directories.
* @return a non null set of File objects.
*/
- Set<File> getDirectories();
+ @NonNull
+ Set<File> getSrcDirs();
}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceFile.java b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceFile.java
index 4f5fd35..4cffb03 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceFile.java
+++ b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceFile.java
@@ -32,7 +32,7 @@
* Returns the file.
* @return the file input.
*/
- File getFile();
+ File getSrcFile();
/**
* Sets the location of the file.
diff --git a/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceSet.groovy b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceSet.groovy
index c1b1636..a922161 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceSet.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceSet.groovy
@@ -16,6 +16,7 @@
package com.android.build.gradle
+import com.android.annotations.NonNull
import org.gradle.api.file.SourceDirectorySet
/**
@@ -29,6 +30,7 @@
*
* @return The name. Never returns null.
*/
+ @NonNull
String getName();
/**
@@ -36,6 +38,7 @@
*
* @return the java resources. Never returns null.
*/
+ @NonNull
SourceDirectorySet getResources();
/**
@@ -47,6 +50,7 @@
* @param configureClosure The closure to use to configure the javaResources.
* @return this
*/
+ @NonNull
AndroidSourceSet resources(Closure configureClosure);
/**
@@ -55,6 +59,7 @@
*
* @return the Java source. Never returns null.
*/
+ @NonNull
SourceDirectorySet getJava();
/**
@@ -66,6 +71,7 @@
* @param configureClosure The closure to use to configure the Java source.
* @return this
*/
+ @NonNull
AndroidSourceSet java(Closure configureClosure);
/**
@@ -74,6 +80,7 @@
*
* @return the Java source. Never returns null.
*/
+ @NonNull
SourceDirectorySet getAllJava();
/**
@@ -81,18 +88,21 @@
*
* @return the source. Never returns null.
*/
+ @NonNull
SourceDirectorySet getAllSource();
/**
* Returns the name of the compile configuration for this source set.
* @return The configuration name
*/
+ @NonNull
String getCompileConfigurationName();
/**
* Returns the name of the runtime configuration for this source set.
* @return The runtime configuration name
*/
+ @NonNull
String getPackageConfigurationName();
/**
@@ -100,6 +110,7 @@
*
* @return the manifest. Never returns null.
*/
+ @NonNull
AndroidSourceFile getManifest();
/**
@@ -111,6 +122,7 @@
* @param configureClosure The closure to use to configure the Android Manifest.
* @return this
*/
+ @NonNull
AndroidSourceSet manifest(Closure configureClosure);
/**
@@ -118,6 +130,7 @@
*
* @return the resources. Never returns null.
*/
+ @NonNull
AndroidSourceDirectorySet getRes();
/**
@@ -129,6 +142,7 @@
* @param configureClosure The closure to use to configure the Resources.
* @return this
*/
+ @NonNull
AndroidSourceSet res(Closure configureClosure);
/**
@@ -136,6 +150,7 @@
*
* @return the assets. Never returns null.
*/
+ @NonNull
AndroidSourceDirectorySet getAssets();
/**
@@ -147,6 +162,7 @@
* @param configureClosure The closure to use to configure the Assets.
* @return this
*/
+ @NonNull
AndroidSourceSet assets(Closure configureClosure);
/**
@@ -154,6 +170,7 @@
*
* @return the source. Never returns null.
*/
+ @NonNull
AndroidSourceDirectorySet getAidl();
/**
@@ -165,6 +182,7 @@
* @param configureClosure The closure to use to configure the AIDL source.
* @return this
*/
+ @NonNull
AndroidSourceSet aidl(Closure configureClosure);
/**
@@ -172,6 +190,7 @@
*
* @return the source. Never returns null.
*/
+ @NonNull
AndroidSourceDirectorySet getRenderscript();
/**
@@ -183,6 +202,7 @@
* @param configureClosure The closure to use to configure the Renderscript source.
* @return this
*/
+ @NonNull
AndroidSourceSet renderscript(Closure configureClosure);
/**
@@ -190,6 +210,7 @@
*
* @return the source. Never returns null.
*/
+ @NonNull
AndroidSourceDirectorySet getJni();
/**
@@ -201,6 +222,7 @@
* @param configureClosure The closure to use to configure the JNI source.
* @return this
*/
+ @NonNull
AndroidSourceSet jni(Closure configureClosure);
/**
@@ -211,6 +233,6 @@
* @param path the root directory.
* @return this
*/
+ @NonNull
AndroidSourceSet setRoot(String path);
-
}
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 7d37602..9160626 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/BaseExtension.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/BaseExtension.groovy
@@ -125,6 +125,10 @@
action.execute(sourceSetsContainer)
}
+ NamedDomainObjectContainer<AndroidSourceSet> getSourceSets() {
+ sourceSetsContainer
+ }
+
void defaultConfig(Action<ProductFlavor> action) {
action.execute(defaultConfig)
}
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 fa1de59..fe896eb 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/LibraryPlugin.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/LibraryPlugin.groovy
@@ -207,16 +207,16 @@
// package the aidl files into the bundle folder
Sync packageAidl = project.tasks.add("package${variant.name}Aidl", Sync)
// packageAidl from 3 sources. the order is important to make sure the override works well.
- packageAidl.from(defaultConfigData.sourceSet.aidl.directories,
- buildTypeData.sourceSet.aidl.directories).include("**/*.aidl")
+ packageAidl.from(defaultConfigData.sourceSet.aidl.srcDirs,
+ buildTypeData.sourceSet.aidl.srcDirs).include("**/*.aidl")
packageAidl.into(project.file(
"$project.buildDir/$DIR_BUNDLES/${variant.dirName}/$SdkConstants.FD_AIDL"))
// package the renderscript header files files into the bundle folder
Sync packageRenderscript = project.tasks.add("package${variant.name}Renderscript", Sync)
// package from 3 sources. the order is important to make sure the override works well.
- packageRenderscript.from(defaultConfigData.sourceSet.renderscript.directories,
- buildTypeData.sourceSet.renderscript.directories).include("**/*.rsh")
+ packageRenderscript.from(defaultConfigData.sourceSet.renderscript.srcDirs,
+ buildTypeData.sourceSet.renderscript.srcDirs).include("**/*.rsh")
packageRenderscript.into(project.file(
"$project.buildDir/$DIR_BUNDLES/${variant.dirName}/$SdkConstants.FD_RENDERSCRIPT"))
diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceDirectorySet.java b/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceDirectorySet.java
index 50628fc..2b546f6 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceDirectorySet.java
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceDirectorySet.java
@@ -16,6 +16,7 @@
package com.android.build.gradle.internal;
+import com.android.annotations.NonNull;
import com.android.build.gradle.AndroidSourceDirectorySet;
import com.google.common.collect.Lists;
import org.gradle.api.internal.file.FileResolver;
@@ -34,29 +35,33 @@
private final FileResolver fileResolver;
private List<Object> source = Lists.newArrayList();
- DefaultAndroidSourceDirectorySet(String name, FileResolver fileResolver) {
+ DefaultAndroidSourceDirectorySet(@NonNull String name, @NonNull FileResolver fileResolver) {
this.name = name;
this.fileResolver = fileResolver;
}
@Override
+ @NonNull
public String getName() {
return name;
}
@Override
+ @NonNull
public AndroidSourceDirectorySet srcDir(Object srcDir) {
source.add(srcDir);
return this;
}
@Override
+ @NonNull
public AndroidSourceDirectorySet srcDirs(Object... srcDirs) {
Collections.addAll(source, srcDirs);
return this;
}
@Override
+ @NonNull
public AndroidSourceDirectorySet setSrcDirs(Iterable<?> srcDirs) {
source.clear();
for (Object srcDir : srcDirs) {
@@ -66,11 +71,13 @@
}
@Override
- public Set<File> getDirectories() {
+ @NonNull
+ public Set<File> getSrcDirs() {
return fileResolver.resolveFiles(source.toArray()).getFiles();
}
@Override
+ @NonNull
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
index 8080a25..6a31fb5 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceFile.java
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceFile.java
@@ -46,7 +46,7 @@
}
@Override
- public File getFile() {
+ public File getSrcFile() {
return fileResolver.resolve(source);
}
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
index fc03019..bad5879 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceSet.java
+++ b/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceSet.java
@@ -17,6 +17,7 @@
package com.android.build.gradle.internal;
import com.android.SdkConstants;
+import com.android.annotations.NonNull;
import com.android.build.gradle.AndroidSourceDirectorySet;
import com.android.build.gradle.AndroidSourceFile;
import com.android.build.gradle.AndroidSourceSet;
@@ -98,11 +99,13 @@
}
@Override
+ @NonNull
public String getName() {
return name;
}
@Override
+ @NonNull
public String toString() {
return String.format("source set %s", getDisplayName());
}
@@ -112,6 +115,7 @@
}
@Override
+ @NonNull
public String getCompileConfigurationName() {
if (name.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
return "compile";
@@ -121,6 +125,7 @@
}
@Override
+ @NonNull
public String getPackageConfigurationName() {
if (name.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
return "package";
@@ -130,104 +135,123 @@
}
@Override
+ @NonNull
public AndroidSourceFile getManifest() {
return manifest;
}
@Override
+ @NonNull
public AndroidSourceSet manifest(Closure configureClosure) {
ConfigureUtil.configure(configureClosure, getManifest());
return this;
}
@Override
+ @NonNull
public AndroidSourceDirectorySet getRes() {
return res;
}
@Override
+ @NonNull
public AndroidSourceSet res(Closure configureClosure) {
ConfigureUtil.configure(configureClosure, getRes());
return this;
}
@Override
+ @NonNull
public AndroidSourceDirectorySet getAssets() {
return assets;
}
@Override
+ @NonNull
public AndroidSourceSet assets(Closure configureClosure) {
ConfigureUtil.configure(configureClosure, getAssets());
return this;
}
@Override
+ @NonNull
public AndroidSourceDirectorySet getAidl() {
return aidl;
}
@Override
+ @NonNull
public AndroidSourceSet aidl(Closure configureClosure) {
ConfigureUtil.configure(configureClosure, getAidl());
return this;
}
@Override
+ @NonNull
public AndroidSourceDirectorySet getRenderscript() {
return renderscript;
}
@Override
+ @NonNull
public AndroidSourceSet renderscript(Closure configureClosure) {
ConfigureUtil.configure(configureClosure, getRenderscript());
return this;
}
@Override
+ @NonNull
public AndroidSourceDirectorySet getJni() {
return jni;
}
@Override
+ @NonNull
public AndroidSourceSet jni(Closure configureClosure) {
ConfigureUtil.configure(configureClosure, getJni());
return this;
}
@Override
+ @NonNull
public SourceDirectorySet getJava() {
return javaSource;
}
@Override
+ @NonNull
public AndroidSourceSet java(Closure configureClosure) {
ConfigureUtil.configure(configureClosure, getJava());
return this;
}
@Override
+ @NonNull
public SourceDirectorySet getAllJava() {
return allJavaSource;
}
@Override
+ @NonNull
public SourceDirectorySet getResources() {
return javaResources;
}
@Override
+ @NonNull
public AndroidSourceSet resources(Closure configureClosure) {
ConfigureUtil.configure(configureClosure, getResources());
return this;
}
@Override
+ @NonNull
public SourceDirectorySet getAllSource() {
return allSource;
}
@Override
+ @NonNull
public AndroidSourceSet setRoot(String path) {
javaSource.setSrcDirs(Collections.singletonList(path + "/java"));
javaResources.setSrcDirs(Collections.singletonList(path + "/resources"));
@@ -243,32 +267,38 @@
// --- SourceProvider
@Override
+ @NonNull
public File getManifestFile() {
- return getManifest().getFile();
+ return getManifest().getSrcFile();
}
@Override
+ @NonNull
public Set<File> getAidlDirectories() {
- return getAidl().getDirectories();
+ return getAidl().getSrcDirs();
}
@Override
+ @NonNull
public Set<File> getRenderscriptDirectories() {
- return getRenderscript().getDirectories();
+ return getRenderscript().getSrcDirs();
}
@Override
+ @NonNull
public Set<File> getJniDirectories() {
- return getJni().getDirectories();
+ return getJni().getSrcDirs();
}
@Override
+ @NonNull
public Set<File> getResourcesDirectories() {
- return getRes().getDirectories();
+ return getRes().getSrcDirs();
}
@Override
+ @NonNull
public Set<File> getAssetsDirectories() {
- return getAssets().getDirectories();
+ return getAssets().getSrcDirs();
}
}
diff --git a/gradle/src/test/groovy/com/android/build/gradle/AppPluginDslTest.groovy b/gradle/src/test/groovy/com/android/build/gradle/AppPluginDslTest.groovy
index d6f70d1..2fcfc10 100644
--- a/gradle/src/test/groovy/com/android/build/gradle/AppPluginDslTest.groovy
+++ b/gradle/src/test/groovy/com/android/build/gradle/AppPluginDslTest.groovy
@@ -229,6 +229,25 @@
checkNonTestedVariant("F2FcRelease", variants)
}
+ public void testSourceSetsApi() {
+ Project project = ProjectBuilder.builder().withProjectDir(
+ new File(testDir, "basic")).build()
+
+ project.apply plugin: 'android'
+
+ project.android {
+ compileSdkVersion 15
+ }
+
+ // query the sourceSets, will throw if missing
+ println project.android.sourceSets.main.java.srcDirs
+ println project.android.sourceSets.main.resources.srcDirs
+ println project.android.sourceSets.main.manifest.srcFile
+ println project.android.sourceSets.main.res.srcDirs
+ println project.android.sourceSets.main.assets.srcDirs
+ }
+
+
private void checkTestedVariant(String variantName, String testedVariantName,
Set<BuildVariant> variants, Set<BuildVariant> testVariants) {
BuildVariant variant = findVariant(variants, variantName)