[MCOMPILER-304] Introduce plexus-language component
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1804935 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index d5f7c10..5fafc54 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,6 +68,7 @@
<groovyEclipseCompilerVersion>2.7.0-01</groovyEclipseCompilerVersion>
<groovy-eclipse-batch>2.0.4-04</groovy-eclipse-batch>
<openJpaVersion>2.2.0</openJpaVersion>
+ <javaVersion>7</javaVersion>
</properties>
<contributors>
@@ -110,14 +111,9 @@
</dependency>
<dependency>
- <groupId>org.ow2.asm</groupId>
- <artifactId>asm</artifactId>
- <version>6.0_BETA</version>
- </dependency>
- <dependency>
- <groupId>com.thoughtworks.qdox</groupId>
- <artifactId>qdox</artifactId>
- <version>2.0-M7</version>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-java</artifactId>
+ <version>0.9.1</version>
</dependency>
<dependency>
@@ -313,18 +309,4 @@
</dependencies>
</profile>
</profiles>
-
- <repositories>
- <repository>
- <releases>
- <enabled>false</enabled>
- </releases>
- <snapshots>
- <enabled>true</enabled>
- </snapshots>
- <id>plexus-snapshots</id>
- <name>Plexus Snapshot Repository</name>
- <url>https://oss.sonatype.org/content/repositories/plexus-snapshots</url>
- </repository>
- </repositories>
</project>
diff --git a/src/it/MCOMPILER-268_modulepath/pom.xml b/src/it/MCOMPILER-268_modulepath/pom.xml
index 82bf9f2..5ccd455 100644
--- a/src/it/MCOMPILER-268_modulepath/pom.xml
+++ b/src/it/MCOMPILER-268_modulepath/pom.xml
@@ -35,6 +35,11 @@
<dependencies>
<dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.6</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
diff --git a/src/it/MCOMPILER-268_modulepath/src/main/java/module-info.java b/src/it/MCOMPILER-268_modulepath/src/main/java/module-info.java
index c0e023a..d9800e3 100644
--- a/src/it/MCOMPILER-268_modulepath/src/main/java/module-info.java
+++ b/src/it/MCOMPILER-268_modulepath/src/main/java/module-info.java
@@ -18,5 +18,5 @@
*/
module M.N {
-
+ requires org.apache.commons.lang3;
}
\ No newline at end of file
diff --git a/src/it/MCOMPILER-294/app/pom.xml b/src/it/MCOMPILER-294/app/pom.xml
new file mode 100644
index 0000000..6eac746
--- /dev/null
+++ b/src/it/MCOMPILER-294/app/pom.xml
@@ -0,0 +1,41 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache.maven.plugins.compiler.it</groupId>
+ <artifactId>mcompiler294</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>app</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.plugins.compiler.it</groupId>
+ <artifactId>lib</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/src/it/MCOMPILER-294/app/src/main/java/module-info.java b/src/it/MCOMPILER-294/app/src/main/java/module-info.java
new file mode 100644
index 0000000..3cda721
--- /dev/null
+++ b/src/it/MCOMPILER-294/app/src/main/java/module-info.java
@@ -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 org.maven.test.app {
+ requires org.maven.test.lib;
+}
\ No newline at end of file
diff --git a/src/it/MCOMPILER-294/app/src/main/java/org/maven/test/app/Main.java b/src/it/MCOMPILER-294/app/src/main/java/org/maven/test/app/Main.java
new file mode 100644
index 0000000..5d94eec
--- /dev/null
+++ b/src/it/MCOMPILER-294/app/src/main/java/org/maven/test/app/Main.java
@@ -0,0 +1,32 @@
+package org.maven.test.app;
+
+/*
+ * 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 org.maven.test.lib.Sout;
+
+public class Main {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ Sout.println( args );
+ }
+}
\ No newline at end of file
diff --git a/src/it/MCOMPILER-294/invoker.properties b/src/it/MCOMPILER-294/invoker.properties
new file mode 100644
index 0000000..8d76986
--- /dev/null
+++ b/src/it/MCOMPILER-294/invoker.properties
@@ -0,0 +1,19 @@
+# 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+
+invoker.goals = compile
diff --git a/src/it/MCOMPILER-294/lib/pom.xml b/src/it/MCOMPILER-294/lib/pom.xml
new file mode 100644
index 0000000..ec3cc61
--- /dev/null
+++ b/src/it/MCOMPILER-294/lib/pom.xml
@@ -0,0 +1,33 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache.maven.plugins.compiler.it</groupId>
+ <artifactId>mcompiler294</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>lib</artifactId>
+
+</project>
diff --git a/src/it/MCOMPILER-294/lib/src/main/java/module-info.java b/src/it/MCOMPILER-294/lib/src/main/java/module-info.java
new file mode 100644
index 0000000..a218436
--- /dev/null
+++ b/src/it/MCOMPILER-294/lib/src/main/java/module-info.java
@@ -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 org.maven.test.lib {
+ exports org.maven.test.lib;
+}
\ No newline at end of file
diff --git a/src/it/MCOMPILER-294/lib/src/main/java/org/maven/test/lib/Sout.java b/src/it/MCOMPILER-294/lib/src/main/java/org/maven/test/lib/Sout.java
new file mode 100644
index 0000000..658044e
--- /dev/null
+++ b/src/it/MCOMPILER-294/lib/src/main/java/org/maven/test/lib/Sout.java
@@ -0,0 +1,33 @@
+package org.maven.test.lib;
+
+/*
+ * 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 Sout {
+
+ /**
+ * @param args
+ */
+ public static void println(String[] args) {
+ for ( String string : args )
+ {
+ System.out.println( args );
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/it/MCOMPILER-294/pom.xml b/src/it/MCOMPILER-294/pom.xml
new file mode 100644
index 0000000..4e3ec93
--- /dev/null
+++ b/src/it/MCOMPILER-294/pom.xml
@@ -0,0 +1,55 @@
+<?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>mcompiler294</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <url>https://issues.apache.org/jira/browse/MCOMPILER-294</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <release>9</release>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <modules>
+ <module>lib</module>
+ <module>app</module>
+ </modules>
+
+</project>
diff --git a/src/it/automodules-application/verify.groovy b/src/it/automodules-application/verify.groovy
index 9524a2f..4ce088d 100644
--- a/src/it/automodules-application/verify.groovy
+++ b/src/it/automodules-application/verify.groovy
@@ -19,4 +19,4 @@
buildLog = new File( basedir, 'build.log' ).text;
-assert buildLog.contains("[INFO] Required automodules detected. Please don't publish this project to a public artifact repository!");
+assert buildLog.contains("[INFO] Required filename-based automodules detected. Please don't publish this project to a public artifact repository!");
diff --git a/src/it/automodules-library/verify.groovy b/src/it/automodules-library/verify.groovy
index 15c7a52..fb2d1d1 100644
--- a/src/it/automodules-library/verify.groovy
+++ b/src/it/automodules-library/verify.groovy
@@ -19,4 +19,4 @@
buildLog = new File( basedir, 'build.log' ).text;
-assert buildLog.contains("[WARNING] * Required automodules detected. Please don't publish this project to a public artifact repository! *");
+assert buildLog.contains("[WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *");
diff --git a/src/it/automodules-transitive-module/verify.groovy b/src/it/automodules-transitive-module/verify.groovy
index 15c7a52..fb2d1d1 100644
--- a/src/it/automodules-transitive-module/verify.groovy
+++ b/src/it/automodules-transitive-module/verify.groovy
@@ -19,4 +19,4 @@
buildLog = new File( basedir, 'build.log' ).text;
-assert buildLog.contains("[WARNING] * Required automodules detected. Please don't publish this project to a public artifact repository! *");
+assert buildLog.contains("[WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *");
diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
index a7857e9..84bb300 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -1227,7 +1227,7 @@
//TODO remove the part with ToolchainManager lookup once we depend on
//3.0.9 (have it as prerequisite). Define as regular component field then.
- private Toolchain getToolchain()
+ protected final Toolchain getToolchain()
{
Toolchain tc = null;
diff --git a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
index ef9db32..be6f096 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
@@ -31,12 +31,6 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.compiler.module.JavaModuleDescriptor;
-import org.apache.maven.plugin.compiler.module.ModuleInfoParser;
-import org.apache.maven.plugin.compiler.module.ProjectAnalyzer;
-import org.apache.maven.plugin.compiler.module.ProjectAnalyzerRequest;
-import org.apache.maven.plugin.compiler.module.ProjectAnalyzerResult;
-import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
@@ -44,9 +38,17 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.shared.utils.logging.MessageUtils;
+import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.java.DefaultJavaToolChain;
import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner;
import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
+import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
+import org.codehaus.plexus.languages.java.jpms.LocationManager;
+import org.codehaus.plexus.languages.java.jpms.QDoxModuleInfoParser;
+import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest;
+import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult;
+import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult.ModuleNameSource;
/**
* Compiles application sources
@@ -115,11 +117,9 @@
@Parameter
private boolean allowPartialRequirements;
- @Component( hint = "qdox" )
- private ModuleInfoParser moduleInfoParser;
+ private QDoxModuleInfoParser moduleInfoParser = new QDoxModuleInfoParser();
- @Component
- private ProjectAnalyzer projectAnalyzer;
+ private LocationManager locationManager = new LocationManager();
private List<String> classpathElements;
@@ -177,7 +177,7 @@
{
try
{
- moduleDescriptor = moduleInfoParser.getModuleDescriptor( sourceFile.getParentFile() );
+ moduleDescriptor = moduleInfoParser.fromSourcePath( sourceFile.getParentFile().toPath() );
}
catch ( IOException e )
{
@@ -197,92 +197,57 @@
modulepathElements = new ArrayList<String>( compilePath.size() );
classpathElements = new ArrayList<String>( compilePath.size() );
- ProjectAnalyzerResult analyzerResult;
+ ResolvePathsResult<File> analyzerResult;
try
{
Collection<File> dependencyArtifacts = getCompileClasspathElements( getProject() );
-
- ProjectAnalyzerRequest analyzerRequest = new ProjectAnalyzerRequest()
- .setBaseModuleDescriptor( moduleDescriptor )
- .setDependencyArtifacts( dependencyArtifacts );
-
- analyzerResult = projectAnalyzer.analyze( analyzerRequest );
-
- if ( !analyzerResult.getRequiredAutomaticModules().isEmpty() )
+
+ ResolvePathsRequest<File> request =
+ ResolvePathsRequest.withFiles( dependencyArtifacts ).setMainModuleDescriptor( moduleDescriptor );
+
+ Toolchain toolchain = getToolchain();
+ if ( toolchain != null && toolchain instanceof DefaultJavaToolChain )
{
- boolean filenameBased = false;
-
- for ( String automodule : analyzerResult.getRequiredAutomaticModules() )
+ request.setJdkHome( new File( ( (DefaultJavaToolChain) toolchain ).getJavaHome() ) );
+ }
+
+ analyzerResult = locationManager.resolvePaths( request );
+
+ for ( Map.Entry<File, ModuleNameSource> entry : analyzerResult.getModulepathElements().entrySet() )
+ {
+ if ( ModuleNameSource.FILENAME.equals( entry.getValue() ) )
{
- filenameBased =
- ProjectAnalyzerResult.ModuleNameSource.FILENAME.equals(
- analyzerResult.getModuleNameSource( automodule ) );
-
- if ( filenameBased )
+ final String message = "Required filename-based automodules detected. "
+ + "Please don't publish this project to a public artifact repository!";
+
+ if ( moduleDescriptor.exports().isEmpty() )
{
- final String message = "Required automodules detected. "
- + "Please don't publish this project to a public artifact repository!";
-
- if ( moduleDescriptor.exports().isEmpty() )
- {
- // application
- getLog().info( message );
- }
- else
- {
- // library
- writeBoxedWarning( message );
- }
-
- break;
+ // application
+ getLog().info( message );
}
+ else
+ {
+ // library
+ writeBoxedWarning( message );
+ }
+ break;
}
}
- for ( Map.Entry<File, JavaModuleDescriptor> entry : analyzerResult.getPathElements().entrySet() )
+ for ( File file : analyzerResult.getClasspathElements() )
{
- if ( !allowPartialRequirements )
- {
- modulepathElements.add( entry.getKey().getPath() );
- }
- else if ( entry.getValue() == null )
- {
- classpathElements.add( entry.getKey().getPath() );
- }
- else if ( analyzerResult.getRequiredNormalModules().contains( entry.getValue().name() ) )
- {
- modulepathElements.add( entry.getKey().getPath() );
- }
- else if ( analyzerResult.getRequiredAutomaticModules().contains( entry.getValue().name() ) )
- {
- modulepathElements.add( entry.getKey().getPath() );
- }
- else
- {
- classpathElements.add( entry.getKey().getPath() );
- }
+ classpathElements.add( file.getPath() );
+ }
+
+ for ( File file : analyzerResult.getModulepathElements().keySet() )
+ {
+ modulepathElements.add( file.getPath() );
}
}
catch ( IOException e )
{
getLog().warn( e.getMessage() );
}
-
-// if ( !classpathElements.isEmpty() )
-// {
-// if ( compilerArgs == null )
-// {
-// compilerArgs = new ArrayList<String>();
-// }
-// compilerArgs.add( "--add-reads" );
-// compilerArgs.add( moduleDescriptor.name() + "=ALL-UNNAMED" );
-//
-// if ( !modulepathElements.isEmpty() )
-// {
-// compilerArgs.add( "--add-reads" );
-// compilerArgs.add( "ALL-MODULE-PATH=ALL-UNNAMED" );
-// }
-// }
}
else
{
diff --git a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
index 0651508..9f4c7c0 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
@@ -20,25 +20,30 @@
*/
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.compiler.module.ModuleInfoParser;
-import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.java.DefaultJavaToolChain;
import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner;
import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
+import org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser;
+import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
+import org.codehaus.plexus.languages.java.jpms.LocationManager;
+import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest;
+import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult;
/**
* Compiles application test sources.
@@ -153,13 +158,14 @@
@Parameter( defaultValue = "${project.testClasspathElements}", readonly = true )
private List<String> testPath;
+
+ private AsmModuleInfoParser asmModuleInfoParser = new AsmModuleInfoParser();
- @Component
- private Map<String, ModuleInfoParser> moduleInfoParsers;
+ private LocationManager locationManager = new LocationManager();
- private List<String> classpathElements;
+ private Collection<String> classpathElements;
- private List<String> modulepathElements;
+ private Collection<String> modulepathElements;
public void execute()
throws MojoExecutionException, CompilationFailureException
@@ -179,13 +185,13 @@
protected List<String> getClasspathElements()
{
- return classpathElements;
+ return new ArrayList<>( classpathElements );
}
-
+
@Override
protected List<String> getModulepathElements()
{
- return modulepathElements;
+ return new ArrayList<>( modulepathElements );
}
protected File getOutputDirectory()
@@ -213,9 +219,6 @@
}
}
- List<String> testScopedElements = new ArrayList<String>( testPath );
- testScopedElements.removeAll( compilePath );
-
if ( release != null )
{
if ( Integer.valueOf( release ) < 9 )
@@ -255,18 +258,39 @@
{
if ( hasMainModuleDescriptor )
{
- modulepathElements = compilePath;
- classpathElements = testScopedElements;
+ JavaModuleDescriptor moduleDescriptor;
+ ResolvePathsResult<String> result;
+
+ try
+ {
+ moduleDescriptor = getModuleDescriptor( mainOutputDirectory );
+
+ ResolvePathsRequest<String> request =
+ ResolvePathsRequest.withStrings( testPath ).setMainModuleDescriptor( moduleDescriptor );
+
+ Toolchain toolchain = getToolchain();
+ if ( toolchain != null && toolchain instanceof DefaultJavaToolChain )
+ {
+ request.setJdkHome( new File( ( (DefaultJavaToolChain) toolchain ).getJavaHome() ) );
+ }
+
+ result = locationManager.resolvePaths( request );
+ }
+ catch ( IOException e )
+ {
+ throw new RuntimeException( e );
+ }
+
+ modulepathElements = result.getModulepathElements().keySet();
+ classpathElements = result.getClasspathElements();
+
if ( compilerArgs == null )
{
compilerArgs = new ArrayList<String>();
}
-
- String moduleName = getModuleName( mainOutputDirectory );
-
compilerArgs.add( "--patch-module" );
- StringBuilder addReadsValue = new StringBuilder( moduleName )
+ StringBuilder addReadsValue = new StringBuilder( moduleDescriptor.name() )
.append( '=' )
.append( mainOutputDirectory )
.append( PS );
@@ -278,7 +302,7 @@
compilerArgs.add( addReadsValue.toString() );
compilerArgs.add( "--add-reads" );
- compilerArgs.add( moduleName + "=ALL-UNNAMED" );
+ compilerArgs.add( moduleDescriptor.name() + "=ALL-UNNAMED" );
}
else
{
@@ -288,46 +312,9 @@
}
}
- private String getModuleName( File mainOutputDirectory )
+ private JavaModuleDescriptor getModuleDescriptor( File mainOutputDirectory ) throws IOException
{
- String moduleName = null;
-
- Map<String, Exception> exceptionMap = new LinkedHashMap<String, Exception>( moduleInfoParsers.size() );
-
- List<String> parserKeys = Arrays.asList( "reflect", "asm" );
-
- // The class format is still changing, for that reason provide multiple strategies to parse module-info
- for ( String parserKey: parserKeys )
- {
- ModuleInfoParser parser = moduleInfoParsers.get( parserKey );
-
- try
- {
- moduleName = parser.getModuleDescriptor( mainOutputDirectory ).name();
-
- if ( moduleName != null )
- {
- break;
- }
- }
- catch ( Exception e )
- {
- exceptionMap.put( parserKey, e );
- }
- }
-
- if ( moduleName == null )
- {
- getLog().error( "Failed to parse module-info:" );
-
- for ( Map.Entry<String, Exception> exception : exceptionMap.entrySet() )
- {
- getLog().error( "With " + exception.getKey() + ": " + exception.getValue().getMessage() );
- }
-
- throw new RuntimeException( "Failed to parse module-info" );
- }
- return moduleName;
+ return asmModuleInfoParser.getModuleDescriptor( mainOutputDirectory.toPath() );
}
protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis )
diff --git a/src/main/java/org/apache/maven/plugin/compiler/module/AsmModuleInfoParser.java b/src/main/java/org/apache/maven/plugin/compiler/module/AsmModuleInfoParser.java
deleted file mode 100644
index af86c1e..0000000
--- a/src/main/java/org/apache/maven/plugin/compiler/module/AsmModuleInfoParser.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package org.apache.maven.plugin.compiler.module;
-
-/*
- * 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 java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-import org.codehaus.plexus.component.annotations.Component;
-import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.ClassVisitor;
-import org.objectweb.asm.ModuleVisitor;
-import org.objectweb.asm.Opcodes;
-
-/**
- * Extract information from module with ASM
- *
- * @author Robert Scholte
- * @since 3.6
- */
-@Component( role = ModuleInfoParser.class, hint = "asm" )
-public class AsmModuleInfoParser
- implements ModuleInfoParser
-{
- @Override
- public Type getType()
- {
- return Type.CLASS;
- }
-
-
- @Override
- public JavaModuleDescriptor getModuleDescriptor( File modulePath )
- throws IOException
- {
- final JavaModuleDescriptorWrapper wrapper = new JavaModuleDescriptorWrapper();
-
- InputStream in = getModuleInfoClass( modulePath );
-
- if ( in != null )
- {
- ClassReader reader = new ClassReader( in );
- reader.accept( new ClassVisitor( Opcodes.ASM6 )
- {
- @Override
- public ModuleVisitor visitModule( String name, int arg1, String arg2 )
- {
- wrapper.builder = JavaModuleDescriptor.newModule( name );
-
- return new ModuleVisitor( Opcodes.ASM6 )
- {
- @Override
- public void visitRequire( String module, int access, String version )
- {
- wrapper.builder.requires( module );
- }
- };
- }
- }, 0 );
-
- in.close();
- }
- else
- {
- wrapper.builder = JavaModuleDescriptor.newAutomaticModule( null );
- }
-
- return wrapper.builder.build();
- }
-
- private InputStream getModuleInfoClass( File modulePath )
- throws FileNotFoundException, IOException
- {
- InputStream in;
- if ( modulePath.isDirectory() )
- {
- in = new FileInputStream( new File( modulePath, "module-info.class" ) );
- }
- else
- {
- //
- JarFile jarFile = new JarFile( modulePath );
- JarEntry moduleInfo = jarFile.getJarEntry( "/module-info.class" );
-
- if ( moduleInfo != null )
- {
- in = jarFile.getInputStream( moduleInfo );
- }
- else
- {
- in = null;
- }
- }
- return in;
- }
-
- private static class JavaModuleDescriptorWrapper
- {
- private JavaModuleDescriptor.Builder builder;
- }
-}
diff --git a/src/main/java/org/apache/maven/plugin/compiler/module/JavaModuleDescriptor.java b/src/main/java/org/apache/maven/plugin/compiler/module/JavaModuleDescriptor.java
deleted file mode 100644
index c571b96..0000000
--- a/src/main/java/org/apache/maven/plugin/compiler/module/JavaModuleDescriptor.java
+++ /dev/null
@@ -1,159 +0,0 @@
-package org.apache.maven.plugin.compiler.module;
-
-/*
- * 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 java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Simple representation of a Module containing info required by this plugin.
- * It will provide only methods matching Java 9 ModuleDescriptor, so once Java 9 is required, we can easily switch
- *
- * @author Robert Scholte
- * @since 3.7.0
- *
- */
-public class JavaModuleDescriptor
-{
- private String name;
-
- private boolean automatic;
-
- private Set<JavaRequires> requires = new HashSet<JavaRequires>();
-
- private Set<JavaExports> exports = new HashSet<JavaExports>();
-
- public String name()
- {
- return name;
- }
-
- public boolean isAutomatic()
- {
- return automatic;
- }
-
- public Set<JavaRequires> requires()
- {
- return Collections.unmodifiableSet( requires );
- }
-
- public Set<JavaExports> exports()
- {
- return Collections.unmodifiableSet( exports );
- }
-
- public static JavaModuleDescriptor.Builder newModule( String name )
- {
- return new Builder( name ).setAutomatic( false );
- }
-
- public static Builder newAutomaticModule( String name )
- {
- return new Builder( name ).setAutomatic( true );
- }
-
- /**
- * A JavaModuleDescriptor Builder
- *
- * @author Robert Scholte
- * @since 3.7.0
- */
- public static final class Builder
- {
- private JavaModuleDescriptor jModule;
-
- private Builder( String name )
- {
- jModule = new JavaModuleDescriptor();
- jModule.name = name;
- }
-
- private Builder setAutomatic( boolean isAutomatic )
- {
- jModule.automatic = isAutomatic;
- return this;
- }
-
- public Builder requires( String name )
- {
- JavaRequires requires = new JavaRequires( name );
- jModule.requires.add( requires );
- return this;
- }
-
- public Builder exports( String source )
- {
- JavaExports exports = new JavaExports( source );
- jModule.exports.add( exports );
- return this;
- }
-
- public JavaModuleDescriptor build()
- {
- return jModule;
- }
- }
-
- /**
- * Represents Module.Requires
- *
- * @author Robert Scholte
- * @since 3.7.0
- */
- public static class JavaRequires
- {
- private final String name;
-
- private JavaRequires( String name )
- {
- this.name = name;
- }
-
- public String name()
- {
- return name;
- }
- }
-
- /**
- * Represents Module.Exports
- *
- * @author Robert Scholte
- * @since 3.7.0
- *
- */
- public static class JavaExports
- {
- private final String source;
-
- private JavaExports( String source )
- {
- this.source = source;
- }
-
- public String source()
- {
- return source;
- }
- }
-
-}
diff --git a/src/main/java/org/apache/maven/plugin/compiler/module/ModuleInfoParser.java b/src/main/java/org/apache/maven/plugin/compiler/module/ModuleInfoParser.java
deleted file mode 100644
index 166da01..0000000
--- a/src/main/java/org/apache/maven/plugin/compiler/module/ModuleInfoParser.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package org.apache.maven.plugin.compiler.module;
-
-/*
- * 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 java.io.File;
-import java.io.IOException;
-
-/**
- * Extract information from the module-info file
- *
- * @author Robert Scholte
- * @since 3.6.0
- */
-public interface ModuleInfoParser
-{
- /**
- * Defines the type of parser, i.e. using the source or the class files
- */
- public enum Type
- {
- SOURCE, CLASS
- }
-
- /**
- * What kind of file does the parser use
- *
- * @return the type
- */
- Type getType();
-
- /**
- * Extracts the name from the module-info file
- *
- * @param modulePath
- * @return
- * @throws IOException
- */
- JavaModuleDescriptor getModuleDescriptor( File modulePath )
- throws IOException;
-}
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugin/compiler/module/ProjectAnalyzer.java b/src/main/java/org/apache/maven/plugin/compiler/module/ProjectAnalyzer.java
deleted file mode 100644
index afb96b6..0000000
--- a/src/main/java/org/apache/maven/plugin/compiler/module/ProjectAnalyzer.java
+++ /dev/null
@@ -1,198 +0,0 @@
-package org.apache.maven.plugin.compiler.module;
-
-/*
- * 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 java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-
-import org.apache.maven.plugin.compiler.module.ProjectAnalyzerResult.ModuleNameSource;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-
-/**
- * Maps artifacts to modules and analyzes the type of required modules
- *
- * @author Robert Scholte
- * @since 3.7.0
- */
-@Component( role = ProjectAnalyzer.class )
-public class ProjectAnalyzer extends AbstractLogEnabled
-{
- @Requirement( hint = "asm" )
- private ModuleInfoParser asmParser;
-
- @Requirement( hint = "reflect" )
- private ModuleInfoParser reflectParser;
-
- public ProjectAnalyzerResult analyze( ProjectAnalyzerRequest request )
- throws IOException
- {
- ProjectAnalyzerResult result = new ProjectAnalyzerResult();
-
- Map<File, JavaModuleDescriptor> pathElements =
- new LinkedHashMap<File, JavaModuleDescriptor>( request.getDependencyArtifacts().size() );
-
- JavaModuleDescriptor baseModuleDescriptor = request.getBaseModuleDescriptor();
-
- Map<String, JavaModuleDescriptor> availableNamedModules = new HashMap<String, JavaModuleDescriptor>();
-
- Map<String, ModuleNameSource> moduleNameSources = new HashMap<String, ModuleNameSource>();
-
- // start from root
- result.setBaseModuleDescriptor( baseModuleDescriptor );
-
- // collect all modules from path
- for ( File file : request.getDependencyArtifacts() )
- {
- JavaModuleDescriptor descriptor = extractDescriptor( file );
-
- if ( descriptor != null )
- {
- availableNamedModules.put( descriptor.name(), descriptor );
- }
-
- if ( descriptor == null || descriptor.isAutomatic() )
- {
- Manifest manifest = extractManifest( file );
-
- String modulename = null;
-
- if ( manifest != null )
- {
- modulename = manifest.getMainAttributes().getValue( "Automatic-Module-Name" );
- }
-
- if ( modulename != null )
- {
- moduleNameSources.put( modulename, ModuleNameSource.MANIFEST );
- }
- else if ( descriptor != null )
- {
- moduleNameSources.put( descriptor.name(), ModuleNameSource.FILENAME );
- }
- }
- else
- {
- moduleNameSources.put( descriptor.name(), ModuleNameSource.MODULEDESCRIPTOR );
- }
-
- pathElements.put( file, descriptor );
- }
- result.setPathElements( pathElements );
-
- result.setModuleNameSources( moduleNameSources );
-
- if ( baseModuleDescriptor != null )
- {
- Set<String> requiredNamedModules = new HashSet<String>();
- Set<String> requiredUnnamedModules = new HashSet<String>();
-
- select( baseModuleDescriptor, Collections.unmodifiableMap( availableNamedModules ), requiredNamedModules,
- requiredUnnamedModules );
-
- result.setRequiredNormalModules( requiredNamedModules );
- result.setRequiredAutomaticModules( requiredUnnamedModules );
- }
-
- return result;
- }
-
- private JavaModuleDescriptor extractDescriptor( File file )
- throws IOException
- {
- JavaModuleDescriptor moduleDescriptor;
- if ( file.isFile() || new File( file, "module-info.class" ).exists() )
- {
- moduleDescriptor = reflectParser.getModuleDescriptor( file );
-
- if ( moduleDescriptor == null )
- {
- moduleDescriptor = asmParser.getModuleDescriptor( file );
- }
- }
- else
- {
- moduleDescriptor = null;
- }
- return moduleDescriptor;
- }
-
- private Manifest extractManifest( File file )
- throws IOException
- {
- Manifest manifest;
- if ( file.isFile() )
- {
- JarFile jarFile = null;
- try
- {
- jarFile = new JarFile( file );
- manifest = jarFile.getManifest();
- }
- finally
- {
- jarFile.close();
- }
- }
- else if ( new File( file, "META-INF/MANIFEST.MF" ).exists() )
- {
- manifest = new Manifest( new FileInputStream( new File( file, "META-INF/MANIFEST.MF" ) ) );
- }
- else
- {
- manifest = null;
- }
-
- return manifest;
- }
-
-
- private void select( JavaModuleDescriptor module, Map<String, JavaModuleDescriptor> availableModules,
- Set<String> namedModules, Set<String> unnamedModules )
- {
- for ( JavaModuleDescriptor.JavaRequires requires : module.requires() )
- {
- String requiresName = requires.name();
- JavaModuleDescriptor requiredModule = availableModules.get( requiresName );
-
- if ( requiredModule != null && !requiredModule.isAutomatic() )
- {
- if ( namedModules.add( requiresName ) )
- {
- select( requiredModule, availableModules, namedModules, unnamedModules );
- }
- }
- else
- {
- unnamedModules.add( requiresName );
- }
- }
- }
-}
diff --git a/src/main/java/org/apache/maven/plugin/compiler/module/ProjectAnalyzerRequest.java b/src/main/java/org/apache/maven/plugin/compiler/module/ProjectAnalyzerRequest.java
deleted file mode 100644
index 397ab34..0000000
--- a/src/main/java/org/apache/maven/plugin/compiler/module/ProjectAnalyzerRequest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package org.apache.maven.plugin.compiler.module;
-
-/*
- * 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 java.io.File;
-import java.util.Collection;
-
-/**
- * Contains all information required to analyze the project
- *
- * @author Robert Scholte
- * @since 3.7.0
- */
-public class ProjectAnalyzerRequest
-{
- private JavaModuleDescriptor baseModuleDescriptor;
-
- private Collection<File> dependencyArtifacts;
-
- public JavaModuleDescriptor getBaseModuleDescriptor()
- {
- return baseModuleDescriptor;
- }
-
- public ProjectAnalyzerRequest setBaseModuleDescriptor( JavaModuleDescriptor baseModuleDescriptor )
- {
- this.baseModuleDescriptor = baseModuleDescriptor;
- return this;
- }
-
- public Collection<File> getDependencyArtifacts()
- {
- return dependencyArtifacts;
- }
-
- public ProjectAnalyzerRequest setDependencyArtifacts( Collection<File> dependencyArtifacts )
- {
- this.dependencyArtifacts = dependencyArtifacts;
- return this;
- }
-}
diff --git a/src/main/java/org/apache/maven/plugin/compiler/module/ProjectAnalyzerResult.java b/src/main/java/org/apache/maven/plugin/compiler/module/ProjectAnalyzerResult.java
deleted file mode 100644
index 3efc0b6..0000000
--- a/src/main/java/org/apache/maven/plugin/compiler/module/ProjectAnalyzerResult.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.apache.maven.plugin.compiler.module;
-
-/*
- * 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 java.io.File;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Holds the results of the project analyzer
- *
- * @author Robert Scholte
- * @since 3.7.0
- */
-public class ProjectAnalyzerResult
-{
- /**
- * Source of the modulename
- */
- public enum ModuleNameSource
- {
- FILENAME, MANIFEST, MODULEDESCRIPTOR
- }
-
- private JavaModuleDescriptor baseModuleDescriptor;
-
- /**
- * Ordered map, respects the classpath order
- */
- private Map<File, JavaModuleDescriptor> pathElements;
-
- private Map<String, ModuleNameSource> moduleNameSources = new HashMap<String, ModuleNameSource>();
-
- private Set<String> requiredNormalModules = new HashSet<String>();
-
- private Set<String> requiredAutomaticModules = new HashSet<String>();
-
- public void setBaseModuleDescriptor( JavaModuleDescriptor baseModuleDescriptor )
- {
- this.baseModuleDescriptor = baseModuleDescriptor;
- }
-
- public JavaModuleDescriptor getBaseModuleDescriptor()
- {
- return baseModuleDescriptor;
- }
-
- public void setPathElements( Map<File, JavaModuleDescriptor> pathElements )
- {
- this.pathElements = pathElements;
- }
-
- /**
- * Ordered map, respects the classpath order
- */
- public Map<File, JavaModuleDescriptor> getPathElements()
- {
- return pathElements;
- }
-
- public void setModuleNameSources( Map<String, ModuleNameSource> moduleNameSources )
- {
- this.moduleNameSources = moduleNameSources;
- }
-
- public ModuleNameSource getModuleNameSource( String name )
- {
- return moduleNameSources.get( name );
- }
-
- public void setRequiredNormalModules( Set<String> requiredNormalModules )
- {
- this.requiredNormalModules = requiredNormalModules;
- }
-
- public Set<String> getRequiredNormalModules()
- {
- return requiredNormalModules;
- }
-
- public void setRequiredAutomaticModules( Set<String> requiredAutomaticModules )
- {
- this.requiredAutomaticModules = requiredAutomaticModules;
- }
-
- public Set<String> getRequiredAutomaticModules()
- {
- return requiredAutomaticModules;
- }
-}
diff --git a/src/main/java/org/apache/maven/plugin/compiler/module/QDoxModuleInfoParser.java b/src/main/java/org/apache/maven/plugin/compiler/module/QDoxModuleInfoParser.java
deleted file mode 100644
index f795efa..0000000
--- a/src/main/java/org/apache/maven/plugin/compiler/module/QDoxModuleInfoParser.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package org.apache.maven.plugin.compiler.module;
-
-/*
- * 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 java.io.File;
-import java.io.IOException;
-
-import org.codehaus.plexus.component.annotations.Component;
-
-import com.thoughtworks.qdox.JavaProjectBuilder;
-import com.thoughtworks.qdox.model.JavaModuleDescriptor;
-
-/**
- * Extract information from module with QDox
- *
- * @author Robert Scholte
- * @since 3.6.1
- */
-@Component( role = ModuleInfoParser.class, hint = "qdox" )
-public class QDoxModuleInfoParser
- implements ModuleInfoParser
-{
-
- @Override
- public Type getType()
- {
- return Type.SOURCE;
- }
-
- @Override
- public org.apache.maven.plugin.compiler.module.JavaModuleDescriptor getModuleDescriptor( File modulePath )
- throws IOException
- {
- File moduleDescriptor = new File( modulePath, "module-info.java" );
-
- org.apache.maven.plugin.compiler.module.JavaModuleDescriptor.Builder builder;
- if ( moduleDescriptor.exists() )
- {
- JavaModuleDescriptor descriptor = new JavaProjectBuilder().addSourceFolder( modulePath ).getDescriptor();
-
- builder = org.apache.maven.plugin.compiler.module.JavaModuleDescriptor.newModule( descriptor.getName() );
-
- for ( JavaModuleDescriptor.JavaRequires requires : descriptor.getRequires() )
- {
- builder.requires( requires.getModule().getName() );
- }
-
- for ( JavaModuleDescriptor.JavaExports exports : descriptor.getExports() )
- {
- builder.exports( exports.getSource().getName() );
- }
- }
- else
- {
- builder = org.apache.maven.plugin.compiler.module.JavaModuleDescriptor.newAutomaticModule( null );
- }
-
- return builder.build();
- }
-
-}
diff --git a/src/main/java/org/apache/maven/plugin/compiler/module/ReflectModuleInfoParser.java b/src/main/java/org/apache/maven/plugin/compiler/module/ReflectModuleInfoParser.java
deleted file mode 100644
index caf8abf..0000000
--- a/src/main/java/org/apache/maven/plugin/compiler/module/ReflectModuleInfoParser.java
+++ /dev/null
@@ -1,131 +0,0 @@
-package org.apache.maven.plugin.compiler.module;
-
-/*
- * 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 java.io.File;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Set;
-
-import org.codehaus.plexus.component.annotations.Component;
-
-/**
- * This class is could be replaced with a Java 9 MultiRelease implementation
- *
- * @author Robert Scholte
- * @since 3.7.0
- */
-@Component( role = ModuleInfoParser.class, hint = "reflect" )
-public class ReflectModuleInfoParser implements ModuleInfoParser
-{
- @Override
- public Type getType()
- {
- return Type.CLASS;
- }
-
- @Override
- public JavaModuleDescriptor getModuleDescriptor( File modulePath )
- throws IOException
- {
- JavaModuleDescriptor moduleDescriptor = null;
-
- try
- {
- // Use Java9 code to get moduleName, don't try to do it better with own implementation
- Class moduleFinderClass = Class.forName( "java.lang.module.ModuleFinder" );
-
- java.nio.file.Path path = modulePath.toPath();
-
- Method ofMethod = moduleFinderClass.getMethod( "of", java.nio.file.Path[].class );
- Object moduleFinderInstance = ofMethod.invoke( null, new Object[] { new java.nio.file.Path[] { path } } );
-
- Method findAllMethod = moduleFinderClass.getMethod( "findAll" );
- Set<Object> moduleReferences = (Set<Object>) findAllMethod.invoke( moduleFinderInstance );
-
- Object moduleReference = moduleReferences.iterator().next();
- Method descriptorMethod = moduleReference.getClass().getMethod( "descriptor" );
- Object moduleDescriptorInstance = descriptorMethod.invoke( moduleReference );
-
- JavaModuleDescriptor.Builder builder = getBuilder( moduleDescriptorInstance );
-
- Method requiresMethod = moduleDescriptorInstance.getClass().getMethod( "requires" );
- Set<Object> requires = (Set<Object>) requiresMethod.invoke( moduleDescriptorInstance );
-
- for ( Object requiresInstance : requires )
- {
- Method nameMethod = requiresInstance.getClass().getMethod( "name" );
- String name = (String) nameMethod.invoke( requiresInstance );
-
- builder.requires( name );
- }
-
- moduleDescriptor = builder.build();
- }
- catch ( ClassNotFoundException e )
- {
- // do nothing
- }
- catch ( NoSuchMethodException e )
- {
- e.printStackTrace();
- }
- catch ( SecurityException e )
- {
- // do nothing
- }
- catch ( IllegalAccessException e )
- {
- // do nothing
- }
- catch ( IllegalArgumentException e )
- {
- // do nothing
- }
- catch ( InvocationTargetException e )
- {
- // do nothing
- }
- return moduleDescriptor;
- }
-
- private JavaModuleDescriptor.Builder getBuilder( Object moduleDescriptorInstance )
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
- {
- JavaModuleDescriptor.Builder builder;
- Method nameMethod = moduleDescriptorInstance.getClass().getMethod( "name" );
- String name = (String) nameMethod.invoke( moduleDescriptorInstance );
-
- Method isAutomaticMethod = moduleDescriptorInstance.getClass().getMethod( "isAutomatic" );
- boolean automatic = (Boolean) isAutomaticMethod.invoke( moduleDescriptorInstance );
-
- if ( automatic )
- {
- builder = JavaModuleDescriptor.newAutomaticModule( name );
- }
- else
- {
- builder = JavaModuleDescriptor.newModule( name );
- }
- return builder;
- }
-
-}