aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRene Groeschke <rene@gradle.com>2015-12-14 22:56:51 +0100
committerRene Groeschke <rene@gradle.com>2015-12-14 23:21:11 +0100
commit7fb3f43096fa6b142eb059e1eeaca79abcaa3009 (patch)
tree69c098b1c37495c77b29d66eefe5376f7117facd
parentfcac60e0205340ed303ee58781e2d697e5630b90 (diff)
downloadfrege-gradle-plugin-7fb3f43096fa6b142eb059e1eeaca79abcaa3009.tar.gz
frege-gradle-plugin-7fb3f43096fa6b142eb059e1eeaca79abcaa3009.tar.bz2
frege-gradle-plugin-7fb3f43096fa6b142eb059e1eeaca79abcaa3009.zip
seme more coverage and work on frege doc task.
TODO fix fregedoc task for mixed java + frege sources
-rw-r--r--src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy3
-rw-r--r--src/integTest/groovy/frege/gradle/plugins/FregePluginIntegTest.groovy44
-rw-r--r--src/main/groovy/frege/gradle/FregeSourceSet.java6
-rw-r--r--src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java1
-rw-r--r--src/main/groovy/frege/gradle/plugins/FregePlugin.groovy20
-rw-r--r--src/main/groovy/frege/gradle/tasks/FregeDoc.groovy66
6 files changed, 92 insertions, 48 deletions
diff --git a/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy b/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy
index 6bcd339..7415ef1 100644
--- a/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy
+++ b/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy
@@ -17,8 +17,7 @@ class AbstractFregeIntegrationSpec extends Specification {
def setup() {
buildFile = testProjectDir.newFile('build.gradle')
-
- testProjectDir.newFolder("src", "main", "java", "org", "frege")
+ testProjectDir.newFolder("src", "main", "java", "org", "frege", "java")
testProjectDir.newFolder("src", "main", "frege", "org", "frege")
def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.txt")
diff --git a/src/integTest/groovy/frege/gradle/plugins/FregePluginIntegTest.groovy b/src/integTest/groovy/frege/gradle/plugins/FregePluginIntegTest.groovy
index 7272113..c394e48 100644
--- a/src/integTest/groovy/frege/gradle/plugins/FregePluginIntegTest.groovy
+++ b/src/integTest/groovy/frege/gradle/plugins/FregePluginIntegTest.groovy
@@ -2,6 +2,7 @@ package frege.gradle.plugins
import frege.gradle.integtest.fixtures.AbstractFregeIntegrationSpec
import org.gradle.testkit.runner.BuildResult
+import spock.lang.Ignore
import spock.lang.Unroll
import static org.gradle.testkit.runner.TaskOutcome.*
@@ -94,6 +95,41 @@ class FregePluginIntegTest extends AbstractFregeIntegrationSpec {
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"
+ }
+ """
+
+ and:
+ fregeModule()
+ when:
+ BuildResult result = run("fregeDoc")
+ then:
+ result.task(":fregeDoc").outcome == SUCCESS
+ }
+
+
+ @Ignore
+ 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:
@@ -131,8 +167,8 @@ class FregePluginIntegTest extends AbstractFregeIntegrationSpec {
fregeSourceFile << """
module org.frege.HelloFrege where
- data StaticHello = pure native org.frege.StaticHello where
- pure native helloJava org.frege.StaticHello.helloJava:: () -> String
+ data StaticHello = pure native org.frege.java.StaticHello where
+ pure native helloJava org.frege.java.StaticHello.helloJava:: () -> String
main _ = do
@@ -142,10 +178,10 @@ class FregePluginIntegTest extends AbstractFregeIntegrationSpec {
}
def javaCode(String sourceRoot = "java") {
- def javaSourceFile = testProjectDir.newFile("src/main/$sourceRoot/org/frege/StaticHello.java")
+ def javaSourceFile = testProjectDir.newFile("src/main/$sourceRoot/org/frege/java/StaticHello.java")
javaSourceFile << """
- package org.frege;
+ package org.frege.java;
public class StaticHello {
public static String helloJava() {
diff --git a/src/main/groovy/frege/gradle/FregeSourceSet.java b/src/main/groovy/frege/gradle/FregeSourceSet.java
index 8706ee2..7540930 100644
--- a/src/main/groovy/frege/gradle/FregeSourceSet.java
+++ b/src/main/groovy/frege/gradle/FregeSourceSet.java
@@ -1,7 +1,7 @@
package frege.gradle;
-/**
- * Created by Rene on 20/11/15.
- */
+import org.gradle.api.file.SourceDirectorySet;
+
public interface FregeSourceSet {
+ SourceDirectorySet getFrege();
}
diff --git a/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java b/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java
index a2ebc25..6d7a639 100644
--- a/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java
+++ b/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java
@@ -71,6 +71,7 @@ public class FregeBasePlugin implements Plugin<Project> {
compile.setDescription(String.format("Compiles the %s Frege source.", sourceSet.getName()));
compile.setSource(fregeSourceSet.getFrege());
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
index 88864cc..13c1e9a 100644
--- a/src/main/groovy/frege/gradle/plugins/FregePlugin.groovy
+++ b/src/main/groovy/frege/gradle/plugins/FregePlugin.groovy
@@ -1,11 +1,13 @@
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.file.FileCollection
+import org.gradle.api.tasks.SourceSet
+import org.gradle.api.tasks.util.PatternSet
class FregePlugin implements Plugin<Project> {
@@ -25,10 +27,24 @@ class FregePlugin implements Plugin<Project> {
project.tasks.test.dependsOn("fregeQuickCheck")
- project.task('fregeDoc', type: FregeDoc, group: 'frege', dependsOn: 'compileFrege')
+
+ 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.classesDir.absolutePath
+ fregeDoc.classpath = mainSourceSet.runtimeClasspath
+ }
+
+
+ FileCollection findJavaModulesToExclude(SourceSet sourceSet) {
+ return sourceSet.allJava.asFileTree.matching { PatternSet pattern -> pattern.include("**/*.java")}
+ }
}
diff --git a/src/main/groovy/frege/gradle/tasks/FregeDoc.groovy b/src/main/groovy/frege/gradle/tasks/FregeDoc.groovy
index 7ac49a7..af4b924 100644
--- a/src/main/groovy/frege/gradle/tasks/FregeDoc.groovy
+++ b/src/main/groovy/frege/gradle/tasks/FregeDoc.groovy
@@ -1,14 +1,13 @@
package frege.gradle.tasks
+import org.gradle.api.Action
import org.gradle.api.DefaultTask
-import org.gradle.api.internal.file.FileResolver
+import org.gradle.api.file.FileCollection
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
+import org.gradle.process.JavaExecSpec
class FregeDoc extends DefaultTask {
@@ -30,53 +29,46 @@ class FregeDoc extends DefaultTask {
*
*/
- 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
+ String module // module name or directory or class path. Default is all production modules
- @Input @Optional
+ @Input
+ @Optional
String exclude = null
- @Input @Optional
+ @Input
+ @Optional
Boolean verbose = null
+ FileCollection classpath
+
@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()
+ def result = project.javaexec(new Action<JavaExecSpec>() {
+ @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 = System.err
+ javaExecSpec.classpath = this.classpath
+ }
+ })
}
}