summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDierk Koenig <dierk.koenig@canoo.com>2015-02-24 00:23:56 +0100
committerDierk Koenig <dierk.koenig@canoo.com>2015-02-24 00:23:56 +0100
commit27e2877f5b31b6c1fa387a46c20dc4cd40227ca5 (patch)
treef34476c6520eb23815da5c2c8a63584b96c6ed6c
parent4f32ab3ae5f7f8ef5ef1f5efdc0a5efdeaad8d53 (diff)
downloadfrege-gradle-plugin-27e2877f5b31b6c1fa387a46c20dc4cd40227ca5.tar.gz
frege-gradle-plugin-27e2877f5b31b6c1fa387a46c20dc4cd40227ca5.tar.bz2
frege-gradle-plugin-27e2877f5b31b6c1fa387a46c20dc4cd40227ca5.zip
adding a task openFregeRepl that opens the repl with the current compile classpath on the source directory. Since the repl dependencies cannot be loaded from mavenCentral, one has to set the replDir where the download is. Default is <user.home>/.frege/repl
-rw-r--r--build.gradle1
-rw-r--r--src/main/groovy/org/gradle/frege/FregePlugin.groovy4
-rw-r--r--src/main/groovy/org/gradle/frege/FregeReplTask.groovy60
-rw-r--r--todo.txt2
4 files changed, 67 insertions, 0 deletions
diff --git a/build.gradle b/build.gradle
index 1ff2833..46699f6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -27,5 +27,6 @@ dependencies {
compile "com.theoryinpractise.frege:frege:$fregeVersion$fregeClassifier"
compile gradleApi()
compile localGroovy()
+
}
diff --git a/src/main/groovy/org/gradle/frege/FregePlugin.groovy b/src/main/groovy/org/gradle/frege/FregePlugin.groovy
index a401eb7..16bcecf 100644
--- a/src/main/groovy/org/gradle/frege/FregePlugin.groovy
+++ b/src/main/groovy/org/gradle/frege/FregePlugin.groovy
@@ -13,6 +13,10 @@ class FregePlugin implements Plugin<Project> {
}
project.tasks.classes.dependsOn("compileFrege")
+
+ def oFR = project.task('openFregeRepl', type: FregeReplTask, group: 'Runtime', dependsOn: 'classes')
+ oFR.outputs.upToDateWhen { false }
+
}
}
diff --git a/src/main/groovy/org/gradle/frege/FregeReplTask.groovy b/src/main/groovy/org/gradle/frege/FregeReplTask.groovy
new file mode 100644
index 0000000..03ac78d
--- /dev/null
+++ b/src/main/groovy/org/gradle/frege/FregeReplTask.groovy
@@ -0,0 +1,60 @@
+package org.gradle.frege
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.internal.file.FileResolver
+import org.gradle.api.tasks.*
+import org.gradle.process.internal.DefaultJavaExecAction
+import org.gradle.process.internal.JavaExecAction
+
+import javax.management.relation.Relation
+
+class FregeReplTask extends DefaultTask {
+
+ static String DEFAULT_SRC_DIR = "src/main/frege" // TODO: should this come from a source set?
+
+ @Optional @InputDirectory
+ File replDir
+
+ @Optional @InputDirectory
+ File sourceDir = new File(project.projectDir, DEFAULT_SRC_DIR)
+
+ @TaskAction
+ void openFregeRepl() {
+
+ if (! replDir) replDir = new File(System.properties.'user.home'.toString(), "/.frege/repl")
+
+ def replJarFileNames = []
+
+ if (! replDir.exists() ) {
+ throw new StopActionException("REPL installation directory '${replDir.absolutePath}' does not exist. Cannot start the REPL.")
+ }
+
+ replDir.eachFileRecurse { file ->
+ if (file.name ==~ /^(frege-|ecj-|jline).*\.jar$/) {
+ replJarFileNames << file.absolutePath
+ }
+ }
+ logger.debug "repl installation jar file names are ${replJarFileNames}"
+
+ if (replJarFileNames.size() < 6) {
+ throw new StopActionException("Found only ${replJarFileNames.size()} jars in REPL installation directory '${replDir.absolutePath}'. Cannot start the REPL.")
+ }
+
+ if (! sourceDir.exists() ) {
+ def currentDir = new File('.')
+ logger.info "Intended source dir '${sourceDir.absolutePath}' doesn't exist. Using current dir '${currentDir.absolutePath}' ."
+ sourceDir = currentDir
+ }
+
+
+ FileResolver fileResolver = getServices().get(FileResolver.class)
+ JavaExecAction action = new DefaultJavaExecAction(fileResolver)
+ action.setMain("frege.repl.FregeRepl")
+ action.workingDir = sourceDir
+ action.standardInput = System.in
+ action.setClasspath(project.files(project.configurations.compile , *replJarFileNames))
+
+ action.execute()
+ }
+
+} \ No newline at end of file
diff --git a/todo.txt b/todo.txt
new file mode 100644
index 0000000..027fb84
--- /dev/null
+++ b/todo.txt
@@ -0,0 +1,2 @@
+- add task for QuickCheck
+- add task for FregeDoc \ No newline at end of file