Skip to content
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
41 changes: 12 additions & 29 deletions cdtool/cdgradle/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
/* (c) https://github.com/MontiCore/monticore */
buildscript {
dependencies {
classpath "de.se_rwth.commons:se-commons-gradle:$mc_version"
}
}
plugins {
id 'java-library'
id 'java-gradle-plugin'
id 'maven-publish'
}


configurations {
cdTool
}


dependencies {
implementation "de.se_rwth.commons:se-commons-gradle:$mc_version"
cdTool "de.monticore.lang:cd4analysis:$mc_version"
compileOnly(project(":cdlang")) // As the main/cdtool dependency does not have an api dependency to cdlang
// compileOnly(project(":cdlang")) // As the main/cdtool dependency does not have an api dependency to cdlang

testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junit_version"
Expand All @@ -25,12 +23,6 @@ dependencies {
}


sourceSets {
main.compileClasspath += configurations.cdTool
test.compileClasspath += configurations.cdTool
}


gradlePlugin {
plugins {
cdplugin {
Expand All @@ -55,29 +47,20 @@ test.dependsOn(project(":cdlang").tasks.jar)
test.inputs.files(project(":cdlang").tasks.jar)

// Write the version to the jar
def buildInfoVersion = project.version.toString()

tasks.register('generateResources') {
ext {
propFile = layout.buildDirectory.file("generated/buildInfo.properties")
}
outputs.file propFile
doLast {
File f = propFile.get().asFile
f.parentFile.mkdirs()
f.text = "version=$buildInfoVersion"
}
import de.monticore.gradle.common.MCBuildInfoTask;
tasks.register("writeMCBuildInfo", MCBuildInfoTask.class){
getVersion().set(project.provider(() -> project.getVersion().toString()));
}

processResources {
from files(generateResources)
dependsOn generateResources
dependsOn tasks.named("writeMCBuildInfo")
}

tasks.withType(Test).configureEach {
useJUnitPlatform()
dependsOn project.tasks.getByPath(":cdlang:jar")
dependsOn project.tasks.getByPath(":cd-runtime:jar")
dependsOn generateResources
dependsOn tasks.named("writeMCBuildInfo")

// For the MontiVerse
systemProperty "maven.repo.local", System.getProperty("maven.repo.local")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.cdgen.gradleplugin;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.plugins.JavaLibraryPlugin;

import java.io.IOException;
import java.util.Properties;

@SuppressWarnings("unused")
public class CDGenGradleDependenciesPlugin implements Plugin<Project> {

/**
* Configuration containing the classpath of the generator tool.
*/
public static final String CONFIG_TOOL = "cdTool";

/**
* Configuration containing the classpath of the target.
* it will be added to the api configuration & passed as a symbol path for class2mc
*/
public static final String CONFIG_TARGET_RUNTIME = "cdToolTargetRuntime";

@Override
public void apply(Project project) {
project.getPluginManager().apply(JavaLibraryPlugin.class);

// Setup cdTool dependency
var properties = loadProperties();
String version = properties.getProperty("version");

Configuration toolConfig = project.getConfigurations().maybeCreate(CONFIG_TOOL);
toolConfig.setCanBeResolved(true);
Configuration toolRuntimeConfig = project.getConfigurations().maybeCreate(
CONFIG_TARGET_RUNTIME);
toolRuntimeConfig.setCanBeResolved(true);

toolConfig.defaultDependencies(dependencies -> {
dependencies.add(project.getDependencies().create("de.monticore.lang:cd4analysis:"
+ version));
});

toolRuntimeConfig.defaultDependencies(dependencies -> {
dependencies.add(project.getDependencies().create("de.monticore.lang:cd-runtime:" + version
+ ":cd-runtime"));
});

project.getTasks().withType(CDGenTask.class).configureEach(t -> t.getExtraClasspathElements()
.from(toolConfig));

project.getTasks().withType(CDGenTask.class).configureEach(t -> t.getTargetSymbolPath().from(
toolRuntimeConfig));

project.getConfigurations().named("api").configure(api -> api.extendsFrom(toolRuntimeConfig));

}

public Properties loadProperties() {
Properties properties = new Properties();
try {
properties.load(this.getClass().getClassLoader().getResourceAsStream("buildInfo.properties"));
}
catch (IOException e) {
throw new RuntimeException(e);
}
return properties;
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.cdgen.gradleplugin;

import java.io.IOException;
import java.util.Properties;
import java.util.stream.Collectors;

import de.monticore.gradle.queue.CachedQueueServicePlugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.file.Directory;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.SourceDirectorySet;
import org.gradle.api.internal.lambdas.SerializableLambdas;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.plugins.JavaLibraryPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSet;
Expand All @@ -22,57 +20,23 @@
@SuppressWarnings("unused")
public class CDGenGradlePlugin implements Plugin<Project> {

/**
* Configuration containing the classpath of the generator tool.
*/
public static final String CONFIG_TOOL = "cdTool";

private final ObjectFactory objectFactory;

@Inject
public CDGenGradlePlugin(ObjectFactory objectFactory) {
this.objectFactory = objectFactory;
}

/**
* Configuration containing the classpath of the target.
* it will be added to the api configuration & passed as a symbol path for class2mc
*/
public static final String CONFIG_TARGET_RUNTIME = "cdToolTargetRuntime";

@Override
public void apply(Project project) {
project.getPluginManager().apply(JavaLibraryPlugin.class);

// Setup cdTool dependency
var properties = loadProperties();
String version = properties.getProperty("version");
// Set up the improved work-queue
project.getPluginManager().apply(CachedQueueServicePlugin.class);

Configuration toolConfig = project.getConfigurations().maybeCreate(CONFIG_TOOL);
toolConfig.setCanBeResolved(true);
Configuration toolRuntimeConfig = project.getConfigurations().maybeCreate(
CONFIG_TARGET_RUNTIME);
toolRuntimeConfig.setCanBeResolved(true);
// Populate the "cdTool" configuration with the generator itself and
// Populate the "cdToolTargetRuntime" configuration with the runtime
project.getPluginManager().apply(CDGenGradleDependenciesPlugin.class);

toolConfig.defaultDependencies(dependencies -> {
dependencies.add(project.getDependencies().create("de.monticore.lang:cd4analysis:"
+ version));
});

toolRuntimeConfig.defaultDependencies(dependencies -> {
dependencies.add(project.getDependencies().create("de.monticore.lang:cd-runtime:" + version
+ ":cd-runtime"));
});

project.getTasks().withType(CDGenTask.class).configureEach(t -> t.getExtraClasspathElements()
.from(toolConfig));

project.getTasks().withType(CDGenTask.class).configureEach(t -> t.getTargetSymbolPath().from(
toolRuntimeConfig));

project.getConfigurations().named("api").configure(api -> api.extendsFrom(toolRuntimeConfig));

// Set up source-Sets
// Set up source-(directory)-Sets
project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().all(sourceSet -> {
var cdSrcDirSet = addSourceSetExtension(sourceSet, project);

Expand Down Expand Up @@ -100,17 +64,6 @@ public void apply(Project project) {
});
}

public Properties loadProperties() {
Properties properties = new Properties();
try {
properties.load(this.getClass().getClassLoader().getResourceAsStream("buildInfo.properties"));
}
catch (IOException e) {
throw new RuntimeException(e);
}
return properties;
}

/** Adds the "cd" extension to every source set */
protected CDSourceDirectorySet addSourceSetExtension(SourceSet sourceSet, Project project) {
SourceDirectorySet vanillaSrcDirSet = project.getObjects().sourceDirectorySet(
Expand All @@ -136,8 +89,7 @@ protected CDSourceDirectorySet addSourceSetExtension(SourceSet sourceSet, Projec
cdSrcDirSet.getFilter().include("**/*.cd");

// Casting the SrcDirSet to a FileCollection seems to be necessary due to compatibility reasons
// with the
// configuration cache.
// with the configuration cache.
// See
// https://github.com/gradle/gradle/blob/d36380f26658d5cf0bf1bfb3180b9eee6d1b65a5/subprojects/scala/src/main/java/org/gradle/api/plugins/scala/ScalaBasePlugin.java#L194
FileCollection mcSrcSetCast = cdSrcDirSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.cdgen.gradleplugin;

import de.monticore.gradle.common.AToolAction;
import de.monticore.gradle.common.MCAllFilesTask;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

import de.monticore.gradle.queue.ICachedQueueTask;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.provider.ListProperty;
Expand All @@ -21,10 +20,11 @@
* B.cd is allowed
*/
@CacheableTask
public abstract class CDGenTask extends MCAllFilesTask {
public abstract class CDGenTask extends MCAllFilesTask implements ICachedQueueTask {

public CDGenTask() {
super("CDGenTask", null);
getMainClass().convention("de.monticore.cdgen.CDGenTool");
}

@Optional
Expand Down Expand Up @@ -113,9 +113,10 @@ public void startGeneration(List<String> args, String progressName) {
}

@Override
protected Class<? extends AToolAction> getToolAction() { return CDGenAction.class; }

@Override
protected Consumer<String[]> getRunMethod() { return CDGenToolInvoker::run; }
protected void prepareWorkQueue() {
// Use the improved shared-isolated-work-queue of se-commons
this.workQueue = doGetSharedQueueService().newWorkQueue(getWorkerExecutor(),
getExtraClasspathElements());
}

}

This file was deleted.

Loading