Meikel  Brandmeyer avatar Meikel Brandmeyer committed 9bc42ac

Use ant builder and let Exceptions bubble out of the Compile class

Fixes #1

Comments (0)

Files changed (2)

src/main/groovy/de/kotka/gradle/ClojureCompileTask.groovy

 import org.apache.tools.ant.types.Environment
 import org.apache.tools.ant.types.Path
 
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
 import java.io.File
 
 public class ClojureCompileTask extends SourceTask {
+    private static Logger logger = LoggerFactory.getLogger(ClojureCompileTask)
+
     private File sourceDir
     private File destinationDir
     private FileCollection classpath
 
     private void initialise() {
         def action = [ execute: { ClojureCompileTask task ->
+            String sourceDir = task.sourceDir.path
+            File destDir = task.destinationDir
             FileTree source = task.source
-            File destDir = task.destinationDir
-            Project project = task.project.ant.project
-            String cp = task.classpath.getAsPath()
-            Java java = new Java()
+            FileCollection cp = task.classpath
 
-            Path path = new Path(project)
-            path.append(new Path(project, task.sourceDir.path))
-            path.append(new Path(project, destDir.path))
-            path.append(new Path(project, cp))
+            Map args = [
+                classname:    'de.kotka.gradle.ClojureCompile',
+                failOnError:  true,
+                fork:         true,
+                classpathref: 'compile.classpath'
+            ]
 
-            java.project = project
-            java.classpath = path
-            java.classname = "de.kotka.gradle.ClojureCompile"
-            task.addProperty(java, "clojure.compile.path", destDir)
-            task.addProperty(java, "clojure.compile.warn-on-reflection",
-                "false")
-            java.fork = true
+            ant.path(id: 'compile.classpath') {
+                logger.debug("Add {} (source dir) to Ant classpath!", sourceDir)
+                pathelement(location: sourceDir)
 
-            source.each {
-                task.addCommandLineArgument(java, it)
+                logger.debug("Add {} (dest dir) to Ant classpath!",
+                    destDir.path)
+                pathelement(location: destDir.path)
+
+                cp.each {
+                    logger.debug("Add {} to Ant classpath!", it)
+                    pathelement(location: it)
+                }
             }
 
             destDir.mkdirs()
-            java.execute()
+
+            ant.java(args) {
+                sysproperty(key: "clojure.compile.path", value: destDir)
+                sysproperty(key: "clojure.compile.warn-on-reflection",
+                    value: "false")
+                source.each {
+                    arg(value: it)
+                }
+            }
         } ] as Action
 
         this.doLast(action)

src/main/java/de/kotka/gradle/ClojureCompile.java

         return s.next().first();
     }
 
-    public static void main(String[] files) {
+    public static void main(String[] files) throws Exception {
         String compilePath = System.getProperty(COMPILE_PATH_PROP);
         boolean warnOnReflection =
             System.getProperty(WARN_ON_REFLECTION_PROP).equals("true");
                     if (ns != null && !seen.contains(ns))
                         compile.invoke(ns);
                     seen = (IPersistentSet)seen.cons(ns);
-                } catch(Exception e) {
-                    e.printStackTrace();
                 } finally {
                     rdr.close();
                 }
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.