Author: rfscholte
Date: Tue Aug 9 21:35:45 2016
New Revision: 1755655
URL: http://svn.apache.org/viewvc?rev=1755655&view=rev
Log:
[MCOMPILER-269] Support modulepath (Java9/Jigsaw)
Introduce ModuleInfoParser, required in case of test-compile
Added:
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AsmModuleInfoParser.java
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/ModuleInfoParser.java
Modified:
maven/plugins/trunk/maven-compiler-plugin/pom.xml
Modified: maven/plugins/trunk/maven-compiler-plugin/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/pom.xml?rev=1755655&r1=1755654&r2=1755655&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-compiler-plugin/pom.xml Tue Aug 9 21:35:45 2016
@@ -115,6 +115,12 @@ under the License.
</dependency>
<dependency>
+ <groupId>org.ow2.asm</groupId>
+ <artifactId>asm</artifactId>
+ <version>5.1</version>
+ </dependency>
+
+ <dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
<version>${plexusCompilerVersion}</version>
Added:
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AsmModuleInfoParser.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AsmModuleInfoParser.java?rev=1755655&view=auto
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AsmModuleInfoParser.java
(added)
+++
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AsmModuleInfoParser.java
Tue Aug 9 21:35:45 2016
@@ -0,0 +1,90 @@
+package org.apache.maven.plugin.compiler;
+
+/*
+ * 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.objectweb.asm.ClassReader;
+
+/**
+ * Extract information from module with ASM
+ *
+ * @author Robert Scholte
+ * @since 3.5
+ */
+public class AsmModuleInfoParser implements ModuleInfoParser
+{
+ @Override
+ public String getModuleName( File modulePath )
+ throws IOException
+ {
+ InputStream in = getModuleInfoClass( modulePath );
+
+ ClassReader reader = new ClassReader( in );
+ String className = reader.getClassName();
+ int index = className.indexOf( "/module-info" );
+
+ String moduleName;
+ if ( index >= 1 )
+ {
+ moduleName = className.substring( 0, index ).replace( '/', '.' );
+ }
+ else
+ {
+ moduleName = null;
+ }
+
+ return moduleName;
+ }
+
+ 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 = null;
+ try
+ {
+ jarFile = new JarFile( modulePath );
+ JarEntry moduleInfo = jarFile.getJarEntry(
"/module-info.class" );
+ in = jarFile.getInputStream( moduleInfo );
+ }
+ finally
+ {
+ if ( jarFile != null )
+ {
+ jarFile.close();
+ }
+ }
+ }
+ return in;
+ }
+}
Added:
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/ModuleInfoParser.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/ModuleInfoParser.java?rev=1755655&view=auto
==============================================================================
---
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/ModuleInfoParser.java
(added)
+++
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/ModuleInfoParser.java
Tue Aug 9 21:35:45 2016
@@ -0,0 +1,37 @@
+package org.apache.maven.plugin.compiler;
+
+/*
+ * 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 module
+ *
+ * @author Robert Scholte
+ * @since 3.5
+ */
+public interface ModuleInfoParser
+{
+
+ String getModuleName( File modulePath )
+ throws IOException;
+
+}
\ No newline at end of file