From b725f1e95bc075c0c3a1823768fe5137247e6354 Mon Sep 17 00:00:00 2001 From: Keegan Witt Date: Fri, 17 Sep 2021 22:22:08 -0400 Subject: [PATCH] Java 17 support (closes #196) --- .../gmavenplus/mojo/AbstractCompileMojo.java | 19 ++++++++++++++- .../mojo/AbstractGenerateStubsMojo.java | 24 ++++++++++++++++++- .../mojo/AbstractCompileMojoTest.java | 21 ++++++++++++++++ .../mojo/AbstractGenerateStubsMojoTest.java | 21 ++++++++++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/AbstractCompileMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/AbstractCompileMojo.java index 75778788..d8a71157 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/AbstractCompileMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/AbstractCompileMojo.java @@ -40,11 +40,21 @@ */ public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo { + /** + * Groovy 4.0.0 alpha-3 version. + */ + protected static final Version GROOVY_4_0_0_ALPHA3 = new Version(4, 0, 0, "alpha-3"); + /** * Groovy 4.0.0 alpha-1 version. */ protected static final Version GROOVY_4_0_0_ALPHA1 = new Version(4, 0, 0, "alpha-1"); + /** + * Groovy 3.0.9 version. + */ + protected static final Version GROOVY_3_0_8 = new Version(3, 0, 8); + /** * Groovy 3.0.6 version. */ @@ -157,6 +167,7 @@ public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo { *
  • 14
  • *
  • 15
  • *
  • 16
  • + *
  • 17
  • * * Using 1.6 or 1.7 requires Groovy >= 2.1.3. * Using 1.8 requires Groovy >= 2.3.3. @@ -166,6 +177,8 @@ public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo { * Using 13 requires Groovy >= 2.5.7, or Groovy >= 3.0.0-beta-1, but not any 2.6 versions. * Using 14 requires Groovy >= 3.0.0 beta-2. * Using 15 requires Groovy >= 3.0.3. + * Using 16 requires Groovy >= 3.0.6. + * Using 17 requires Groovy >= 3.0.8 or Groovy > 4.0.0-alpha-3. */ @Parameter(property = "maven.compiler.target", defaultValue = "1.8") protected String targetBytecode; @@ -476,7 +489,11 @@ protected Object setupCompilerConfiguration(final File compileOutputDirectory, f * org.codehaus.groovy.classgen.asm.WriterController. */ protected void verifyGroovyVersionSupportsTargetBytecode() { - if ("16".equals(targetBytecode)) { + if ("17".equals(targetBytecode)) { + if (groovyOlderThan(GROOVY_3_0_8) || (groovyAtLeast(GROOVY_4_0_0_ALPHA1) && groovyOlderThan(GROOVY_4_0_0_ALPHA3))) { + throw new IllegalArgumentException("Target bytecode 17 requires Groovy " + GROOVY_3_0_8 + "/" + GROOVY_4_0_0_ALPHA3 + " or newer."); + } + } else if ("16".equals(targetBytecode)) { if (groovyOlderThan(GROOVY_3_0_6)) { throw new IllegalArgumentException("Target bytecode 16 requires Groovy " + GROOVY_3_0_6 + " or newer."); } diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/AbstractGenerateStubsMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/AbstractGenerateStubsMojo.java index e8d24bad..43f49a75 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/AbstractGenerateStubsMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/AbstractGenerateStubsMojo.java @@ -44,6 +44,21 @@ public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSource * (although it does create the target directory) when I use other versions. */ + /** + * Groovy 4.0.0 alpha-3 version. + */ + protected static final Version GROOVY_4_0_0_ALPHA3 = new Version(4, 0, 0, "alpha-3"); + + /** + * Groovy 4.0.0 alpha-1 version. + */ + protected static final Version GROOVY_4_0_0_ALPHA1 = new Version(4, 0, 0, "alpha-1"); + + /** + * Groovy 3.0.9 version. + */ + protected static final Version GROOVY_3_0_8 = new Version(3, 0, 8); + /** * Groovy 3.0.6 version. */ @@ -151,6 +166,7 @@ public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSource *
  • 14
  • *
  • 15
  • *
  • 16
  • + *
  • 17
  • * * Using 1.6 or 1.7 requires Groovy >= 2.1.3. * Using 1.8 requires Groovy >= 2.3.3. @@ -160,6 +176,8 @@ public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSource * Using 13 requires Groovy >= 2.5.7, or Groovy >= 3.0.0-beta-1, but not any 2.6 versions. * Using 14 requires Groovy >= 3.0.0 beta-2. * Using 15 requires Groovy >= 3.0.3. + * Using 16 requires Groovy >= 3.0.6. + * Using 17 requires Groovy >= 3.0.8 or Groovy > 4.0.0-alpha-3. * * @since 1.0-beta-3 */ @@ -380,7 +398,11 @@ protected void resetStubModifiedDates(final Set stubs) { * org.codehaus.groovy.classgen.asm.WriterController. */ protected void verifyGroovyVersionSupportsTargetBytecode() { - if ("16".equals(targetBytecode)) { + if ("17".equals(targetBytecode)) { + if (groovyOlderThan(GROOVY_3_0_8) || (groovyAtLeast(GROOVY_4_0_0_ALPHA1) && groovyOlderThan(GROOVY_4_0_0_ALPHA3))) { + throw new IllegalArgumentException("Target bytecode 17 requires Groovy " + GROOVY_3_0_8 + "/" + GROOVY_4_0_0_ALPHA3 + " or newer."); + } + } else if ("16".equals(targetBytecode)) { if (groovyOlderThan(GROOVY_3_0_6)) { throw new IllegalArgumentException("Target bytecode 16 requires Groovy " + GROOVY_3_0_6 + " or newer."); } diff --git a/src/test/java/org/codehaus/gmavenplus/mojo/AbstractCompileMojoTest.java b/src/test/java/org/codehaus/gmavenplus/mojo/AbstractCompileMojoTest.java index 3427f8fb..95587265 100644 --- a/src/test/java/org/codehaus/gmavenplus/mojo/AbstractCompileMojoTest.java +++ b/src/test/java/org/codehaus/gmavenplus/mojo/AbstractCompileMojoTest.java @@ -320,6 +320,27 @@ public void testJava16WithSupportedGroovy() { testMojo.verifyGroovyVersionSupportsTargetBytecode(); } + @Test(expected = IllegalArgumentException.class) + public void testJava17WithUnsupportedGroovy() { + testMojo = new TestMojo("3.0.7"); + testMojo.targetBytecode = "17"; + testMojo.verifyGroovyVersionSupportsTargetBytecode(); + } + + @Test + public void testJava17WithSupportedGroovy() { + testMojo = new TestMojo("3.0.8"); + testMojo.targetBytecode = "17"; + testMojo.verifyGroovyVersionSupportsTargetBytecode(); + } + + @Test + public void testJava17WithSupportedGroovy4() { + testMojo = new TestMojo("4.0.0-alpha-3"); + testMojo.targetBytecode = "17"; + testMojo.verifyGroovyVersionSupportsTargetBytecode(); + } + @Test(expected = IllegalArgumentException.class) public void testUnrecognizedJava() { testMojo = new TestMojo("2.1.2"); diff --git a/src/test/java/org/codehaus/gmavenplus/mojo/AbstractGenerateStubsMojoTest.java b/src/test/java/org/codehaus/gmavenplus/mojo/AbstractGenerateStubsMojoTest.java index e058a973..adda3c9e 100644 --- a/src/test/java/org/codehaus/gmavenplus/mojo/AbstractGenerateStubsMojoTest.java +++ b/src/test/java/org/codehaus/gmavenplus/mojo/AbstractGenerateStubsMojoTest.java @@ -342,6 +342,27 @@ public void testJava15WithSupportedGroovy() { testMojo.verifyGroovyVersionSupportsTargetBytecode(); } + @Test(expected = IllegalArgumentException.class) + public void testJava17WithUnsupportedGroovy() { + testMojo = new TestMojo("3.0.7"); + testMojo.targetBytecode = "17"; + testMojo.verifyGroovyVersionSupportsTargetBytecode(); + } + + @Test + public void testJava17WithSupportedGroovy() { + testMojo = new TestMojo("3.0.8"); + testMojo.targetBytecode = "17"; + testMojo.verifyGroovyVersionSupportsTargetBytecode(); + } + + @Test + public void testJava17WithSupportedGroovy4() { + testMojo = new TestMojo("4.0.0-alpha-3"); + testMojo.targetBytecode = "17"; + testMojo.verifyGroovyVersionSupportsTargetBytecode(); + } + protected static class TestMojo extends AbstractGenerateStubsMojo { protected TestMojo() { this(GROOVY_1_8_2.toString(), false);