aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGalder Zamarreño <galder@zamarreno.com>2013-10-17 21:39:24 +0200
committerGalder Zamarreño <galder@zamarreno.com>2013-10-17 21:39:24 +0200
commitab07b29c22a0979ddfce1d5fde9150996e6a5345 (patch)
tree3e9ee0db0bdc6eb1c15c0a80d57b5b9e15cf3cd8 /src/main
parentc0295b839de7c2c2a32c0e32fea7a58fd893383f (diff)
downloadfrege-gradle-plugin-ab07b29c22a0979ddfce1d5fde9150996e6a5345.tar.gz
frege-gradle-plugin-ab07b29c22a0979ddfce1d5fde9150996e6a5345.tar.bz2
frege-gradle-plugin-ab07b29c22a0979ddfce1d5fde9150996e6a5345.zip
Reshuffle to make plugin a first level project
Diffstat (limited to 'src/main')
-rw-r--r--src/main/frege/HelloWorld.fr2
-rw-r--r--src/main/groovy/org/gradle/frege/FregePlugin.groovy13
-rw-r--r--src/main/groovy/org/gradle/frege/FregeTask.groovy77
-rw-r--r--src/main/resources/META-INF/gradle-plugins/frege.properties1
4 files changed, 91 insertions, 2 deletions
diff --git a/src/main/frege/HelloWorld.fr b/src/main/frege/HelloWorld.fr
deleted file mode 100644
index c47a6f2..0000000
--- a/src/main/frege/HelloWorld.fr
+++ /dev/null
@@ -1,2 +0,0 @@
-module HelloWorld where
-main _ = println "Hello World" \ No newline at end of file
diff --git a/src/main/groovy/org/gradle/frege/FregePlugin.groovy b/src/main/groovy/org/gradle/frege/FregePlugin.groovy
new file mode 100644
index 0000000..93c5f26
--- /dev/null
+++ b/src/main/groovy/org/gradle/frege/FregePlugin.groovy
@@ -0,0 +1,13 @@
+package org.gradle.frege
+
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+
+class FregePlugin implements Plugin<Project> {
+
+ void apply(Project project) {
+ project.apply(plugin: 'base')
+ project.task('compileFrege', type: FregeTask, group: 'Build')
+ }
+
+}
diff --git a/src/main/groovy/org/gradle/frege/FregeTask.groovy b/src/main/groovy/org/gradle/frege/FregeTask.groovy
new file mode 100644
index 0000000..26598b9
--- /dev/null
+++ b/src/main/groovy/org/gradle/frege/FregeTask.groovy
@@ -0,0 +1,77 @@
+package org.gradle.frege
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.GradleException
+import org.gradle.api.InvalidUserDataException
+import org.gradle.api.tasks.*
+import org.gradle.process.internal.DefaultJavaExecAction
+import org.gradle.process.internal.JavaExecAction
+import org.gradle.api.internal.file.FileResolver
+
+class FregeTask extends DefaultTask {
+
+ private static final FREGE_FILE_EXTENSION_PATTERN = ~/.*\.fr?$/
+
+ @Input boolean hints
+
+ @Input boolean verbose
+
+ @Input boolean inline = true
+
+ @Input boolean make = true
+
+ @Input boolean skipCompile
+
+ @Input boolean includeStale
+
+ // TODO: Find default
+ @OutputDirectory File outputDir = new File("build/classes")
+
+ @TaskAction
+ void executeCompile() {
+ println "Compiling Frege to " + outputDir
+
+ FileResolver fileResolver = getServices().get(FileResolver.class)
+ JavaExecAction action = new DefaultJavaExecAction(fileResolver)
+ action.setMain("frege.compiler.Main")
+ action.setClasspath(project.files(project.configurations.compile))
+
+ List args = []
+ if (hints)
+ args << "-hints"
+ if (inline)
+ args << "-inline"
+ if (make)
+ args << "-make"
+ if (verbose)
+ args << "-v"
+ if (skipCompile)
+ args << "-j"
+
+ args << "-d"
+ args << outputDir
+
+
+ eachFileRecurse(new File("src/main/frege")) { File file ->
+ if (file.name =~ FREGE_FILE_EXTENSION_PATTERN) {
+ args << file
+ }
+
+ }
+
+ action.args(args)
+
+ action.execute()
+ }
+
+ private static void eachFileRecurse(File dir, Closure fileProcessor) {
+ dir.eachFile { File file ->
+ if (file.directory) {
+ eachFileRecurse(file, fileProcessor)
+ } else {
+ fileProcessor(file)
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/main/resources/META-INF/gradle-plugins/frege.properties b/src/main/resources/META-INF/gradle-plugins/frege.properties
new file mode 100644
index 0000000..cc3210c
--- /dev/null
+++ b/src/main/resources/META-INF/gradle-plugins/frege.properties
@@ -0,0 +1 @@
+implementation-class=org.gradle.frege.FregePlugin