From f3d085304bad105e65ce0c77f25ae59161fd8776 Mon Sep 17 00:00:00 2001 From: Thibault Gagnaux Date: Mon, 28 Jun 2021 11:10:10 +0200 Subject: Inits branch with a simple groovy test --- .../fixtures/AbstractFregeIntegrationSpec.groovy | 67 ------- .../gradle/plugins/FregePluginIntegTest.groovy | 208 -------------------- .../gradle/tasks/FregeCompileIntegTest.groovy | 106 ---------- .../groovy/frege/gradle/DefaultFregeSourceSet.java | 31 --- .../frege/gradle/FregeSourceDirectorySet.groovy | 26 --- src/main/groovy/frege/gradle/FregeSourceSet.java | 8 - .../gradle/FregeSourceSetDirectoryFactory.groovy | 30 --- .../frege/gradle/FregeSourceSetOutputs.groovy | 7 - .../frege/gradle/plugins/FregeBasePlugin.java | 87 --------- .../groovy/frege/gradle/plugins/FregePlugin.groovy | 44 ----- .../gradle/plugins/FregePluginExtension.groovy | 11 -- .../groovy/frege/gradle/tasks/FregeCompile.groovy | 214 --------------------- src/main/groovy/frege/gradle/tasks/FregeDoc.groovy | 86 --------- .../frege/gradle/tasks/FregeNativeGen.groovy | 61 ------ .../frege/gradle/tasks/FregeQuickCheck.groovy | 93 --------- .../groovy/frege/gradle/tasks/FregeRepl.groovy | 40 ---- .../gradle-plugins/org.frege-lang.base.properties | 1 - .../gradle-plugins/org.frege-lang.properties | 1 - .../FregePluginFunctionalTest.groovy | 18 ++ .../gradle/plugins/FregeBasePluginTest.groovy | 30 --- .../frege/gradle/plugins/FregePluginTest.groovy | 36 ---- .../frege/gradle/tasks/FregeCompileTest.groovy | 39 ---- 22 files changed, 18 insertions(+), 1226 deletions(-) delete mode 100644 src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy delete mode 100644 src/integTest/groovy/frege/gradle/plugins/FregePluginIntegTest.groovy delete mode 100644 src/integTest/groovy/frege/gradle/tasks/FregeCompileIntegTest.groovy delete mode 100644 src/main/groovy/frege/gradle/DefaultFregeSourceSet.java delete mode 100644 src/main/groovy/frege/gradle/FregeSourceDirectorySet.groovy delete mode 100644 src/main/groovy/frege/gradle/FregeSourceSet.java delete mode 100644 src/main/groovy/frege/gradle/FregeSourceSetDirectoryFactory.groovy delete mode 100644 src/main/groovy/frege/gradle/FregeSourceSetOutputs.groovy delete mode 100644 src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java delete mode 100644 src/main/groovy/frege/gradle/plugins/FregePlugin.groovy delete mode 100644 src/main/groovy/frege/gradle/plugins/FregePluginExtension.groovy delete mode 100644 src/main/groovy/frege/gradle/tasks/FregeCompile.groovy delete mode 100644 src/main/groovy/frege/gradle/tasks/FregeDoc.groovy delete mode 100644 src/main/groovy/frege/gradle/tasks/FregeNativeGen.groovy delete mode 100644 src/main/groovy/frege/gradle/tasks/FregeQuickCheck.groovy delete mode 100644 src/main/groovy/frege/gradle/tasks/FregeRepl.groovy delete mode 100644 src/main/resources/META-INF/gradle-plugins/org.frege-lang.base.properties delete mode 100644 src/main/resources/META-INF/gradle-plugins/org.frege-lang.properties create mode 100644 src/test/groovy/ch.fhnw.thga.fregeplugin/FregePluginFunctionalTest.groovy delete mode 100644 src/test/groovy/frege/gradle/plugins/FregeBasePluginTest.groovy delete mode 100644 src/test/groovy/frege/gradle/plugins/FregePluginTest.groovy delete mode 100644 src/test/groovy/frege/gradle/tasks/FregeCompileTest.groovy (limited to 'src') diff --git a/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy b/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy deleted file mode 100644 index 71d3ea8..0000000 --- a/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy +++ /dev/null @@ -1,67 +0,0 @@ -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.24.405" - List pluginClasspath - - @Rule - final TemporaryFolder testProjectDir = new TemporaryFolder() - File buildFile - - def setup() { - buildFile = testProjectDir.newFile('build.gradle') - - testProjectDir.newFolder("src", "main", "java", "org", "frege", "java") - 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 deleted file mode 100644 index 798d333..0000000 --- a/src/integTest/groovy/frege/gradle/plugins/FregePluginIntegTest.groovy +++ /dev/null @@ -1,208 +0,0 @@ -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.NO_SOURCE -import static org.gradle.testkit.runner.TaskOutcome.SUCCESS -import static org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE - -class FregePluginIntegTest extends AbstractFregeIntegrationSpec { - - def setup() { - buildFile << """ - plugins { - id 'org.frege-lang' - } - - repositories { - jcenter() - flatDir { - dirs '${new File(".").absolutePath}/lib' - } - } - compileFrege { - classpath = files() - } - """ - } - - def "can handle non existing source directories"() { - given: - buildFile << """ - dependencies { - compile "org.frege-lang:frege:$DEFAULT_FREGE_VERSION" - } - """ - - when: - def result = run(gradleVersion, "classes") - then: - result.task(":compileFrege").outcome == NO_SOURCE - where: - gradleVersion << ["4.0", "5.0", "5.3.1"] - } - - @Unroll - def "can compile and run frege code (gradle: #gradleVersion, frege: #fregeVersion)"() { - given: - buildFile << """ - dependencies { - compile "org.frege-lang:frege:$fregeVersion" - } - ${sayHelloTask()} - """ - - fregeModule() - - when: - def result = run(gradleVersion, "sayHello") - - then: - result.output.contains("Hello Frege!") - result.task(":sayHello").outcome == SUCCESS - - where: - fregeVersion | gradleVersion - DEFAULT_FREGE_VERSION | "5.3.1" - DEFAULT_FREGE_VERSION | "5.0" - DEFAULT_FREGE_VERSION | "4.0" - "3.22.367-g2737683" | "2.12" - } - - private void fregeModule(String modulePath = "src/main/frege/org/frege/HelloFrege.fr") { - def moduleFolder = new File(testProjectDir.root, modulePath).parentFile - moduleFolder.mkdirs() - def moduleSource = testProjectDir.newFile(modulePath) - moduleSource << """ - module org.frege.HelloFrege where - - greeting = "Hello Frege!" - - main _ = do - println greeting - """ - } - - 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 "can run frege doc on frege module"() { - given: - buildFile << """ - dependencies { - compile "org.frege-lang:frege:$DEFAULT_FREGE_VERSION" - } - ext.destinationDir = "docs" - """ - - and: - fregeModule() - when: - BuildResult result = run("fregeDoc") - then: - result.task(":fregeDoc").outcome == SUCCESS - } - - - def "frege doc works with mixed sources"() { - given: - buildFile << """ - dependencies { - compile "org.frege-lang:frege:$DEFAULT_FREGE_VERSION" - } - """ - - and: - javaCode() - fregeCallingJava() - when: - BuildResult result = run("fregeDoc") - then: - result.task(":fregeDoc").outcome == SUCCESS - } - - def "supports additional source sets"() { - given: - buildFile << """ - - sourceSets { - api - } - - dependencies { - apiCompile "org.frege-lang:frege:$DEFAULT_FREGE_VERSION" - } - - - """ - and: - javaCode() - fregeModule("src/api/frege/org/frege/HelloFrege.fr") - when: - BuildResult result = run("apiClasses") - then: - result.task(":compileApiJava").outcome == UP_TO_DATE - result.task(":compileApiFrege").outcome == SUCCESS - classFileExists("api/org/frege/HelloFrege.class") - } - - def classFileExists(String relativeClasspath) { - assert new File(testProjectDir.root, "build/classes/$relativeClasspath/").exists() - true - } - - 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.java.StaticHello where - pure native helloJava org.frege.java.StaticHello.helloJava:: () -> String - - - main _ = do - println(StaticHello.helloJava()) - - """ - } - - def javaCode(String sourceRoot = "java") { - def javaSourceFile = testProjectDir.newFile("src/main/$sourceRoot/org/frege/java/StaticHello.java") - - javaSourceFile << """ - package org.frege.java; - - 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 deleted file mode 100644 index 2f2b9d4..0000000 --- a/src/integTest/groovy/frege/gradle/tasks/FregeCompileIntegTest.groovy +++ /dev/null @@ -1,106 +0,0 @@ -package frege.gradle.tasks -import frege.gradle.integtest.fixtures.AbstractFregeIntegrationSpec - -import static org.gradle.testkit.runner.TaskOutcome.FAILED -import static org.gradle.testkit.runner.TaskOutcome.SUCCESS -import static org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE - -class FregeCompileIntegTest extends AbstractFregeIntegrationSpec { - - List pluginClasspath - - def setup() { - buildFile << """ - plugins { - id 'org.frege-lang.base' - } - - import frege.gradle.tasks.FregeCompile - - repositories { - jcenter() - flatDir { - dirs '${new File(".").absolutePath}/lib' - } - } - - 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 "is incremental"() { - given: - simpleFrege() - - buildFile << """ - compile.doLast { - println System.identityHashCode(compile.allJvmArgs) - println compile.allJvmArgs - println compile.allJvmArgs.getClass() - } -""" - when: - def result = run("compile") - - then: - result.task(":compile").outcome == SUCCESS - - when: - result = run("compile") - - then: - result.task(":compile").outcome == UP_TO_DATE - } - - - 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/main/groovy/frege/gradle/DefaultFregeSourceSet.java b/src/main/groovy/frege/gradle/DefaultFregeSourceSet.java deleted file mode 100644 index a1650a1..0000000 --- a/src/main/groovy/frege/gradle/DefaultFregeSourceSet.java +++ /dev/null @@ -1,31 +0,0 @@ -package frege.gradle; - -import groovy.lang.Closure; -import org.gradle.api.file.SourceDirectorySet; -import org.gradle.util.ConfigureUtil; - -public class DefaultFregeSourceSet implements FregeSourceSet { - private final SourceDirectorySet frege; - private final SourceDirectorySet allFrege; - - public DefaultFregeSourceSet(String displayName, FregeSourceSetDirectoryFactory sourceSetFactory) { - this.frege = sourceSetFactory.newSourceSetDirectory(String.format("%s Frege source", new Object[]{displayName})); - this.frege.getFilter().include(new String[]{"**/*.fr"}); - this.allFrege = sourceSetFactory.newSourceSetDirectory(String.format("%s Frege source", new Object[]{displayName})); - this.allFrege.source(this.frege); - this.allFrege.getFilter().include(new String[]{"**/*.fr"}); - } - - public SourceDirectorySet getFrege() { - return this.frege; - } - - public FregeSourceSet frege(Closure configureClosure) { - ConfigureUtil.configure(configureClosure, this.getFrege()); - return this; - } - - public SourceDirectorySet getAllFrege() { - return this.allFrege; - } -} diff --git a/src/main/groovy/frege/gradle/FregeSourceDirectorySet.groovy b/src/main/groovy/frege/gradle/FregeSourceDirectorySet.groovy deleted file mode 100644 index 35110f5..0000000 --- a/src/main/groovy/frege/gradle/FregeSourceDirectorySet.groovy +++ /dev/null @@ -1,26 +0,0 @@ -package frege.gradle - -import org.gradle.api.file.FileTree -import org.gradle.api.tasks.util.PatternFilterable - -interface FregeSourceDirectorySet extends PatternFilterable { - def String getName() - - def FregeSourceDirectorySet srcDir(Object srcPath) - - def FregeSourceDirectorySet srcDirs(Object... srcPaths) - - def Set getSrcDirs() - - def FregeSourceDirectorySet setSrcDirs(Iterable srcPaths) - - def FileTree getFiles() - - def PatternFilterable getFilter() - - def FregeSourceSetOutputs getOutput() - - def String getGeneratorTaskName() - - boolean contains(File file) -} \ No newline at end of file diff --git a/src/main/groovy/frege/gradle/FregeSourceSet.java b/src/main/groovy/frege/gradle/FregeSourceSet.java deleted file mode 100644 index 27654f1..0000000 --- a/src/main/groovy/frege/gradle/FregeSourceSet.java +++ /dev/null @@ -1,8 +0,0 @@ -package frege.gradle; - -import org.gradle.api.file.SourceDirectorySet; - -public interface FregeSourceSet { - SourceDirectorySet getFrege(); - SourceDirectorySet getAllFrege(); -} diff --git a/src/main/groovy/frege/gradle/FregeSourceSetDirectoryFactory.groovy b/src/main/groovy/frege/gradle/FregeSourceSetDirectoryFactory.groovy deleted file mode 100644 index 96abc8f..0000000 --- a/src/main/groovy/frege/gradle/FregeSourceSetDirectoryFactory.groovy +++ /dev/null @@ -1,30 +0,0 @@ -package frege.gradle - -import org.gradle.api.file.SourceDirectorySet -import org.gradle.api.internal.file.DefaultSourceDirectorySet -import org.gradle.api.internal.file.FileResolver -import org.gradle.api.internal.file.SourceDirectorySetFactory -import org.gradle.api.internal.project.ProjectInternal -import org.gradle.util.GradleVersion - -public class FregeSourceSetDirectoryFactory { - private final boolean useFactory; - private final FileResolver fileResolver - private final ProjectInternal project - - public FregeSourceSetDirectoryFactory(ProjectInternal project, FileResolver fileResolver) { - this.fileResolver = fileResolver - this.project = project - this.useFactory = GradleVersion.current().compareTo(GradleVersion.version("2.12")) >= 0; - - } - - public SourceDirectorySet newSourceSetDirectory(String displayName) { - if (useFactory) { - SourceDirectorySetFactory factory = project.getServices().get(SourceDirectorySetFactory.class); - return factory.create(displayName); - } else { - return new DefaultSourceDirectorySet(displayName, fileResolver); - } - } -} diff --git a/src/main/groovy/frege/gradle/FregeSourceSetOutputs.groovy b/src/main/groovy/frege/gradle/FregeSourceSetOutputs.groovy deleted file mode 100644 index 07e90a3..0000000 --- a/src/main/groovy/frege/gradle/FregeSourceSetOutputs.groovy +++ /dev/null @@ -1,7 +0,0 @@ -package frege.gradle - -import org.gradle.api.file.FileCollection - -interface FregeSourceSetOutputs { - FileCollection getDirs() -} \ 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 deleted file mode 100644 index 59fe46e..0000000 --- a/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java +++ /dev/null @@ -1,87 +0,0 @@ -package frege.gradle.plugins; - -import frege.gradle.DefaultFregeSourceSet; -import frege.gradle.FregeSourceSetDirectoryFactory; -import frege.gradle.tasks.FregeCompile; -import org.gradle.api.Action; -import org.gradle.api.Plugin; -import org.gradle.api.Project; -import org.gradle.api.file.FileTreeElement; -import org.gradle.api.internal.file.FileResolver; -import org.gradle.api.internal.plugins.DslObject; -import org.gradle.api.internal.project.ProjectInternal; -import org.gradle.api.internal.tasks.DefaultSourceSet; -import org.gradle.api.plugins.JavaBasePlugin; -import org.gradle.api.plugins.JavaPluginConvention; -import org.gradle.api.specs.Spec; -import org.gradle.api.tasks.SourceSet; -import org.gradle.internal.classpath.DefaultClassPath; - -import javax.inject.Inject; -import java.io.File; -import java.util.concurrent.Callable; - -public class FregeBasePlugin implements Plugin { - private FileResolver fileResolver; - - private static String EXTENSION_NAME = "frege"; - private FregePluginExtension fregePluginExtension; - private Project project; - - @Inject - public FregeBasePlugin(FileResolver fileResolver) { - this.fileResolver = fileResolver; - } - - @Override - 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); - configureSourceSetDefaults(javaBasePlugin); - } - - - private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) { - project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action() { - public void execute(final SourceSet sourceSet) { - FregeSourceSetDirectoryFactory factory = new FregeSourceSetDirectoryFactory((ProjectInternal) project, fileResolver); - final DefaultFregeSourceSet fregeSourceSet = new DefaultFregeSourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), factory); - new DslObject(sourceSet).getConvention().getPlugins().put("frege", fregeSourceSet); - - final String defaultSourcePath = String.format("src/%s/frege", sourceSet.getName()); - fregeSourceSet.getFrege().srcDir(defaultSourcePath); - sourceSet.getResources().getFilter().exclude(new Spec() { - public boolean isSatisfiedBy(FileTreeElement element) { - return fregeSourceSet.getFrege().contains(element.getFile()); - } - }); - sourceSet.getAllJava().source(fregeSourceSet.getFrege()); - sourceSet.getAllSource().source(fregeSourceSet.getFrege()); - - String compileTaskName = sourceSet.getCompileTaskName("frege"); - FregeCompile compile = project.getTasks().create(compileTaskName, FregeCompile.class); - compile.setModule(project.file(defaultSourcePath).getAbsolutePath()); -// javaBasePlugin.configureForSourceSet(sourceSet, compile); - compile.getConventionMapping().map("fregepath", 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()); - -// compile.setClasspath(sourceSet.getCompileClasspath()); -// compile.setDestinationDir((File)null); - - - project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compileTaskName); - sourceSet.compiledBy(compile); - } - }); - } -} diff --git a/src/main/groovy/frege/gradle/plugins/FregePlugin.groovy b/src/main/groovy/frege/gradle/plugins/FregePlugin.groovy deleted file mode 100644 index 3dd7ccc..0000000 --- a/src/main/groovy/frege/gradle/plugins/FregePlugin.groovy +++ /dev/null @@ -1,44 +0,0 @@ -package frege.gradle.plugins -import frege.gradle.tasks.FregeDoc -import frege.gradle.tasks.FregeNativeGen -import frege.gradle.tasks.FregeQuickCheck -import frege.gradle.tasks.FregeRepl -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.tasks.SourceSet - -class FregePlugin implements Plugin { - - Project project - - void apply(Project project) { - this.project = project - - project.plugins.apply(FregeBasePlugin) - project.plugins.apply("java") - - def replTask = project.task('fregeRepl', type: FregeRepl, group: 'frege', dependsOn: 'compileFrege') - replTask.outputs.upToDateWhen { false } // always run, regardless of up to date checks - - def checkTask = project.task('fregeQuickCheck', type: FregeQuickCheck, group: 'frege', dependsOn: 'testClasses') - checkTask.outputs.upToDateWhen { false } // always run, regardless of up to date checks - - project.tasks.test.dependsOn("fregeQuickCheck") - - - configureFregeDoc() - - project.task('fregeNativeGen', type: FregeNativeGen, group: 'frege') - - } - - def configureFregeDoc() { - FregeDoc fregeDoc = project.tasks.create('fregeDoc', FregeDoc) - fregeDoc.group = 'frege' - fregeDoc.dependsOn "compileFrege" // TODO remove - SourceSet mainSourceSet = project.sourceSets.main - fregeDoc.module = mainSourceSet.output.classesDirs.first().absolutePath - fregeDoc.classpath = mainSourceSet.runtimeClasspath - } - -} diff --git a/src/main/groovy/frege/gradle/plugins/FregePluginExtension.groovy b/src/main/groovy/frege/gradle/plugins/FregePluginExtension.groovy deleted file mode 100644 index ae180ec..0000000 --- a/src/main/groovy/frege/gradle/plugins/FregePluginExtension.groovy +++ /dev/null @@ -1,11 +0,0 @@ -package frege.gradle.plugins - -/** - * Created by mperry on 6/02/2015. - */ -class FregePluginExtension { - - - String key1 - -} diff --git a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy deleted file mode 100644 index d619158..0000000 --- a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy +++ /dev/null @@ -1,214 +0,0 @@ -package frege.gradle.tasks - -import groovy.transform.TypeChecked -import org.gradle.api.Action -import org.gradle.api.file.Directory -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 -import org.gradle.process.JavaExecSpec - -/* Compiler flags as of 3.25.84 - --d directory target directory for *.java and *.class files --fp classpath where to find imported frege packages --enc charset charset for source code files, standard is UTF-8 --enc DEFAULT platform default charset for source code files --target n.m generate code for java version n.m, also passed to javac --nocp exclude java classpath from -fp --hints print more detailed error messages and warnings --inline inline functions where possible --strict-pats check patterns in multi-argument functions strictly from left to right --comments generate commented code --explain i[-j] print some debugging output from type checker - regarding line(s) i (to j). May help to understand - inexplicable type errors better. --nowarn don't print warnings (not recommended) --v verbose mode on --make build outdated or missing imports --sp srcpath look for source files in srcpath, default is . --target x.y generate code for java version x.y, default is the - version of the JVM the compiler is running in. --j do not run the java compiler --ascii do not use →, ⇒, ∀ and ∷ when presenting types, - and use ascii characters for java generics variables --greek make greek type variables --fraktur make 𝖋𝖗𝖆𝖐𝖙𝖚𝖗 type variables --latin make latin type variables - -*/ - - - -@TypeChecked -class FregeCompile extends AbstractCompile { - - FileCollection classpath - - @Input - String stackSize = "4m" - - @Input - boolean hints = false - - @Input - boolean optimize = false - - @Input - boolean strictPats = false - - @Input - boolean excludeJavaClasspath = false - - boolean verbose = false - - @Input - boolean inline = true - - @Input - boolean make = true - - @Input - boolean compileGeneratedJava = true - - @Input - String target = "" - - @Input - boolean comments = false - - @Input - boolean suppressWarnings = false - - @Input - String explain = "" - - @Input - String extraArgs = "" - - @Input - String allArgs = "" // this is an option to overrule all other settings - - @Input - String module = "" - - @Optional @InputFiles - FileCollection fregepath - - @Input - File destinationDir - - @Input - String mainClass = "frege.compiler.Main" - - @Input - List allJvmArgs = [] - - @Input - String encoding = "" - - @Input - String prefix = "" - - List sourcePaths = [] - - // @Override // spurious compile error - @TaskAction - protected void compile() { - def jvmArgumentsToUse = allJvmArgs.empty ? ["-Xss$stackSize"] : new ArrayList(allJvmArgs) - def compilerArgs = allArgs ? allArgs.split().toList() : assembleArguments() - - logger.info("Calling Frege compiler with compilerArgs: '$compilerArgs'") - //TODO integrate with gradle compiler daemon infrastructure and skip internal execution - project.javaexec(new Action() { - @Override - void execute(JavaExecSpec javaExecSpec) { - javaExecSpec.args = compilerArgs - javaExecSpec.classpath = FregeCompile.this.classpath - javaExecSpec.main = mainClass - javaExecSpec.jvmArgs = jvmArgumentsToUse as List - javaExecSpec.errorOutput = System.err; - javaExecSpec.standardOutput = System.out; - } - }); - - } - - public FregeCompile source(Object... sources) { - super.source(sources); - // track directory roots - for (Object source : sources) { - sourcePaths.add(project.file(source)) - } - return this; - } - - protected List assembleArguments() { - List args = [] - if (hints) - args << "-hints" - if (optimize) { - args << "-O" - args << "-inline" - } - if (inline & !optimize) - args << "-inline" - if (strictPats) - args << "-strict-pats" - if (excludeJavaClasspath) - args << "-nocp" - if (make) - args << "-make" - if (!compileGeneratedJava) - args << "-j" - if (target != "") { - args << "-target" - args << target - } - if (comments) - args << "-comments" - if (suppressWarnings) - args << "-nowarn" - if (explain != "") { - args << "-explain" - args << explain - } - if (verbose) - args << "-v" - - - if (fregepath != null && !fregepath.isEmpty()) { - args << "-fp" - args << fregepath.files.collect { f -> f.absolutePath }.join(File.pathSeparator) - } - - if (sourcePaths != null && !sourcePaths.isEmpty()) { - args << "-sp" - args << sourcePaths.collect { d -> d.absolutePath }.join(File.pathSeparator) - } - - if (encoding != "") { - args << "-enc" - args << encoding - } - - if (prefix != "") { - args << "-prefix" - args << prefix - } - - args << "-d" - args << getDestinationDir().absolutePath - - if (!module.isEmpty()) { - logger.info "compiling module '$module'" - args << module - } else { - args = (args + extraArgs.split().toList()).toList() - } - args - } -} diff --git a/src/main/groovy/frege/gradle/tasks/FregeDoc.groovy b/src/main/groovy/frege/gradle/tasks/FregeDoc.groovy deleted file mode 100644 index ddd7bca..0000000 --- a/src/main/groovy/frege/gradle/tasks/FregeDoc.groovy +++ /dev/null @@ -1,86 +0,0 @@ -package frege.gradle.tasks - -import org.gradle.api.Action -import org.gradle.api.DefaultTask -import org.gradle.api.GradleException -import org.gradle.api.file.FileCollection -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Optional -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.TaskAction -import org.gradle.internal.impldep.org.apache.commons.io.output.TeeOutputStream -import org.gradle.process.JavaExecSpec - -class FregeDoc extends DefaultTask { - - /* Usage: java -jar fregec.jar frege.tools.Doc [-v] [-d opt] [-x mod,...] modules ... - * -v print a message for each processed module - * -d docdir specify root directory for documentation - * Documentation for module x.y.Z will be writen to - * $docdir/x/y/Z.html - * -cp classpath class path for doc tool - * -x mod1[,mod2] exclude modules whose name starts with 'mod1' or 'mod2' - * - * Modules can be specified in three ways: - * my.nice.Modul by name, the Java class for this module must be on the class path - * directory/ all modules that could be loaded if the given directory was on the class path, except exxcluded ones - * path.jar all modules in the specified JAR file, except excluded ones - * - * Example: document base frege distribution without compiler modules - * java -cp fregec.jar frege.tools.Doc -d doc -x frege.compiler fregec.jar - * - */ - - static String DEFAULT_DOCS_SUBDIR = "docs/frege" // TODO: should this come from a convention? - - @Optional - @OutputDirectory - File targetDir = new File(project.buildDir, DEFAULT_DOCS_SUBDIR) - - @Input - String module // module name or directory or class path. Default is all production modules - - @Input - @Optional - String exclude = null - - @Input - @Optional - Boolean verbose = null - - FileCollection classpath - - @TaskAction - void fregedoc() { - ByteArrayOutputStream berr = new ByteArrayOutputStream() - def teeOutputStream = new TeeOutputStream(System.err, berr) - def result = project.javaexec(new Action() { - @Override - void execute(JavaExecSpec javaExecSpec) { - if (verbose) { - javaExecSpec.args '-v' - } - javaExecSpec.args '-d', targetDir.absolutePath - if (exclude) { - javaExecSpec.args '-x', exclude - } - javaExecSpec.args(module) - javaExecSpec.main = "frege.tools.Doc" - javaExecSpec.workingDir = project.projectDir - javaExecSpec.standardInput = System.in - javaExecSpec.standardOutput = System.out - javaExecSpec.errorOutput = teeOutputStream - javaExecSpec.classpath = this.classpath - - javaExecSpec.ignoreExitValue = true - } - }) - - //Workaround for failing with java sources. should result in exit value 0 anyway. - def berrString = berr.toString() - if (result.exitValue !=0 && !berrString.contains("there were errors for")) { - throw new GradleException("Non zero exit value running FregeDoc."); - } - } -} - diff --git a/src/main/groovy/frege/gradle/tasks/FregeNativeGen.groovy b/src/main/groovy/frege/gradle/tasks/FregeNativeGen.groovy deleted file mode 100644 index 02edefd..0000000 --- a/src/main/groovy/frege/gradle/tasks/FregeNativeGen.groovy +++ /dev/null @@ -1,61 +0,0 @@ -package frege.gradle.tasks - -import org.gradle.api.DefaultTask -import org.gradle.api.internal.file.FileResolver -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.Optional -import org.gradle.api.tasks.OutputFile -import org.gradle.api.tasks.TaskAction -import org.gradle.process.internal.DefaultExecActionFactory -import org.gradle.process.internal.DefaultJavaExecAction -import org.gradle.process.internal.JavaExecAction - -class FregeNativeGen extends DefaultTask { - - /* - * Example from https://github.com/Frege/frege-native-gen: - * java -cp /path/to/guava-15.0.jar:lib/frege-YY.jar:frege-native-gen-XX.jar frege.nativegen.Main com.google.common.collect.ImmutableCollection - */ - - // help not currently supported by native gen tool - Boolean help = false - - @Optional - @InputFile - File typesFile = new File(project.projectDir, "types.properties") - - @Input - String className = null - - @Optional - @OutputFile - File outputFile = new File(project.buildDir, "generated/frege/NativeGenOutput.fr") - - - @TaskAction - void gen() { - - FileResolver fileResolver = getServices().get(FileResolver.class) - JavaExecAction action = new DefaultExecActionFactory(fileResolver).newJavaExecAction() - action.setMain("frege.nativegen.Main") - action.workingDir = project.projectDir - action.standardInput = System.in - action.standardOutput = outputFile.newOutputStream() - action.errorOutput = System.err - action.setClasspath(project.files(project.configurations.compile) + project.files("$project.buildDir/classes/main")) - - def args = [] - if (help) { - args << "-h" - } else { - args << className - args << typesFile.absolutePath - } - logger.info("Calling Frege NativeGen with args: '$args'") - action.args args - action.execute() - } - - -} diff --git a/src/main/groovy/frege/gradle/tasks/FregeQuickCheck.groovy b/src/main/groovy/frege/gradle/tasks/FregeQuickCheck.groovy deleted file mode 100644 index afeacac..0000000 --- a/src/main/groovy/frege/gradle/tasks/FregeQuickCheck.groovy +++ /dev/null @@ -1,93 +0,0 @@ -package frege.gradle.tasks -import org.gradle.api.DefaultTask -import org.gradle.api.internal.file.FileResolver -import org.gradle.api.tasks.TaskAction -import org.gradle.process.internal.DefaultExecActionFactory -import org.gradle.process.internal.DefaultJavaExecAction -import org.gradle.process.internal.JavaExecAction - -class FregeQuickCheck extends DefaultTask { - - // more options to consider: -/* - Looks up quick check predicates in the given modules and tests them. - - [Usage:] java -cp fregec.jar frege.tools.Quick [ option ... ] modulespec ... - - Options: - - - -v print a line for each pedicate that passed - - -n num run _num_ tests per predicate, default is 100 - - -p pred1,pred2,... only test the given predicates - - -x pred1,pred2,... do not test the given predicates - - -l just print the names of the predicates available. - - Ways to specify modules: - - - module the module name (e.g. my.great.Module), will be lookup up in - the current class path. - - dir/ A directory path. The directory is searched for class files, - and for each class files an attempt is made to load it as if - the given directory was in the class path. The directory must - be the root of the classes contained therein, otherwise the - classes won't get loaded. - - path-to.jar A jar or zip file is searched for class files, and for each - class file found an attempt is made to load it as if the - jar was in the class path. - - The number of passed/failed tests is reported. If any test failed or other - errors occured, the exit code will be non zero. - - The code will try to heat up your CPU by running tests on all available cores. - This should be faster on multi-core computers than running the tests - sequentially. It makes it feasable to run more tests per predicate. - - */ - - Boolean verbose = true - Boolean listAvailable = false - Boolean help = false - Integer num = 100 - List includePredicates - List excludePredicates - String moduleName - String moduleDirectory - String moduleJar - List classpathDirectories = ["$project.buildDir/classes/main", "$project.buildDir/classes/test"] - String moduleDir = "$project.buildDir/classes/test" - List allJvmArgs = [] - - @TaskAction - void runQuickCheck() { - - FileResolver fileResolver = getServices().get(FileResolver.class) - JavaExecAction action = new DefaultExecActionFactory(fileResolver).newJavaExecAction() - action.setMain("frege.tools.Quick") - - action.standardInput = System.in - action.standardOutput = System.out - action.errorOutput = System.err - - def f = project.files(classpathDirectories.collect { s -> new File(s) }) - action.setClasspath(project.files(project.configurations.compile).plus(project.files(project.configurations.testRuntime)).plus(f)) - - - project.configurations.testRuntime.each { println it } - - def args = [] - if (help) { - - } else { - if (verbose) args << "-v" - if (listAvailable) args << "-l" - if (!allJvmArgs.isEmpty()) { - action.setJvmArgs(allJvmArgs) - } - args = args + [moduleDir] - } - logger.info("Calling Frege QuickCheck with args: '$args'") - action.args args - action.execute() - } - -} diff --git a/src/main/groovy/frege/gradle/tasks/FregeRepl.groovy b/src/main/groovy/frege/gradle/tasks/FregeRepl.groovy deleted file mode 100644 index 693e076..0000000 --- a/src/main/groovy/frege/gradle/tasks/FregeRepl.groovy +++ /dev/null @@ -1,40 +0,0 @@ -package frege.gradle.tasks - -import org.gradle.api.DefaultTask -import org.gradle.api.internal.file.FileResolver -import org.gradle.api.tasks.* -import org.gradle.process.internal.DefaultExecActionFactory -import org.gradle.process.internal.DefaultJavaExecAction -import org.gradle.process.internal.JavaExecAction - -class FregeRepl extends DefaultTask { - - static String DEFAULT_SRC_DIR = "src/main/frege" // TODO: should this come from a source set? - static String DEFAULT_CLASSES_SUBDIR = "classes/main" // TODO: should this come from a convention? - - @Optional @InputDirectory - File sourceDir = new File(project.projectDir, DEFAULT_SRC_DIR).exists() ? new File(project.projectDir, DEFAULT_SRC_DIR) : null - - @Optional @OutputDirectory - File targetDir = new File(project.buildDir, DEFAULT_CLASSES_SUBDIR) - - @TaskAction - void openFregeRepl() { - - if (sourceDir != null && !sourceDir.exists() ) { - def currentDir = new File('.') - logger.info "Intended source dir '${sourceDir.absolutePath}' doesn't exist. Using current dir '${currentDir.absolutePath}' ." - sourceDir = currentDir - } - - FileResolver fileResolver = getServices().get(FileResolver.class) - JavaExecAction action = new DefaultExecActionFactory(fileResolver).newJavaExecAction() - action.setMain("frege.repl.FregeRepl") - action.workingDir = sourceDir ?: project.projectDir - action.standardInput = System.in - action.setClasspath(project.files(project.configurations.runtime ) + project.files(targetDir.absolutePath)) - - action.execute() - } - -} diff --git a/src/main/resources/META-INF/gradle-plugins/org.frege-lang.base.properties b/src/main/resources/META-INF/gradle-plugins/org.frege-lang.base.properties deleted file mode 100644 index 50f947e..0000000 --- a/src/main/resources/META-INF/gradle-plugins/org.frege-lang.base.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=frege.gradle.plugins.FregeBasePlugin diff --git a/src/main/resources/META-INF/gradle-plugins/org.frege-lang.properties b/src/main/resources/META-INF/gradle-plugins/org.frege-lang.properties deleted file mode 100644 index db20350..0000000 --- a/src/main/resources/META-INF/gradle-plugins/org.frege-lang.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=frege.gradle.plugins.FregePlugin diff --git a/src/test/groovy/ch.fhnw.thga.fregeplugin/FregePluginFunctionalTest.groovy b/src/test/groovy/ch.fhnw.thga.fregeplugin/FregePluginFunctionalTest.groovy new file mode 100644 index 0000000..889f6f0 --- /dev/null +++ b/src/test/groovy/ch.fhnw.thga.fregeplugin/FregePluginFunctionalTest.groovy @@ -0,0 +1,18 @@ +package ch.fhnw.thga.fregeplugin + +import org.junit.jupiter.api.io.TempDir; +import spock.lang.Specification + +class FregePluginFunctionalTests extends Specification { + @TempDir File testProjectDir + File buildFile + + def setup() { + buildFile = newFile(testProjectDir, 'build.gradle') + buildFile << """ + plugins { + id 'ch.fhnw.thga.frege' + } + """ + } +} \ No newline at end of file diff --git a/src/test/groovy/frege/gradle/plugins/FregeBasePluginTest.groovy b/src/test/groovy/frege/gradle/plugins/FregeBasePluginTest.groovy deleted file mode 100644 index 04b5587..0000000 --- a/src/test/groovy/frege/gradle/plugins/FregeBasePluginTest.groovy +++ /dev/null @@ -1,30 +0,0 @@ -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 deleted file mode 100644 index 34532c7..0000000 --- a/src/test/groovy/frege/gradle/plugins/FregePluginTest.groovy +++ /dev/null @@ -1,36 +0,0 @@ -package frege.gradle.plugins -import org.gradle.api.Project -import org.gradle.testfixtures.ProjectBuilder -import spock.lang.Specification -import spock.lang.Unroll - -class FregePluginTest extends Specification { - - Project project = ProjectBuilder.builder().build() - - def setup(){ - when: - project.plugins.apply(FregePlugin) - } - - 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") - } - - @Unroll - def "adds #fregeTaskName task"(){ - when: - def fregeTask = project.tasks.findByName(fregeTaskName) - then: - fregeTask != null - fregeTask.group == "frege" - where: - fregeTaskName << ["fregeRepl", "fregeDoc", "fregeQuickCheck", "fregeNativeGen"] - } -} diff --git a/src/test/groovy/frege/gradle/tasks/FregeCompileTest.groovy b/src/test/groovy/frege/gradle/tasks/FregeCompileTest.groovy deleted file mode 100644 index c9224ea..0000000 --- a/src/test/groovy/frege/gradle/tasks/FregeCompileTest.groovy +++ /dev/null @@ -1,39 +0,0 @@ -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