Meikel  Brandmeyer avatar Meikel Brandmeyer committed 7cff9e7

Make repl options of start task lazy

Comments (0)

Files changed (2)

src/main/groovy/clojuresque/nrepl/tasks/StartTask.groovy

 
 package clojuresque.nrepl.tasks
 
+import clojuresque.nrepl.Utils
+
 import org.gradle.api.DefaultTask
 import org.gradle.api.tasks.TaskAction
 
 public class StartTask extends DefaultTask {
     def replInfo
     def replClasspath
-    def int replPort = 0
+    def replPort
     def init = []
 
+    def getReplInfo() {
+        def info = Utils.lazyValue(this.replInfo)
+        info ? project.file(info) : null
+    }
+
+    def getReplClasspath() {
+        def path = Utils.lazyValue(this.replClasspath)
+        path ? project.files(path) : null
+    }
+
+    def getReplPort() {
+        Utils.lazyValue(this.replPort, 0)
+    }
+
     @TaskAction
     void startNRepl() {
         ant.java(
             spawn:     true,
             fork:      true
         ) {
-            classpath path: project.files(this.replClasspath).asPath
+            classpath path: getReplClasspath().asPath
             arg value: "-e"
             arg value: this.commandString()
         }
     }
 
     String commandString() {
+        def info = getReplInfo()
+        def port = getReplPort()
+
         String.format('''
                 (do
                   %s
                   %s)
                 ''',
                 init.join(" "),
-                replPort,
-                replInfo ?
+                port,
+                info ?
                     String.format('''
                         (with-open [writer (java.io.FileWriter. "%s")]
                           (binding [*out* writer]
                             (prn (:port server))
                             (flush))))
                         ''',
-                        project.file(replInfo).path.
+                        info.
+                            path.
                             replaceAll("\\\\", "\\\\").
                             replaceAll("\"", "\\\"")) :
                     "")

src/test/groovy/clojuresque/nrepl/TestNReplPlugin.groovy

         then:
         p.startNRepl instanceof StartTask
         p.stopNRepl  instanceof StopTask
-        p.file(p.startNRepl.replInfo) == p.file(p.stopNRepl.replInfo)
+        p.startNRepl.replInfo == p.stopNRepl.replInfo
     }
 }
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.