From b53817cd366bdd15ec142fc880fe68c7e5ea00a1 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Wed, 18 Nov 2015 23:36:21 +0000 Subject: introduce frege-base plugin for basic frege functionality --- .../frege/plugin/FregePluginIntegTest.groovy | 46 +++++++++++++++++----- src/main/groovy/frege/gradle/CompileTask.groovy | 2 +- .../groovy/frege/gradle/FregeBasePlugin.groovy | 17 ++++++++ src/main/groovy/frege/gradle/FregePlugin.groovy | 11 +----- .../gradle-plugins/org.frege-lang.base.properties | 1 + .../groovy/frege/gradle/FregeBasePluginTest.groovy | 29 ++++++++++++++ .../groovy/frege/gradle/FregePluginTest.groovy | 30 ++++++++++++++ 7 files changed, 117 insertions(+), 19 deletions(-) create mode 100644 src/main/groovy/frege/gradle/FregeBasePlugin.groovy create mode 100644 src/main/resources/META-INF/gradle-plugins/org.frege-lang.base.properties create mode 100644 src/test/groovy/frege/gradle/FregeBasePluginTest.groovy create mode 100644 src/test/groovy/frege/gradle/FregePluginTest.groovy diff --git a/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy b/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy index 5c985e8..a67620f 100644 --- a/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy +++ b/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy @@ -1,14 +1,15 @@ 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 @@ -18,6 +19,15 @@ class FregePluginIntegTest extends Specification { 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 @@ -29,26 +39,36 @@ class FregePluginIntegTest extends Specification { pluginClasspath = pluginClasspathResource.readLines().collect { new File(it) } } - def "can compile frege production code"() { + def "can handle non existing source directories"() { given: buildFile << """ - plugins { - id 'org.frege-lang' + dependencies { + compile "org.frege-lang:frege:$DEFAULT_FREGE_VERSION" } + """ - repositories { - jcenter() - } + 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"() { + given: + buildFile << """ dependencies { - compile "org.frege-lang:frege:3.22.367-g2737683" + compile "org.frege-lang:frege:$fregeVersion" } task sayHello(type: JavaExec){ classpath = sourceSets.main.runtimeClasspath main = 'HelloFrege' } - """ testProjectDir.newFolder("src", "main", "frege") @@ -65,6 +85,7 @@ main _ = do when: def result = GradleRunner.create() + .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.root) .withArguments('sayHello') .withPluginClasspath(pluginClasspath) @@ -73,5 +94,12 @@ main _ = do 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" } } \ No newline at end of file diff --git a/src/main/groovy/frege/gradle/CompileTask.groovy b/src/main/groovy/frege/gradle/CompileTask.groovy index 07850a5..d297d3d 100644 --- a/src/main/groovy/frege/gradle/CompileTask.groovy +++ b/src/main/groovy/frege/gradle/CompileTask.groovy @@ -81,7 +81,7 @@ class CompileTask extends DefaultTask { @Optional @Input List fregePaths = [] - @Optional @Input + @InputFiles List sourcePaths = [deduceSourceDir(project)] @Optional @OutputDirectory diff --git a/src/main/groovy/frege/gradle/FregeBasePlugin.groovy b/src/main/groovy/frege/gradle/FregeBasePlugin.groovy new file mode 100644 index 0000000..5af7a86 --- /dev/null +++ b/src/main/groovy/frege/gradle/FregeBasePlugin.groovy @@ -0,0 +1,17 @@ +package frege.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.JavaBasePlugin + +class FregeBasePlugin implements Plugin { + static String EXTENSION_NAME = "frege" + + @Override + void apply(Project project) { + // Workaround to build proper jars on Windows, see https://github.com/Frege/frege-gradle-plugin/issues/9 + System.setProperty("file.encoding", "UTF-8") + project.getPluginManager().apply(JavaBasePlugin.class); + project.extensions.create(EXTENSION_NAME, FregePluginExtension) + } +} diff --git a/src/main/groovy/frege/gradle/FregePlugin.groovy b/src/main/groovy/frege/gradle/FregePlugin.groovy index 29be393..e8ee2d5 100644 --- a/src/main/groovy/frege/gradle/FregePlugin.groovy +++ b/src/main/groovy/frege/gradle/FregePlugin.groovy @@ -1,20 +1,13 @@ package frege.gradle - -import groovy.transform.TypeChecked +import fj.data.Option import org.gradle.api.Plugin import org.gradle.api.Project -import fj.data.Option -import org.gradle.api.plugins.JavaPlugin - //@TypeChecked class FregePlugin implements Plugin { void apply(Project project) { - // Workaround to build proper jars on Windows, see https://github.com/Frege/frege-gradle-plugin/issues/9 - System.setProperty("file.encoding", "UTF-8") - project.plugins.apply(JavaPlugin) - def e = (FregePluginExtension) project.extensions.create("frege", FregePluginExtension) + project.plugins.apply(FregeBasePlugin) project.task('compileFrege', type: CompileTask, group: 'Build', dependsOn: "compileJava") { module = CompileTask.deduceSourceDir(project).absolutePath 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 new file mode 100644 index 0000000..6ab972a --- /dev/null +++ b/src/main/resources/META-INF/gradle-plugins/org.frege-lang.base.properties @@ -0,0 +1 @@ +implementation-class=frege.gradle.FregeBasePlugin diff --git a/src/test/groovy/frege/gradle/FregeBasePluginTest.groovy b/src/test/groovy/frege/gradle/FregeBasePluginTest.groovy new file mode 100644 index 0000000..ebdb7d3 --- /dev/null +++ b/src/test/groovy/frege/gradle/FregeBasePluginTest.groovy @@ -0,0 +1,29 @@ +package frege.gradle +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 new file mode 100644 index 0000000..61001de --- /dev/null +++ b/src/test/groovy/frege/gradle/FregePluginTest.groovy @@ -0,0 +1,30 @@ +package frege.gradle + +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") + } +} -- cgit From d47c934650540277c911514d4cf7ddf55a69492a Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Sat, 21 Nov 2015 00:59:06 +0000 Subject: create frege compile task per sourceSet --- .../frege/plugin/FregePluginIntegTest.groovy | 15 +- src/main/groovy/frege/gradle/CompileTask.groovy | 273 --------------------- .../groovy/frege/gradle/DefaultFregeSourceSet.java | 33 +++ src/main/groovy/frege/gradle/DocTask.groovy | 83 ------- .../groovy/frege/gradle/FregeBasePlugin.groovy | 17 -- src/main/groovy/frege/gradle/FregePlugin.groovy | 39 --- .../frege/gradle/FregePluginExtension.groovy | 11 - src/main/groovy/frege/gradle/FregeSourceSet.java | 7 + src/main/groovy/frege/gradle/NativeGenTask.groovy | 61 ----- src/main/groovy/frege/gradle/QuickCheckTask.groovy | 96 -------- src/main/groovy/frege/gradle/ReplTask.groovy | 39 --- .../frege/gradle/plugins/FregeBasePlugin.java | 87 +++++++ .../groovy/frege/gradle/plugins/FregeJarFile.java | 34 +++ .../groovy/frege/gradle/plugins/FregePlugin.groovy | 34 +++ .../gradle/plugins/FregePluginExtension.groovy | 11 + .../groovy/frege/gradle/plugins/FregeRuntime.java | 63 +++++ .../groovy/frege/gradle/tasks/FregeCompile.groovy | 198 +++++++++++++++ src/main/groovy/frege/gradle/tasks/FregeDoc.groovy | 83 +++++++ .../frege/gradle/tasks/FregeNativeGen.groovy | 61 +++++ .../frege/gradle/tasks/FregeQuickCheck.groovy | 92 +++++++ .../groovy/frege/gradle/tasks/FregeRepl.groovy | 39 +++ .../gradle-plugins/org.frege-lang.base.properties | 2 +- .../gradle-plugins/org.frege-lang.properties | 2 +- .../groovy/frege/gradle/FregeBasePluginTest.groovy | 2 + .../groovy/frege/gradle/FregePluginTest.groovy | 2 + 25 files changed, 757 insertions(+), 627 deletions(-) delete mode 100644 src/main/groovy/frege/gradle/CompileTask.groovy create mode 100644 src/main/groovy/frege/gradle/DefaultFregeSourceSet.java delete mode 100644 src/main/groovy/frege/gradle/DocTask.groovy delete mode 100644 src/main/groovy/frege/gradle/FregeBasePlugin.groovy delete mode 100644 src/main/groovy/frege/gradle/FregePlugin.groovy delete mode 100644 src/main/groovy/frege/gradle/FregePluginExtension.groovy create mode 100644 src/main/groovy/frege/gradle/FregeSourceSet.java delete mode 100644 src/main/groovy/frege/gradle/NativeGenTask.groovy delete mode 100644 src/main/groovy/frege/gradle/QuickCheckTask.groovy delete mode 100644 src/main/groovy/frege/gradle/ReplTask.groovy create mode 100644 src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java create mode 100644 src/main/groovy/frege/gradle/plugins/FregeJarFile.java create mode 100644 src/main/groovy/frege/gradle/plugins/FregePlugin.groovy create mode 100644 src/main/groovy/frege/gradle/plugins/FregePluginExtension.groovy create mode 100644 src/main/groovy/frege/gradle/plugins/FregeRuntime.java create mode 100644 src/main/groovy/frege/gradle/tasks/FregeCompile.groovy create mode 100644 src/main/groovy/frege/gradle/tasks/FregeDoc.groovy create mode 100644 src/main/groovy/frege/gradle/tasks/FregeNativeGen.groovy create mode 100644 src/main/groovy/frege/gradle/tasks/FregeQuickCheck.groovy create mode 100644 src/main/groovy/frege/gradle/tasks/FregeRepl.groovy diff --git a/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy b/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy index a67620f..56c2eae 100644 --- a/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy +++ b/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy @@ -58,7 +58,7 @@ class FregePluginIntegTest extends Specification { } @Unroll - def "can compile and run frege code"() { + def "can compile and run frege code (gradle: #gradleVersion, frege: #fregeVersion)"() { given: buildFile << """ dependencies { @@ -66,6 +66,9 @@ class FregePluginIntegTest extends Specification { } task sayHello(type: JavaExec){ + doFirst { + println classpath.files + } classpath = sourceSets.main.runtimeClasspath main = 'HelloFrege' } @@ -86,8 +89,8 @@ main _ = do when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) - .withProjectDir(testProjectDir.root) - .withArguments('sayHello') + .withDebug(true).withProjectDir(testProjectDir.root) + .withArguments('sayHello', '--stacktrace', '-i') .withPluginClasspath(pluginClasspath) .build() @@ -98,8 +101,8 @@ main _ = do 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" +// DEFAULT_FREGE_VERSION | "2.8" +// "3.22.367-g2737683" | "2.9" +// "3.22.367-g2737683" | "2.8" } } \ No newline at end of file diff --git a/src/main/groovy/frege/gradle/CompileTask.groovy b/src/main/groovy/frege/gradle/CompileTask.groovy deleted file mode 100644 index d297d3d..0000000 --- a/src/main/groovy/frege/gradle/CompileTask.groovy +++ /dev/null @@ -1,273 +0,0 @@ -package frege.gradle - -import frege.compiler.Main -import frege.prelude.PreludeBase -import frege.runtime.Lambda -import groovy.transform.TypeChecked -import groovy.transform.TypeCheckingMode -import org.gradle.api.DefaultTask -import org.gradle.api.Project -import org.gradle.api.artifacts.Configuration -import org.gradle.api.file.FileCollection -import org.gradle.api.tasks.* -import org.gradle.process.internal.DefaultJavaExecAction -import org.gradle.process.internal.JavaExecAction -import org.gradle.api.internal.file.FileResolver - -@TypeChecked -class CompileTask extends DefaultTask { - - // see help at https://github.com/Frege/frege/wiki/Compiler-Manpage - - static String DEFAULT_CLASSES_SUBDIR = "classes/main" // TODO: should this come from a convention? - static String DEFAULT_SRC_DIR = "src/main/frege" // TODO: should this come from a source set? - - static String DEFAULT_TEST_CLASSES_DIR = "classes/test" - static String DEFAULT_TEST_SRC_DIR = "src/test/frege" - - static Boolean USE_EXTERNAl = true - - @Optional @Input - boolean enabled = true - - @Optional @Input - Boolean help = false - - @Optional @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 - boolean skipCompile = false - - @Optional @Input - String extraArgs = "" - - @Optional @Input - String allArgs = "" // this is an option to overrule all other settings - - @Optional @Input - String module = "" - - @Optional @Input - List fregePaths = [] - - @InputFiles - List sourcePaths = [deduceSourceDir(project)] - - @Optional @OutputDirectory - File outputDir = deduceClassesDir(project) - - @Optional @Input - String mainClass = "frege.compiler.Main" - - @Optional @Input - List allJvmArgs = [] - - @Optional @Input - String encoding = "" - - @Optional @Input - String prefix = "" - - // TODO: Missing presentation of types (ascii, symbols, latin, greek, faktur) - - static File deduceSourceDir(File projectDir, String subdir) { - new File(projectDir, subdir) - } - - static File deduceSourceDir(Project project) { - deduceSourceDir(project.projectDir, DEFAULT_SRC_DIR) - } - - static File deduceClassesDir(File projectDir, String subdir) { - new File(projectDir, subdir) - } - - static File deduceClassesDir(Project project) { - deduceClassesDir(project.buildDir, DEFAULT_CLASSES_SUBDIR) - } - - static File deduceTestClassesDir(Project project) { - deduceClassesDir(project.buildDir, DEFAULT_TEST_CLASSES_DIR) - } - - static File deduceTestSourceDir(Project project) { - deduceSourceDir(project.projectDir, DEFAULT_TEST_SRC_DIR) - } - - @TaskAction - void executeCompile() { - - if (!enabled) { - logger.info("Frege compiler disabled.") - return; - } - - if (!outputDir.exists() ) { - logger.info "Creating output directory '${outputDir.absolutePath}'." - outputDir.mkdirs() - } - // access extension configuration values as ${project.frege.key1} - - FileResolver fileResolver = getServices().get(FileResolver.class) - JavaExecAction action = new DefaultJavaExecAction(fileResolver) - action.setMain(mainClass) - - logConfigurationInfo() - - action.setClasspath(actionClasspath(project)) - - def args = [] - if (help) { - args << "-help" - } else { - def jvmArgs = allJvmArgs - if (jvmArgs.isEmpty()) { - jvmArgs << "-Xss$stackSize".toString() - } - action.setJvmArgs(jvmArgs) - args = allArgs ? allArgs.split().toList() : assembleArguments() - } - - logger.info("Calling Frege compiler with args: '$args'") - action.args(args) - - if (USE_EXTERNAl) { - action.execute() - } else { - compile(args as String[]) - } - } - - void logConfigurationInfo() { - def path = project.files(compileConfig()).getAsPath() - logger.info("Compile configuation as path: $path") - - } - - FileCollection actionClasspath(Project p) { - p.files(compileConfig()) + p.files(deduceClassesDir(p)) - } - - // TODO: This should be removed or integrated so an external Java process does not need to be started. - // The Java generated uses System.exit() which does not work well with Gradle - // This was taken from the frege fork /compiler1/build/classes/main/afrege/compiler/Main.java:main() - void compile(String[] paramArrayOfString) { - long l1 = System.nanoTime(); - Integer localInteger = frege.runtime.Runtime.runMain( - PreludeBase.TST.performUnsafe( - (Lambda)Main.IJ._mainƒd0fa0028.inst.apply(PreludeBase._toList(paramArrayOfString)).forced() - ) - ); - long l2 = System.nanoTime(); - ((PrintWriter)frege.runtime.Runtime.stderr.get()).println("runtime " + (l2 - l1 + 500000L) / 1000000L / 1000.0D + " wallclock seconds."); - if (localInteger != null) { -// System.exit(localInteger.intValue()); - } - } - - List totalFregeClasspath(List fp) { - def result = [] - result.addAll(project.files(compileConfig()).getFiles().toList()) - result.addAll(fp) - result - } - - @TypeChecked(TypeCheckingMode.SKIP) - Configuration compileConfig() { - project.configurations.compile - } - - protected List assembleArguments() { - List args = [] - if (hints) - args << "-hints" - if (optimize) { - args << "-O" - args << "-inline" - } - if (inline & !optimize) - args << "-inline" - 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 (skipCompile) - args << "-j" - - def fp = USE_EXTERNAl ? fregePaths : totalFregeClasspath(fregePaths) - if (!fp.isEmpty()) { - args << "-fp" - args << fp.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 << outputDir - - 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/DefaultFregeSourceSet.java b/src/main/groovy/frege/gradle/DefaultFregeSourceSet.java new file mode 100644 index 0000000..3a9bcfc --- /dev/null +++ b/src/main/groovy/frege/gradle/DefaultFregeSourceSet.java @@ -0,0 +1,33 @@ +package frege.gradle; + +import groovy.lang.Closure; +import org.gradle.api.file.SourceDirectorySet; +import org.gradle.api.internal.file.DefaultSourceDirectorySet; +import org.gradle.api.internal.file.FileResolver; +import org.gradle.util.ConfigureUtil; + +public class DefaultFregeSourceSet implements FregeSourceSet { + private final SourceDirectorySet frege; + private final SourceDirectorySet allFrege; + + public DefaultFregeSourceSet(String displayName, FileResolver fileResolver) { + this.frege = new DefaultSourceDirectorySet(String.format("%s Frege source", new Object[]{displayName}), fileResolver); + this.frege.getFilter().include(new String[]{"**/*.fr"}); + this.allFrege = new DefaultSourceDirectorySet(String.format("%s Frege source", new Object[]{displayName}), fileResolver); + 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/DocTask.groovy b/src/main/groovy/frege/gradle/DocTask.groovy deleted file mode 100644 index 061ae00..0000000 --- a/src/main/groovy/frege/gradle/DocTask.groovy +++ /dev/null @@ -1,83 +0,0 @@ -package frege.gradle - -import org.gradle.api.DefaultTask -import org.gradle.api.internal.file.FileResolver -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.Optional -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.TaskAction -import org.gradle.process.internal.DefaultJavaExecAction -import org.gradle.process.internal.JavaExecAction - -class DocTask 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_SRC_DIR = "src/main/frege" // TODO: should this come from a source set? - static String DEFAULT_DOCS_SUBDIR = "docs/frege" // TODO: should this come from a convention? - - Boolean help = false - - @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_DOCS_SUBDIR) - - @Input - String module = "$project.buildDir/classes/main" // module name or directory or class path. Default is all production modules - - @Input @Optional - String exclude = null - - @Input @Optional - Boolean verbose = null - - @TaskAction - void fregedoc() { - - FileResolver fileResolver = getServices().get(FileResolver.class) - JavaExecAction action = new DefaultJavaExecAction(fileResolver) - action.setMain("frege.tools.Doc") - action.workingDir = sourceDir ?: project.projectDir - action.standardInput = System.in - action.standardOutput = System.out - action.errorOutput = System.err - action.setClasspath(project.files(project.configurations.compile) + project.files("$project.buildDir/classes/main")) - - def args = [] - if (help) { - args << "-h" - } else { - if (verbose) args << '-v' - args << '-d' << targetDir.absolutePath - if (exclude) args << '-x' << exclude - args << module - } - - logger.info("Calling Frege Doc with args: '$args'") - action.args args - action.execute() - } - -} - diff --git a/src/main/groovy/frege/gradle/FregeBasePlugin.groovy b/src/main/groovy/frege/gradle/FregeBasePlugin.groovy deleted file mode 100644 index 5af7a86..0000000 --- a/src/main/groovy/frege/gradle/FregeBasePlugin.groovy +++ /dev/null @@ -1,17 +0,0 @@ -package frege.gradle - -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.plugins.JavaBasePlugin - -class FregeBasePlugin implements Plugin { - static String EXTENSION_NAME = "frege" - - @Override - void apply(Project project) { - // Workaround to build proper jars on Windows, see https://github.com/Frege/frege-gradle-plugin/issues/9 - System.setProperty("file.encoding", "UTF-8") - project.getPluginManager().apply(JavaBasePlugin.class); - project.extensions.create(EXTENSION_NAME, FregePluginExtension) - } -} diff --git a/src/main/groovy/frege/gradle/FregePlugin.groovy b/src/main/groovy/frege/gradle/FregePlugin.groovy deleted file mode 100644 index e8ee2d5..0000000 --- a/src/main/groovy/frege/gradle/FregePlugin.groovy +++ /dev/null @@ -1,39 +0,0 @@ -package frege.gradle -import fj.data.Option -import org.gradle.api.Plugin -import org.gradle.api.Project -//@TypeChecked -class FregePlugin implements Plugin { - - void apply(Project project) { - - project.plugins.apply(FregeBasePlugin) - - project.task('compileFrege', type: CompileTask, group: 'Build', dependsOn: "compileJava") { - module = CompileTask.deduceSourceDir(project).absolutePath - } - project.tasks.classes.dependsOn("compileFrege") - - project.task('compileTestFrege', type: CompileTask, group: 'Build', dependsOn: "compileTestJava") { - module = CompileTask.deduceTestSourceDir(project).absolutePath - outputDir = CompileTask.deduceTestClassesDir(project) - fregePaths = Option.fromNull(CompileTask.deduceClassesDir(project)) - .map{d -> [d]}.orSome([]) - } - project.tasks.testClasses.dependsOn("compileTestFrege") - - def replTask = project.task('fregeRepl', type: ReplTask, group: 'Tools', dependsOn: 'compileFrege') - replTask.outputs.upToDateWhen { false } // always run, regardless of up to date checks - - def checkTask = project.task('fregeQuickCheck', type: QuickCheckTask, group: 'Verification', dependsOn: 'testClasses') - checkTask.outputs.upToDateWhen { false } // always run, regardless of up to date checks - - project.tasks.test.dependsOn("fregeQuickCheck") - - project.task('fregeDoc', type: DocTask, group: 'Documentation', dependsOn: 'compileFrege') - - project.task('fregeNativeGen', type: NativeGenTask, group: 'Tools') - - } - -} diff --git a/src/main/groovy/frege/gradle/FregePluginExtension.groovy b/src/main/groovy/frege/gradle/FregePluginExtension.groovy deleted file mode 100644 index dbf0d2a..0000000 --- a/src/main/groovy/frege/gradle/FregePluginExtension.groovy +++ /dev/null @@ -1,11 +0,0 @@ -package frege.gradle - -/** - * Created by mperry on 6/02/2015. - */ -class FregePluginExtension { - - - String key1 - -} diff --git a/src/main/groovy/frege/gradle/FregeSourceSet.java b/src/main/groovy/frege/gradle/FregeSourceSet.java new file mode 100644 index 0000000..8706ee2 --- /dev/null +++ b/src/main/groovy/frege/gradle/FregeSourceSet.java @@ -0,0 +1,7 @@ +package frege.gradle; + +/** + * Created by Rene on 20/11/15. + */ +public interface FregeSourceSet { +} diff --git a/src/main/groovy/frege/gradle/NativeGenTask.groovy b/src/main/groovy/frege/gradle/NativeGenTask.groovy deleted file mode 100644 index c9128ca..0000000 --- a/src/main/groovy/frege/gradle/NativeGenTask.groovy +++ /dev/null @@ -1,61 +0,0 @@ -package frege.gradle - -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.DefaultJavaExecAction -import org.gradle.process.internal.JavaExecAction - -class NativeGenTask 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 DefaultJavaExecAction(fileResolver) - 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/QuickCheckTask.groovy b/src/main/groovy/frege/gradle/QuickCheckTask.groovy deleted file mode 100644 index 11065ad..0000000 --- a/src/main/groovy/frege/gradle/QuickCheckTask.groovy +++ /dev/null @@ -1,96 +0,0 @@ -package frege.gradle - -import org.gradle.api.DefaultTask -import org.gradle.api.Project -import org.gradle.api.internal.file.FileResolver -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.Optional -import org.gradle.api.tasks.TaskAction -import org.gradle.process.internal.DefaultJavaExecAction -import org.gradle.process.internal.JavaExecAction - -class QuickCheckTask 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 DefaultJavaExecAction(fileResolver) - 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() - } - -} \ No newline at end of file diff --git a/src/main/groovy/frege/gradle/ReplTask.groovy b/src/main/groovy/frege/gradle/ReplTask.groovy deleted file mode 100644 index 1f570eb..0000000 --- a/src/main/groovy/frege/gradle/ReplTask.groovy +++ /dev/null @@ -1,39 +0,0 @@ -package frege.gradle - -import org.gradle.api.DefaultTask -import org.gradle.api.internal.file.FileResolver -import org.gradle.api.tasks.* -import org.gradle.process.internal.DefaultJavaExecAction -import org.gradle.process.internal.JavaExecAction - -class ReplTask 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 DefaultJavaExecAction(fileResolver) - 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() - } - -} \ 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 new file mode 100644 index 0000000..8bf5399 --- /dev/null +++ b/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java @@ -0,0 +1,87 @@ +package frege.gradle.plugins; + +import frege.gradle.DefaultFregeSourceSet; +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.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 javax.inject.Inject; +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(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); + } + + + private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) { + project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action() { + public void execute(SourceSet sourceSet) { + final DefaultFregeSourceSet fregeSourceSet = new DefaultFregeSourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), fileResolver); + 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.dependsOn(sourceSet.getCompileJavaTaskName()); + compile.setDescription(String.format("Compiles the %s Frege source.", sourceSet.getName())); + compile.setSource(fregeSourceSet.getFrege()); + project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compileTaskName); + } + }); + } + + 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 new file mode 100644 index 0000000..eaf7d8f --- /dev/null +++ b/src/main/groovy/frege/gradle/plugins/FregeJarFile.java @@ -0,0 +1,34 @@ +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/FregePlugin.groovy b/src/main/groovy/frege/gradle/plugins/FregePlugin.groovy new file mode 100644 index 0000000..af05228 --- /dev/null +++ b/src/main/groovy/frege/gradle/plugins/FregePlugin.groovy @@ -0,0 +1,34 @@ +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 + +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: 'Tools', dependsOn: 'compileFrege') + replTask.outputs.upToDateWhen { false } // always run, regardless of up to date checks + + def checkTask = project.task('fregeQuickCheck', type: FregeQuickCheck, group: 'Verification', dependsOn: 'testClasses') + checkTask.outputs.upToDateWhen { false } // always run, regardless of up to date checks + + project.tasks.test.dependsOn("fregeQuickCheck") + + project.task('fregeDoc', type: FregeDoc, group: 'Documentation', dependsOn: 'compileFrege') + + project.task('fregeNativeGen', type: FregeNativeGen, group: 'Tools') + + } + +} diff --git a/src/main/groovy/frege/gradle/plugins/FregePluginExtension.groovy b/src/main/groovy/frege/gradle/plugins/FregePluginExtension.groovy new file mode 100644 index 0000000..ae180ec --- /dev/null +++ b/src/main/groovy/frege/gradle/plugins/FregePluginExtension.groovy @@ -0,0 +1,11 @@ +package frege.gradle.plugins + +/** + * Created by mperry on 6/02/2015. + */ +class FregePluginExtension { + + + String key1 + +} diff --git a/src/main/groovy/frege/gradle/plugins/FregeRuntime.java b/src/main/groovy/frege/gradle/plugins/FregeRuntime.java new file mode 100644 index 0000000..4265d0b --- /dev/null +++ b/src/main/groovy/frege/gradle/plugins/FregeRuntime.java @@ -0,0 +1,63 @@ +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 new file mode 100644 index 0000000..13b617c --- /dev/null +++ b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy @@ -0,0 +1,198 @@ +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 +import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.compile.AbstractCompile +import org.gradle.process.JavaExecSpec + +@TypeChecked +class FregeCompile extends AbstractCompile { + + FileCollection fregeClasspath + FileCollection classpath + + @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 = [] + + @Input + String mainClass = "frege.compiler.Main" + + @Optional + @Input + List allJvmArgs = [] + + @Optional + @Input + String encoding = "" + + @Optional + @Input + String prefix = "" + + List sourcePaths = [] + + @Override + @TaskAction + protected void compile() { + logConfigurationInfo() + + def jvmArgs = allJvmArgs + if (jvmArgs.isEmpty()) { + jvmArgs << "-Xss$stackSize".toString() + } + 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 + FregeCompile.this.fregeClasspath + javaExecSpec.main = mainClass + } + }); + } + + public FregeCompile source(Object... sources) { + super.source(sources); + // track directory roots + for (Object source : sources) { + sourcePaths.add(project.file(source)) + } + 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) + args << "-hints" + if (optimize) { + args << "-O" + args << "-inline" + } + if (inline & !optimize) + args << "-inline" + 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" + + def fp = fregePaths + if (!fp.isEmpty()) { + args << "-fp" + args << fp.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() + + 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 new file mode 100644 index 0000000..7ac49a7 --- /dev/null +++ b/src/main/groovy/frege/gradle/tasks/FregeDoc.groovy @@ -0,0 +1,83 @@ +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.InputDirectory +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction +import org.gradle.process.internal.DefaultJavaExecAction +import org.gradle.process.internal.JavaExecAction + +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_SRC_DIR = "src/main/frege" // TODO: should this come from a source set? + static String DEFAULT_DOCS_SUBDIR = "docs/frege" // TODO: should this come from a convention? + + Boolean help = false + + @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_DOCS_SUBDIR) + + @Input + String module = "$project.buildDir/classes/main" // module name or directory or class path. Default is all production modules + + @Input @Optional + String exclude = null + + @Input @Optional + Boolean verbose = null + + @TaskAction + void fregedoc() { + + FileResolver fileResolver = getServices().get(FileResolver.class) + JavaExecAction action = new DefaultJavaExecAction(fileResolver) + action.setMain("frege.tools.Doc") + action.workingDir = sourceDir ?: project.projectDir + action.standardInput = System.in + action.standardOutput = System.out + action.errorOutput = System.err + action.setClasspath(project.files(project.configurations.compile) + project.files("$project.buildDir/classes/main")) + + def args = [] + if (help) { + args << "-h" + } else { + if (verbose) args << '-v' + args << '-d' << targetDir.absolutePath + if (exclude) args << '-x' << exclude + args << module + } + + logger.info("Calling Frege Doc with args: '$args'") + action.args args + action.execute() + } + +} + diff --git a/src/main/groovy/frege/gradle/tasks/FregeNativeGen.groovy b/src/main/groovy/frege/gradle/tasks/FregeNativeGen.groovy new file mode 100644 index 0000000..6f51218 --- /dev/null +++ b/src/main/groovy/frege/gradle/tasks/FregeNativeGen.groovy @@ -0,0 +1,61 @@ +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.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 DefaultJavaExecAction(fileResolver) + 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 new file mode 100644 index 0000000..e06236f --- /dev/null +++ b/src/main/groovy/frege/gradle/tasks/FregeQuickCheck.groovy @@ -0,0 +1,92 @@ +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.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 DefaultJavaExecAction(fileResolver) + 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() + } + +} \ No newline at end of file diff --git a/src/main/groovy/frege/gradle/tasks/FregeRepl.groovy b/src/main/groovy/frege/gradle/tasks/FregeRepl.groovy new file mode 100644 index 0000000..64e0186 --- /dev/null +++ b/src/main/groovy/frege/gradle/tasks/FregeRepl.groovy @@ -0,0 +1,39 @@ +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.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 DefaultJavaExecAction(fileResolver) + 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() + } + +} \ No newline at end of file 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 index 6ab972a..50f947e 100644 --- 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 @@ -1 +1 @@ -implementation-class=frege.gradle.FregeBasePlugin +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 index 25a44ac..db20350 100644 --- a/src/main/resources/META-INF/gradle-plugins/org.frege-lang.properties +++ b/src/main/resources/META-INF/gradle-plugins/org.frege-lang.properties @@ -1 +1 @@ -implementation-class=frege.gradle.FregePlugin +implementation-class=frege.gradle.plugins.FregePlugin diff --git a/src/test/groovy/frege/gradle/FregeBasePluginTest.groovy b/src/test/groovy/frege/gradle/FregeBasePluginTest.groovy index ebdb7d3..3ca1bb2 100644 --- a/src/test/groovy/frege/gradle/FregeBasePluginTest.groovy +++ b/src/test/groovy/frege/gradle/FregeBasePluginTest.groovy @@ -1,4 +1,6 @@ package frege.gradle + +import frege.gradle.plugins.FregeBasePlugin import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder import spock.lang.Specification diff --git a/src/test/groovy/frege/gradle/FregePluginTest.groovy b/src/test/groovy/frege/gradle/FregePluginTest.groovy index 61001de..2fc6d86 100644 --- a/src/test/groovy/frege/gradle/FregePluginTest.groovy +++ b/src/test/groovy/frege/gradle/FregePluginTest.groovy @@ -1,5 +1,7 @@ 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 -- cgit From 06b6bfbfd1b1f62d191c494d093fae637e144a7a Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Sat, 21 Nov 2015 01:07:39 +0000 Subject: some integTest cleanup + more test coverage --- src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy b/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy index 56c2eae..547c939 100644 --- a/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy +++ b/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy @@ -90,7 +90,7 @@ main _ = do def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withDebug(true).withProjectDir(testProjectDir.root) - .withArguments('sayHello', '--stacktrace', '-i') + .withArguments('sayHello') .withPluginClasspath(pluginClasspath) .build() @@ -101,8 +101,8 @@ main _ = do 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" + DEFAULT_FREGE_VERSION | "2.8" + "3.22.367-g2737683" | "2.9" + "3.22.367-g2737683" | "2.8" } } \ No newline at end of file -- cgit From 73dd702743a5b4d8816e495e55c19f391669fc25 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Sat, 21 Nov 2015 01:09:13 +0000 Subject: some integTest cleanup + more test coverage --- src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy b/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy index 547c939..b6936a8 100644 --- a/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy +++ b/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy @@ -89,7 +89,7 @@ main _ = do when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) - .withDebug(true).withProjectDir(testProjectDir.root) + .withProjectDir(testProjectDir.root) .withArguments('sayHello') .withPluginClasspath(pluginClasspath) .build() -- cgit