diff options
author | Xavier Ducrohet <xav@google.com> | 2013-11-25 14:08:44 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@google.com> | 2013-11-25 14:08:44 -0800 |
commit | b002f4a0506e158fa6aeb8fc0f0ec74f10a0097b (patch) | |
tree | d7a3360205ff451ad1565552fb560448f9b56d66 | |
parent | 6e00045fd570c43f8e37109e9bc8b32b1a6cb510 (diff) | |
download | build-b002f4a0506e158fa6aeb8fc0f0ec74f10a0097b.tar.gz |
Tweak generated source folder API.
Change-Id: Iebc7de34b90a14fc74c5a2e8c101d81a625311e3
5 files changed, 68 insertions, 15 deletions
diff --git a/changelog.txt b/changelog.txt index 6525120..b5809d6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -14,13 +14,16 @@ buildConfigField "<type>", "<name>", "<value>" This allows override a field (see 'basic' sample) Also, BuildConfig now automatically contains constants for - PACKAGE_NAME, VERSION_CODE, VERSION_NAME, BUILD_TYPE, FLAVOR s well as FLAVOR1, FLAVOR2, etc... if there are several flavor dimensions. + PACKAGE_NAME, VERSION_CODE, VERSION_NAME, BUILD_TYPE, FLAVOR as well as FLAVOR1, FLAVOR2, etc... if there are several flavor dimensions. - Switch to ProGuard 4.10 - Added ability to test proguarded (obfuscated) apps. - Jar files are now pre-dexed for faster dexing. - First pass at NDK integration - API to add new generated source folders: - variant.addGeneratedSourceFolders(generatingTask, sourceFolder1, sourceFolders2,...) + variant.addJavaSourceFoldersToModel(sourceFolder1, sourceFolders2,...) + This adds the source folder to the model (for IDE support). + Another API: + variant.registerJavaGeneratingTask(task, sourceFolder1, sourceFolders2,...) This automatically adds the dependency on the task, sets up the JavaCompile task inputs and propagates the folders to the model for IDE integration. diff --git a/gradle/src/main/groovy/com/android/build/gradle/api/BaseVariant.java b/gradle/src/main/groovy/com/android/build/gradle/api/BaseVariant.java index 854f4a5..297121d 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/api/BaseVariant.java +++ b/gradle/src/main/groovy/com/android/build/gradle/api/BaseVariant.java @@ -32,6 +32,7 @@ import org.gradle.api.tasks.Copy; import org.gradle.api.tasks.compile.JavaCompile; import java.io.File; +import java.util.Collection; /** * A Build variant and all its public data. This is the base class for items common to apps, @@ -154,24 +155,50 @@ public interface BaseVariant { Task getAssemble(); /** - * Adds to the variant a task that generates Java source Code. + * Adds new Java source folders to the model. + * + * These source folders will not be used for the default build + * system, but will be passed along the default Java source folders + * to whoever queries the model. + * + * @param sourceFolders the source folders where the generated source code is. + */ + void addJavaSourceFoldersToModel(@NonNull File... sourceFolders); + + /** + * Adds new Java source folders to the model. + * + * These source folders will not be used for the default build + * system, but will be passed along the default Java source folders + * to whoever queries the model. + * + * @param sourceFolders the source folders where the generated source code is. + */ + void addJavaSourceFoldersToModel(@NonNull Collection<File> sourceFolders); + + /** + * Adds to the variant a task that generates Java source code. * * This will make the compileJava task depend on this task and add the * new source folders as compilation inputs. * + * The new source folders are also added to the model. + * * @param task the task * @param sourceFolders the source folders where the generated source code is. */ - void addGeneratedSourceFolders(@NonNull Task task, @NonNull File... sourceFolders); + void registerJavaGeneratingTask(@NonNull Task task, @NonNull File... sourceFolders); /** - * Adds to the variant a task that generates Java source Code. + * Adds to the variant a task that generates Java source code. * * This will make the compileJava task depend on this task and add the * new source folders as compilation inputs. * + * The new source folders are also added to the model. + * * @param task the task * @param sourceFolders the source folders where the generated source code is. */ - void addGeneratedSourceFolders(@NonNull Task task, @NonNull Iterable<File> sourceFolders); + void registerJavaGeneratingTask(@NonNull Task task, @NonNull Collection<File> sourceFolders); } diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/api/BaseVariantImpl.java b/gradle/src/main/groovy/com/android/build/gradle/internal/api/BaseVariantImpl.java index 94ee0ab..1e99d91 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/internal/api/BaseVariantImpl.java +++ b/gradle/src/main/groovy/com/android/build/gradle/internal/api/BaseVariantImpl.java @@ -34,6 +34,7 @@ import org.gradle.api.tasks.Copy; import org.gradle.api.tasks.compile.JavaCompile; import java.io.File; +import java.util.Collection; abstract class BaseVariantImpl implements BaseVariant { @@ -139,12 +140,22 @@ abstract class BaseVariantImpl implements BaseVariant { } @Override - public void addGeneratedSourceFolders(@NonNull Task task, @NonNull File... sourceFolders) { - getVariantData().addGeneratedSourceFolders(task, sourceFolders); + public void addJavaSourceFoldersToModel(@NonNull File... generatedSourceFolders) { + getVariantData().addJavaSourceFoldersToModel(generatedSourceFolders); } @Override - public void addGeneratedSourceFolders(@NonNull Task task, @NonNull Iterable<File> sourceFolders) { - getVariantData().addGeneratedSourceFolders(task, sourceFolders); + public void addJavaSourceFoldersToModel(@NonNull Collection<File> generatedSourceFolders) { + getVariantData().addJavaSourceFoldersToModel(generatedSourceFolders); + } + + @Override + public void registerJavaGeneratingTask(@NonNull Task task, @NonNull File... sourceFolders) { + getVariantData().registerJavaGeneratingTask(task, sourceFolders); + } + + @Override + public void registerJavaGeneratingTask(@NonNull Task task, @NonNull Collection<File> sourceFolders) { + getVariantData().registerJavaGeneratingTask(task, sourceFolders); } } diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/variant/BaseVariantData.java b/gradle/src/main/groovy/com/android/build/gradle/internal/variant/BaseVariantData.java index 6c68201..83794e8 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/internal/variant/BaseVariantData.java +++ b/gradle/src/main/groovy/com/android/build/gradle/internal/variant/BaseVariantData.java @@ -38,6 +38,8 @@ import org.gradle.api.tasks.compile.JavaCompile; import proguard.gradle.ProGuardTask; import java.io.File; +import java.util.Collection; +import java.util.Collections; import java.util.List; /** @@ -134,7 +136,15 @@ public abstract class BaseVariantData { return extraGeneratedSourceFolders; } - public void addGeneratedSourceFolders(@NonNull Task task, @NonNull File... generatedSourceFolders) { + public void addJavaSourceFoldersToModel(@NonNull File... generatedSourceFolders) { + Collections.addAll(extraGeneratedSourceFolders, generatedSourceFolders); + } + + public void addJavaSourceFoldersToModel(@NonNull Collection<File> generatedSourceFolders) { + extraGeneratedSourceFolders.addAll(generatedSourceFolders); + } + + public void registerJavaGeneratingTask(@NonNull Task task, @NonNull File... generatedSourceFolders) { if (extraGeneratedSourceFolders == null) { extraGeneratedSourceFolders = Lists.newArrayList(); } @@ -142,12 +152,13 @@ public abstract class BaseVariantData { javaCompileTask.dependsOn(task); for (File f : generatedSourceFolders) { - extraGeneratedSourceFolders.add(f); javaCompileTask.source(f); } + + addJavaSourceFoldersToModel(generatedSourceFolders); } - public void addGeneratedSourceFolders(@NonNull Task task, @NonNull Iterable<File> generatedSourceFolders) { + public void registerJavaGeneratingTask(@NonNull Task task, @NonNull Collection<File> generatedSourceFolders) { if (extraGeneratedSourceFolders == null) { extraGeneratedSourceFolders = Lists.newArrayList(); } @@ -155,8 +166,9 @@ public abstract class BaseVariantData { javaCompileTask.dependsOn(task); for (File f : generatedSourceFolders) { - extraGeneratedSourceFolders.add(f); javaCompileTask.source(f); } + + addJavaSourceFoldersToModel(generatedSourceFolders); } } diff --git a/tests/genFolderApi/build.gradle b/tests/genFolderApi/build.gradle index 542d956..3f35366 100644 --- a/tests/genFolderApi/build.gradle +++ b/tests/genFolderApi/build.gradle @@ -41,5 +41,5 @@ android.applicationVariants.all { variant -> outputFile file("${sourceFolder.absolutePath}/com/custom/Foo.java") } - variant.addGeneratedSourceFolders(javaGenerationTask, sourceFolder) + variant.registerJavaGeneratingTask(javaGenerationTask, sourceFolder) }
\ No newline at end of file |