From 10e0ef10c68db0dde1c3aec0fc074f161024b643 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Sat, 21 Nov 2015 20:06:06 +0000 Subject: remove optional annotations for property that are not optional but configurable --- .../groovy/frege/gradle/tasks/FregeCompile.groovy | 33 ---------------------- 1 file changed, 33 deletions(-) (limited to 'src/main/groovy') diff --git a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy index 13b617c..d39f15f 100644 --- a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy +++ b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy @@ -1,8 +1,6 @@ package frege.gradle.tasks import groovy.transform.TypeChecked -import groovy.transform.TypeCheckingMode import org.gradle.api.Action -import org.gradle.api.artifacts.Configuration import org.gradle.api.file.FileCollection import org.gradle.api.tasks.Input import org.gradle.api.tasks.Optional @@ -19,59 +17,44 @@ class FregeCompile extends AbstractCompile { @Input String stackSize = "4m" - @Optional @Input boolean hints = false - @Optional @Input boolean optimize = false - @Optional - @Input boolean verbose = false - @Optional @Input boolean inline = true - @Optional @Input boolean make = true - @Optional @Input boolean compileGeneratedJava = true - @Optional @Input String target = "" - @Optional @Input boolean comments = false - @Optional @Input boolean suppressWarnings = false - @Optional @Input String explain = "" - @Optional @Input String extraArgs = "" - @Optional @Input String allArgs = "" // this is an option to overrule all other settings - @Optional @Input String module = "" - @Optional @Input List fregePaths = [] @@ -82,11 +65,9 @@ class FregeCompile extends AbstractCompile { @Input List allJvmArgs = [] - @Optional @Input String encoding = "" - @Optional @Input String prefix = "" @@ -95,8 +76,6 @@ class FregeCompile extends AbstractCompile { @Override @TaskAction protected void compile() { - logConfigurationInfo() - def jvmArgs = allJvmArgs if (jvmArgs.isEmpty()) { jvmArgs << "-Xss$stackSize".toString() @@ -125,16 +104,6 @@ class FregeCompile extends AbstractCompile { return this; } - void logConfigurationInfo() { - def path = project.files(compileConfig()).getAsPath() - logger.info("Compile configuation as path: $path") - } - - @TypeChecked(TypeCheckingMode.SKIP) - Configuration compileConfig() { - project.configurations.compile - } - protected List assembleArguments() { List args = [] if (hints) @@ -191,8 +160,6 @@ class FregeCompile extends AbstractCompile { } else { args = (args + extraArgs.split().toList()).toList() } - args } - } -- cgit From 3bbf59cb3e080b9abcdf82d1c82e36337ea01ed1 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Sat, 21 Nov 2015 21:16:18 +0000 Subject: simplify implementation and remove use of internal api that is shaded by classloader --- .../frege/gradle/plugins/FregeBasePlugin.java | 19 +------ .../groovy/frege/gradle/plugins/FregeJarFile.java | 34 ------------ .../groovy/frege/gradle/plugins/FregeRuntime.java | 63 ---------------------- .../groovy/frege/gradle/tasks/FregeCompile.groovy | 3 +- 4 files changed, 2 insertions(+), 117 deletions(-) delete mode 100644 src/main/groovy/frege/gradle/plugins/FregeJarFile.java delete mode 100644 src/main/groovy/frege/gradle/plugins/FregeRuntime.java (limited to 'src/main/groovy') diff --git a/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java b/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java index 8bf5399..9f8ebd9 100644 --- a/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java +++ b/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java @@ -15,7 +15,6 @@ import org.gradle.api.specs.Spec; import org.gradle.api.tasks.SourceSet; import javax.inject.Inject; -import java.util.concurrent.Callable; public class FregeBasePlugin implements Plugin { private FileResolver fileResolver; @@ -30,15 +29,13 @@ public class FregeBasePlugin implements Plugin { } @Override - public void apply(Project project) { + public void apply(final Project project) { // Workaround to build proper jars on Windows, see https://github.com/Frege/frege-gradle-plugin/issues/9 this.project = project; System.setProperty("file.encoding", "UTF-8"); project.getPluginManager().apply(JavaBasePlugin.class); fregePluginExtension = project.getExtensions().create(EXTENSION_NAME, FregePluginExtension.class); JavaBasePlugin javaBasePlugin = project.getPlugins().getPlugin(JavaBasePlugin.class); - - configureCompileDefaults(new FregeRuntime(project)); configureSourceSetDefaults(javaBasePlugin); } @@ -70,18 +67,4 @@ public class FregeBasePlugin implements Plugin { } }); } - - private void configureCompileDefaults(final FregeRuntime fregeRuntime) { - this.project.getTasks().withType(FregeCompile.class, new Action() { - public void execute(final FregeCompile compile) { - compile.getConventionMapping().map("fregeClasspath", new Callable() { - public Object call() throws Exception { - return fregeRuntime.inferFregeClasspath(compile.getClasspath()); - } - - }); - } - }); - } - } diff --git a/src/main/groovy/frege/gradle/plugins/FregeJarFile.java b/src/main/groovy/frege/gradle/plugins/FregeJarFile.java deleted file mode 100644 index eaf7d8f..0000000 --- a/src/main/groovy/frege/gradle/plugins/FregeJarFile.java +++ /dev/null @@ -1,34 +0,0 @@ -package frege.gradle.plugins; - -import org.gradle.util.VersionNumber; - -import java.io.File; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class FregeJarFile { - private static final Pattern FILE_NAME_PATTERN = Pattern.compile("(frege(?:-all)?)-(\\d.*?)(-indy)?.jar"); - private final File file; - private final Matcher matcher; - private String version; - - private FregeJarFile(File file, Matcher matcher) { - this.file = file; - this.matcher = matcher; - } - - - public static FregeJarFile parse(File file) { - Matcher matcher = FILE_NAME_PATTERN.matcher(file.getName()); - return matcher.matches() ? new FregeJarFile(file, matcher) : null; - } - - public String getDependencyNotation() { - return "org.frege-lang:frege:" + getVersion(); - - } - - public VersionNumber getVersion() { - return VersionNumber.parse(matcher.group(2)); - } -} diff --git a/src/main/groovy/frege/gradle/plugins/FregeRuntime.java b/src/main/groovy/frege/gradle/plugins/FregeRuntime.java deleted file mode 100644 index 4265d0b..0000000 --- a/src/main/groovy/frege/gradle/plugins/FregeRuntime.java +++ /dev/null @@ -1,63 +0,0 @@ -package frege.gradle.plugins; - -import com.google.common.collect.Lists; -import org.gradle.api.Buildable; -import org.gradle.api.GradleException; -import org.gradle.api.Project; -import org.gradle.api.artifacts.Dependency; -import org.gradle.api.file.FileCollection; -import org.gradle.api.internal.file.collections.LazilyInitializedFileCollection; -import org.gradle.api.internal.tasks.TaskDependencyResolveContext; - -import java.io.File; -import java.util.List; - -public class FregeRuntime { - - private final Project project; - - public FregeRuntime(Project project) { - this.project = project; - } - - - public FileCollection inferFregeClasspath(final Iterable classpath) { - return new LazilyInitializedFileCollection() { - public String getDisplayName() { - return "Frege runtime classpath"; - } - - public FileCollection createDelegate() { - final FregeJarFile fregeJar = FregeRuntime.this.findFregeJarFile(classpath); - if (fregeJar == null) { - throw new GradleException(String.format("Cannot infer Frege class path because no Frege Jar was found on class path: %s", classpath)); - } - String notation = fregeJar.getDependencyNotation(); - List dependencies = Lists.newArrayList(); - dependencies.add(project.getDependencies().create(notation)); - return project.getConfigurations().detachedConfiguration(dependencies.toArray(new Dependency[dependencies.size()])); - } - - public void visitDependencies(TaskDependencyResolveContext context) { - if (classpath instanceof Buildable) { - context.add(classpath); - } - } - - }; - } - - private FregeJarFile findFregeJarFile(Iterable classpath) { - if (classpath == null) { - return null; - } - for (File file : classpath) { - FregeJarFile fregeJar = FregeJarFile.parse(file); - if (fregeJar != null) { - return fregeJar; - } - } - return null; - } - -} diff --git a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy index d39f15f..3da2b34 100644 --- a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy +++ b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy @@ -11,7 +11,6 @@ import org.gradle.process.JavaExecSpec @TypeChecked class FregeCompile extends AbstractCompile { - FileCollection fregeClasspath FileCollection classpath @Input @@ -89,7 +88,7 @@ class FregeCompile extends AbstractCompile { @Override void execute(JavaExecSpec javaExecSpec) { javaExecSpec.args = compilerArgs - javaExecSpec.classpath = FregeCompile.this.classpath + FregeCompile.this.fregeClasspath + javaExecSpec.classpath = FregeCompile.this.classpath javaExecSpec.main = mainClass } }); -- cgit From fdc7b27d69b22e0ffa151d56c8f3812dcd229555 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Sun, 22 Nov 2015 00:50:45 +0000 Subject: some more work on coverage and some cleanup - get packages for integ tests right - introduce common AbstractFregeIntegrationSpec - first stab of unit test coverage for FregeCompile - minor cleanup on FregeCompile - configure fregePath as part as part of base plugin convention --- .../groovy/frege/gradle/plugins/FregeBasePlugin.java | 9 ++++++++- .../groovy/frege/gradle/tasks/FregeCompile.groovy | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) (limited to 'src/main/groovy') diff --git a/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java b/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java index 9f8ebd9..7ced11b 100644 --- a/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java +++ b/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java @@ -15,6 +15,7 @@ import org.gradle.api.specs.Spec; import org.gradle.api.tasks.SourceSet; import javax.inject.Inject; +import java.util.concurrent.Callable; public class FregeBasePlugin implements Plugin { private FileResolver fileResolver; @@ -42,7 +43,7 @@ public class FregeBasePlugin implements Plugin { private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) { project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action() { - public void execute(SourceSet sourceSet) { + public void execute(final SourceSet sourceSet) { final DefaultFregeSourceSet fregeSourceSet = new DefaultFregeSourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), fileResolver); new DslObject(sourceSet).getConvention().getPlugins().put("frege", fregeSourceSet); @@ -60,6 +61,12 @@ public class FregeBasePlugin implements Plugin { FregeCompile compile = project.getTasks().create(compileTaskName, FregeCompile.class); compile.setModule(project.file(defaultSourcePath).getAbsolutePath()); javaBasePlugin.configureForSourceSet(sourceSet, compile); + compile.getConventionMapping().map("classpath", new Callable() { + public Object call() throws Exception { + return sourceSet.getCompileClasspath(); + } + }); + compile.dependsOn(sourceSet.getCompileJavaTaskName()); compile.setDescription(String.format("Compiles the %s Frege source.", sourceSet.getName())); compile.setSource(fregeSourceSet.getFrege()); diff --git a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy index 3da2b34..8c63df6 100644 --- a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy +++ b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy @@ -1,8 +1,10 @@ package frege.gradle.tasks + import groovy.transform.TypeChecked import org.gradle.api.Action import org.gradle.api.file.FileCollection import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Optional import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.compile.AbstractCompile @@ -54,8 +56,8 @@ class FregeCompile extends AbstractCompile { @Input String module = "" - @Input - List fregePaths = [] + @Optional @InputFiles + FileCollection fregePath @Input String mainClass = "frege.compiler.Main" @@ -84,14 +86,20 @@ class FregeCompile extends AbstractCompile { logger.info("Calling Frege compiler with compilerArgs: '$compilerArgs'") //TODO integrate with gradle compiler daemon infrastructure and skip internal execution + + def errOutputStream = new ByteArrayOutputStream(); + def outOutputStream = new ByteArrayOutputStream(); project.javaexec(new Action() { @Override void execute(JavaExecSpec javaExecSpec) { javaExecSpec.args = compilerArgs javaExecSpec.classpath = FregeCompile.this.classpath javaExecSpec.main = mainClass + javaExecSpec.errorOutput = System.err; + javaExecSpec.standardOutput = System.out; } }); + } public FregeCompile source(Object... sources) { @@ -129,10 +137,10 @@ class FregeCompile extends AbstractCompile { if (verbose) args << "-v" - def fp = fregePaths - if (!fp.isEmpty()) { + + if (fregePath != null && !fregePath.isEmpty()) { args << "-fp" - args << fp.collect { f -> f.absolutePath }.join(File.pathSeparator) + args << fregePath.files.collect { f -> f.absolutePath }.join(File.pathSeparator) } if (sourcePaths != null && !sourcePaths.isEmpty()) { @@ -151,7 +159,7 @@ class FregeCompile extends AbstractCompile { } args << "-d" - args << getDestinationDir() + args << getDestinationDir().absolutePath if (!module.isEmpty()) { logger.info "compiling module '$module'" -- cgit From 61196dfe58d3fd38f09c3ddfbcc8cb932d240c1e Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Sun, 22 Nov 2015 00:58:41 +0000 Subject: fix fregepath handling --- src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java | 2 +- src/main/groovy/frege/gradle/tasks/FregeCompile.groovy | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/main/groovy') diff --git a/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java b/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java index 7ced11b..a2ebc25 100644 --- a/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java +++ b/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java @@ -61,7 +61,7 @@ public class FregeBasePlugin implements Plugin { FregeCompile compile = project.getTasks().create(compileTaskName, FregeCompile.class); compile.setModule(project.file(defaultSourcePath).getAbsolutePath()); javaBasePlugin.configureForSourceSet(sourceSet, compile); - compile.getConventionMapping().map("classpath", new Callable() { + compile.getConventionMapping().map("fregepath", new Callable() { public Object call() throws Exception { return sourceSet.getCompileClasspath(); } diff --git a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy index 8c63df6..290f750 100644 --- a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy +++ b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy @@ -57,7 +57,7 @@ class FregeCompile extends AbstractCompile { String module = "" @Optional @InputFiles - FileCollection fregePath + FileCollection fregepath @Input String mainClass = "frege.compiler.Main" @@ -138,9 +138,9 @@ class FregeCompile extends AbstractCompile { args << "-v" - if (fregePath != null && !fregePath.isEmpty()) { + if (fregepath != null && !fregepath.isEmpty()) { args << "-fp" - args << fregePath.files.collect { f -> f.absolutePath }.join(File.pathSeparator) + args << fregepath.files.collect { f -> f.absolutePath }.join(File.pathSeparator) } if (sourcePaths != null && !sourcePaths.isEmpty()) { -- cgit