diff options
Diffstat (limited to 'src/main/groovy/frege')
-rw-r--r-- | src/main/groovy/frege/gradle/FregePlugin.groovy | 18 | ||||
-rw-r--r-- | src/main/groovy/frege/gradle/FregePluginExtension.groovy | 11 | ||||
-rw-r--r-- | src/main/groovy/frege/gradle/FregeTask.groovy | 101 |
3 files changed, 130 insertions, 0 deletions
diff --git a/src/main/groovy/frege/gradle/FregePlugin.groovy b/src/main/groovy/frege/gradle/FregePlugin.groovy new file mode 100644 index 0000000..b509651 --- /dev/null +++ b/src/main/groovy/frege/gradle/FregePlugin.groovy @@ -0,0 +1,18 @@ +package frege.gradle + +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/frege/gradle/FregePluginExtension.groovy b/src/main/groovy/frege/gradle/FregePluginExtension.groovy new file mode 100644 index 0000000..dbf0d2a --- /dev/null +++ b/src/main/groovy/frege/gradle/FregePluginExtension.groovy @@ -0,0 +1,11 @@ +package frege.gradle + +/** + * Created by mperry on 6/02/2015. + */ +class FregePluginExtension { + + + String key1 + +} diff --git a/src/main/groovy/frege/gradle/FregeTask.groovy b/src/main/groovy/frege/gradle/FregeTask.groovy new file mode 100644 index 0000000..fc3152d --- /dev/null +++ b/src/main/groovy/frege/gradle/FregeTask.groovy @@ -0,0 +1,101 @@ +package frege.gradle + +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.* +import org.gradle.process.internal.DefaultJavaExecAction +import org.gradle.process.internal.JavaExecAction +import org.gradle.api.internal.file.FileResolver +import org.gradle.tooling.BuildException + +class FregeTask extends DefaultTask { + + static String DEFAULT_CLASSES_SUBDIR = "classes/main" // TODO: should this come from a convention? + static String DEFAULT_SRC_DIR = "src/main/frege" // TODO: should this come from a source set? + + @Optional @Input + boolean hints = false + + @Optional @Input + boolean verbose = false + + @Optional @Input + boolean inline = true + + @Optional @Input + boolean make = true + + @Optional @Input + boolean skipCompile = false + + @Optional @Input + String extraArgs = "" + + @Optional @Input + String allArgs = "" // this is an option to overrule all other settings + + @Optional @Input + String module = "" + + @Optional @InputDirectory + File sourceDir = new File(project.projectDir, DEFAULT_SRC_DIR).exists() ? new File(project.projectDir, DEFAULT_SRC_DIR) : null + + @Optional @OutputDirectory + File outputDir = new File(project.buildDir, DEFAULT_CLASSES_SUBDIR) + + @TaskAction + void executeCompile() { + if (! outputDir.exists() ) { + logger.info "Creating output directory '${outputDir.absolutePath}'." + outputDir.mkdirs() + } + + // 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)) + + def args = allArgs ? allArgs.split().toList() : assembleArguments() + + logger.info("Calling Frege compiler with args: '$args'") + action.args(args) + action.execute() + } + + protected List assembleArguments() { + List args = [] + if (hints) + args << "-hints" + if (inline) + args << "-inline" + if (make) + args << "-make" + if (verbose) + args << "-v" + if (skipCompile) + args << "-j" + + if (sourceDir != null) { + args << "-sp" + args << sourceDir.absolutePath + } + + args << "-d" + args << outputDir + + if (!module && !extraArgs) { + logger.info "no module and no extra args given: compiling all of the sourceDir" + if (sourceDir != null) { + args << sourceDir.absolutePath + } + + } else if (module) { + logger.info "compiling module '$module'" + args << module + } else { + args = args + extraArgs.split().toList() + } + args + } +}
\ No newline at end of file |