Skip to content

Commit

Permalink
changes to support GROOVY-7423 (issue #45)
Browse files Browse the repository at this point in the history
  • Loading branch information
keeganwitt committed Jun 8, 2017
1 parent be040b1 commit fa29d7d
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 2 deletions.
8 changes: 6 additions & 2 deletions integrationTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ groovyVersions = ["1.5.0", "1.5.1", "1.5.2", "1.5.3", "1.5.4", "1.5.5", "1.5.6",
"2.1.0-beta-1", "2.1.0-rc-1", "2.1.0-rc-2", "2.1.0-rc-3", "2.1.0", "2.1.1", "2.1.2", "2.1.3", "2.1.4", "2.1.5", "2.1.6", "2.1.7",
"2.2.0-beta-1", "2.2.0-beta-2", "2.2.0-rc-1", "2.2.0-rc-2", "2.2.0-rc-3", "2.2.0", "2.2.1", "2.2.2",
"2.3.0-beta-1", "2.3.0-beta-2", "2.3.0-rc-1", "2.3.0-rc-2", "2.3.0-rc-4", "2.3.0", "2.3.1", "2.3.2", "2.3.3", "2.3.4", "2.3.5", "2.3.6", "2.3.7", "2.3.8", "2.3.9", "2.3.10", "2.3.11",
"2.4.0-beta-1", "2.4.0-beta-2", "2.4.0-beta-3", "2.4.0-beta-4", "2.4.0-rc-1", "2.4.0-rc-2", "2.4.0", "2.4.1", "2.4.2", "2.4.3", "2.4.4", "2.4.5", "2.4.6", "2.4.7", "2.4.8", "2.4.9", "2.4.10", "2.4.11"]
"2.4.0-beta-1", "2.4.0-beta-2", "2.4.0-beta-3", "2.4.0-beta-4", "2.4.0-rc-1", "2.4.0-rc-2", "2.4.0", "2.4.1", "2.4.2", "2.4.3", "2.4.4", "2.4.5", "2.4.6", "2.4.7", "2.4.8", "2.4.9", "2.4.10", "2.4.10",
"2.5.0-alpha-1", "2.5.0-beta-1"]
for (int i = 0; i < groovyVersions.size(); i++) {
def groovyVersion = groovyVersions[i]
System.out.print "Testing Groovy ${groovyVersion}..."
def pom = new File("pom.xml")
pom.write((pom.text =~ /<groovyVersion>.+/).replaceFirst("<groovyVersion>${groovyVersion}</groovyVersion>"))
testLabel = groovyVersion
os = new FileOutputStream(new File("groovy-${testLabel}.log"))
profile = "${i < groovyVersions.indexOf("2.3.0") ? 'pre2.3-' : ''}nonindy"
if (i >= groovyVersions.indexOf("2.5.0-beta-1"))
profile = "parameters"
else
profile = "${i < groovyVersions.indexOf("2.3.0") ? 'pre2.3-' : ''}nonindy"
testVersion()
if (i >= groovyVersions.indexOf("2.0.0-beta-3")) {
System.out.print "Testing Groovy ${groovyVersion}-indy..."
Expand Down
13 changes: 13 additions & 0 deletions src/it/mixedCompileMultiModule/groovyModule/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>parameters</id>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-ant</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>

<build>
Expand Down
13 changes: 13 additions & 0 deletions src/it/mixedCompileMultiModule2/groovyModule/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>parameters</id>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-ant</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>

<build>
Expand Down
2 changes: 2 additions & 0 deletions src/it/parametersCompile/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = clean test
#invoker.debug = true
104 changes: 104 additions & 0 deletions src/it/parametersCompile/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin-it-root</artifactId>
<version>testing</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>gmavenplus-plugin-it-parametersCompile</artifactId>
<version>testing</version>
<name>GMavenPlus Plugin Parameters Compile Test</name>
<description>The simplest compile with parameters use case. This will fail for all Groovy versions before 2.5.0-beta-1.</description>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>

<profiles>
<profile>
<id>indy</id>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<classifier>indy</classifier>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-ant</artifactId>
<classifier>indy</classifier>
</dependency>
</dependencies>
</profile>
<profile>
<id>nonindy</id>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-ant</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>pre2.3-indy</id>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<classifier>indy</classifier>
</dependency>
</dependencies>
</profile>
<profile>
<id>pre2.3-nonindy</id>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<configuration>
<parameters>true</parameters>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.codehaus.gmavenplus


class SomeClass {

void someMethod(String param1, String param2) { }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.codehaus.gmavenplus;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;


public class SomeClassTest {

@Test
public void testSomeMethod() {
Method method = SomeClass.class.getDeclaredMethod("someMethod", String.class, String.class);
List<String> parameterNames = Arrays.asList(method.getParameters());

Assert.assertEquals(2, parameterNames.size());
Assert.assertEquals("param1", parameterNames.get(0));
Assert.assertEquals("param1", parameterNames.get(1));
}

}
13 changes: 13 additions & 0 deletions src/it/shadedGroovy/uberModule/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>parameters</id>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-ant</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
*/
public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {

/**
* Groovy 2.5.0 beta-1 version.
*/
protected static final Version GROOVY_2_5_0_BETA1 = new Version(2, 5, 0, "beta-1");

/**
* Groovy 2.3.3 version.
*/
Expand Down Expand Up @@ -157,6 +162,14 @@ public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {
*/
protected File configScript;

/**
* Generate metadata for reflection on method parameter names using the functionality provided by JEP 118
* (requires Java 8 or greater and Groovy 2.5.0-beta-1 or greater)
*
* @parameter property="parameters" default-value="false"
*/
protected boolean parameters;

/**
* Performs compilation of compile mojos.
*
Expand Down Expand Up @@ -302,6 +315,17 @@ protected Object setupCompilerConfiguration(final File compileOutputDirectory, f
getLog().warn("Requested to use invokeDynamic, but your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support it (must be " + GROOVY_2_0_0_BETA3 + " or newer). Ignoring invokeDynamic parameter.");
}
}
if (parameters) {
if (groovyAtLeast(GROOVY_2_5_0_BETA1)) {
if (isJavaSupportParameters()) {
invokeMethod(findMethod(compilerConfigurationClass, "setParameters", boolean.class), compilerConfiguration, parameters);
} else {
getLog().warn("Requested to use to use parameters, but your Java version (" + getJavaVersionString() + ") doesn't support it. Ignoring parameters parameter.");
}
} else {
getLog().warn("Requested to use parameters, but your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support it (must be " + GROOVY_2_5_0_BETA1 + " or newer). Ignoring parameters parameter.");
}
}

return compilerConfiguration;
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/codehaus/gmavenplus/mojo/AbstractGroovyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public abstract class AbstractGroovyMojo extends AbstractMojo {
*/
protected static final Version JAVA_1_7 = new Version(1, 7);

/**
* Java 1.8 version.
*/
protected static final Version JAVA_1_8 = new Version(1, 8);

/**
* Groovy 1.5.0 version.
*/
Expand Down Expand Up @@ -134,6 +139,15 @@ protected boolean isJavaSupportIndy() {
return getJavaVersion().compareTo(JAVA_1_7, false) >= 0;
}

/**
* Determines whether the version of Java executing this mojo supports JEP 118 (is at least 1.8).
*
* @return <code>true</code> if the running Java supports parameters, <code>false</code> otherwise
*/
protected boolean isJavaSupportParameters() {
return getJavaVersion().compareTo(JAVA_1_8, false) >= 0;
}

/**
* Gets the version of Java executing this mojo as a Version object.
*
Expand Down

0 comments on commit fa29d7d

Please sign in to comment.