From 968c45d9d7fef5362a6b741c7f75861071bd4a35 Mon Sep 17 00:00:00 2001 From: William Webb Date: Tue, 16 Feb 2016 23:07:46 -0600 Subject: [PATCH 1/6] Upgrade android tools version to 1.5.0 to support Transform api Moved weaving logic to HugoExec Refactored HugoPlugin to move logic to HugoExec, register Transform New HugoTransform class to interface with Transform api --- build.gradle | 2 +- hugo-example/build.gradle | 4 + hugo-plugin/build.gradle | 2 +- .../hugo/weaving/plugin/HugoExec.groovy | 59 +++++++++ .../hugo/weaving/plugin/HugoPlugin.groovy | 83 +++++-------- .../hugo/weaving/plugin/HugoTransform.groovy | 114 ++++++++++++++++++ 6 files changed, 209 insertions(+), 55 deletions(-) create mode 100644 hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoExec.groovy create mode 100644 hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy diff --git a/build.gradle b/build.gradle index cf6d2bc..cb59ae5 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { dependencies { classpath 'org.gradle.api.plugins:gradle-nexus-plugin:0.7' - classpath 'com.android.tools.build:gradle:1.3.1' + classpath 'com.android.tools.build:gradle:1.5.0' classpath 'org.aspectj:aspectjtools:1.8.6' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' } diff --git a/hugo-example/build.gradle b/hugo-example/build.gradle index aa7ac54..b58a283 100644 --- a/hugo-example/build.gradle +++ b/hugo-example/build.gradle @@ -39,3 +39,7 @@ android { } } } + +hugo { + enabled false +} \ No newline at end of file diff --git a/hugo-plugin/build.gradle b/hugo-plugin/build.gradle index 21cb5e5..7721d9b 100644 --- a/hugo-plugin/build.gradle +++ b/hugo-plugin/build.gradle @@ -8,7 +8,7 @@ sourceCompatibility = JavaVersion.VERSION_1_7 dependencies { compile gradleApi() compile localGroovy() - compile 'com.android.tools.build:gradle:1.3.1' + compile "com.android.tools.build:gradle:1.5.0" compile 'org.aspectj:aspectjtools:1.8.6' compile 'org.aspectj:aspectjrt:1.8.6' } diff --git a/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoExec.groovy b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoExec.groovy new file mode 100644 index 0000000..c70e9f8 --- /dev/null +++ b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoExec.groovy @@ -0,0 +1,59 @@ +package hugo.weaving.plugin + +import groovy.transform.CompileStatic +import org.aspectj.bridge.IMessage +import org.aspectj.bridge.MessageHandler +import org.aspectj.tools.ajc.Main +import org.gradle.api.Project + +@CompileStatic +class HugoExec { + + String inpath; + String aspectpath; + String destinationpath; + String classpath; + String bootclasspath; + + private final Project project; + + HugoExec(Project project) { + this.project = project; + } + + public void exec() { + final def log = project.logger + + String[] args = [ + "-showWeaveInfo", + "-1.5", + "-inpath", inpath, + "-aspectpath", aspectpath, + "-d", destinationpath, + "-classpath", classpath, + "-bootclasspath", bootclasspath + ] +// System.out.println "ajc args: " + Arrays.toString(args.join("\n")) + + MessageHandler handler = new MessageHandler(true); + new Main().run(args, handler); + for (IMessage message : handler.getMessages(null, true)) { + switch (message.getKind()) { + case IMessage.ABORT: + case IMessage.ERROR: + case IMessage.FAIL: + log.error message.message, message.thrown + break; + case IMessage.WARNING: + log.warn message.message, message.thrown + break; + case IMessage.INFO: + log.info message.message, message.thrown + break; + case IMessage.DEBUG: + log.debug message.message, message.thrown + break; + } + } + } +} \ No newline at end of file diff --git a/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoPlugin.groovy b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoPlugin.groovy index 5e9fe8a..ed36894 100644 --- a/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoPlugin.groovy +++ b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoPlugin.groovy @@ -1,28 +1,40 @@ package hugo.weaving.plugin +import com.android.build.gradle.AppExtension import com.android.build.gradle.AppPlugin +import com.android.build.gradle.LibraryExtension import com.android.build.gradle.LibraryPlugin -import org.aspectj.bridge.IMessage -import org.aspectj.bridge.MessageHandler -import org.aspectj.tools.ajc.Main +import com.android.build.gradle.api.BaseVariant import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.tasks.compile.JavaCompile class HugoPlugin implements Plugin { - @Override void apply(Project project) { + + @Override + void apply(Project project) { def hasApp = project.plugins.withType(AppPlugin) def hasLib = project.plugins.withType(LibraryPlugin) if (!hasApp && !hasLib) { throw new IllegalStateException("'android' or 'android-library' plugin required.") } - final def log = project.logger - final def variants - if (hasApp) { - variants = project.android.applicationVariants + def transform = new HugoTransform(project, isEnabled(project)) + + if (hasLib) { + def android = project.extensions.getByType(LibraryExtension) + android.registerTransform(transform) + + android.libraryVariants.all { BaseVariant variant -> + configureCompileJavaTask(variant, variant.javaCompile, transform) + } } else { - variants = project.android.libraryVariants + def android = project.extensions.getByType(AppExtension) + android.registerTransform(transform) + + android.applicationVariants.all { BaseVariant variant -> + configureCompileJavaTask(variant, variant.javaCompile, transform) + } } project.dependencies { @@ -31,52 +43,17 @@ class HugoPlugin implements Plugin { debugCompile 'org.aspectj:aspectjrt:1.8.6' compile 'com.jakewharton.hugo:hugo-annotations:1.2.2-SNAPSHOT' } - project.extensions.create('hugo', HugoExtension) + } - variants.all { variant -> - if (!variant.buildType.isDebuggable()) { - log.debug("Skipping non-debuggable build type '${variant.buildType.name}'.") - return; - } else if (!project.hugo.enabled) { - log.debug("Hugo is not disabled.") - return; - } - - JavaCompile javaCompile = variant.javaCompile - javaCompile.doLast { - String[] args = [ - "-showWeaveInfo", - "-1.5", - "-inpath", javaCompile.destinationDir.toString(), - "-aspectpath", javaCompile.classpath.asPath, - "-d", javaCompile.destinationDir.toString(), - "-classpath", javaCompile.classpath.asPath, - "-bootclasspath", project.android.bootClasspath.join(File.pathSeparator) - ] - log.debug "ajc args: " + Arrays.toString(args) - - MessageHandler handler = new MessageHandler(true); - new Main().run(args, handler); - for (IMessage message : handler.getMessages(null, true)) { - switch (message.getKind()) { - case IMessage.ABORT: - case IMessage.ERROR: - case IMessage.FAIL: - log.error message.message, message.thrown - break; - case IMessage.WARNING: - log.warn message.message, message.thrown - break; - case IMessage.INFO: - log.info message.message, message.thrown - break; - case IMessage.DEBUG: - log.debug message.message, message.thrown - break; - } - } - } + private static boolean isEnabled(Project project) { + if(project.hasProperty("hugo") && project.hugo.hasProperty("enabled")) { + return project.hugo.enabled; } + return true; + } + + private static configureCompileJavaTask(BaseVariant variant, JavaCompile javaCompileTask, HugoTransform transform) { + transform.putJavaCompileTask(variant.flavorName, variant.buildType.name, javaCompileTask) } } diff --git a/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy new file mode 100644 index 0000000..84d2d2f --- /dev/null +++ b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy @@ -0,0 +1,114 @@ +package hugo.weaving.plugin + +import com.android.build.api.transform.* +import com.android.utils.Pair +import com.google.common.collect.ImmutableMap +import groovy.transform.CompileStatic +import org.gradle.api.Project +import org.gradle.api.ProjectConfigurationException +import org.gradle.api.file.FileCollection +import org.gradle.api.tasks.compile.JavaCompile + +import static com.android.build.api.transform.Status.* + +/** + * Created by williamwebb on 2/16/16. + */ +@CompileStatic +class HugoTransform extends Transform { + + private final Project project + private final Map, JavaCompile> javaCompileTasks = new HashMap<>() + private final boolean enabled; + public HugoTransform(Project project, boolean enabled) { + this.project = project + this.enabled = enabled; + } + + /** + * We need to set this later because the classpath is not fully calculated until the last + * possible moment when the java compile task runs. While a Transform currently doesn't have any + * variant information, we can guess the variant based off the input path. + */ + public void putJavaCompileTask(String flavorName, String buildTypeName, JavaCompile javaCompileTask) { + javaCompileTasks.put(Pair.of(flavorName, buildTypeName), javaCompileTask) + } + + @Override + void transform(Context context, Collection inputs, Collection referencedInputs, TransformOutputProvider outputProvider, boolean isIncremental) throws IOException, TransformException, InterruptedException { + boolean debug = context.path.toLowerCase().endsWith("debug"); + if(!enabled || !debug) return; + + inputs.each { TransformInput input -> + def outputDir = outputProvider.getContentLocation("hugo", outputTypes, scopes, Format.DIRECTORY) + JavaCompile javaCompile = javaCompileTasks.get(Pair.of("", "debug")) + + input.directoryInputs.each { DirectoryInput directoryInput -> + + String inPath; + if (isIncremental) { + FileCollection changed = project.files() + directoryInput.changedFiles.each { File file, Status status -> + if (status == ADDED || status == CHANGED) { + changed += project.files(file.parent); + } + } + inPath = changed.asPath + } else { + inPath = javaCompile.destinationDir.toString() + } + + def exec = new HugoExec(project) + exec.inpath = inPath + exec.aspectpath = javaCompile.classpath.asPath + exec.destinationpath = outputDir + exec.classpath = javaCompile.classpath.asPath + exec.bootclasspath = getBootClassPath(javaCompile).asPath + exec.exec() + } + } + } + + private FileCollection getBootClassPath(JavaCompile javaCompile) { + def bootClasspath = javaCompile.options.bootClasspath + if (bootClasspath) { + return project.files(bootClasspath.tokenize(File.pathSeparator)) + } else { + // If this is null it means the javaCompile task didn't need to run, however, we still + // need to run but can't without the bootClasspath. Just fail and ask the user to rebuild. + throw new ProjectConfigurationException("Unable to obtain the bootClasspath. This may happen if your javaCompile tasks didn't run but retrolambda did. You must rebuild your project or otherwise force javaCompile to run.", null) + } + } + + @Override + public String getName() { + return "hugo" + } + + @Override + Set getInputTypes() { + return Collections.singleton(QualifiedContent.DefaultContentType.CLASSES) + } + + @Override + Set getScopes() { + return Collections.singleton(QualifiedContent.Scope.PROJECT) + } + + @Override + Set getReferencedScopes() { + return Collections.singleton(QualifiedContent.Scope.PROJECT) + } + + @Override + public Map getParameterInputs() { + return ImmutableMap. builder() + .put("enabled", enabled) // project.hugo.enabled) + .build(); + } + + @Override + public boolean isIncremental() { + return true + } +} \ No newline at end of file From b5f4ab7f51f219d8c6a9e680adb8a0cc8710712c Mon Sep 17 00:00:00 2001 From: William Webb Date: Tue, 16 Feb 2016 23:09:25 -0600 Subject: [PATCH 2/6] reenable flag --- hugo-example/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hugo-example/build.gradle b/hugo-example/build.gradle index b58a283..3a94420 100644 --- a/hugo-example/build.gradle +++ b/hugo-example/build.gradle @@ -41,5 +41,5 @@ android { } hugo { - enabled false + enabled true } \ No newline at end of file From e7dfc8873d1e9c40c166bb0ec506ca377083c54d Mon Sep 17 00:00:00 2001 From: William Webb Date: Wed, 17 Feb 2016 21:00:17 -0600 Subject: [PATCH 3/6] Fix usage with library projects --- .../hugo/weaving/plugin/HugoTransform.groovy | 66 +++++++++++++++++-- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy index 84d2d2f..7eff404 100644 --- a/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy +++ b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy @@ -4,9 +4,11 @@ import com.android.build.api.transform.* import com.android.utils.Pair import com.google.common.collect.ImmutableMap import groovy.transform.CompileStatic +import org.apache.commons.io.FileUtils import org.gradle.api.Project import org.gradle.api.ProjectConfigurationException import org.gradle.api.file.FileCollection +import org.gradle.api.internal.file.collections.SimpleFileCollection import org.gradle.api.tasks.compile.JavaCompile import static com.android.build.api.transform.Status.* @@ -37,20 +39,28 @@ class HugoTransform extends Transform { @Override void transform(Context context, Collection inputs, Collection referencedInputs, TransformOutputProvider outputProvider, boolean isIncremental) throws IOException, TransformException, InterruptedException { boolean debug = context.path.toLowerCase().endsWith("debug"); - if(!enabled || !debug) return; inputs.each { TransformInput input -> def outputDir = outputProvider.getContentLocation("hugo", outputTypes, scopes, Format.DIRECTORY) + JavaCompile javaCompile = javaCompileTasks.get(Pair.of("", "debug")) input.directoryInputs.each { DirectoryInput directoryInput -> + File inputFile = directoryInput.file + + // All classes need to be copied regardless for some reason. So if we want to + // disable hugo just use aspectj to copy everything with no modification(no aspects) + if(!enabled || !debug) { + FileUtils.copyDirectory(inputFile,outputDir) + return + } String inPath; if (isIncremental) { - FileCollection changed = project.files() + FileCollection changed = new SimpleFileCollection(project.files().asList()) directoryInput.changedFiles.each { File file, Status status -> if (status == ADDED || status == CHANGED) { - changed += project.files(file.parent); + changed += project.files(file); } } inPath = changed.asPath @@ -58,11 +68,21 @@ class HugoTransform extends Transform { inPath = javaCompile.destinationDir.toString() } + FileCollection classpath = getClasspath(inputFile, referencedInputs) + + String aspectsPath = classpath + .filter { File f -> f.path.contains("hugo")} + .asPath + + String aspectClasspath = classpath + .filter {File f -> f.path.contains("aspectjrt")} + .asPath + def exec = new HugoExec(project) exec.inpath = inPath - exec.aspectpath = javaCompile.classpath.asPath + exec.aspectpath = aspectsPath // aspects exec.destinationpath = outputDir - exec.classpath = javaCompile.classpath.asPath + exec.classpath = aspectClasspath // aspectj.jar exec.bootclasspath = getBootClassPath(javaCompile).asPath exec.exec() } @@ -80,6 +100,42 @@ class HugoTransform extends Transform { } } + private FileCollection getClasspath(File inputFile, Collection referencedInputs) { + String buildName = inputFile.name + String flavorName = inputFile.parentFile.name + + // If either one starts with a number or is 'folders', it's probably the result of a transform, keep moving + // up the dir structure until we find the right folders. + // Yes I know this is bad, but hopefully per-variant transforms will land soon. + File current = inputFile + while (Character.isDigit(buildName.charAt(0)) || Character.isDigit(flavorName.charAt(0)) || buildName.equals("folders") || flavorName.equals("folders")) { + current = current.parentFile + buildName = current.name + flavorName = current.parentFile.name + } + + def javaCompileTask = javaCompileTasks.get(Pair.of(flavorName, buildName)) + if (javaCompileTask == null) { + // Flavor might not exist + javaCompileTask = javaCompileTasks.get(Pair.of("", buildName)) + } + + def classpathFiles = javaCompileTask.classpath + referencedInputs.each { TransformInput input -> classpathFiles += project.files(input.directoryInputs*.file) } + + // bootClasspath isn't set until the last possible moment because it's expensive to look + // up the android sdk path. + def bootClasspath = javaCompileTask.options.bootClasspath + if (bootClasspath) { + classpathFiles += project.files(bootClasspath.tokenize(File.pathSeparator)) + } else { + // If this is null it means the javaCompile task didn't need to run, however, we still + // need to run but can't without the bootClasspath. Just fail and ask the user to rebuild. + throw new ProjectConfigurationException("Unable to obtain the bootClasspath. This may happen if your javaCompile tasks didn't run but retrolambda did. You must rebuild your project or otherwise force javaCompile to run.", null) + } + return classpathFiles + } + @Override public String getName() { return "hugo" From d73b971ee4cb62c99f7982b38198e55bdf43bb35 Mon Sep 17 00:00:00 2001 From: William Webb Date: Wed, 17 Feb 2016 21:06:57 -0600 Subject: [PATCH 4/6] Fix unintented change. --- .../src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy index 7eff404..ffa0815 100644 --- a/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy +++ b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy @@ -49,7 +49,7 @@ class HugoTransform extends Transform { File inputFile = directoryInput.file // All classes need to be copied regardless for some reason. So if we want to - // disable hugo just use aspectj to copy everything with no modification(no aspects) + // disable hugo simply copy files. if(!enabled || !debug) { FileUtils.copyDirectory(inputFile,outputDir) return @@ -60,7 +60,7 @@ class HugoTransform extends Transform { FileCollection changed = new SimpleFileCollection(project.files().asList()) directoryInput.changedFiles.each { File file, Status status -> if (status == ADDED || status == CHANGED) { - changed += project.files(file); + changed += project.files(file.parent); } } inPath = changed.asPath From 8f17777e0e8412ec217e72ca705f4a1150beaac6 Mon Sep 17 00:00:00 2001 From: William Webb Date: Thu, 18 Feb 2016 23:15:55 -0600 Subject: [PATCH 5/6] Fixing library projects... --- .../hugo/weaving/plugin/HugoTransform.groovy | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy index ffa0815..0002111 100644 --- a/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy +++ b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy @@ -2,7 +2,6 @@ package hugo.weaving.plugin import com.android.build.api.transform.* import com.android.utils.Pair -import com.google.common.collect.ImmutableMap import groovy.transform.CompileStatic import org.apache.commons.io.FileUtils import org.gradle.api.Project @@ -68,21 +67,11 @@ class HugoTransform extends Transform { inPath = javaCompile.destinationDir.toString() } - FileCollection classpath = getClasspath(inputFile, referencedInputs) - - String aspectsPath = classpath - .filter { File f -> f.path.contains("hugo")} - .asPath - - String aspectClasspath = classpath - .filter {File f -> f.path.contains("aspectjrt")} - .asPath - def exec = new HugoExec(project) exec.inpath = inPath - exec.aspectpath = aspectsPath // aspects + exec.aspectpath = javaCompile.classpath.asPath exec.destinationpath = outputDir - exec.classpath = aspectClasspath // aspectj.jar + exec.classpath = (getClasspath(inputFile, referencedInputs) + project.files(inputFile)).asPath exec.bootclasspath = getBootClassPath(javaCompile).asPath exec.exec() } @@ -156,13 +145,6 @@ class HugoTransform extends Transform { return Collections.singleton(QualifiedContent.Scope.PROJECT) } - @Override - public Map getParameterInputs() { - return ImmutableMap. builder() - .put("enabled", enabled) // project.hugo.enabled) - .build(); - } - @Override public boolean isIncremental() { return true From 080795c2660bf8dafbe4cb109f996c53db32f170 Mon Sep 17 00:00:00 2001 From: William Webb Date: Fri, 19 Feb 2016 08:46:25 -0600 Subject: [PATCH 6/6] Refactoring --- .../hugo/weaving/plugin/HugoTransform.groovy | 68 ++++++++++--------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy index 0002111..a188c3f 100644 --- a/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy +++ b/hugo-plugin/src/main/groovy/hugo/weaving/plugin/HugoTransform.groovy @@ -42,8 +42,6 @@ class HugoTransform extends Transform { inputs.each { TransformInput input -> def outputDir = outputProvider.getContentLocation("hugo", outputTypes, scopes, Format.DIRECTORY) - JavaCompile javaCompile = javaCompileTasks.get(Pair.of("", "debug")) - input.directoryInputs.each { DirectoryInput directoryInput -> File inputFile = directoryInput.file @@ -54,7 +52,7 @@ class HugoTransform extends Transform { return } - String inPath; + String inputDirs; if (isIncremental) { FileCollection changed = new SimpleFileCollection(project.files().asList()) directoryInput.changedFiles.each { File file, Status status -> @@ -62,34 +60,58 @@ class HugoTransform extends Transform { changed += project.files(file.parent); } } - inPath = changed.asPath + inputDirs = changed.asPath } else { - inPath = javaCompile.destinationDir.toString() + inputDirs = inputFile.path } + JavaCompile javaCompileTask = getJavaCompile(inputFile) + + String classpath = (getClasspath(javaCompileTask, referencedInputs) + project.files(inputFile)).asPath + String bootClasspath = getBootClassPath(javaCompileTask).asPath + def exec = new HugoExec(project) - exec.inpath = inPath - exec.aspectpath = javaCompile.classpath.asPath + exec.inpath = inputDirs + exec.aspectpath = classpath exec.destinationpath = outputDir - exec.classpath = (getClasspath(inputFile, referencedInputs) + project.files(inputFile)).asPath - exec.bootclasspath = getBootClassPath(javaCompile).asPath + exec.classpath = classpath + exec.bootclasspath = bootClasspath exec.exec() } } } - private FileCollection getBootClassPath(JavaCompile javaCompile) { - def bootClasspath = javaCompile.options.bootClasspath + private FileCollection getBootClassPath(JavaCompile javaCompileTask) { + + def bootClasspath = javaCompileTask.options.bootClasspath if (bootClasspath) { return project.files(bootClasspath.tokenize(File.pathSeparator)) } else { // If this is null it means the javaCompile task didn't need to run, however, we still // need to run but can't without the bootClasspath. Just fail and ask the user to rebuild. - throw new ProjectConfigurationException("Unable to obtain the bootClasspath. This may happen if your javaCompile tasks didn't run but retrolambda did. You must rebuild your project or otherwise force javaCompile to run.", null) + throw new ProjectConfigurationException("Unable to obtain the bootClasspath. This may happen if your javaCompile tasks didn't run but hugo did. You must rebuild your project or otherwise force javaCompile to run.", null) + } + } + + private FileCollection getClasspath(JavaCompile javaCompileTask, Collection referencedInputs) { + + def classpathFiles = javaCompileTask.classpath + referencedInputs.each { TransformInput input -> classpathFiles += project.files(input.directoryInputs*.file) } + + // bootClasspath isn't set until the last possible moment because it's expensive to look + // up the android sdk path. + def bootClasspath = javaCompileTask.options.bootClasspath + if (bootClasspath) { + classpathFiles += project.files(bootClasspath.tokenize(File.pathSeparator)) + } else { + // If this is null it means the javaCompile task didn't need to run, however, we still + // need to run but can't without the bootClasspath. Just fail and ask the user to rebuild. + throw new ProjectConfigurationException("Unable to obtain the bootClasspath. This may happen if your javaCompile tasks didn't run but hugo did. You must rebuild your project or otherwise force javaCompile to run.", null) } + return classpathFiles } - private FileCollection getClasspath(File inputFile, Collection referencedInputs) { + private JavaCompile getJavaCompile(File inputFile) { String buildName = inputFile.name String flavorName = inputFile.parentFile.name @@ -109,20 +131,7 @@ class HugoTransform extends Transform { javaCompileTask = javaCompileTasks.get(Pair.of("", buildName)) } - def classpathFiles = javaCompileTask.classpath - referencedInputs.each { TransformInput input -> classpathFiles += project.files(input.directoryInputs*.file) } - - // bootClasspath isn't set until the last possible moment because it's expensive to look - // up the android sdk path. - def bootClasspath = javaCompileTask.options.bootClasspath - if (bootClasspath) { - classpathFiles += project.files(bootClasspath.tokenize(File.pathSeparator)) - } else { - // If this is null it means the javaCompile task didn't need to run, however, we still - // need to run but can't without the bootClasspath. Just fail and ask the user to rebuild. - throw new ProjectConfigurationException("Unable to obtain the bootClasspath. This may happen if your javaCompile tasks didn't run but retrolambda did. You must rebuild your project or otherwise force javaCompile to run.", null) - } - return classpathFiles + return javaCompileTask; } @Override @@ -140,11 +149,6 @@ class HugoTransform extends Transform { return Collections.singleton(QualifiedContent.Scope.PROJECT) } - @Override - Set getReferencedScopes() { - return Collections.singleton(QualifiedContent.Scope.PROJECT) - } - @Override public boolean isIncremental() { return true