diff --git a/example-project/build.gradle b/example-project/build.gradle index 77ea9d0..b9cf616 100644 --- a/example-project/build.gradle +++ b/example-project/build.gradle @@ -1,5 +1,6 @@ plugins { - id 'ch.fhnw.thga.frege' version '2.0.0-alpha' + id 'ch.fhnw.thga.frege' version 'latest' + id 'java' } frege { @@ -7,4 +8,4 @@ frege { release = '3.25alpha' mainModule = 'ch.fhnw.thga.HelloFrege' replModule = 'ch.fhnw.thga.HelloFrege' -} \ No newline at end of file +} diff --git a/example-project/settings.gradle b/example-project/settings.gradle index 91a56b3..08439eb 100644 --- a/example-project/settings.gradle +++ b/example-project/settings.gradle @@ -1,8 +1,13 @@ pluginManagement { - repositories { - mavenLocal() - gradlePluginPortal() + resolutionStrategy { + eachPlugin { + if (requested.id.id == "ch.fhnw.thga.frege") { + var x = new Properties() + x.load(new FileInputStream(file("../gradle.properties"))) + useVersion(x.get("version")) + } + } } } - -rootProject.name = 'example-project' \ No newline at end of file +rootProject.name = 'example-project' +includeBuild("..") diff --git a/example-project/src/main/frege/ch/fhnw/thga/Hello2.fr b/example-project/src/main/frege/ch/fhnw/thga/Hello2.fr new file mode 100644 index 0000000..b7e6760 --- /dev/null +++ b/example-project/src/main/frege/ch/fhnw/thga/Hello2.fr @@ -0,0 +1,4 @@ +module ch.fhnw.thga.Hello2 where + +main args = do + putStrLn "Hello from File 2" diff --git a/src/main/java/ch/fhnw/thga/gradleplugins/FregePlugin.java b/src/main/java/ch/fhnw/thga/gradleplugins/FregePlugin.java index 8aaedee..7b39fba 100644 --- a/src/main/java/ch/fhnw/thga/gradleplugins/FregePlugin.java +++ b/src/main/java/ch/fhnw/thga/gradleplugins/FregePlugin.java @@ -3,9 +3,12 @@ import org.gradle.api.NamedDomainObjectProvider; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.Task; import org.gradle.api.artifacts.Configuration; import org.gradle.api.logging.LogLevel; import org.gradle.api.plugins.BasePlugin; +import org.gradle.api.plugins.JavaPluginExtension; +import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.TaskProvider; public class FregePlugin implements Plugin @@ -13,6 +16,7 @@ public class FregePlugin implements Plugin public static final String SETUP_FREGE_TASK_NAME = "setupFrege"; public static final String COMPILE_FREGE_TASK_NAME = "compileFrege"; public static final String RUN_FREGE_TASK_NAME = "runFrege"; + public static final String RUN_FREGE_ALT_TASK_NAME = "fregeRun"; public static final String TEST_FREGE_TASK_NAME = "testFrege"; public static final String REPL_FREGE_TASK_NAME = "replFrege"; public static final String INIT_FREGE_TASK_NAME = "initFrege"; @@ -22,6 +26,7 @@ public class FregePlugin implements Plugin public static final String HELLO_FREGE_DEFAULT_MODULE_NAME = "examples.HelloFrege"; public static final String FREGE_TEST_MODULE_NAME = "frege.tools.Quick"; public static final String FREGE_TEST_DEFAULT_ARGS = "-v"; + public static final String RUN_FREGE_TASK_MODULE_OVERRIDE = "class_name"; // Used by the intellij-frege plugin to run arbitary files @Override public void apply(Project project) @@ -36,13 +41,17 @@ public void apply(Project project) config.setCanBeConsumed(true); } ); + Configuration implementation = project.getConfigurations().maybeCreate("implementation"); + NamedDomainObjectProvider fregeResolved = project.getConfigurations().register("fregeResolved"); + implementation.extendsFrom(fregeConfiguration.get()); + implementation.extendsFrom(fregeResolved.get()); FregeExtension extension = project .getExtensions() .create( FREGE_EXTENSION_NAME, FregeExtension.class); - + project.getPlugins().apply(BasePlugin.class); project.getTasks().register( @@ -82,26 +91,33 @@ public void apply(Project project) } ); - project.getTasks().register( - RUN_FREGE_TASK_NAME, - RunFregeTask.class, - task -> - { - task.getMainModule().set(extension.getMainModule()); - task.dependsOn(compileFregeTask.map( - compileTask -> - { - compileTask.getFregeCompileItem().set(task.getMainModule()); - return compileTask; - } - ).get()); - task.getFregeCompilerJar().set( - setupFregeCompilerTask.get().getFregeCompilerOutputPath()); - task.getFregeOutputDir().set(extension.getOutputDir()); - task.getFregeDependencies().set(fregeConfiguration.get().getAsPath()); - } + TaskProvider runTask = project.getTasks().register( + RUN_FREGE_TASK_NAME, + RunFregeTask.class, + task -> + { + if (project.hasProperty(RUN_FREGE_TASK_MODULE_OVERRIDE)) + task.getMainModule().set(project.findProperty(RUN_FREGE_TASK_MODULE_OVERRIDE).toString()); + else + task.getMainModule().set(extension.getMainModule()); + task.dependsOn(compileFregeTask.map( + compileTask -> + { + compileTask.getFregeCompileItem().set(task.getMainModule()); + return compileTask; + } + ).get()); + task.getFregeCompilerJar().set( + setupFregeCompilerTask.get().getFregeCompilerOutputPath()); + task.getFregeOutputDir().set(extension.getOutputDir()); + task.getFregeDependencies().set(fregeConfiguration.get().getAsPath()); + } ); - + + project.getTasks().register(RUN_FREGE_ALT_TASK_NAME, task -> { + task.dependsOn(runTask); + }); + project.getTasks().register( TEST_FREGE_TASK_NAME, TestFregeTask.class, @@ -145,5 +161,20 @@ public void apply(Project project) task.getFregeMainSourceDir().set(extension.getMainSourceDir()); } ); + project.afterEvaluate(ignored -> { + project.getDependencies().add("implementation", setupFregeCompilerTask.map(SetupFregeTask::getFregeCompilerOutputPath).map(project::files)); + + JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class); + if(javaPluginExtension != null) { + SourceSet main = javaPluginExtension.getSourceSets().findByName("main"); + if(main != null) { + main.getOutput().dir(compileFregeTask.get().getOutputs()); + } + } + Task classes = project.getTasks().findByName("classes"); + if(classes != null) { + classes.dependsOn(compileFregeTask); + } + }); } }