Commits

Meikel Brandmeyer committed f6a72ab

Move compilation to clojureexec

Including ClojureSourceTask cleanup and move of compile driver to
a clean tasks in the runtime.

Comments (0)

Files changed (4)

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

 
 package clojuresque
 
+import org.gradle.api.file.FileCollection
+import org.gradle.api.file.SourceDirectorySet
+import org.gradle.api.tasks.OutputDirectory
 import org.gradle.api.tasks.StopExecutionException
 import org.gradle.api.tasks.TaskAction
 
+import java.io.File
 import java.io.InputStream
 
+import groovy.lang.Closure
+
 public class ClojureCompileTask extends ClojureSourceTask {
-    public InputStream compileOrRequire() {
-        String cmd = String.format(
-            this.class.getResourceAsStream("ClojureCompileDriver.clj").text,
-            source.collect {
-                String.format("(java.io.File. \"%s\")",
-                    it.path.replace("\\", "\\\\"))
-            }.join(" "),
-            project.aotCompile ? "compile" : "require"
-        )
+    def File destinationDir
+    def FileCollection compileClasspath
+    def SourceDirectorySet clojureRoots
+    def Closure jvmOptions = {}
 
-        return clojureInput(cmd)
+    @OutputDirectory
+    public File getDestinationDir() {
+        return this.destinationDir
     }
 
     @TaskAction
         }
         destinationDir.mkdirs()
 
-        project.javaexec {
-            this.jvmClosure()
+        List<String> options = []
+        if (project.aotCompile) {
+            options.add("--compile")
+        }
+        if (project.warnOnReflection) {
+            options.add("--warn-on-reflection")
+        }
+
+
+        project.clojureexec {
+            this.jvmOptions()
             systemProperties "clojure.compile.path": this.destinationDir.path
             classpath = project.files(
                 this.clojureRoots.srcDirs,
                 this.destinationDir,
-                project.configurations.development,
                 this.compileClasspath
             )
-            main = "clojure.main"
-            args = [ "-" ]
-            standardInput = this.compileOrRequire()
+            main = "clojuresque.tasks.compile/main"
+            args = options + this.source.files
         }
 
         if (!project.aotCompile) {

clojuresque/src/main/groovy/clojuresque/ClojureSourceTask.groovy

 
 package clojuresque
 
-import org.gradle.api.file.FileCollection
-import org.gradle.api.file.SourceDirectorySet
-import org.gradle.api.tasks.OutputDirectory
 import org.gradle.api.tasks.SourceTask
-import org.gradle.api.tasks.SourceSet
-import org.gradle.api.tasks.StopExecutionException
-import org.gradle.api.tasks.TaskAction
-
-import groovy.lang.Closure
-
-import java.io.File
-import java.io.ByteArrayInputStream
-import java.util.ArrayList;
-import java.util.List;
 
 public class ClojureSourceTask extends SourceTask {
-    def Closure jvmClosure = {}
-    def FileCollection compileClasspath
-    def File destinationDir
-    def SourceDirectorySet clojureRoots
-
-    public ByteArrayInputStream clojureInput(String cmd) {
-        return new ByteArrayInputStream(cmd.bytes)
-    }
-
-    @OutputDirectory
-    public File getDestinationDir() {
-        return this.destinationDir
-    }
-
-    public ClojureCompileTask jvm(Closure closure) {
-        this.jvmClosure = closure
-        return this
-    }
-
     /* Duplicate the functionality of ClojureSourceSet. */
-    public ClojureCompileTask includeNamespace(String pattern) {
+    public ClojureSourceTask includeNamespace(String pattern) {
         include(pattern.replaceAll("-", "_").replaceAll("\\.", "/") + ".clj")
         return this
     }
 
-    public ClojureCompileTask excludeNamespace(String pattern) {
+    public ClojureSourceTask excludeNamespace(String pattern) {
         exclude(pattern.replaceAll("-", "_").replaceAll("\\.", "/") + ".clj")
         return this
     }

clojuresque/src/main/resources/clojuresque/ClojureCompileDriver.clj

-(in-ns 'user)
-
-(let [find-namespace
-      (fn [file]
-        (let [of-interest '#{ns clojure.core/ns}
-              eof         (Object.)
-              input       (clojure.lang.LineNumberingPushbackReader.
-                            (java.io.FileReader. file))
-              in-seq      (take-while #(not (identical? %% eof))
-                                      (repeatedly #(read input false eof)))
-              candidate   (first
-                            (drop-while
-                              #(or (not (instance? clojure.lang.ISeq %%))
-                                   (not (contains? of-interest (first %%))))
-                              in-seq))]
-          (when candidate
-            (second candidate))))
-      namespaces
-      (set (map find-namespace [%1$s]))]
-  (doseq [nspace namespaces :when nspace]
-    (%2$s nspace)))

runtime/src/main/resources/clojuresque/tasks/compile.clj

+(ns clojuresque.tasks.compile)
+
+(defn find-namespace
+  [file]
+  (let [of-interest '#{ns clojure.core/ns}
+        eof         (Object.)
+        input       (clojure.lang.LineNumberingPushbackReader.
+                      (java.io.FileReader. file))
+        in-seq      (take-while #(not (identical? % eof))
+                                (repeatedly #(read input false eof)))
+        candidate   (first
+                      (drop-while
+                        #(or (not (instance? clojure.lang.ISeq %))
+                             (not (contains? of-interest (first %))))
+                        in-seq))]
+    (when candidate
+      (second candidate))))
+
+(defn main
+  [args]
+  (let [[mode args] (if (= (first args) "--compile")
+                      [compile (next args)]
+                      [require args])
+        [warn args] (if (= (first args) "--warn-on-reflection")
+                      [true  (next args)]
+                      [false args])
+        namespaces  (map find-namespace args)]
+    (binding [*warn-on-reflection* warn
+              *compile-path*       (System/getProperty "clojure.compile.path")]
+      (doseq [nspace namespaces :when nspace]
+        (mode nspace)))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.