From bc4f5979232600f981b805a204302b5e5f235c8e Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Fri, 10 Jan 2025 12:27:57 +0100 Subject: [PATCH] Allow passing extra arguments to SableCC --- README.md | 2 ++ .../de/hhu/stups/sablecc/gradle/SableCCTask.java | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 0b8e60a..cbae578 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ You normally don't need to do this - all of these options have reasonable defaul tasks.named("generateSableCCSource").configure { sableCCClasspath = sourceSets.something.runtimeClasspath maxHeapSize = "512M" + arguments = ["--no-inline"] // WARNING: The destination dirs will be DELETED every time the SableCC task runs! destinationJavaDir = "my/custom/out/java" destinationResourcesDir = "my/custom/out/resources" @@ -62,6 +63,7 @@ tasks.named("generateSableCCSource").configure { ## Version 1.2.0 (not released yet) +* Add ability to pass extra arguments to SableCC using the new `arguments` property of `SableCCTask`. * Fix deprecation warnings on Gradle 8.12 about accessing `Project` at execution time. ## Version 1.1.0 diff --git a/src/main/java/de/hhu/stups/sablecc/gradle/SableCCTask.java b/src/main/java/de/hhu/stups/sablecc/gradle/SableCCTask.java index 27466f9..8afe9d3 100644 --- a/src/main/java/de/hhu/stups/sablecc/gradle/SableCCTask.java +++ b/src/main/java/de/hhu/stups/sablecc/gradle/SableCCTask.java @@ -6,6 +6,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import javax.inject.Inject; @@ -35,6 +36,7 @@ public abstract class SableCCTask extends SourceTask { private FileCollection sableCCClasspath; private String maxHeapSize; + private List<String> arguments; private final DirectoryProperty destinationJavaDir; private final DirectoryProperty destinationResourcesDir; @@ -47,6 +49,7 @@ public abstract class SableCCTask extends SourceTask { this.sableCCClasspath = null; this.maxHeapSize = null; + this.arguments = new ArrayList<>(); this.destinationJavaDir = objectFactory.directoryProperty(); this.destinationResourcesDir = objectFactory.directoryProperty(); } @@ -84,6 +87,15 @@ public abstract class SableCCTask extends SourceTask { this.maxHeapSize = maxHeapSize; } + @Input + public List<String> getArguments() { + return this.arguments; + } + + public void setArguments(List<String> arguments) { + this.arguments = Objects.requireNonNull(arguments, "arguments"); + } + @OutputDirectory public Directory getDestinationJavaDir() { return this.destinationJavaDir.get(); @@ -120,6 +132,7 @@ public abstract class SableCCTask extends SourceTask { List<String> args = new ArrayList<>(); args.add("-d"); args.add(destinationJavaPath.toString()); + args.addAll(this.getArguments()); for (File file : this.getSource().getFiles()) { args.add(file.getPath()); } -- GitLab