Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the frege-intellij plugin #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions example-project/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
plugins {
id 'ch.fhnw.thga.frege' version '2.0.0-alpha'
id 'ch.fhnw.thga.frege' version 'latest'
id 'java'
}

frege {
version = '3.25.84'
release = '3.25alpha'
mainModule = 'ch.fhnw.thga.HelloFrege'
replModule = 'ch.fhnw.thga.HelloFrege'
}
}
15 changes: 10 additions & 5 deletions example-project/settings.gradle
Original file line number Diff line number Diff line change
@@ -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'
rootProject.name = 'example-project'
includeBuild("..")
4 changes: 4 additions & 0 deletions example-project/src/main/frege/ch/fhnw/thga/Hello2.fr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ch.fhnw.thga.Hello2 where

main args = do
putStrLn "Hello from File 2"
71 changes: 51 additions & 20 deletions src/main/java/ch/fhnw/thga/gradleplugins/FregePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
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<Project>
{
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";
Expand All @@ -22,6 +26,7 @@ public class FregePlugin implements Plugin<Project>
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)
Expand All @@ -36,13 +41,17 @@ public void apply(Project project)
config.setCanBeConsumed(true);
}
);
Configuration implementation = project.getConfigurations().maybeCreate("implementation");
NamedDomainObjectProvider<Configuration> 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(
Expand Down Expand Up @@ -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<RunFregeTask> 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,
Expand Down Expand Up @@ -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);
}
});
}
}