Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.stream.Collectors;
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;
Expand All @@ -21,6 +22,9 @@
@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;
Expand All @@ -30,31 +34,43 @@ 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");
var toolConfig = project.getConfigurations().maybeCreate(CONFIG_TOOL);

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.getConfigurations().named("api").configure(api -> {
api.withDependencies(dependencies -> {
dependencies.add(project.getDependencies().create("de.monticore.lang:cd-runtime:" + version
+ ":cd-runtime"));
});

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

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

// Set up source-Sets
project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().all(sourceSet -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
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 org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.*;

/**
* Gradle Task of the {@link de.monticore.cdgen.CDGenTool} It is an all-files task, as -i A.cd -i
Expand Down Expand Up @@ -61,6 +62,16 @@ public CDGenTask() {
@OutputDirectory
abstract DirectoryProperty getDecoratedSymbolOutput();

/**
* the symbol path of the target artifact (e.g., containing the cd-runtime)
*
* @return -path values
*/
@Optional
@InputFiles
@PathSensitive(PathSensitivity.RELATIVE)
abstract ConfigurableFileCollection getTargetSymbolPath();

@Override
protected List<String> createArgList(Function<Path, String> handlePath) {
var list = super.createArgList(handlePath);
Expand All @@ -71,6 +82,12 @@ protected List<String> createArgList(Function<Path, String> handlePath) {
if (getClass2MC().isPresent() && getClass2MC().get()) {
list.add("--class2mc");
}
if (!getTargetSymbolPath().isEmpty()) { // model paths
List<Path> modelPath = new ArrayList<>();
getTargetSymbolPath().forEach(it -> modelPath.add(it.toPath()));
list.add("-path");
modelPath.forEach(p -> list.add(handlePath.apply(p)));
}
if (getCoCos().getOrElse(true)) {
list.add("--checkcococs");
}
Expand Down
Loading