diff options
author | Xavier Ducrohet <xav@android.com> | 2012-12-11 18:12:55 -0800 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2012-12-11 18:12:56 -0800 |
commit | d151714ad2364060f65481749376af1c0a5b607c (patch) | |
tree | d6e54a1eb5b1104ce6f320706ea8c4514365b480 /gradle | |
parent | 925238ba75354fa2ea2cea6f3cc612d10ee1b5f5 (diff) | |
parent | 997a04c1559fcec9e199287070ec5cbfd2cca155 (diff) | |
download | build-d151714ad2364060f65481749376af1c0a5b607c.tar.gz |
Merge "Add support for multiple res folders in all source sets."
Diffstat (limited to 'gradle')
10 files changed, 131 insertions, 61 deletions
diff --git a/gradle/src/integration-test/groovy/com/android/build/gradle/ProjectTest.groovy b/gradle/src/integration-test/groovy/com/android/build/gradle/ProjectTest.groovy index da4425d..20d6d22 100644 --- a/gradle/src/integration-test/groovy/com/android/build/gradle/ProjectTest.groovy +++ b/gradle/src/integration-test/groovy/com/android/build/gradle/ProjectTest.groovy @@ -84,6 +84,10 @@ class ProjectTest extends BaseTest { buildProject("multiproject") } + void testMultires() { + buildProject("multires") + } + void testOverlay1() { File project = buildProject("overlay1") File drawableOutput = new File(project, "build/res/debug/drawable" ) diff --git a/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceDirectory.java b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceDirectorySet.java index 8219421..c3590e4 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceDirectory.java +++ b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceDirectorySet.java @@ -16,12 +16,13 @@ package com.android.build.gradle; -import org.gradle.tooling.model.SourceDirectory; +import java.io.File; +import java.util.Set; /** - * An AndroidSourceDirectory represents a single directory input for an Android project. + * An AndroidSourceDirectorySet represents a lit of directory input for an Android project. */ -public interface AndroidSourceDirectory extends SourceDirectory { +public interface AndroidSourceDirectorySet { /** * A concise name for the source directory (typically used to identify it in a collection). @@ -31,9 +32,24 @@ public interface AndroidSourceDirectory extends SourceDirectory { /** * Sets the location of the directory. * - * @param srcPath The source directory. This is evaluated as for + * @param srcDir The source directory. This is evaluated as for * {@link org.gradle.api.Project#file(Object)} - * @return the AndroidSourceDirectory object + * @return the AndroidSourceDirectorySet object */ - AndroidSourceDirectory srcDir(Object srcPath); + AndroidSourceDirectorySet srcDir(Object srcDir); + + /** + * Sets the location of the directory. + * + * @param srcDirs The source directories. These are evaluated as for + * {@link org.gradle.api.Project#files(Object...)} + * @return the AndroidSourceDirectorySet object + */ + AndroidSourceDirectorySet srcDirs(Object... srcDirs); + + /** + * Returns the resolved directories. + * @return a non null set of File objects. + */ + Set<File> getDirectories(); } 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 5864c34..d3c2768 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceSet.groovy +++ b/gradle/src/main/groovy/com/android/build/gradle/AndroidSourceSet.groovy @@ -118,13 +118,13 @@ public interface AndroidSourceSet { * * @return the resources. Never returns null. */ - AndroidSourceDirectory getRes(); + AndroidSourceDirectorySet getRes(); /** * Configures the location of the Android Resources for this set. * - * <p>The given closure is used to configure the {@link AndroidSourceDirectory} which contains - * the resources. + * <p>The given closure is used to configure the {@link AndroidSourceDirectorySet} + * which contains the resources. * * @param configureClosure The closure to use to configure the Resources. * @return this @@ -136,13 +136,13 @@ public interface AndroidSourceSet { * * @return the assets. Never returns null. */ - AndroidSourceDirectory getAssets(); + AndroidSourceDirectorySet getAssets(); /** * Configures the location of the Android Assets for this set. * - * <p>The given closure is used to configure the {@link AndroidSourceDirectory} which contains - * the assets. + * <p>The given closure is used to configure the {@link AndroidSourceDirectorySet} + * which contains the assets. * * @param configureClosure The closure to use to configure the Assets. * @return this @@ -154,13 +154,13 @@ public interface AndroidSourceSet { * * @return the source. Never returns null. */ - AndroidSourceDirectory getAidl(); + AndroidSourceDirectorySet getAidl(); /** * Configures the location of the Android AIDL source for this set. * - * <p>The given closure is used to configure the {@link AndroidSourceDirectory} which contains - * the AIDL source. + * <p>The given closure is used to configure the {@link AndroidSourceDirectorySet} + * which contains the AIDL source. * * @param configureClosure The closure to use to configure the AIDL source. * @return this @@ -172,13 +172,13 @@ public interface AndroidSourceSet { * * @return the source. Never returns null. */ - AndroidSourceDirectory getRenderscript(); + AndroidSourceDirectorySet getRenderscript(); /** * Configures the location of the Android Renderscript source for this set. * - * <p>The given closure is used to configure the {@link AndroidSourceDirectory} which contains - * the Renderscript source. + * <p>The given closure is used to configure the {@link AndroidSourceDirectorySet} + * which contains the Renderscript source. * * @param configureClosure The closure to use to configure the Renderscript source. * @return this @@ -190,13 +190,13 @@ public interface AndroidSourceSet { * * @return the source. Never returns null. */ - AndroidSourceDirectory getJni(); + AndroidSourceDirectorySet getJni(); /** * Configures the location of the Android JNI source for this set. * - * <p>The given closure is used to configure the {@link AndroidSourceDirectory} which contains - * the JNI source. + * <p>The given closure is used to configure the {@link AndroidSourceDirectorySet} + * which contains the JNI source. * * @param configureClosure The closure to use to configure the JNI source. * @return this 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 697d19f..f964a05 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy +++ b/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy @@ -387,7 +387,7 @@ public abstract class BasePlugin { } processResources.conventionMapping.assetsDir = { - getOptionalDir(config.defaultSourceSet.assetsDir) + getFirstOptionalDir(config.defaultSourceSet.assetsDirectories) } processResources.conventionMapping.libraries = { @@ -935,7 +935,7 @@ public abstract class BasePlugin { useDependedOn, otherProjectTaskName)); } - protected File getOptionalDir(File dir) { + protected static File getOptionalDir(File dir) { if (dir.isDirectory()) { return dir } @@ -943,6 +943,22 @@ public abstract class BasePlugin { return null } + /** + * TODO: remove once assets support more than one folder. + * @param dirs + * @return + */ + protected static File getFirstOptionalDir(Set<File> dirs) { + Iterator<File> iterator = dirs.iterator(); + + File dir = iterator.hasNext() ? iterator.next() : null; + if (dir != null && dir.isDirectory()) { + return dir + } + + return null + } + protected List<ManifestDependency> getManifestDependencies(List<AndroidDependency> libraries) { List<ManifestDependency> list = Lists.newArrayListWithCapacity(libraries.size()) 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 de13955..d391339 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/LibraryPlugin.groovy +++ b/gradle/src/main/groovy/com/android/build/gradle/LibraryPlugin.groovy @@ -185,8 +185,8 @@ public class LibraryPlugin extends BasePlugin implements Plugin<Project> { // 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.sourceSet.aidl.directory, - buildTypeData.sourceSet.aidl.directory) + packageAidl.from(defaultConfigData.sourceSet.aidl.directories, + buildTypeData.sourceSet.aidl.directories) packageAidl.into(project.file("$project.buildDir/$DIR_BUNDLES/${variant.dirName}/aidl")) // package the R symbol text file into the bundle folder diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceDirectory.java b/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceDirectorySet.java index 4ab3322..5ff37d1 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceDirectory.java +++ b/gradle/src/main/groovy/com/android/build/gradle/internal/DefaultAndroidSourceDirectorySet.java @@ -16,20 +16,24 @@ package com.android.build.gradle.internal; -import com.android.build.gradle.AndroidSourceDirectory; +import com.android.build.gradle.AndroidSourceDirectorySet; +import com.google.common.collect.Lists; import org.gradle.api.internal.file.FileResolver; import java.io.File; +import java.util.List; +import java.util.Set; /** + * Default implementation of the AndroidSourceDirectorySet. */ -public class DefaultAndroidSourceDirectory implements AndroidSourceDirectory { +public class DefaultAndroidSourceDirectorySet implements AndroidSourceDirectorySet { private final String name; private final FileResolver fileResolver; - private Object source; + private List<Object> source = Lists.newArrayList(); - DefaultAndroidSourceDirectory(String name, FileResolver fileResolver) { + DefaultAndroidSourceDirectorySet(String name, FileResolver fileResolver) { this.name = name; this.fileResolver = fileResolver; } @@ -40,14 +44,22 @@ public class DefaultAndroidSourceDirectory implements AndroidSourceDirectory { } @Override - public AndroidSourceDirectory srcDir(Object o) { - source = o; + public AndroidSourceDirectorySet srcDir(Object srcDir) { + source.add(srcDir); return this; } @Override - public File getDirectory() { - return fileResolver.resolve(source); + public AndroidSourceDirectorySet srcDirs(Object... srcDirs) { + for (Object srcDir : srcDirs) { + source.add(srcDir); + } + return this; + } + + @Override + public Set<File> getDirectories() { + return fileResolver.resolveFiles(source.toArray()).getFiles(); } @Override 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 6821d7f..6d52086 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 @@ -16,7 +16,7 @@ package com.android.build.gradle.internal; -import com.android.build.gradle.AndroidSourceDirectory; +import com.android.build.gradle.AndroidSourceDirectorySet; import com.android.build.gradle.AndroidSourceFile; import com.android.build.gradle.AndroidSourceSet; import com.android.builder.SourceProvider; @@ -31,6 +31,7 @@ import org.gradle.util.ConfigureUtil; import org.gradle.util.GUtil; import java.io.File; +import java.util.Set; /** */ @@ -40,11 +41,11 @@ public class DefaultAndroidSourceSet implements AndroidSourceSet, SourceProvider private final SourceDirectorySet allJavaSource; private final SourceDirectorySet javaResources; private final AndroidSourceFile manifest; - private final AndroidSourceDirectory assets; - private final AndroidSourceDirectory res; - private final AndroidSourceDirectory aidl; - private final AndroidSourceDirectory renderscript; - private final AndroidSourceDirectory jni; + private final AndroidSourceDirectorySet assets; + private final AndroidSourceDirectorySet res; + private final AndroidSourceDirectorySet aidl; + private final AndroidSourceDirectorySet renderscript; + private final AndroidSourceDirectorySet jni; private final String displayName; private final SourceDirectorySet allSource; @@ -78,19 +79,19 @@ public class DefaultAndroidSourceSet implements AndroidSourceSet, SourceProvider manifest = new DefaultAndroidSourceFile(manifestDisplayName, fileResolver); String assetsDisplayName = String.format("%s assets", displayName); - assets = new DefaultAndroidSourceDirectory(assetsDisplayName, fileResolver); + assets = new DefaultAndroidSourceDirectorySet(assetsDisplayName, fileResolver); String resourcesDisplayName = String.format("%s resources", displayName); - res = new DefaultAndroidSourceDirectory(resourcesDisplayName, fileResolver); + res = new DefaultAndroidSourceDirectorySet(resourcesDisplayName, fileResolver); String aidlDisplayName = String.format("%s aidl", displayName); - aidl = new DefaultAndroidSourceDirectory(aidlDisplayName, fileResolver); + aidl = new DefaultAndroidSourceDirectorySet(aidlDisplayName, fileResolver); String renderscriptDisplayName = String.format("%s renderscript", displayName); - renderscript = new DefaultAndroidSourceDirectory(renderscriptDisplayName, fileResolver); + renderscript = new DefaultAndroidSourceDirectorySet(renderscriptDisplayName, fileResolver); String jniDisplayName = String.format("%s jni", displayName); - jni = new DefaultAndroidSourceDirectory(jniDisplayName, fileResolver); + jni = new DefaultAndroidSourceDirectorySet(jniDisplayName, fileResolver); } @Override @@ -137,7 +138,7 @@ public class DefaultAndroidSourceSet implements AndroidSourceSet, SourceProvider } @Override - public AndroidSourceDirectory getRes() { + public AndroidSourceDirectorySet getRes() { return res; } @@ -148,7 +149,7 @@ public class DefaultAndroidSourceSet implements AndroidSourceSet, SourceProvider } @Override - public AndroidSourceDirectory getAssets() { + public AndroidSourceDirectorySet getAssets() { return assets; } @@ -159,7 +160,7 @@ public class DefaultAndroidSourceSet implements AndroidSourceSet, SourceProvider } @Override - public AndroidSourceDirectory getAidl() { + public AndroidSourceDirectorySet getAidl() { return aidl; } @@ -170,7 +171,7 @@ public class DefaultAndroidSourceSet implements AndroidSourceSet, SourceProvider } @Override - public AndroidSourceDirectory getRenderscript() { + public AndroidSourceDirectorySet getRenderscript() { return renderscript; } @@ -181,7 +182,7 @@ public class DefaultAndroidSourceSet implements AndroidSourceSet, SourceProvider } @Override - public AndroidSourceDirectory getJni() { + public AndroidSourceDirectorySet getJni() { return jni; } @@ -231,27 +232,27 @@ public class DefaultAndroidSourceSet implements AndroidSourceSet, SourceProvider } @Override - public File getAidlDir() { - return getAidl().getDirectory(); + public Set<File> getAidlDirectories() { + return getAidl().getDirectories(); } @Override - public File getRenderscriptDir() { - return getRenderscript().getDirectory(); + public Set<File> getRenderscriptDirectories() { + return getRenderscript().getDirectories(); } @Override - public File getJniDir() { - return getJni().getDirectory(); + public Set<File> getJniDirectories() { + return getJni().getDirectories(); } @Override - public File getResourcesDir() { - return getRes().getDirectory(); + public Set<File> getResourcesDirectories() { + return getRes().getDirectories(); } @Override - public File getAssetsDir() { - return getAssets().getDirectory(); + public Set<File> getAssetsDirectories() { + return getAssets().getDirectories(); } } diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/ManifestDependencyImpl.java b/gradle/src/main/groovy/com/android/build/gradle/internal/ManifestDependencyImpl.java index 2c9d40d..49ff01d 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/internal/ManifestDependencyImpl.java +++ b/gradle/src/main/groovy/com/android/build/gradle/internal/ManifestDependencyImpl.java @@ -34,7 +34,7 @@ public class ManifestDependencyImpl implements ManifestDependency{ @Nested private List<ManifestDependency> dependencies; - ManifestDependencyImpl(File manifest, List<ManifestDependency> dependencies) { + public ManifestDependencyImpl(File manifest, List<ManifestDependency> dependencies) { this.manifest = manifest; this.dependencies = dependencies; } diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/SymbolFileProviderImpl.java b/gradle/src/main/groovy/com/android/build/gradle/internal/SymbolFileProviderImpl.java index dbe2af7..002f9c0 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/internal/SymbolFileProviderImpl.java +++ b/gradle/src/main/groovy/com/android/build/gradle/internal/SymbolFileProviderImpl.java @@ -32,7 +32,7 @@ public class SymbolFileProviderImpl implements SymbolFileProvider { @InputFile private File symbolFile; - SymbolFileProviderImpl(File manifest, File symbolFile) { + public SymbolFileProviderImpl(File manifest, File symbolFile) { this.manifest = manifest; this.symbolFile = symbolFile; } 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 b8f994e..aa599cc 100644 --- a/gradle/src/test/groovy/com/android/build/gradle/AppPluginDslTest.groovy +++ b/gradle/src/test/groovy/com/android/build/gradle/AppPluginDslTest.groovy @@ -49,6 +49,27 @@ public class AppPluginDslTest extends BaseTest { checkNonTestedVariant("Release", variants) } + public void testMultiRes() { + Project project = ProjectBuilder.builder().withProjectDir( + new File(testDir, "multires")).build() + + project.apply plugin: 'android' + + project.android { + target "android-15" + + sourceSets { + main { + res { + srcDirs 'src/main/res1', 'src/main/res2' + } + } + } + } + + // nothing to be done here. If the DSL fails, it'll throw an exception + } + public void testBuildTypes() { Project project = ProjectBuilder.builder().withProjectDir( new File(testDir, "basic")).build() |