Skip to content

Commit

Permalink
Java 17 support (closes #196)
Browse files Browse the repository at this point in the history
  • Loading branch information
keeganwitt committed Sep 19, 2021
1 parent 8100ada commit 1fe3dbc
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -157,6 +167,7 @@ public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {
* <li>14</li>
* <li>15</li>
* <li>16</li>
* <li>17</li>
* </ul>
* Using 1.6 or 1.7 requires Groovy &gt;= 2.1.3.
* Using 1.8 requires Groovy &gt;= 2.3.3.
Expand All @@ -167,6 +178,7 @@ public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {
* Using 14 requires Groovy &gt;= 3.0.0 beta-2.
* Using 15 requires Groovy &gt;= 3.0.3.
* Using 16 requires Groovy &gt;= 3.0.6.
* Using 17 requires Groovy &gt;= 3.0.8 or Groovy &gt; 4.0.0-alpha-3.
*/
@Parameter(property = "maven.compiler.target", defaultValue = "1.8")
protected String targetBytecode;
Expand Down Expand Up @@ -477,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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -151,6 +166,7 @@ public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSource
* <li>14</li>
* <li>15</li>
* <li>16</li>
* <li>17</li>
* </ul>
* Using 1.6 or 1.7 requires Groovy &gt;= 2.1.3.
* Using 1.8 requires Groovy &gt;= 2.3.3.
Expand All @@ -161,6 +177,7 @@ public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSource
* Using 14 requires Groovy &gt;= 3.0.0 beta-2.
* Using 15 requires Groovy &gt;= 3.0.3.
* Using 16 requires Groovy &gt;= 3.0.6.
* Using 17 requires Groovy &gt;= 3.0.8 or Groovy &gt; 4.0.0-alpha-3.
*
* @since 1.0-beta-3
*/
Expand Down Expand Up @@ -381,7 +398,11 @@ protected void resetStubModifiedDates(final Set<File> 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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,34 @@ 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(expected = IllegalArgumentException.class)
public void testJava17WithUnsupportedGroovy4() {
testMojo = new TestMojo("4.0.0-alpha-2");
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,34 @@ 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(expected = IllegalArgumentException.class)
public void testJava17WithUnsupportedGroovy4() {
testMojo = new TestMojo("4.0.0-alpha-2");
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");
Expand Down

0 comments on commit 1fe3dbc

Please sign in to comment.