Author: rfscholte
Date: Sun Sep 25 19:44:45 2016
New Revision: 1762228
URL: http://svn.apache.org/viewvc?rev=1762228&view=rev
Log:
[MCOMPILER-269] Support modulepath (Java9/Jigsaw)
Improve detection when modulePath should be used.
Added:
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/invoker.properties
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/pom.xml
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/com/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/com/foo/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/com/foo/MyClass.java
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/module-info.java
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/test/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/test/java/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/test/java/com/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/test/java/com/foo/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/test/java/com/foo/MyTest.java
Modified:
maven/plugins/trunk/maven-compiler-plugin/pom.xml
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-268_modulepath/pom.xml
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-268_modulepath/verify.groovy
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-270_release/verify.groovy
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
Modified: maven/plugins/trunk/maven-compiler-plugin/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/pom.xml?rev=1762228&r1=1762227&r2=1762228&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-compiler-plugin/pom.xml Sun Sep 25 19:44:45 2016
@@ -63,7 +63,7 @@ under the License.
! The following property is used in the integration tests MCOMPILER-157
-->
<mavenPluginPluginVersion>3.5</mavenPluginPluginVersion>
- <plexusCompilerVersion>2.8</plexusCompilerVersion>
+ <plexusCompilerVersion>2.8.1-SNAPSHOT</plexusCompilerVersion>
<groovyVersion>1.8.0</groovyVersion>
<groovyEclipseCompilerVersion>2.7.0-01</groovyEclipseCompilerVersion>
<groovy-eclipse-batch>2.0.4-04</groovy-eclipse-batch>
Modified:
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-268_modulepath/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-268_modulepath/pom.xml?rev=1762228&r1=1762227&r2=1762228&view=diff
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-268_modulepath/pom.xml
(original)
+++
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-268_modulepath/pom.xml
Sun Sep 25 19:44:45 2016
@@ -49,7 +49,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>@project.version@</version>
<configuration>
- <release>9</release>
+ <source>9</source>
+ <target>9</target>
</configuration>
</plugin>
</plugins>
Modified:
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-268_modulepath/verify.groovy
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-268_modulepath/verify.groovy?rev=1762228&r1=1762227&r2=1762228&view=diff
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-268_modulepath/verify.groovy
(original)
+++
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-268_modulepath/verify.groovy
Sun Sep 25 19:44:45 2016
@@ -18,8 +18,4 @@
*/
def log = new File( basedir, 'build.log').text
-assert log.count( " -release" ) == 2
-
-assert !( log =~ /\s-source\s/ )
-assert !( log =~ /\s-target\s/ )
-
+assert log.count( " --module-path" ) == 2
Modified:
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-270_release/verify.groovy
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-270_release/verify.groovy?rev=1762228&r1=1762227&r2=1762228&view=diff
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-270_release/verify.groovy
(original)
+++
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-270_release/verify.groovy
Sun Sep 25 19:44:45 2016
@@ -18,7 +18,7 @@
*/
def log = new File( basedir, 'build.log').text
-assert log.count( " -release" ) == 2
+assert log.count( " --release" ) == 2
assert !( log =~ /\s-source\s/ )
assert !( log =~ /\s-target\s/ )
Added:
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/invoker.properties
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/invoker.properties?rev=1762228&view=auto
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/invoker.properties
(added)
+++
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/invoker.properties
Sun Sep 25 19:44:45 2016
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+
+invoker.java.version = 9+
Added:
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/pom.xml?rev=1762228&view=auto
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/pom.xml
(added)
+++
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/pom.xml
Sun Sep 25 19:44:45 2016
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you 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.
+ -->
+
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.compiler.it</groupId>
+ <artifactId>mcompiler270</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <url>https://issues.apache.org/jira/browse/MCOMPILER-270</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>@project.version@</version>
+ <executions>
+ <execution>
+ <id>default-compile</id>
+ <configuration>
+ <excludes>
+ <exclude>module-info.java</exclude>
+ </excludes>
+ <!-- ideally this would be 1.5, but with CI's it is hard to have
a proper toolchains.xml in place -->
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </execution>
+ <execution>
+ <id>moduleinfo-compile</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>module-info.java</include>
+ </includes>
+ <jdkToolchain>
+ <version>9</version>
+ </jdkToolchain>
+ <fork>true</fork>
+ <release>9</release>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added:
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/com/foo/MyClass.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/com/foo/MyClass.java?rev=1762228&view=auto
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/com/foo/MyClass.java
(added)
+++
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/com/foo/MyClass.java
Sun Sep 25 19:44:45 2016
@@ -0,0 +1,25 @@
+package com.foo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+public class MyClass
+{
+
+}
Added:
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/module-info.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/module-info.java?rev=1762228&view=auto
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/module-info.java
(added)
+++
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/main/java/module-info.java
Sun Sep 25 19:44:45 2016
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+module M.N {
+
+}
\ No newline at end of file
Added:
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/test/java/com/foo/MyTest.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/test/java/com/foo/MyTest.java?rev=1762228&view=auto
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/test/java/com/foo/MyTest.java
(added)
+++
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/src/test/java/com/foo/MyTest.java
Sun Sep 25 19:44:45 2016
@@ -0,0 +1,28 @@
+package com.foo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import junit.framework.TestCase;
+
+public class MyTest
+ extends TestCase
+{
+ private MyClass myClass = new MyClass();
+}
Modified:
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java?rev=1762228&r1=1762227&r2=1762228&view=diff
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
(original)
+++
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
Sun Sep 25 19:44:45 2016
@@ -84,6 +84,13 @@ public abstract class AbstractCompilerMo
extends AbstractMojo
{
+ static final String DEFAULT_SOURCE = "1.5";
+
+ static final String DEFAULT_TARGET = "1.5";
+
+ // Used to compare with older targets
+ static final String MODULE_INFO_TARGET = "1.9";
+
// ----------------------------------------------------------------------
// Configurables
// ----------------------------------------------------------------------
@@ -129,13 +136,13 @@ public abstract class AbstractCompilerMo
/**
* The -source argument for the Java compiler.
*/
- @Parameter( property = "maven.compiler.source", defaultValue = "1.5" )
+ @Parameter( property = "maven.compiler.source", defaultValue =
DEFAULT_SOURCE )
protected String source;
/**
* The -target argument for the Java compiler.
*/
- @Parameter( property = "maven.compiler.target", defaultValue = "1.5" )
+ @Parameter( property = "maven.compiler.target", defaultValue =
DEFAULT_TARGET )
protected String target;
/**
@@ -459,6 +466,8 @@ public abstract class AbstractCompilerMo
protected abstract List<String> getModulepathElements();
protected abstract List<String> getCompileSourceRoots();
+
+ protected abstract void preparePaths( Set<File> sourceFiles );
protected abstract File getOutputDirectory();
@@ -532,14 +541,6 @@ public abstract class AbstractCompilerMo
return;
}
- if ( getLog().isDebugEnabled() )
- {
- getLog().debug( "Source directories: " +
compileSourceRoots.toString().replace( ',', '\n' ) );
- getLog().debug( "Classpath: " +
getClasspathElements().toString().replace( ',', '\n' ) );
- getLog().debug( "Modulepath: " +
getModulepathElements().toString().replace( ',', '\n' ) );
- getLog().debug( "Output directory: " + getOutputDirectory() );
- }
-
//
----------------------------------------------------------------------
// Create the compiler configuration
//
----------------------------------------------------------------------
@@ -548,10 +549,6 @@ public abstract class AbstractCompilerMo
compilerConfiguration.setOutputLocation(
getOutputDirectory().getAbsolutePath() );
- compilerConfiguration.setClasspathEntries( getClasspathElements() );
-
- compilerConfiguration.setModulepathEntries( getModulepathElements() );
-
compilerConfiguration.setOptimize( optimize );
compilerConfiguration.setDebug( debug );
@@ -628,49 +625,6 @@ public abstract class AbstractCompilerMo
compilerConfiguration.setSourceEncoding( encoding );
- Map<String, String> effectiveCompilerArguments =
getCompilerArguments();
-
- String effectiveCompilerArgument = getCompilerArgument();
-
- if ( ( effectiveCompilerArguments != null ) || (
effectiveCompilerArgument != null )
- || ( compilerArgs != null ) )
- {
- LinkedHashMap<String, String> cplrArgsCopy = new
LinkedHashMap<String, String>();
- if ( effectiveCompilerArguments != null )
- {
- for ( Map.Entry<String, String> me :
effectiveCompilerArguments.entrySet() )
- {
- String key = me.getKey();
- String value = me.getValue();
- if ( !key.startsWith( "-" ) )
- {
- key = "-" + key;
- }
-
- if ( key.startsWith( "-A" ) && StringUtils.isNotEmpty(
value ) )
- {
- cplrArgsCopy.put( key + "=" + value, null );
- }
- else
- {
- cplrArgsCopy.put( key, value );
- }
- }
- }
- if ( !StringUtils.isEmpty( effectiveCompilerArgument ) )
- {
- cplrArgsCopy.put( effectiveCompilerArgument, null );
- }
- if ( compilerArgs != null )
- {
- for ( String arg : compilerArgs )
- {
- cplrArgsCopy.put( arg, null );
- }
- }
- compilerConfiguration.setCustomCompilerArguments( cplrArgsCopy );
- }
-
compilerConfiguration.setFork( fork );
if ( fork )
@@ -762,6 +716,8 @@ public abstract class AbstractCompilerMo
canUpdateTarget = compiler.canUpdateTarget(
compilerConfiguration );
sources = getCompileSources( compiler, compilerConfiguration );
+
+ preparePaths( sources );
incrementalBuildHelperRequest = new
IncrementalBuildHelperRequest().inputFiles( sources );
@@ -815,6 +771,8 @@ public abstract class AbstractCompilerMo
{
compilerConfiguration.setSourceFiles( staleSources );
}
+
+ preparePaths( compilerConfiguration.getSourceFiles() );
}
catch ( CompilerException e )
{
@@ -828,10 +786,58 @@ public abstract class AbstractCompilerMo
return;
}
}
+
+ // Dividing pathElements of classPath and modulePath is based on
sourceFiles
+ compilerConfiguration.setClasspathEntries( getClasspathElements() );
+
+ compilerConfiguration.setModulepathEntries( getModulepathElements() );
+
+ Map<String, String> effectiveCompilerArguments =
getCompilerArguments();
+
+ String effectiveCompilerArgument = getCompilerArgument();
+
+ if ( ( effectiveCompilerArguments != null ) || (
effectiveCompilerArgument != null )
+ || ( compilerArgs != null ) )
+ {
+ LinkedHashMap<String, String> cplrArgsCopy = new
LinkedHashMap<String, String>();
+ if ( effectiveCompilerArguments != null )
+ {
+ for ( Map.Entry<String, String> me :
effectiveCompilerArguments.entrySet() )
+ {
+ String key = me.getKey();
+ String value = me.getValue();
+ if ( !key.startsWith( "-" ) )
+ {
+ key = "-" + key;
+ }
+
+ if ( key.startsWith( "-A" ) && StringUtils.isNotEmpty(
value ) )
+ {
+ cplrArgsCopy.put( key + "=" + value, null );
+ }
+ else
+ {
+ cplrArgsCopy.put( key, value );
+ }
+ }
+ }
+ if ( !StringUtils.isEmpty( effectiveCompilerArgument ) )
+ {
+ cplrArgsCopy.put( effectiveCompilerArgument, null );
+ }
+ if ( compilerArgs != null )
+ {
+ for ( String arg : compilerArgs )
+ {
+ cplrArgsCopy.put( arg, null );
+ }
+ }
+ compilerConfiguration.setCustomCompilerArguments( cplrArgsCopy );
+ }
+
//
----------------------------------------------------------------------
// Dump configuration
//
----------------------------------------------------------------------
-
if ( getLog().isDebugEnabled() )
{
getLog().debug( "Classpath:" );
@@ -869,7 +875,7 @@ public abstract class AbstractCompilerMo
}
String[] cl = compiler.createCommandLine(
compilerConfiguration );
- if ( cl != null && cl.length > 0 )
+ if ( getLog().isDebugEnabled() && cl != null && cl.length > 0 )
{
StringBuilder sb = new StringBuilder();
sb.append( cl[0] );
Modified:
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java?rev=1762228&r1=1762227&r2=1762228&view=diff
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
(original)
+++
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
Sun Sep 25 19:44:45 2016
@@ -20,7 +20,6 @@ package org.apache.maven.plugin.compiler
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Parameter;
@@ -98,6 +97,9 @@ public class CompilerMojo
@Parameter ( property = "maven.main.skip" )
private boolean skipMain;
+ @Parameter( defaultValue = "${project.compileClasspathElements}", readonly
= true, required = true )
+ private List<String> compilePath;
+
private List<String> classpathElements;
private List<String> modulepathElements;
@@ -132,15 +134,6 @@ public class CompilerMojo
return;
}
- try
- {
- preparePaths();
- }
- catch ( DependencyResolutionRequiredException e )
- {
- throw new MojoExecutionException( e.getMessage() );
- }
-
super.execute();
if ( outputDirectory.isDirectory() )
@@ -149,26 +142,33 @@ public class CompilerMojo
}
}
- private void preparePaths() throws DependencyResolutionRequiredException
+ @Override
+ protected void preparePaths( Set<File> sourceFiles )
{
+ assert compilePath != null;
+
boolean hasModuleDescriptor = false;
- for ( String sourceRoot : getProject().getCompileSourceRoots() )
+ for ( File sourceFile : sourceFiles )
{
- hasModuleDescriptor |= new File( sourceRoot, "module-info.java"
).exists();
+ if ( "module-info.java".equals( sourceFile.getName() ) )
+ {
+ hasModuleDescriptor = true;
+ break;
+ }
}
- List<String> pathElements = getProject().getCompileClasspathElements();
-
if ( hasModuleDescriptor )
{
- modulepathElements = pathElements;
+ modulepathElements = compilePath;
classpathElements = Collections.emptyList();
}
else
{
- classpathElements = pathElements;
+ classpathElements = compilePath;
modulepathElements = Collections.emptyList();
}
+
+ getLog().debug( "classpathElements: " + getClasspathElements() );
}
protected SourceInclusionScanner getSourceInclusionScanner( int
staleMillis )
Modified:
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java?rev=1762228&r1=1762227&r2=1762228&view=diff
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
(original)
+++
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
Sun Sep 25 19:44:45 2016
@@ -19,7 +19,6 @@ package org.apache.maven.plugin.compiler
* under the License.
*/
-import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@@ -145,6 +144,12 @@ public class TestCompilerMojo
@Parameter ( defaultValue =
"${project.build.directory}/generated-test-sources/test-annotations" )
private File generatedTestSourcesDirectory;
+ @Parameter( defaultValue = "${project.compileClasspathElements}", readonly
= true )
+ private List<String> compilePath;
+
+ @Parameter( defaultValue = "${project.testClasspathElements}", readonly =
true )
+ private List<String> testPath;
+
private List<String> classpathElements;
private List<String> modulepathElements;
@@ -156,19 +161,7 @@ public class TestCompilerMojo
{
getLog().info( "Not compiling test sources" );
}
- else
- {
- try
- {
- preparePaths();
- }
- catch ( DependencyResolutionRequiredException e )
- {
- throw new MojoExecutionException( e.getMessage() );
- }
-
- super.execute();
- }
+ super.execute();
}
protected List<String> getCompileSourceRoots()
@@ -192,8 +185,8 @@ public class TestCompilerMojo
return outputDirectory;
}
- private void preparePaths()
- throws DependencyResolutionRequiredException
+ @Override
+ protected void preparePaths( Set<File> sourceFiles )
{
File mainOutputDirectory = new File(
getProject().getBuild().getOutputDirectory() );
@@ -202,20 +195,38 @@ public class TestCompilerMojo
boolean hasMainModuleDescriptor = mainModuleInfo.exists();
boolean hasTestModuleDescriptor = false;
- for ( String sourceRoot : getProject().getTestCompileSourceRoots() )
+ for ( File sourceFile : sourceFiles )
{
- hasTestModuleDescriptor |= new File( sourceRoot,
"module-info.java" ).exists();
+ // @todo verify if it is the root of a sourcedirectory?
+ if ( "module-info.java".equals( sourceFile.getName() ) )
+ {
+ hasTestModuleDescriptor = true;
+ break;
+ }
}
- List<String> compilePathElements =
getProject().getCompileClasspathElements();
- List<String> testPathElements =
getProject().getTestClasspathElements();
-
- List<String> testScopedElements = new ArrayList<String>(
testPathElements );
- testScopedElements.removeAll( compilePathElements );
+ List<String> testScopedElements = new ArrayList<String>( testPath );
+ testScopedElements.removeAll( compilePath );
+ if ( release != null )
+ {
+ if ( Integer.valueOf( release ) < 9 )
+ {
+ modulepathElements = Collections.emptyList();
+ classpathElements = testPath;
+ return;
+ }
+ }
+ else if ( Double.valueOf( getTarget() ) < Double.valueOf(
MODULE_INFO_TARGET ) )
+ {
+ modulepathElements = Collections.emptyList();
+ classpathElements = testPath;
+ return;
+ }
+
if ( hasTestModuleDescriptor )
{
- modulepathElements = testPathElements;
+ modulepathElements = testPath;
classpathElements = Collections.emptyList();
if ( hasMainModuleDescriptor )
@@ -236,7 +247,7 @@ public class TestCompilerMojo
{
if ( hasMainModuleDescriptor )
{
- modulepathElements = compilePathElements;
+ modulepathElements = compilePath;
classpathElements = testScopedElements;
if ( compilerArgs == null )
{
@@ -249,6 +260,8 @@ public class TestCompilerMojo
compilerArgs.add( "-Xmodule:" + moduleName );
compilerArgs.add( "--add-modules" );
compilerArgs.add( moduleName );
+ compilerArgs.add( "--add-reads" );
+ compilerArgs.add( moduleName + "=ALL-UNNAMED" );
}
catch ( IOException e )
{
@@ -258,7 +271,7 @@ public class TestCompilerMojo
else
{
modulepathElements = Collections.emptyList();
- classpathElements = testPathElements;
+ classpathElements = testPath;
}
}
}
Modified:
maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java?rev=1762228&r1=1762227&r2=1762228&view=diff
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
(original)
+++
maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
Sun Sep 25 19:44:45 2016
@@ -47,9 +47,9 @@ public class CompilerMojoTestCase
extends AbstractMojoTestCase
{
- private String source;
-
- private String target;
+ private String source = AbstractCompilerMojo.DEFAULT_SOURCE;
+
+ private String target = AbstractCompilerMojo.DEFAULT_TARGET;
@Override
protected void setUp()
@@ -321,7 +321,7 @@ public class CompilerMojoTestCase
setVariableValueToObject( mojo, "log", new DebugEnabledLog() );
setVariableValueToObject( mojo, "projectArtifact", new ArtifactStub()
);
- setVariableValueToObject( mojo, "classpathElements",
Collections.EMPTY_LIST );
+ setVariableValueToObject( mojo, "compilePath", Collections.EMPTY_LIST
);
setVariableValueToObject( mojo, "session", getMockMavenSession() );
setVariableValueToObject( mojo, "project", getMockMavenProject() );
setVariableValueToObject( mojo, "mojoExecution",
getMockMojoExecution() );
@@ -366,6 +366,7 @@ public class CompilerMojoTestCase
}
when ( junitArtifact.getFile() ).thenReturn( artifactFile );
+ testClasspathList.add( artifactFile.getAbsolutePath() );
testClasspathList.add( compilerMojo.getOutputDirectory().getPath() );
String testSourceRoot = testPom.getParent() + "/src/test/java";
@@ -375,6 +376,8 @@ public class CompilerMojoTestCase
project.setArtifacts( Collections.singleton( junitArtifact ) );
project.getBuild().setOutputDirectory( new File( buildDir, "classes"
).getAbsolutePath() );
setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "compilePath", Collections.EMPTY_LIST
);
+ setVariableValueToObject( mojo, "testPath", testClasspathList );
setVariableValueToObject( mojo, "session", getMockMavenSession() );
setVariableValueToObject( mojo, "mojoExecution",
getMockMojoExecution() );
setVariableValueToObject( mojo, "source", source );
@@ -382,7 +385,7 @@ public class CompilerMojoTestCase
return mojo;
}
-
+
private MavenProject getMockMavenProject()
{
MavenProject mp = new MavenProject();