From ab07b29c22a0979ddfce1d5fde9150996e6a5345 Mon Sep 17 00:00:00 2001 From: Galder ZamarrenĖƒo Date: Thu, 17 Oct 2013 21:39:24 +0200 Subject: Reshuffle to make plugin a first level project --- src/main/frege/HelloWorld.fr | 2 - .../groovy/org/gradle/frege/FregePlugin.groovy | 13 ++++ src/main/groovy/org/gradle/frege/FregeTask.groovy | 77 ++++++++++++++++++++++ .../META-INF/gradle-plugins/frege.properties | 1 + 4 files changed, 91 insertions(+), 2 deletions(-) delete mode 100644 src/main/frege/HelloWorld.fr create mode 100644 src/main/groovy/org/gradle/frege/FregePlugin.groovy create mode 100644 src/main/groovy/org/gradle/frege/FregeTask.groovy create mode 100644 src/main/resources/META-INF/gradle-plugins/frege.properties (limited to 'src') 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 { + + 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 -- cgit