Skip to content

Commit

Permalink
Support Java 20 bytecode
Browse files Browse the repository at this point in the history
  • Loading branch information
keeganwitt committed Oct 20, 2022
1 parent 5fabc17 commit 70cc954
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
*/
public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {

/**
* Groovy 4.0.6 version.
*/
protected static final Version GROOVY_4_0_6 = new Version(4, 0, 6);

/**
* Groovy 4.0.2 version.
*/
Expand Down Expand Up @@ -196,6 +201,7 @@ public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {
* Using 17 requires Groovy >= 3.0.8 or Groovy > 4.0.0-alpha-3.
* Using 18 requires Groovy > 4.0.0-beta-1.
* Using 19 requires Groovy > 4.0.2.
* Using 20 requires Groovy > 4.0.6.
*/
@Parameter(property = "maven.compiler.target", defaultValue = "1.8")
protected String targetBytecode;
Expand Down Expand Up @@ -484,7 +490,11 @@ protected Object setupCompilerConfiguration(final File compileOutputDirectory, f
* org.codehaus.groovy.classgen.asm.WriterController.
*/
protected void verifyGroovyVersionSupportsTargetBytecode() {
if ("19".equals(targetBytecode)) {
if ("20".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_6)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_6 + " or newer.");
}
} else if ("19".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_2)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_2 + " or newer.");
}
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 4.0.6 version.
*/
protected static final Version GROOVY_4_0_6 = new Version(4, 0, 6);

/**
* Groovy 4.0.2 version.
*/
Expand Down Expand Up @@ -199,6 +204,7 @@ public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSource
* Using 17 requires Groovy >= 3.0.8 or Groovy > 4.0.0-alpha-3.
* Using 18 requires Groovy > 4.0.0-beta-1.
* Using 19 requires Groovy > 4.0.2.
* Using 20 requires Groovy > 4.0.6.
*
* @since 1.0-beta-3
*/
Expand Down Expand Up @@ -411,7 +417,11 @@ protected void resetStubModifiedDates(final Set<File> stubs) {
* org.codehaus.groovy.classgen.asm.WriterController.
*/
protected void verifyGroovyVersionSupportsTargetBytecode() {
if ("19".equals(targetBytecode)) {
if ("20".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_6)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_6 + " or newer.");
}
} else if ("19".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_2)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_2 + " or newer.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,20 @@ public void testJava19WithSupportedGroovy() {
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testJava20WithUnsupportedGroovy() {
testMojo = new TestMojo("4.0.5");
testMojo.targetBytecode = "20";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test
public void testJava20WithSupportedGroovy() {
testMojo = new TestMojo("4.0.6");
testMojo.targetBytecode = "20";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testUnrecognizedJava() {
testMojo = new TestMojo("2.1.2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,20 @@ public void testJava19WithSupportedGroovy() {
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testJava20WithUnsupportedGroovy() {
testMojo = new TestMojo("4.0.5");
testMojo.targetBytecode = "20";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test
public void testJava20WithSupportedGroovy() {
testMojo = new TestMojo("4.0.6");
testMojo.targetBytecode = "20";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testUnrecognizedJava() {
testMojo = new TestMojo("2.1.2");
Expand Down

0 comments on commit 70cc954

Please sign in to comment.