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
44 changes: 44 additions & 0 deletions se-commons-gradle/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/* (c) https://github.com/MontiCore/monticore */

plugins {
id 'java-gradle-plugin' // No plugin will be published, but for tests
}

description = 'se-commons: gradle'

dependencies {
implementation gradleApi()
implementation project(":se-commons-utilities")
implementation project(":se-commons-logging")
implementation 'com.google.code.gson:gson:2.13.2'

implementation "org.apache.commons:commons-lang3:3.8.1"
implementation "com.google.guava:guava:33.1.0-jre"
Expand All @@ -18,3 +23,42 @@ publishing {
}
}
}

// Test our plugin infrastructure with a test-plugin
sourceSets {
testPlugin {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
}
configurations {
testPluginImplementation.extendsFrom implementation
testPluginRuntimeOnly.extendsFrom runtimeOnly
}

dependencies {
testPluginImplementation gradleApi()
testImplementation gradleTestKit()
testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.0")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
tasks.named('test', Test) {
useJUnitPlatform()
// Parallel test execution
systemProperty("junit.jupiter.execution.parallel.enabled", true)
systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent")
}

gradlePlugin {
testSourceSet sourceSets.test
}

tasks.register('testPluginJar', Jar) {
archiveClassifier = 'testPlugin'
from sourceSets.testPlugin.output
}

tasks.pluginUnderTestMetadata {
pluginClasspath.from(tasks.testPluginJar)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

Expand Down Expand Up @@ -96,13 +97,11 @@ public void setInput(Object... paths){


@Deprecated // old-school hwcDir = ..
@Internal
public void setHwcDir(File f){
this.getHandWrittenCodeDir().setFrom(f);
}

@Deprecated // old-school hwcDir = [...] / hwcDir +=
@Internal
public void setHwcDir(Iterable<File> f){
this.getHandWrittenCodeDir().setFrom(f);
}
Expand All @@ -114,13 +113,11 @@ public ConfigurableFileCollection getHwcDir(){
}

@Deprecated
@Internal
public void setHwgDir(File f){
this.getHandWrittenGrammarDir().setFrom(f);
}

@Deprecated
@Internal
public void setHwgDir(Iterable<File> f){
this.getHandWrittenGrammarDir().setFrom(f);
}
Expand Down Expand Up @@ -156,7 +153,7 @@ public ConfigurableFileCollection getHwgDir(){
@Incremental // Incremental symbol path (such as MC generation the modelpath)
@Optional
// Absolute, since this can contain elements from the gradle jar cache, outside the project
@PathSensitive(PathSensitivity.ABSOLUTE) // TODO: really absolute?
@Classpath // The content of the jar file is normalized so that time stamps and order of the zip entries in the jar file do not matter
public abstract ConfigurableFileCollection getIncrementalSymbolPath();


Expand Down Expand Up @@ -386,17 +383,34 @@ protected void startGeneration(List<String> args, String progressName) {
workQueue.submit(getToolAction(), param -> {
param.getArgs().set(args);
param.getProgressName().set(progressName);
param.getPrefix().set("[" + progressName + "]");
// A unique name for the stats reporter, etc.
int classPathHash = getExtraClasspathElements().getFiles().stream().map(File::getName).collect(Collectors.joining(",")).hashCode();
param.getStatsUniqueName().set( "[" + getPath() + "(" + getClass().getSimpleName() + ")"
+ "[" + classPathHash + "]"
+ "#" + progressName + "]");
param.getExtraClasspathElements().setFrom(this.getExtraClasspathElements());
param.getProgressLogger().set(getProgressLoggerService());
this.specParam(param);
});
}
}

/**
* Customize the tool parameters
* @param param the params being constructed
*/
protected void specParam(ToolArgActionParameter param) {
// noop
}

@Internal
public abstract Property<ProgressLoggerService> getProgressLoggerService();

@Internal
protected abstract Consumer<String[]> getRunMethod();
protected Consumer<String[]> getRunMethod() {
throw new IllegalStateException("No tool invoker present, workQueueDebug is not supported!");
}

@Internal
protected abstract Class<? extends AToolAction> getToolAction();
Expand Down Expand Up @@ -476,5 +490,23 @@ protected static void setIfPathExists(Consumer<File> add, Path path) {
add.accept(f);
}
}

/**
* Turn a path into string accepted by {@link File#File(String)}.
* This especially contains spaces
*
* @param path the path
* @return a valid argument for File
*/
protected String pathToFileString(Path path) {
return path.toFile().getAbsolutePath();
}

protected String pathToHumanReadableString(Path path, Path projectWorkingDir) {
if (projectWorkingDir.getRoot().equals(path.getRoot())) {
return projectWorkingDir.relativize(path).toString();
}
return pathToFileString(path);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ public void run(InputChanges inputChanges) throws IOException {

Path cwd = getProject().getProjectDir().toPath().toAbsolutePath();
getLogger().debug("Starting Tool with args: \n{} for {}",
String.join(" ", createArgList(p -> "." + File.separator +
(cwd.getRoot().equals(p.getRoot()) ? cwd.relativize(p) : p.toAbsolutePath()))),
this.getName());
String.join(" ", createArgList(p -> this.pathToHumanReadableString(p, cwd))),
this.getName());

List<String> args = createArgList(p -> p.toAbsolutePath().toString());
List<String> args = createArgList(this::pathToFileString);
startGeneration(args, this.getName());
} else {
getLogger().info("UP-TO-DATE, no action required");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ protected void runOnSingleInputFile(File f, InputChanges changedInput) {
private void startGeneration(File f) {
Path cwd = getProject().getProjectDir().toPath().toAbsolutePath();
getLogger().debug("Starting Tool: \n{} for {}",
String.join(" ", createArgList(f.toPath(), p -> "." + File.separator +
(cwd.getRoot().equals(p.getRoot()) ? cwd.relativize(p) : p.toAbsolutePath()))),
this.getName());
String.join(" ", createArgList(f.toPath(), p -> pathToHumanReadableString(p, cwd))),
this.getName());

List<String> args = this.createArgList(f.toPath(), p -> p.toAbsolutePath().toString());
List<String> args = this.createArgList(f.toPath(), this::pathToFileString);
startGeneration(args, f.getName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
package de.monticore.gradle.common;

import de.monticore.gradle.internal.ProgressLoggerService;
import de.monticore.gradle.queue.CachedIsolatedWorkQueue;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
import org.gradle.workers.WorkParameters;

/**
* work parameters consisting of CLI arguments
*/
public interface ToolArgActionParameter extends WorkParameters {
public interface ToolArgActionParameter extends CachedIsolatedWorkQueue.WorkQueueParameters {
/**
* Arguments passed to a Tool
*/
Expand All @@ -19,6 +19,7 @@ public interface ToolArgActionParameter extends WorkParameters {
/**
* Name of this work action, passed to the log
*/
@Deprecated
Property<String> getProgressName();

/**
Expand Down
Loading
Loading