summaryrefslogtreecommitdiff
path: root/src/main/groovy
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/groovy')
-rw-r--r--src/main/groovy/org/gradle/frege/FregePlugin.groovy13
-rw-r--r--src/main/groovy/org/gradle/frege/FregeTask.groovy77
2 files changed, 90 insertions, 0 deletions
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