Skip to content

Commit

Permalink
Add support for all three classpath possibilities (closes #140)
Browse files Browse the repository at this point in the history
  • Loading branch information
keeganwitt committed Sep 8, 2019
1 parent 234c183 commit 4f255cd
Show file tree
Hide file tree
Showing 29 changed files with 411 additions and 59 deletions.
2 changes: 2 additions & 0 deletions src/it/pluginAndProjectClasspath/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = clean test
#invoker.debug = true
195 changes: 195 additions & 0 deletions src/it/pluginAndProjectClasspath/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?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-pluginAndProjectClasspath</artifactId>
<version>testing</version>
<name>GMavenPlus Plugin Plugin and Project Classpath test</name>
<description>Compiling, generating stubs, and GroovyDoc, using Groovy as a plugin dependency, while also including project dependencies.</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</artifactId>
<classifier>indy</classifier>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-groovydoc</artifactId>
<classifier>indy</classifier>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>@groovyVersion@</version>
<classifier>indy</classifier>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-groovydoc</artifactId>
<version>@groovyVersion@</version>
<classifier>indy</classifier>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>nonindy</id>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-groovydoc</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>@groovyVersion@</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-groovydoc</artifactId>
<version>@groovyVersion@</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>pre2.3-indy</id>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<classifier>indy</classifier>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>@groovyVersion@</version>
<classifier>indy</classifier>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>pre2.3-nonindy</id>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>@groovyVersion@</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<configuration>
<includeClasspath>PROJECT_AND_PLUGIN</includeClasspath>
</configuration>
<executions>
<execution>
<phase>generate-test-sources</phase>
<goals>
<goal>addSources</goal>
<goal>generateStubs</goal>
<goal>groovydoc</goal>
<goal>compile</goal>
<goal>removeStubs</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,36 @@
/*
* Copyright (C) 2018 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


/**
* Some Example Cass
*
* @author Keegan Witt
* @version super awesome
*/
class SomeClass {

/**
* This method does absolutely nothing
* @param unusedParam a useless parameter
*/
String someMethod(String unusedParam) {
return "Hello, world."
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2018 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 org.junit.Assert;
import org.junit.Test;

import java.io.File;


public class SomeClassTest {

@Test
public void testSomeClassExists() {
File generatedGroovyDoc = new File("target/gapidocs/org/codehaus/gmavenplus/SomeClass.html");
Assert.assertTrue(generatedGroovyDoc + " does not exist.", generatedGroovyDoc.exists());
Assert.assertTrue(generatedGroovyDoc + " is empty.", generatedGroovyDoc.length() > 0);
}

@Test
public void testOverviewSummaryExists() {
File generatedGroovyDoc = new File("target/gapidocs/overview-summary.html");
Assert.assertTrue(generatedGroovyDoc + " does not exist.", generatedGroovyDoc.exists());
Assert.assertTrue(generatedGroovyDoc + " is empty.", generatedGroovyDoc.length() > 0);
}

@Test
public void testSomeMethod() {
SomeClass someClass = new SomeClass();
Assert.assertEquals("Hello, world.", someClass.someMethod(""));
}

}
2 changes: 1 addition & 1 deletion src/it/pluginClasspath/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<configuration>
<useSharedClassLoader>true</useSharedClassLoader>
<includeClasspath>PLUGIN_ONLY</includeClasspath>
</configuration>
<executions>
<execution>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/codehaus/gmavenplus/model/IncludeClasspath.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.codehaus.gmavenplus.model;

/**
* The possible classpaths to include.
*/
public enum IncludeClasspath {
PROJECT_ONLY,
PROJECT_AND_PLUGIN,
PLUGIN_ONLY
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.codehaus.gmavenplus.mojo;

import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.gmavenplus.model.IncludeClasspath;
import org.codehaus.gmavenplus.model.Version;

import java.io.File;
Expand Down Expand Up @@ -194,13 +195,18 @@ public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {
protected boolean parameters;

/**
* Whether to use a shared classloader that includes both the project classpath and plugin classpath.
* What classpath to include. One of
* <ul>
* <li>PROJECT_ONLY</li>
* <li>PROJECT_AND_PLUGIN</li>
* <li>PLUGIN_ONLY</li>
* </ul>
* Uses the same scope as the required dependency resolution of this mojo. Use only if you know what you're doing.
*
* @since 1.6.3
* @since 1.8.0
*/
@Parameter(defaultValue = "false")
protected boolean useSharedClassLoader;
@Parameter(defaultValue = "PROJECT_ONLY")
protected IncludeClasspath includeClasspath;

/**
* Whether the bytecode version has preview features enabled (JEP 12).
Expand Down Expand Up @@ -231,7 +237,7 @@ protected synchronized void doCompile(final Set<File> sources, final List classp
return;
}

setupClassWrangler(classpath, useSharedClassLoader);
setupClassWrangler(classpath, includeClasspath);

logPluginClasspath();
classWrangler.logGroovyVersion(mojoExecution.getMojoDescriptor().getGoal());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.gmavenplus.groovyworkarounds.DotGroovyFile;
import org.codehaus.gmavenplus.model.IncludeClasspath;
import org.codehaus.gmavenplus.model.Version;
import org.codehaus.gmavenplus.util.FileUtils;

Expand Down Expand Up @@ -180,14 +181,18 @@ public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSource
protected int tolerance;

/**
* Whether to use a shared classloader that includes both the project classpath and plugin classpath.
* What classpath to include. One of
* <ul>
* <li>PROJECT_ONLY</li>
* <li>PROJECT_AND_PLUGIN</li>
* <li>PLUGIN_ONLY</li>
* </ul>
* Uses the same scope as the required dependency resolution of this mojo. Use only if you know what you're doing.
*
* @since 1.6.3
* @since 1.8.0
*/
@Parameter(defaultValue = "false")
protected boolean useSharedClassLoader;

@Parameter(defaultValue = "PROJECT_ONLY")
protected IncludeClasspath includeClasspath;

/**
* Whether the bytecode version has preview features enabled (JEP 12).
Expand Down Expand Up @@ -216,7 +221,7 @@ protected synchronized void doStubGeneration(final Set<File> stubSources, final
return;
}

setupClassWrangler(classpath, useSharedClassLoader);
setupClassWrangler(classpath, includeClasspath);

logPluginClasspath();
classWrangler.logGroovyVersion(mojoExecution.getMojoDescriptor().getGoal());
Expand Down
Loading

0 comments on commit 4f255cd

Please sign in to comment.