From fbe87d88730623d70afe471605f420f50088f885 Mon Sep 17 00:00:00 2001 From: Alexander Zolotov Date: Sat, 6 Feb 2016 20:03:09 +0300 Subject: [PATCH] Use all srcDirs while instrumenting code Fixes #73 --- .../IntelliJInstrumentCodeAction.groovy | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/groovy/org/jetbrains/intellij/IntelliJInstrumentCodeAction.groovy b/src/main/groovy/org/jetbrains/intellij/IntelliJInstrumentCodeAction.groovy index cef2a17331..fe9c2af6c6 100644 --- a/src/main/groovy/org/jetbrains/intellij/IntelliJInstrumentCodeAction.groovy +++ b/src/main/groovy/org/jetbrains/intellij/IntelliJInstrumentCodeAction.groovy @@ -4,6 +4,8 @@ import org.apache.tools.ant.BuildException import org.gradle.api.Action import org.gradle.api.Task import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.internal.HasConvention import org.gradle.api.tasks.compile.AbstractCompile import org.jetbrains.annotations.NotNull @@ -26,20 +28,24 @@ class IntelliJInstrumentCodeAction implements Action { IntelliJPlugin.LOG.info("Compiling forms and instrumenting code with nullability preconditions") boolean instrumentNotNull = prepareNotNullInstrumenting(task, classpath) - assert task instanceof AbstractCompile - def srcDirs = Utils.mainSourceSet(task.project).compiledBy(task).java.srcDirs.findAll { it.exists() } + - Utils.testSourceSet(task.project).compiledBy(task).java.srcDirs.findAll { it.exists() }; + assert task instanceof AbstractCompile && task instanceof HasConvention + def mainSourceSet = Utils.mainSourceSet(task.project).compiledBy(task) + def testSourceSet = Utils.testSourceSet(task.project).compiledBy(task) + def srcDirs = existingDirs(mainSourceSet.allSource) - existingDirs(mainSourceSet.resources) + + existingDirs(testSourceSet.allSource) - existingDirs(testSourceSet.resources) if (!srcDirs.empty) { instrumentCode(task, srcDirs, instrumentNotNull) } } + private static HashSet existingDirs(SourceDirectorySet sourceDirectorySet) { + return sourceDirectorySet.srcDirs.findAll { it.exists() } + } + private static boolean prepareNotNullInstrumenting(@NotNull Task task, @NotNull ConfigurableFileCollection classpath) { try { - task.project.ant.typedef(name: 'skip', - classpath: classpath.asPath, - loaderref: LOADER_REF, + task.project.ant.typedef(name: 'skip', classpath: classpath.asPath, loaderref: LOADER_REF, classname: FILTER_ANNOTATION_REGEXP_CLASS) } catch (BuildException e) { def cause = e.getCause()