aboutsummaryrefslogtreecommitdiff
path: root/src/main/groovy/frege/gradle
diff options
context:
space:
mode:
authorDierk König <dierk.koenig@canoo.com>2015-11-22 10:17:13 +0100
committerDierk König <dierk.koenig@canoo.com>2015-11-22 10:17:13 +0100
commite2575d292ef1158dcc7a5421b12fd0ad6be20820 (patch)
tree9f6561b11f660941da3dd304b64d5d5a484a7c19 /src/main/groovy/frege/gradle
parentf0807811f48c50b6a5fe7816ef48c148be9f9903 (diff)
parent61196dfe58d3fd38f09c3ddfbcc8cb932d240c1e (diff)
downloadfrege-gradle-plugin-e2575d292ef1158dcc7a5421b12fd0ad6be20820.tar.gz
frege-gradle-plugin-e2575d292ef1158dcc7a5421b12fd0ad6be20820.tar.bz2
frege-gradle-plugin-e2575d292ef1158dcc7a5421b12fd0ad6be20820.zip
Merge pull request #29 from breskeby/with-java
some more basic cleanup and fixing
Diffstat (limited to 'src/main/groovy/frege/gradle')
-rw-r--r--src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java26
-rw-r--r--src/main/groovy/frege/gradle/plugins/FregeJarFile.java34
-rw-r--r--src/main/groovy/frege/gradle/plugins/FregeRuntime.java63
-rw-r--r--src/main/groovy/frege/gradle/tasks/FregeCompile.groovy56
4 files changed, 23 insertions, 156 deletions
diff --git a/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java b/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java
index 8bf5399..a2ebc25 100644
--- a/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java
+++ b/src/main/groovy/frege/gradle/plugins/FregeBasePlugin.java
@@ -30,22 +30,20 @@ public class FregeBasePlugin implements Plugin<Project> {
}
@Override
- public void apply(Project project) {
+ public void apply(final Project project) {
// Workaround to build proper jars on Windows, see https://github.com/Frege/frege-gradle-plugin/issues/9
this.project = project;
System.setProperty("file.encoding", "UTF-8");
project.getPluginManager().apply(JavaBasePlugin.class);
fregePluginExtension = project.getExtensions().create(EXTENSION_NAME, FregePluginExtension.class);
JavaBasePlugin javaBasePlugin = project.getPlugins().getPlugin(JavaBasePlugin.class);
-
- configureCompileDefaults(new FregeRuntime(project));
configureSourceSetDefaults(javaBasePlugin);
}
private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) {
project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {
- public void execute(SourceSet sourceSet) {
+ public void execute(final SourceSet sourceSet) {
final DefaultFregeSourceSet fregeSourceSet = new DefaultFregeSourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), fileResolver);
new DslObject(sourceSet).getConvention().getPlugins().put("frege", fregeSourceSet);
@@ -63,6 +61,12 @@ public class FregeBasePlugin implements Plugin<Project> {
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());
@@ -70,18 +74,4 @@ public class FregeBasePlugin implements Plugin<Project> {
}
});
}
-
- private void configureCompileDefaults(final FregeRuntime fregeRuntime) {
- this.project.getTasks().withType(FregeCompile.class, new Action<FregeCompile>() {
- public void execute(final FregeCompile compile) {
- compile.getConventionMapping().map("fregeClasspath", new Callable() {
- public Object call() throws Exception {
- return fregeRuntime.inferFregeClasspath(compile.getClasspath());
- }
-
- });
- }
- });
- }
-
}
diff --git a/src/main/groovy/frege/gradle/plugins/FregeJarFile.java b/src/main/groovy/frege/gradle/plugins/FregeJarFile.java
deleted file mode 100644
index eaf7d8f..0000000
--- a/src/main/groovy/frege/gradle/plugins/FregeJarFile.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package frege.gradle.plugins;
-
-import org.gradle.util.VersionNumber;
-
-import java.io.File;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class FregeJarFile {
- private static final Pattern FILE_NAME_PATTERN = Pattern.compile("(frege(?:-all)?)-(\\d.*?)(-indy)?.jar");
- private final File file;
- private final Matcher matcher;
- private String version;
-
- private FregeJarFile(File file, Matcher matcher) {
- this.file = file;
- this.matcher = matcher;
- }
-
-
- public static FregeJarFile parse(File file) {
- Matcher matcher = FILE_NAME_PATTERN.matcher(file.getName());
- return matcher.matches() ? new FregeJarFile(file, matcher) : null;
- }
-
- public String getDependencyNotation() {
- return "org.frege-lang:frege:" + getVersion();
-
- }
-
- public VersionNumber getVersion() {
- return VersionNumber.parse(matcher.group(2));
- }
-}
diff --git a/src/main/groovy/frege/gradle/plugins/FregeRuntime.java b/src/main/groovy/frege/gradle/plugins/FregeRuntime.java
deleted file mode 100644
index 4265d0b..0000000
--- a/src/main/groovy/frege/gradle/plugins/FregeRuntime.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package frege.gradle.plugins;
-
-import com.google.common.collect.Lists;
-import org.gradle.api.Buildable;
-import org.gradle.api.GradleException;
-import org.gradle.api.Project;
-import org.gradle.api.artifacts.Dependency;
-import org.gradle.api.file.FileCollection;
-import org.gradle.api.internal.file.collections.LazilyInitializedFileCollection;
-import org.gradle.api.internal.tasks.TaskDependencyResolveContext;
-
-import java.io.File;
-import java.util.List;
-
-public class FregeRuntime {
-
- private final Project project;
-
- public FregeRuntime(Project project) {
- this.project = project;
- }
-
-
- public FileCollection inferFregeClasspath(final Iterable<File> 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<Dependency> 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<File> classpath) {
- if (classpath == null) {
- return null;
- }
- for (File file : classpath) {
- FregeJarFile fregeJar = FregeJarFile.parse(file);
- if (fregeJar != null) {
- return fregeJar;
- }
- }
- return null;
- }
-
-}
diff --git a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy
index 13b617c..290f750 100644
--- a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy
+++ b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy
@@ -1,10 +1,10 @@
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.InputFiles
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.compile.AbstractCompile
@@ -13,67 +13,51 @@ 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<File> fregePaths = []
+ @Optional @InputFiles
+ FileCollection fregepath
@Input
String mainClass = "frege.compiler.Main"
@@ -82,11 +66,9 @@ class FregeCompile extends AbstractCompile {
@Input
List<String> allJvmArgs = []
- @Optional
@Input
String encoding = ""
- @Optional
@Input
String prefix = ""
@@ -95,8 +77,6 @@ class FregeCompile extends AbstractCompile {
@Override
@TaskAction
protected void compile() {
- logConfigurationInfo()
-
def jvmArgs = allJvmArgs
if (jvmArgs.isEmpty()) {
jvmArgs << "-Xss$stackSize".toString()
@@ -106,14 +86,20 @@ class FregeCompile extends AbstractCompile {
logger.info("Calling Frege compiler with compilerArgs: '$compilerArgs'")
//TODO integrate with gradle compiler daemon infrastructure and skip internal execution
+
+ def errOutputStream = new ByteArrayOutputStream();
+ def outOutputStream = new ByteArrayOutputStream();
project.javaexec(new Action<JavaExecSpec>() {
@Override
void execute(JavaExecSpec javaExecSpec) {
javaExecSpec.args = compilerArgs
- javaExecSpec.classpath = FregeCompile.this.classpath + FregeCompile.this.fregeClasspath
+ javaExecSpec.classpath = FregeCompile.this.classpath
javaExecSpec.main = mainClass
+ javaExecSpec.errorOutput = System.err;
+ javaExecSpec.standardOutput = System.out;
}
});
+
}
public FregeCompile source(Object... sources) {
@@ -125,16 +111,6 @@ class FregeCompile extends AbstractCompile {
return this;
}
- void logConfigurationInfo() {
- def path = project.files(compileConfig()).getAsPath()
- logger.info("Compile configuation as path: $path")
- }
-
- @TypeChecked(TypeCheckingMode.SKIP)
- Configuration compileConfig() {
- project.configurations.compile
- }
-
protected List<String> assembleArguments() {
List args = []
if (hints)
@@ -161,10 +137,10 @@ class FregeCompile extends AbstractCompile {
if (verbose)
args << "-v"
- def fp = fregePaths
- if (!fp.isEmpty()) {
+
+ if (fregepath != null && !fregepath.isEmpty()) {
args << "-fp"
- args << fp.collect { f -> f.absolutePath }.join(File.pathSeparator)
+ args << fregepath.files.collect { f -> f.absolutePath }.join(File.pathSeparator)
}
if (sourcePaths != null && !sourcePaths.isEmpty()) {
@@ -183,7 +159,7 @@ class FregeCompile extends AbstractCompile {
}
args << "-d"
- args << getDestinationDir()
+ args << getDestinationDir().absolutePath
if (!module.isEmpty()) {
logger.info "compiling module '$module'"
@@ -191,8 +167,6 @@ class FregeCompile extends AbstractCompile {
} else {
args = (args + extraArgs.split().toList()).toList()
}
-
args
}
-
}