Skip to content

Commit

Permalink
Merge pull request #153 from groovy/152
Browse files Browse the repository at this point in the history
Support for Java 14 and option to skip bytecode check (#152)
  • Loading branch information
keeganwitt authored Mar 30, 2020
2 parents 8cfc29e + fe3320f commit 7ccafd6
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.8.2-SNAPSHOT</version>
<version>1.9.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
*/
public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {

/**
* Groovy 3.0.3 version.
*/
protected static final Version GROOVY_3_0_3 = new Version(3, 0, 3);

/**
* Groovy 3.0.0 beta-2 version.
*/
protected static final Version GROOVY_3_0_0_BETA2 = new Version(3, 0, 0, "beta-2");

/**
* Groovy 3.0.0 beta-1 version.
*/
Expand Down Expand Up @@ -129,17 +139,29 @@ public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {
* <li>11</li>
* <li>12</li>
* <li>13</li>
* <li>14</li>
* <li>15</li>
* </ul>
* Using 1.6 or 1.7 requires Groovy &gt;= 2.1.3.
* Using 1.8 requires Groovy &gt;= 2.3.3.
* Using 9 requires Groovy &gt;= 2.5.3, or Groovy &gt;= 2.6.0 alpha 4, or Groovy &gt;= 3.0.0 alpha 2.
* Using 9 with invokedynamic requires Groovy &gt;= 2.5.3, or Groovy &gt;= 3.0.0 alpha 2, but not any 2.6 versions.
* Using 10, 11, or 12 requires Groovy &gt;= 2.5.3, or Groovy &gt;= 3.0.0 alpha 4, but not any 2.6 versions.
* Using 13 requires Groovy &gt;= 2.5.7, or Groovy &gt;= 3.0.0-beta-1, but not any 2.6 versions.
* Using 14 requires Groovy &gt;= 3.0.0 beta-2.
* Using 15 requires Groovy &gt;= 3.0.3.
*/
@Parameter(property = "maven.compiler.target", defaultValue = "1.8")
protected String targetBytecode;

/**
* Whether to check that the version of Groovy used is able to use the requested <code>targetBytecode</code>.
*
* @since 1.9.0
*/
@Parameter(property = "skipBytecodeCheck", defaultValue = "false")
protected boolean skipBytecodeCheck;

/**
* Whether Groovy compiler should be set to debug.
*/
Expand Down Expand Up @@ -242,7 +264,7 @@ protected synchronized void doCompile(final Set<File> sources, final List classp
logPluginClasspath();
classWrangler.logGroovyVersion(mojoExecution.getMojoDescriptor().getGoal());

if (groovyVersionSupportsAction()) {
if (groovyVersionSupportsAction() && !skipBytecodeCheck) {
verifyGroovyVersionSupportsTargetBytecode();
} else {
getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support compilation. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping compiling.");
Expand Down Expand Up @@ -396,7 +418,15 @@ protected Object setupCompilerConfiguration(final File compileOutputDirectory, f
* org.codehaus.groovy.classgen.asm.WriterController.
*/
protected void verifyGroovyVersionSupportsTargetBytecode() {
if ("13".equals(targetBytecode)) {
if ("15".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_3_0_3)) {
throw new IllegalArgumentException("Target bytecode 15 requires Groovy " + GROOVY_3_0_3 + " or newer.");
}
} else if ("14".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_3_0_0_BETA2)) {
throw new IllegalArgumentException("Target bytecode 14 requires Groovy " + GROOVY_3_0_0_BETA2 + " or newer.");
}
} else if ("13".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_2_5_7) || (groovyAtLeast(GROOVY_2_6_0_ALPHA1) && groovyOlderThan(GROOVY_3_0_0_BETA1))) {
throw new IllegalArgumentException("Target bytecode 13 requires Groovy " + GROOVY_2_5_7 + "/" + GROOVY_3_0_0_BETA1 + " or newer. No 2.6 version is supported.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSource
* (although it does create the target directory) when I use other versions.
*/

/**
* Groovy 3.0.3 version.
*/
protected static final Version GROOVY_3_0_3 = new Version(3, 0, 3);

/**
* Groovy 3.0.0 beta-2 version.
*/
protected static final Version GROOVY_3_0_0_BETA2 = new Version(3, 0, 0, "beta-2");

/**
* Groovy 3.0.0 beta-1 version.
*/
Expand Down Expand Up @@ -133,19 +143,31 @@ public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSource
* <li>11</li>
* <li>12</li>
* <li>13</li>
* <li>14</li>
* <li>15</li>
* </ul>
* Using 1.6 or 1.7 requires Groovy &gt;= 2.1.3.
* Using 1.8 requires Groovy &gt;= 2.3.3.
* Using 9 requires Groovy &gt;= 2.5.3, or Groovy &gt;= 2.6.0 alpha 4, or Groovy &gt;= 3.0.0 alpha 2.
* Using 9 with invokedynamic requires Groovy &gt;= 2.5.3, or Groovy &gt;= 3.0.0 alpha 2, but not any 2.6 versions.
* Using 10, 11, or 12 requires Groovy &gt;= 2.5.3, or Groovy &gt;= 3.0.0 alpha 4, but not any 2.6 versions.
* Using 13 requires Groovy &gt;= 2.5.7, or Groovy &gt;= 3.0.0-beta-1, but not any 2.6 versions.
* Using 14 requires Groovy &gt;= 3.0.0 beta-2.
* Using 15 requires Groovy &gt;= 3.0.3.
*
* @since 1.0-beta-3
*/
@Parameter(property = "maven.compiler.target", defaultValue = "1.8")
protected String targetBytecode;

/**
* Whether to check that the version of Groovy used is able to use the requested <code>targetBytecode</code>.
*
* @since 1.9.0
*/
@Parameter(property = "skipBytecodeCheck", defaultValue = "false")
protected boolean skipBytecodeCheck;

/**
* Whether Groovy compiler should be set to debug.
*/
Expand Down Expand Up @@ -226,7 +248,7 @@ protected synchronized void doStubGeneration(final Set<File> stubSources, final
logPluginClasspath();
classWrangler.logGroovyVersion(mojoExecution.getMojoDescriptor().getGoal());

if (groovyVersionSupportsAction()) {
if (groovyVersionSupportsAction() && !skipBytecodeCheck) {
verifyGroovyVersionSupportsTargetBytecode();
} else {
getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support stub generation. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping stub generation.");
Expand Down Expand Up @@ -364,7 +386,15 @@ protected void resetStubModifiedDates(final Set<File> stubs) {
* org.codehaus.groovy.classgen.asm.WriterController.
*/
protected void verifyGroovyVersionSupportsTargetBytecode() {
if ("13".equals(targetBytecode)) {
if ("15".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_3_0_3)) {
throw new IllegalArgumentException("Target bytecode 15 requires Groovy " + GROOVY_3_0_3 + " or newer.");
}
} else if ("14".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_3_0_0_BETA2)) {
throw new IllegalArgumentException("Target bytecode 14 requires Groovy " + GROOVY_3_0_0_BETA2 + " or newer.");
}
} else if ("13".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_2_5_7) || (groovyAtLeast(GROOVY_2_6_0_ALPHA1) && groovyOlderThan(GROOVY_3_0_0_BETA1))) {
throw new IllegalArgumentException("Target bytecode 13 requires Groovy " + GROOVY_2_5_7 + "/" + GROOVY_3_0_0_BETA1 + " or newer. No 2.6 version is supported.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public abstract class AbstractGroovyDocMojo extends AbstractGroovySourcesMojo {
*
* @since 1.6
*/
@Parameter(property = "maven.groovydoc.skip", defaultValue = "false")
@Parameter(property = "skipGroovydoc", defaultValue = "false")
protected boolean skipGroovyDoc;

/**
Expand Down Expand Up @@ -168,7 +168,7 @@ public abstract class AbstractGroovyDocMojo extends AbstractGroovySourcesMojo {
*/
protected synchronized void doGroovyDocGeneration(final FileSet[] sourceDirectories, final List<?> classpath, final File outputDirectory) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, InstantiationException, MalformedURLException {
if (skipGroovyDoc) {
getLog().info("Skipping generation of GroovyDoc because ${maven.groovydoc.skip} was set to true.");
getLog().info("Skipping generation of GroovyDoc because ${skipGroovydoc} was set to true.");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,34 @@ public void testJava13WithSupportedGroovy3() {
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testJava14WithUnsupportedGroovy() {
testMojo = new TestMojo("3.0.0-beta-1");
testMojo.targetBytecode = "14";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test
public void testJava14WithSupportedGroovy() {
testMojo = new TestMojo("3.0.0-beta-2");
testMojo.targetBytecode = "14";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testJava15WithUnsupportedGroovy() {
testMojo = new TestMojo("3.0.2");
testMojo.targetBytecode = "15";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test
public void testJava15WithSupportedGroovy() {
testMojo = new TestMojo("3.0.3");
testMojo.targetBytecode = "15";
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 @@ -314,6 +314,34 @@ public void testJava13WithSupportedGroovy3() {
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testJava14WithUnsupportedGroovy() {
testMojo = new TestMojo("3.0.0-beta-1");
testMojo.targetBytecode = "14";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test
public void testJava14WithSupportedGroovy() {
testMojo = new TestMojo("3.0.0-beta-2");
testMojo.targetBytecode = "14";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testJava15WithUnsupportedGroovy() {
testMojo = new TestMojo("3.0.2");
testMojo.targetBytecode = "15";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test
public void testJava15WithSupportedGroovy() {
testMojo = new TestMojo("3.0.3");
testMojo.targetBytecode = "15";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

protected static class TestMojo extends AbstractGenerateStubsMojo {
protected TestMojo() {
this(GROOVY_1_8_2.toString(), false);
Expand Down

0 comments on commit 7ccafd6

Please sign in to comment.