Commits

Meikel Brandmeyer committed d2d8ad5

Switch to delayed configuration for tasks

Comments (0)

Files changed (5)

clojuresque/src/main/groovy/clojuresque/ClojureBasePlugin.groovy

             if (set.equals(project.sourceSets.test))
                 return
             def compileTaskName = set.getCompileTaskName("clojure")
-            def task = project.tasks.add(compileTaskName,
+            def task = project.task(compileTaskName,
                     type: ClojureCompileTask) {
-                destinationDir = set.output.classesDir
+                delayedDestinationDir = { set.output.classesDir }
                 source set.clojure
                 clojureRoots = set.clojure
-                classpath = project.files(
-                    set.compileClasspath,
-                    project.configurations.development
-                )
+                delayedClasspath = {
+                    project.files(
+                        set.compileClasspath,
+                        project.configurations.development
+                    )
+                }
                 description =
                     String.format("Compile the %s Clojure source.",
                             set.name)
             def compileTaskName = set.getCompileTaskName("clojure")
             def docTaskName = set.getTaskName(null, "clojuredoc")
             def compileTask = project.tasks[compileTaskName]
-            def task = project.tasks.add(docTaskName, type: ClojureDocTask) {
-                destinationDir = project.file(
-                    project.docsDir.path + "/clojuredoc"
-                )
+            def task = project.task(docTaskName, type: ClojureDocTask) {
+                delayedDestinationDir = {
+                    project.file(project.docsDir.path + "/clojuredoc")
+                }
                 source set.clojure
                 clojureRoots = set.clojure
-                classpath = compileTask.classpath
+                delayedClasspath = { compileTask.classpath }
                 description =
                     String.format("Generate documentation for the %s Clojure source.",
                             set.name)
     }
 
     private void configureTests(project) {
-        def clojureTest = project.tasks.add("clojureTest",
+        def clojureTest = project.task("clojureTest",
                 type: ClojureTestTask) {
             source project.sourceSets.test.clojure
             testRoots = project.sourceSets.test.clojure
-            classpath = project.configurations.testRuntime
-            classesDir = project.sourceSets.main.output.classesDir
+            delayedClasspath  = { project.configurations.testRuntime }
+            delayedClassesDir = { project.sourceSets.main.output.classesDir }
+            delayedJunitOutputDir = {
+                project.file(project.buildDir.path + "/test-results")
+            }
             dependsOn project.tasks.classes, project.configurations.testRuntime
             description = "Run Clojure tests in src/test."
             if (project.hasProperty("clojuresque.test.vars")) {

clojuresque/src/main/groovy/clojuresque/tasks/ClojureCompileTask.groovy

 
 package clojuresque.tasks
 
+import kotka.gradle.utils.Delayed
+
 import org.gradle.api.file.FileCollection
 import org.gradle.api.file.SourceDirectorySet
 import org.gradle.api.tasks.InputFiles
 import groovy.lang.Closure
 
 public class ClojureCompileTask extends ClojureSourceTask {
-    def File destinationDir
-    def FileCollection classpath
-    def SourceDirectorySet clojureRoots
-    def Closure jvmOptions = {}
-
     @OutputDirectory
-    public File getDestinationDir() {
-        return this.destinationDir
-    }
+    @Delayed
+    def destinationDir
 
     @InputFiles
-    public FileCollection getClasspath() {
-        return this.classpath
-    }
+    @Delayed
+    def classpath
+
+    def clojureRoots
+    def jvmOptions = {}
 
     @TaskAction
     public void compile() {
-        if (destinationDir == null) {
+        def destDir = getDestinationDir()
+        if (destDir == null) {
             throw new StopExecutionException("destinationDir not set!")
         }
-        destinationDir.mkdirs()
+        destDir.mkdirs()
 
         List<String> options = []
         if (project.clojure.aotCompile) {
             options.add("--warn-on-reflection")
         }
 
-
         project.clojureexec {
             project.configure delegate, this.jvmOptions
-            systemProperties "clojure.compile.path": this.destinationDir.path
+            systemProperties "clojure.compile.path": destDir.path
             classpath = project.files(
                 this.clojureRoots.srcDirs,
-                this.destinationDir,
+                destDir,
                 this.classpath
             )
             main = "clojuresque.tasks.compile/main"
 
         if (!project.clojure.aotCompile) {
             project.copy {
-                from this.source
-                into this.destinationDir
+                from source
+                into destDir
             }
         }
     }

clojuresque/src/main/groovy/clojuresque/tasks/ClojureDocTask.groovy

 
 package clojuresque.tasks
 
+import kotka.gradle.utils.Delayed
+
 import org.gradle.api.file.FileCollection
 import org.gradle.api.file.SourceDirectorySet
 import org.gradle.api.tasks.InputFiles
 import groovy.lang.Closure
 
 public class ClojureDocTask extends ClojureSourceTask {
-    def File destinationDir
-    def FileCollection classpath
-    def SourceDirectorySet clojureRoots
-    def Closure jvmOptions = {}
-
     @OutputDirectory
-    public File getDestinationDir() {
-        return this.destinationDir
-    }
+    @Delayed
+    def destinationDir
 
     @InputFiles
-    public FileCollection getClasspath() {
-        return this.classpath
-    }
+    @Delayed
+    def classpath
+
+    def clojureRoots
+    def jvmOptions = {}
 
     @TaskAction
     public void clojuredoc() {
-        if (destinationDir == null) {
+        def destDir = getDestinationDir()
+        if (destDir == null) {
             throw new StopExecutionException("destinationDir not set!")
         }
+        destDir.mkdirs()
 
         project.clojureexec {
-            project.configure delegate, jvmOptions
+            project.configure delegate, this.jvmOptions
             classpath = project.files(
                 this.clojureRoots.srcDirs,
                 this.classpath
             )
             main = "clojuresque.tasks.doc/main"
             args = [
-                "-d", this.destinationDir.path,
-                "-n", this.project.name ?: "",
-                "-D", this.project.description ?: "",
-                "-v", this.project.version ?: ""
-            ] + this.source*.path
+                "-d", destDir.path,
+                "-n", project.name ?: "",
+                "-D", project.description ?: "",
+                "-v", project.version ?: ""
+            ] + source*.path
         }
     }
 }

clojuresque/src/main/groovy/clojuresque/tasks/ClojureSourceSet.groovy

 
 package clojuresque.tasks
 
-import groovy.lang.Closure
+import kotka.gradle.utils.tasks.GenericSourceSet
 
-import org.gradle.api.file.FileTree
-import org.gradle.api.file.SourceDirectorySet
-import org.gradle.api.internal.file.UnionFileTree
-import org.gradle.api.internal.file.DefaultSourceDirectorySet
-import org.gradle.api.internal.file.FileResolver
-import org.gradle.api.tasks.util.PatternFilterable
-import org.gradle.api.tasks.util.PatternSet
-import org.gradle.util.ConfigureUtil
-
+@GenericSourceSet(sourceName="clojure", sourcePatterns=["**/*.clj"])
 class ClojureSourceSet {
-    private final SourceDirectorySet clojure
-    private final UnionFileTree allClojure
-    private final PatternFilterable clojurePatterns = new PatternSet()
-
-    public ClojureSourceSet(String displayName, FileResolver fileResolver) {
-        clojure = new DefaultSourceDirectorySet(String.format("%s Clojure source", displayName), fileResolver)
-        clojure.filter.include("**/*.clj")
-        clojurePatterns.include("**/*.clj")
-        allClojure = new UnionFileTree(String.format("%s Clojure source", displayName), clojure.matching(clojurePatterns))
-    }
-
-    public SourceDirectorySet getClojure() {
-        return clojure
-    }
-
-    public ClojureSourceSet clojure(Closure configureClosure) {
-        ConfigureUtil.configure(configureClosure, this.clojure)
-        return this
-    }
-
-    public PatternFilterable getClojureSourcePatterns() {
-        return clojurePatterns
-    }
-
-    public FileTree getAllClojure() {
-        return allClojure
-    }
-
     public void clojureIncludeNamespace(String pattern) {
         clojure.include(
             pattern.replaceAll("-", "_").replaceAll("\\.", "/") + ".clj"

clojuresque/src/main/groovy/clojuresque/tasks/ClojureTestTask.groovy

 
 package clojuresque.tasks
 
+import kotka.gradle.utils.Delayed
+
 import org.gradle.api.file.FileCollection
 import org.gradle.api.file.SourceDirectorySet
 import org.gradle.api.tasks.InputFiles
 import groovy.lang.Closure
 
 public class ClojureTestTask extends ClojureSourceTask {
-    def File classesDir
-    def FileCollection classpath
-    def SourceDirectorySet testRoots
-    def Closure jvmOptions = {}
-    def boolean junit = false
-    def String junitOutputDir = "build/test-results" 
-    def List<String> tests = []
+    @Delayed
+    def classesDir
 
     @InputFiles
-    public FileCollection getTestClasspath() {
-        return this.classpath
-    }
+    @Delayed
+    def classpath
+
+    def testRoots
+    def jvmOptions = {}
+    def junit = false
+
+    @Delayed
+    def junitOutputDir
+
+    def List<String> tests = []
 
     @TaskAction
     public void runTests() {
             )
             if (junit) {
                 main = "clojuresque.tasks.test-junit/test-namespaces"
-                args = ["-o", junitOutputDir] + this.source.files
+                args = ["-o", this.junitOutputDir] + this.source.files
             } else {
                 if (tests.size() == 0) {
                     main = "clojuresque.tasks.test/test-namespaces"
                     args = this.source.files
                 } else {
                     main = "clojuresque.tasks.test/test-vars"
-                    args = tests
+                    args = this.tests
                 }
             }
         }