Skip to content

Commit

Permalink
Merge pull request #1976 from keeganwitt/GROOVY-11194_groovy30
Browse files Browse the repository at this point in the history
GROOVY-11194 (Groovy 3.0)
  • Loading branch information
keeganwitt authored Nov 26, 2023
2 parents 0200350 + 211be84 commit 09bbff9
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.codehaus.groovy.control.CompilationUnit;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.ConfigurationException;
import org.codehaus.groovy.control.messages.WarningMessage;
import org.codehaus.groovy.runtime.DefaultGroovyStaticMethods;
import org.codehaus.groovy.runtime.StringGroovyMethods;
import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit;
Expand Down Expand Up @@ -357,18 +358,33 @@ public static class CompilationOptions {
@Option(names = "-d", paramLabel = "<dir>", description = "Specify where to place generated class files")
private File targetDir;

@Option(names = {"-de", "--debug"}, description = "If set, outputs a little more information during compilation when errors occur.")
private boolean debug;

@Option(names = {"-e", "--exception"}, description = "Print stack trace on error")
private boolean printStack;

@Option(names = {"-w", "--warningLevel"}, description = "The amount of warnings to print. Set to 0 for none, 1 for likely errors, 2 for possible errors, and 3 for as many warnings as possible.", defaultValue = "1")
private String warningLevel;

@Option(names = {"-pa", "--parameters"}, description = "Generate metadata for reflection on method parameter names (jdk8+ only)")
private boolean parameterMetadata;

@Option(names = {"-pl", "--parallel-parsing"}, description = "Enable parallel parsing")
private boolean parallelParsing;

@Option(names = {"-pr", "--enable-preview"}, description = "Enable preview Java features (jdk12+ only) - must be after classpath but before other arguments")
private boolean previewFeatures;

@Option(names = {"-j", "--jointCompilation"}, description = "Attach javac compiler to compile .java files")
private boolean jointCompilation;

@Option(names = {"-s", "--stubDirectory"}, description = "The directory into which the Java source stub files should be generated")
private String stubDirectory;

@Option(names = {"-ks", "--keepStubs"}, description = "Whether to keep the generated stubs rather than deleting them")
private boolean keepStubs;

@Option(names = {"-b", "--basescript"}, paramLabel = "<class>", description = "Base class name for scripts (must derive from Script)")
private String scriptBaseClass;

Expand All @@ -381,9 +397,12 @@ public static class CompilationOptions {
@Option(names = {"--indy"}, description = "Enables compilation using invokedynamic")
private boolean indy;

@Option(names = {"--configscript"}, paramLabel = "<script>", description = "A script for tweaking the configuration options")
@Option(names = {"-cf", "--configscript"}, paramLabel = "<script>", description = "A script for tweaking the configuration options")
private String configScript;

@Option(names = {"-t", "--tolerance"}, description = "The number of non-fatal errors to allow before bailing")
private int tolerance;

@Option(names = {"-h", "--help"}, usageHelp = true, description = "Show this help message and exit")
private boolean helpRequested;

Expand Down Expand Up @@ -416,12 +435,30 @@ public CompilerConfiguration toCompilerConfiguration() throws IOException {
configuration.setPreviewFeatures(previewFeatures);
configuration.setSourceEncoding(encoding);
configuration.setScriptBaseClass(scriptBaseClass);
if (tolerance > 0) {
configuration.setTolerance(tolerance);
}

if (Integer.parseInt(warningLevel) == WarningMessage.NONE
|| Integer.parseInt(warningLevel) == WarningMessage.LIKELY_ERRORS
|| Integer.parseInt(warningLevel) == WarningMessage.POSSIBLE_ERRORS
|| Integer.parseInt(warningLevel) == WarningMessage.PARANOIA) {
configuration.setWarningLevel(Integer.parseInt(warningLevel));
} else {
System.err.println("error: warning level not recognized: " + warningLevel);
}

// joint compilation parameters
if (jointCompilation) {
Map<String, Object> compilerOptions = new HashMap<>();
compilerOptions.put("flags", javacFlags());
compilerOptions.put("namedValues", javacNamedValues());
if (stubDirectory != null) {
compilerOptions.put("stubDir", stubDirectory);
}
if (keepStubs) {
compilerOptions.put("keepStubs", true);
}
configuration.setJointCompilationOptions(compilerOptions);
}

Expand All @@ -430,6 +467,10 @@ public CompilerConfiguration toCompilerConfiguration() throws IOException {
configuration.getOptimizationOptions().put("indy", Boolean.TRUE);
}

if (parallelParsing) {
configuration.getOptimizationOptions().put("parallelParse", true);
}

final List<String> transformations = new ArrayList<>();
if (compileStatic) {
transformations.add("ast(groovy.transform.CompileStatic)");
Expand Down

0 comments on commit 09bbff9

Please sign in to comment.