diff options
Diffstat (limited to 'src')
4 files changed, 138 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..a401eb7 --- /dev/null +++ b/src/main/groovy/org/gradle/frege/FregePlugin.groovy @@ -0,0 +1,18 @@ +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') + def e = (FregePluginExtension) project.extensions.create("frege", FregePluginExtension) + + project.task('compileFrege', type: FregeTask, group: 'Build') << { + + } + project.tasks.classes.dependsOn("compileFrege") + } + +} diff --git a/src/main/groovy/org/gradle/frege/FregePluginExtension.groovy b/src/main/groovy/org/gradle/frege/FregePluginExtension.groovy new file mode 100644 index 0000000..db81a41 --- /dev/null +++ b/src/main/groovy/org/gradle/frege/FregePluginExtension.groovy @@ -0,0 +1,11 @@ +package org.gradle.frege + +/** + * Created by mperry on 6/02/2015. + */ +class FregePluginExtension { + + + String key1 + +} 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..db2726e --- /dev/null +++ b/src/main/groovy/org/gradle/frege/FregeTask.groovy @@ -0,0 +1,108 @@ +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?$/ + + static String DEFAULT_CLASSES_DIR = "build/classes/main" + static String DEFAULT_SRC_DIR = "src/main/frege" + + @Input + boolean hints = false + + @Input + boolean verbose = false + + @Input + boolean inline = false + + @Input + boolean make = true + + @Input + boolean skipCompile = false + + @Input + boolean includeStale + + @Input + String extraArgs = "" + + @Input + String allArgs = "" + + // TODO: Find default + @OutputDirectory + File outputDir = new File(project.projectDir, DEFAULT_CLASSES_DIR) + + @TaskAction + void executeCompile() { + println "Compiling Frege to " + outputDir + // access extension configuration values as ${project.frege.key1} + + 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 (allArgs != "") { + args = allArgs.split().toList() + } else { + + if (hints) + args << "-hints" + if (inline) + args << "-inline" + if (make) + args << "-make" + if (verbose) + args << "-v" + if (skipCompile) + args << "-j" + + args << "-d" + args << outputDir + + args = args + extraArgs.split().toList() + } + + def dir = project.projectDir + println("FregeTask projectDir: $dir") + eachFileRecurse(new File(dir, DEFAULT_SRC_DIR)) { File file -> + if (file.name =~ FREGE_FILE_EXTENSION_PATTERN) { + args << file + } + } + + + println("Creating output dir: ${outputDir.absolutePath}") + outputDir.mkdir() +// outputDir.mkdirs() + + println("FregeTask args: $args") + 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 |