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/frege') 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/frege') 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 --- .../fixtures/AbstractFregeIntegrationSpec.groovy | 68 +++++++++ .../gradle/plugins/FregePluginIntegTest.groovy | 128 ++++++++++++++++ .../gradle/tasks/FregeCompileIntegTest.groovy | 74 ++++++++++ .../frege/plugin/FregePluginIntegTest.groovy | 161 --------------------- .../frege/gradle/plugins/FregeBasePlugin.java | 9 +- .../groovy/frege/gradle/tasks/FregeCompile.groovy | 20 ++- .../groovy/frege/gradle/FregeBasePluginTest.groovy | 31 ---- .../groovy/frege/gradle/FregePluginTest.groovy | 32 ---- .../gradle/plugins/FregeBasePluginTest.groovy | 30 ++++ .../frege/gradle/plugins/FregePluginTest.groovy | 30 ++++ .../frege/gradle/tasks/FregeCompileTest.groovy | 39 +++++ 11 files changed, 391 insertions(+), 231 deletions(-) create mode 100644 src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy create mode 100644 src/integTest/groovy/frege/gradle/plugins/FregePluginIntegTest.groovy create mode 100644 src/integTest/groovy/frege/gradle/tasks/FregeCompileIntegTest.groovy delete mode 100644 src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy delete mode 100644 src/test/groovy/frege/gradle/FregeBasePluginTest.groovy delete mode 100644 src/test/groovy/frege/gradle/FregePluginTest.groovy create mode 100644 src/test/groovy/frege/gradle/plugins/FregeBasePluginTest.groovy create mode 100644 src/test/groovy/frege/gradle/plugins/FregePluginTest.groovy create mode 100644 src/test/groovy/frege/gradle/tasks/FregeCompileTest.groovy (limited to 'src/main/groovy/frege') diff --git a/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy b/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy new file mode 100644 index 0000000..6bcd339 --- /dev/null +++ b/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy @@ -0,0 +1,68 @@ +package frege.gradle.integtest.fixtures + +import org.gradle.testkit.runner.GradleRunner +import org.gradle.testkit.runner.BuildResult +import org.junit.Rule +import org.junit.rules.TemporaryFolder +import spock.lang.Specification + +class AbstractFregeIntegrationSpec extends Specification { + public static final String DEFAULT_FREGE_VERSION = "3.23.370-g898bc8c" + List pluginClasspath + + @Rule + final TemporaryFolder testProjectDir = new TemporaryFolder() + File buildFile + + def setup() { + buildFile = testProjectDir.newFile('build.gradle') + + + testProjectDir.newFolder("src", "main", "java", "org", "frege") + testProjectDir.newFolder("src", "main", "frege", "org", "frege") + + def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.txt") + if (pluginClasspathResource == null) { + // try again via file reference + pluginClasspathResource = new File("build/createClasspathManifest/plugin-classpath.txt") + if (pluginClasspathResource == null) { + throw new IllegalStateException("Did not find plugin classpath resource, run `integTestClasses` build task.") + } + } + pluginClasspath = pluginClasspathResource.readLines().collect { new File(it) } + } + + + BuildResult run(String task) { + run(null, task); + } + + BuildResult run(String gradleVersion, String task) { + def writer = new StringWriter(); + GradleRunner runner = newRunner(task, writer, gradleVersion) + def result = runner.build() + println writer; + return result; + } + + BuildResult fail(String task) { + def writer = new StringWriter(); + GradleRunner runner = newRunner(task, writer, null) + def result = runner.buildAndFail() + println writer; + return result; + } + + private GradleRunner newRunner(String task, StringWriter writer, String gradleVersion) { + def runner = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments(task) + .withPluginClasspath(pluginClasspath) + .forwardStdOutput(writer) + if (gradleVersion) { + runner.withGradleVersion(gradleVersion) + } + runner + } + +} diff --git a/src/integTest/groovy/frege/gradle/plugins/FregePluginIntegTest.groovy b/src/integTest/groovy/frege/gradle/plugins/FregePluginIntegTest.groovy new file mode 100644 index 0000000..e837a2a --- /dev/null +++ b/src/integTest/groovy/frege/gradle/plugins/FregePluginIntegTest.groovy @@ -0,0 +1,128 @@ +package frege.gradle.plugins + +import frege.gradle.integtest.fixtures.AbstractFregeIntegrationSpec +import org.gradle.testkit.runner.BuildResult +import spock.lang.Unroll +import static org.gradle.testkit.runner.TaskOutcome.* + +class FregePluginIntegTest extends AbstractFregeIntegrationSpec { + + def setup() { + buildFile << """ + plugins { + id 'org.frege-lang' + } + + repositories { + jcenter() + } + """ + } + + def "can handle non existing source directories"() { + given: + buildFile << """ + dependencies { + compile "org.frege-lang:frege:$DEFAULT_FREGE_VERSION" + } + """ + + when: + def result = run("classes") + then: + result.task(":compileFrege").outcome == UP_TO_DATE + } + + @Unroll + def "can compile and run frege code (gradle: #gradleVersion, frege: #fregeVersion)"() { + given: + buildFile << """ + dependencies { + compile "org.frege-lang:frege:$fregeVersion" + } + ${sayHelloTask()} + """ + + def fregeSourceFile = testProjectDir.newFile("src/main/frege/org/frege/HelloFrege.fr") + + fregeSourceFile << """ + module org.frege.HelloFrege where + + greeting = "Hello Frege!" + + main _ = do + println greeting + """ + + when: + def result = run(gradleVersion, "sayHello") + + then: + result.output.contains("Hello Frege!") + result.task(":sayHello").outcome == SUCCESS + + where: + fregeVersion | gradleVersion + DEFAULT_FREGE_VERSION | "2.9" + DEFAULT_FREGE_VERSION | "2.8" + "3.22.367-g2737683" | "2.9" + "3.22.367-g2737683" | "2.8" + } + + def "can reference java from frege"() { + given: + buildFile << """ + dependencies { + compile "org.frege-lang:frege:$DEFAULT_FREGE_VERSION" + } + ${sayHelloTask()} + """ + + and: + javaCode() + fregeCallingJava() + when: + BuildResult result = run("sayHello") + then: + result.task(":compileJava").outcome == SUCCESS + result.task(":compileFrege").outcome == SUCCESS + result.output.contains("hello from java") + } + + def fregeCallingJava() { + + File fregeSourceFile = testProjectDir.newFile("src/main/frege/org/frege/HelloFrege.fr") + fregeSourceFile << """ + module org.frege.HelloFrege where + + data StaticHello = pure native org.frege.StaticHello where + pure native helloJava org.frege.StaticHello.helloJava:: () -> String + + + main _ = do + println(StaticHello.helloJava()) + + """ + } + + def javaCode(String sourceRoot = "java") { + def javaSourceFile = testProjectDir.newFile("src/main/$sourceRoot/org/frege/StaticHello.java") + + javaSourceFile << """ + package org.frege; + + public class StaticHello { + public static String helloJava() { + return "hello from java"; + } + } + """ + } + + def sayHelloTask() { + return """ task sayHello(type: JavaExec) { + classpath = sourceSets.main.runtimeClasspath + main = 'org.frege.HelloFrege' + } """ + } +} \ No newline at end of file diff --git a/src/integTest/groovy/frege/gradle/tasks/FregeCompileIntegTest.groovy b/src/integTest/groovy/frege/gradle/tasks/FregeCompileIntegTest.groovy new file mode 100644 index 0000000..58e21ba --- /dev/null +++ b/src/integTest/groovy/frege/gradle/tasks/FregeCompileIntegTest.groovy @@ -0,0 +1,74 @@ +package frege.gradle.tasks +import frege.gradle.integtest.fixtures.AbstractFregeIntegrationSpec + +import static org.gradle.testkit.runner.TaskOutcome.FAILED + +class FregeCompileIntegTest extends AbstractFregeIntegrationSpec { + + List pluginClasspath + + def setup() { + buildFile << """ + plugins { + id 'org.frege-lang.base' + } + + import frege.gradle.tasks.FregeCompile + + repositories { jcenter() } + + configurations { frege {} } + + dependencies { + frege "org.frege-lang:frege:$DEFAULT_FREGE_VERSION" + } + + task compile(type: FregeCompile) { + destinationDir = file("frege-output") + source("frege-src") + module = "frege-src" + classpath = configurations.frege + fregePath = configurations.frege + } + """ + + testProjectDir.newFolder("frege-src") + } + + def "shows compile errors"() { + given: + simpleFrege() + failingFrege() + when: + def result = fail("compile") + + then: + result.task(":compile").outcome == FAILED + result.output.contains("Failing.fr:6: can't resolve `Hello`") + } + + def failingFrege() { + def failingFrege = testProjectDir.newFile("frege-src/Failing.fr") + failingFrege << """ + + module Failing where + + failingFun _ = do + println(Hello) + """ + } + + def simpleFrege() { + + def helloFrege = testProjectDir.newFile("frege-src/Hello.fr") + helloFrege << """ + + module Hello where + + import frege.prelude.PreludeBase + + main _ = do + println("Hello From Frege") + """ + } +} diff --git a/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy b/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy deleted file mode 100644 index 40afe4a..0000000 --- a/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy +++ /dev/null @@ -1,161 +0,0 @@ -package frege.plugin -import org.gradle.testkit.runner.GradleRunner -import org.junit.Rule -import org.junit.rules.TemporaryFolder -import spock.lang.Specification -import spock.lang.Unroll - -import static org.gradle.testkit.runner.TaskOutcome.SUCCESS - -class FregePluginIntegTest extends Specification { - - public static final String DEFAULT_FREGE_VERSION = "3.23.370-g898bc8c" - @Rule - final TemporaryFolder testProjectDir = new TemporaryFolder() - File buildFile - - List pluginClasspath - - def setup() { - buildFile = testProjectDir.newFile('build.gradle') - - buildFile << """ - plugins { - id 'org.frege-lang' - } - - repositories { - jcenter() - } - """ - def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.txt") - if (pluginClasspathResource == null) { - // try again via file reference - pluginClasspathResource = new File("build/createClasspathManifest/plugin-classpath.txt") - if (pluginClasspathResource == null) { - throw new IllegalStateException("Did not find plugin classpath resource, run `integTestClasses` build task.") - } - } - pluginClasspath = pluginClasspathResource.readLines().collect { new File(it) } - } - - def "can handle non existing source directories"() { - given: - buildFile << """ - dependencies { - compile "org.frege-lang:frege:$DEFAULT_FREGE_VERSION" - } - """ - - when: - def result = GradleRunner.create() - .withProjectDir(testProjectDir.root) - .withArguments('classes') - .withPluginClasspath(pluginClasspath) - .build() - then: - result.task(":compileFrege") != null - } - - @Unroll - def "can compile and run frege code (gradle: #gradleVersion, frege: #fregeVersion)"() { - given: - buildFile << """ - dependencies { - compile "org.frege-lang:frege:$fregeVersion" - } - ${sayHelloTask()} - """ - - testProjectDir.newFolder("src", "main", "frege", "org", "frege") - def fregeSourceFile = testProjectDir.newFile("src/main/frege/org/frege/HelloFrege.fr") - - fregeSourceFile << """ -module org.frege.HelloFrege where - -greeting = "Hello Frege!" - -main _ = do - println greeting -""" - - when: - def result = GradleRunner.create() - .withGradleVersion(gradleVersion) - .withProjectDir(testProjectDir.root) - .withArguments('sayHello') - .withPluginClasspath(pluginClasspath) - .build() - - then: - result.output.contains("Hello Frege!") - result.task(":sayHello").outcome == SUCCESS - - where: - fregeVersion | gradleVersion - DEFAULT_FREGE_VERSION | "2.9" - DEFAULT_FREGE_VERSION | "2.8" - "3.22.367-g2737683" | "2.9" - "3.22.367-g2737683" | "2.8" - } - - - def "can reference java from frege"() { - given: - buildFile << """ - dependencies { - compile "org.frege-lang:frege:$DEFAULT_FREGE_VERSION" - } - - ${sayHelloTask()} - """ - - and: - testProjectDir.newFolder("src", "main", "frege", "org", "frege") - - def fregeSourceFile = testProjectDir.newFile("src/main/frege/org/frege/HelloFrege.fr") - - fregeSourceFile << """ -module org.frege.HelloFrege where - -data StaticHello = pure native org.frege.StaticHello where - pure native helloJava org.frege.StaticHello.helloJava :: () -> String - -main _ = do - println(StaticHello.helloJava()) - -""" - testProjectDir.newFolder("src", "main", "java", "org", "frege") - def javaSourceFile = testProjectDir.newFile("src/main/java/org/frege/StaticHello.java") - - javaSourceFile << """ -package org.frege; - -public class StaticHello { - public static String helloJava() { - return "hello from java"; - } -} -""" - - when: - def result = GradleRunner.create() - .withProjectDir(testProjectDir.root) - .withArguments('sayHello') - .withPluginClasspath(pluginClasspath) - .build() - then: - result.task(":compileJava").outcome == SUCCESS - result.task(":compileFrege").outcome == SUCCESS - - result.output.contains("hello from java") - } - - - def sayHelloTask() { - return """task sayHello(type: JavaExec){ - classpath = sourceSets.main.runtimeClasspath - main = 'org.frege.HelloFrege' - }""" - } -} \ No newline at end of file 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'" diff --git a/src/test/groovy/frege/gradle/FregeBasePluginTest.groovy b/src/test/groovy/frege/gradle/FregeBasePluginTest.groovy deleted file mode 100644 index 3ca1bb2..0000000 --- a/src/test/groovy/frege/gradle/FregeBasePluginTest.groovy +++ /dev/null @@ -1,31 +0,0 @@ -package frege.gradle - -import frege.gradle.plugins.FregeBasePlugin -import org.gradle.api.Project -import org.gradle.testfixtures.ProjectBuilder -import spock.lang.Specification - -public class FregeBasePluginTest extends Specification { - - Project project = ProjectBuilder.builder().build() - - def setup(){ - when: - project.plugins.apply(FregeBasePlugin) - } - - def "adds frege extension"(){ - expect: - project.getExtensions().getByName(FregeBasePlugin.EXTENSION_NAME) != null - } - - def "applies java base plugin"(){ - expect: - project.pluginManager.hasPlugin("java-base") - } - - def "can be identified by id"(){ - expect: - project.pluginManager.hasPlugin("org.frege-lang.base") - } -} \ No newline at end of file diff --git a/src/test/groovy/frege/gradle/FregePluginTest.groovy b/src/test/groovy/frege/gradle/FregePluginTest.groovy deleted file mode 100644 index 2fc6d86..0000000 --- a/src/test/groovy/frege/gradle/FregePluginTest.groovy +++ /dev/null @@ -1,32 +0,0 @@ -package frege.gradle - -import frege.gradle.plugins.FregeBasePlugin -import frege.gradle.plugins.FregePlugin -import org.gradle.api.Project -import org.gradle.testfixtures.ProjectBuilder -import spock.lang.Specification - -class FregePluginTest extends Specification { - - Project project = ProjectBuilder.builder().build() - - def setup(){ - when: - project.plugins.apply(FregePlugin) - } - - def "adds frege extension"(){ - expect: - project.getExtensions().getByName(FregeBasePlugin.EXTENSION_NAME) != null - } - - def "applies frege base plugin"() { - expect: - project.pluginManager.findPlugin("org.frege-lang.base") != null - } - - def "can be identified by id"(){ - expect: - project.pluginManager.hasPlugin("org.frege-lang") - } -} diff --git a/src/test/groovy/frege/gradle/plugins/FregeBasePluginTest.groovy b/src/test/groovy/frege/gradle/plugins/FregeBasePluginTest.groovy new file mode 100644 index 0000000..04b5587 --- /dev/null +++ b/src/test/groovy/frege/gradle/plugins/FregeBasePluginTest.groovy @@ -0,0 +1,30 @@ +package frege.gradle.plugins + +import org.gradle.api.Project +import org.gradle.testfixtures.ProjectBuilder +import spock.lang.Specification + +public class FregeBasePluginTest extends Specification { + + Project project = ProjectBuilder.builder().build() + + def setup(){ + when: + project.plugins.apply(FregeBasePlugin) + } + + def "adds frege extension"(){ + expect: + project.getExtensions().getByName(FregeBasePlugin.EXTENSION_NAME) != null + } + + def "applies java base plugin"(){ + expect: + project.pluginManager.hasPlugin("java-base") + } + + def "can be identified by id"(){ + expect: + project.pluginManager.hasPlugin("org.frege-lang.base") + } +} \ No newline at end of file diff --git a/src/test/groovy/frege/gradle/plugins/FregePluginTest.groovy b/src/test/groovy/frege/gradle/plugins/FregePluginTest.groovy new file mode 100644 index 0000000..1867c88 --- /dev/null +++ b/src/test/groovy/frege/gradle/plugins/FregePluginTest.groovy @@ -0,0 +1,30 @@ +package frege.gradle.plugins + +import org.gradle.api.Project +import org.gradle.testfixtures.ProjectBuilder +import spock.lang.Specification + +class FregePluginTest extends Specification { + + Project project = ProjectBuilder.builder().build() + + def setup(){ + when: + project.plugins.apply(FregePlugin) + } + + def "adds frege extension"(){ + expect: + project.getExtensions().getByName(FregeBasePlugin.EXTENSION_NAME) != null + } + + def "applies frege base plugin"() { + expect: + project.pluginManager.findPlugin("org.frege-lang.base") != null + } + + def "can be identified by id"(){ + expect: + project.pluginManager.hasPlugin("org.frege-lang") + } +} diff --git a/src/test/groovy/frege/gradle/tasks/FregeCompileTest.groovy b/src/test/groovy/frege/gradle/tasks/FregeCompileTest.groovy new file mode 100644 index 0000000..c9224ea --- /dev/null +++ b/src/test/groovy/frege/gradle/tasks/FregeCompileTest.groovy @@ -0,0 +1,39 @@ +package frege.gradle.tasks + +import org.gradle.api.Project +import org.gradle.testfixtures.ProjectBuilder +import spock.lang.Specification + +class FregeCompileTest extends Specification { + Project project = ProjectBuilder.builder().build() + FregeCompile compile + + def setup() { + when: + compile = project.tasks.create("fregeCompile", FregeCompile) + } + + + def "configured sourcePaths tracked"() { + when: + compile.source("someFolder") + then: + compile.sourcePaths == [project.file("someFolder")] + } + + + def "default assembleArguments"() { + given: + compile.destinationDir = project.file("testoutput") + expect: + compile.assembleArguments() == ["-inline", "-make", "-d", project.file("testoutput").absolutePath] + } + + def "with prefix"() { + given: + compile.destinationDir = project.file("testoutput") + compile.prefix = "somePrefix" + expect: + compile.assembleArguments() == ["-inline", "-make", "-prefix", "somePrefix", "-d", project.file("testoutput").absolutePath] + } +} -- 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 --- .../groovy/frege/gradle/tasks/FregeCompileIntegTest.groovy | 2 +- src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java | 2 +- src/main/groovy/frege/gradle/tasks/FregeCompile.groovy | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/main/groovy/frege') diff --git a/src/integTest/groovy/frege/gradle/tasks/FregeCompileIntegTest.groovy b/src/integTest/groovy/frege/gradle/tasks/FregeCompileIntegTest.groovy index 58e21ba..3845e23 100644 --- a/src/integTest/groovy/frege/gradle/tasks/FregeCompileIntegTest.groovy +++ b/src/integTest/groovy/frege/gradle/tasks/FregeCompileIntegTest.groovy @@ -28,7 +28,7 @@ class FregeCompileIntegTest extends AbstractFregeIntegrationSpec { source("frege-src") module = "frege-src" classpath = configurations.frege - fregePath = configurations.frege + fregepath = configurations.frege } """ 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