Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Groovy 5 in CI #270

Merged
merged 2 commits into from
Sep 25, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- 2.5.23
- 3.0.19
- 4.0.15
# - 5.0.0-alpha-2
- 5.0.0-alpha-2
env:
MVN_GROOVY_GROUP_ID: ${{format('{0}{1}', '-DgroovyVersion=', matrix.groovy-version)}}
MVN_GROOVY_VERSION: ${{(startsWith(matrix.groovy-version, '2') || startsWith(matrix.groovy-version, '3')) && '-DgroovyGroupId=org.codehaus.groovy' || '-DgroovyGroupId=org.apache.groovy' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
*/
public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {

/**
* Groovy 5.0.0-alpha-1 version.
*/
protected static final Version GROOVY_5_0_0_ALPHA1 = new Version(5, 0, 0, "alpha-1");

/**
* Groovy 4.0.11 version.
*/
Expand Down Expand Up @@ -496,6 +501,12 @@ protected Object setupCompilerConfiguration(final File compileOutputDirectory, f
* org.codehaus.groovy.classgen.asm.WriterController.
*/
protected void verifyGroovyVersionSupportsTargetBytecode() {
if ("1.5".equals(targetBytecode) || "5".equals(targetBytecode) || "1.6".equals(targetBytecode) || "6".equals(targetBytecode) || "1.7".equals(targetBytecode) || "7".equals(targetBytecode) || "1.8".equals(targetBytecode) || "8".equals(targetBytecode) || "1.9".equals(targetBytecode) || "9".equals(targetBytecode) || "10".equals(targetBytecode)) {
if (groovyNewerThan(GROOVY_5_0_0_ALPHA1)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " isn't accepted by Groovy " + GROOVY_5_0_0_ALPHA1 + " or newer.");
}
}

if ("21".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_11)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_11 + " or newer.");
Expand Down Expand Up @@ -557,7 +568,7 @@ protected void verifyGroovyVersionSupportsTargetBytecode() {
}
}

private static String translateJavacTargetToTargetBytecode(String targetBytecode) {
protected static String translateJavacTargetToTargetBytecode(String targetBytecode) {
Map<String, String> javacTargetToTargetBytecode = new HashMap<>();
javacTargetToTargetBytecode.put("5", "1.5");
javacTargetToTargetBytecode.put("6", "1.6");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
*/
public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSourcesMojo {

/**
* Groovy 5.0.0-alpha-1 version.
*/
protected static final Version GROOVY_5_0_0_ALPHA1 = new Version(5, 0, 0, "alpha-1");

/**
* Groovy 4.0.11 version.
*/
Expand Down Expand Up @@ -417,6 +422,12 @@ protected void resetStubModifiedDates(final Set<File> stubs) {
* org.codehaus.groovy.classgen.asm.WriterController.
*/
protected void verifyGroovyVersionSupportsTargetBytecode() {
if ("1.5".equals(targetBytecode) || "5".equals(targetBytecode) || "1.6".equals(targetBytecode) || "6".equals(targetBytecode) || "1.7".equals(targetBytecode) || "7".equals(targetBytecode) || "1.8".equals(targetBytecode) || "8".equals(targetBytecode) || "1.9".equals(targetBytecode) || "9".equals(targetBytecode) || "10".equals(targetBytecode)) {
if (groovyNewerThan(GROOVY_5_0_0_ALPHA1)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " isn't accepted by Groovy " + GROOVY_5_0_0_ALPHA1 + " or newer.");
}
}

if ("21".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_11)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_11 + " or newer.");
Expand Down Expand Up @@ -478,7 +489,7 @@ protected void verifyGroovyVersionSupportsTargetBytecode() {
}
}

private static String translateJavacTargetToTargetBytecode(String targetBytecode) {
protected static String translateJavacTargetToTargetBytecode(String targetBytecode) {
Map<String, String> javacTargetToTargetBytecode = new HashMap<>();
javacTargetToTargetBytecode.put("5", "1.5");
javacTargetToTargetBytecode.put("6", "1.6");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public void testUnrecognizedJava() {
}

@Test
public void testBytecodeTranslation() throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, InstantiationException {
public void testBytecodeTranslation() {
Map<String, String> expectedTranslations = new LinkedHashMap<>();
expectedTranslations.put("5", "1.5");
expectedTranslations.put("6", "1.6");
Expand All @@ -430,11 +430,7 @@ public void testBytecodeTranslation() throws ClassNotFoundException, InvocationT
for (Map.Entry<String, String> entry : expectedTranslations.entrySet()) {
String javacVersion = entry.getKey();
String expectedGroovycVersion = entry.getValue();
testMojo.targetBytecode = javacVersion;
Class<?> compilerConfigurationClass = Class.forName("org.codehaus.groovy.control.CompilerConfiguration");
File compileOutputDirectory = new File(".");
CompilerConfiguration compilerConfiguration = (CompilerConfiguration) testMojo.setupCompilerConfiguration(compileOutputDirectory, compilerConfigurationClass);
assertEquals(expectedGroovycVersion, compilerConfiguration.getTargetBytecode());
assertEquals(expectedGroovycVersion, AbstractCompileMojo.translateJavacTargetToTargetBytecode(javacVersion));
}
}

Expand Down