Skip to content

Commit

Permalink
Recognize target bytecode 19 (closes #230)
Browse files Browse the repository at this point in the history
  • Loading branch information
keeganwitt committed Oct 11, 2022
1 parent dbcd58e commit e570b38
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 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.2 version.
*/
protected static final Version GROOVY_4_0_2 = new Version(4, 0, 2);

/**
* Groovy 4.0.0 beta-1 version.
*/
Expand Down Expand Up @@ -478,7 +483,11 @@ protected Object setupCompilerConfiguration(final File compileOutputDirectory, f
* org.codehaus.groovy.classgen.asm.WriterController.
*/
protected void verifyGroovyVersionSupportsTargetBytecode() {
if ("18".equals(targetBytecode)) {
if ("19".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_2)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_2 + " or newer.");
}
} else if ("18".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_0_BETA1)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_0_BETA1 + " or newer.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
* @since 1.0-beta-1
*/
public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSourcesMojo {
/*
* TODO: support Groovy 1.5.0 - 1.8.1?
* For some reason, the JavaStubCompilationUnit is silently not creating my stubs
* (although it does create the target directory) when I use other versions.

/**
* Groovy 4.0.2 version.
*/
protected static final Version GROOVY_4_0_2 = new Version(4, 0, 2);

/**
* Groovy 4.0.0 beta-1 version.
Expand Down Expand Up @@ -156,6 +156,12 @@ public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSource
*/
protected static final Version GROOVY_1_8_3 = new Version(1, 8, 3);

/*
* TODO: support Groovy 1.5.0 - 1.8.1?
* For some reason, the JavaStubCompilationUnit is silently not creating my stubs
* (although it does create the target directory) when I use other versions.
*/

/**
* The encoding of source files.
*/
Expand Down Expand Up @@ -404,7 +410,11 @@ protected void resetStubModifiedDates(final Set<File> stubs) {
* org.codehaus.groovy.classgen.asm.WriterController.
*/
protected void verifyGroovyVersionSupportsTargetBytecode() {
if ("18".equals(targetBytecode)) {
if ("19".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_2)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_2 + " or newer.");
}
} else if ("18".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_0_BETA1)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_0_BETA1 + " or newer.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,20 @@ public void testJava18WithSupportedGroovy() {
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testJava19WithUnsupportedGroovy() {
testMojo = new TestMojo("4.0.1");
testMojo.targetBytecode = "19";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test
public void testJava19WithSupportedGroovy() {
testMojo = new TestMojo("4.0.2");
testMojo.targetBytecode = "19";
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 @@ -29,8 +29,14 @@
import java.util.HashSet;
import java.util.Set;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;


/**
Expand Down Expand Up @@ -398,6 +404,20 @@ public void testJava18WithSupportedGroovy() {
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testJava19WithUnsupportedGroovy() {
testMojo = new TestMojo("4.0.1");
testMojo.targetBytecode = "19";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test
public void testJava19WithSupportedGroovy() {
testMojo = new TestMojo("4.0.2");
testMojo.targetBytecode = "19";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

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

0 comments on commit e570b38

Please sign in to comment.