Skip to content

Commit

Permalink
Merge pull request #270 from groovy/add-groovy-5-to-ci
Browse files Browse the repository at this point in the history
Test Groovy 5 in CI
  • Loading branch information
keeganwitt committed Sep 25, 2023
2 parents 0fa9649 + 50c10cf commit 5771746
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
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

0 comments on commit 5771746

Please sign in to comment.