Skip to content

Commit 83ab759

Browse files
authored
Merge pull request #231 from groovy/230
Recognize target bytecode 19 (closes #230)
2 parents dbcd58e + e570b38 commit 83ab759

4 files changed

Lines changed: 61 additions & 8 deletions

File tree

src/main/java/org/codehaus/gmavenplus/mojo/AbstractCompileMojo.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
*/
4545
public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {
4646

47+
/**
48+
* Groovy 4.0.2 version.
49+
*/
50+
protected static final Version GROOVY_4_0_2 = new Version(4, 0, 2);
51+
4752
/**
4853
* Groovy 4.0.0 beta-1 version.
4954
*/
@@ -478,7 +483,11 @@ protected Object setupCompilerConfiguration(final File compileOutputDirectory, f
478483
* org.codehaus.groovy.classgen.asm.WriterController.
479484
*/
480485
protected void verifyGroovyVersionSupportsTargetBytecode() {
481-
if ("18".equals(targetBytecode)) {
486+
if ("19".equals(targetBytecode)) {
487+
if (groovyOlderThan(GROOVY_4_0_2)) {
488+
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_2 + " or newer.");
489+
}
490+
} else if ("18".equals(targetBytecode)) {
482491
if (groovyOlderThan(GROOVY_4_0_0_BETA1)) {
483492
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_0_BETA1 + " or newer.");
484493
}

src/main/java/org/codehaus/gmavenplus/mojo/AbstractGenerateStubsMojo.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
* @since 1.0-beta-1
4646
*/
4747
public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSourcesMojo {
48-
/*
49-
* TODO: support Groovy 1.5.0 - 1.8.1?
50-
* For some reason, the JavaStubCompilationUnit is silently not creating my stubs
51-
* (although it does create the target directory) when I use other versions.
48+
49+
/**
50+
* Groovy 4.0.2 version.
5251
*/
52+
protected static final Version GROOVY_4_0_2 = new Version(4, 0, 2);
5353

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

159+
/*
160+
* TODO: support Groovy 1.5.0 - 1.8.1?
161+
* For some reason, the JavaStubCompilationUnit is silently not creating my stubs
162+
* (although it does create the target directory) when I use other versions.
163+
*/
164+
159165
/**
160166
* The encoding of source files.
161167
*/
@@ -404,7 +410,11 @@ protected void resetStubModifiedDates(final Set<File> stubs) {
404410
* org.codehaus.groovy.classgen.asm.WriterController.
405411
*/
406412
protected void verifyGroovyVersionSupportsTargetBytecode() {
407-
if ("18".equals(targetBytecode)) {
413+
if ("19".equals(targetBytecode)) {
414+
if (groovyOlderThan(GROOVY_4_0_2)) {
415+
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_2 + " or newer.");
416+
}
417+
} else if ("18".equals(targetBytecode)) {
408418
if (groovyOlderThan(GROOVY_4_0_0_BETA1)) {
409419
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_0_BETA1 + " or newer.");
410420
}

src/test/java/org/codehaus/gmavenplus/mojo/AbstractCompileMojoTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,20 @@ public void testJava18WithSupportedGroovy() {
377377
testMojo.verifyGroovyVersionSupportsTargetBytecode();
378378
}
379379

380+
@Test(expected = IllegalArgumentException.class)
381+
public void testJava19WithUnsupportedGroovy() {
382+
testMojo = new TestMojo("4.0.1");
383+
testMojo.targetBytecode = "19";
384+
testMojo.verifyGroovyVersionSupportsTargetBytecode();
385+
}
386+
387+
@Test
388+
public void testJava19WithSupportedGroovy() {
389+
testMojo = new TestMojo("4.0.2");
390+
testMojo.targetBytecode = "19";
391+
testMojo.verifyGroovyVersionSupportsTargetBytecode();
392+
}
393+
380394
@Test(expected = IllegalArgumentException.class)
381395
public void testUnrecognizedJava() {
382396
testMojo = new TestMojo("2.1.2");

src/test/java/org/codehaus/gmavenplus/mojo/AbstractGenerateStubsMojoTest.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@
2929
import java.util.HashSet;
3030
import java.util.Set;
3131

32-
import static org.junit.Assert.*;
33-
import static org.mockito.Mockito.*;
32+
import static org.junit.Assert.assertEquals;
33+
import static org.junit.Assert.assertFalse;
34+
import static org.junit.Assert.assertTrue;
35+
import static org.mockito.Mockito.anyLong;
36+
import static org.mockito.Mockito.atLeastOnce;
37+
import static org.mockito.Mockito.doReturn;
38+
import static org.mockito.Mockito.mock;
39+
import static org.mockito.Mockito.verify;
3440

3541

3642
/**
@@ -398,6 +404,20 @@ public void testJava18WithSupportedGroovy() {
398404
testMojo.verifyGroovyVersionSupportsTargetBytecode();
399405
}
400406

407+
@Test(expected = IllegalArgumentException.class)
408+
public void testJava19WithUnsupportedGroovy() {
409+
testMojo = new TestMojo("4.0.1");
410+
testMojo.targetBytecode = "19";
411+
testMojo.verifyGroovyVersionSupportsTargetBytecode();
412+
}
413+
414+
@Test
415+
public void testJava19WithSupportedGroovy() {
416+
testMojo = new TestMojo("4.0.2");
417+
testMojo.targetBytecode = "19";
418+
testMojo.verifyGroovyVersionSupportsTargetBytecode();
419+
}
420+
401421
@Test(expected = IllegalArgumentException.class)
402422
public void testUnrecognizedJava() {
403423
testMojo = new TestMojo("2.1.2");

0 commit comments

Comments
 (0)