You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2016/04/17 20:48:58 UTC
svn commit: r1739635 - in
/maven/plugins/branches/maven-compiler-plugin_jigsaw-ea: ./
src/main/java/org/apache/maven/plugin/compiler/
Author: rfscholte
Date: Sun Apr 17 18:48:58 2016
New Revision: 1739635
URL: http://svn.apache.org/viewvc?rev=1739635&view=rev
Log:
Add AsmModuleInfoParser to extract module name (required for testing)
Added:
maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/AsmModuleInfoParser.java
maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/ModuleInfoParser.java
Modified:
maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/pom.xml
maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
Modified: maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/pom.xml?rev=1739635&r1=1739634&r2=1739635&view=diff
==============================================================================
--- maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/pom.xml (original)
+++ maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/pom.xml Sun Apr 17 18:48:58 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/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/AsmModuleInfoParser.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/AsmModuleInfoParser.java?rev=1739635&view=auto
==============================================================================
--- maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/AsmModuleInfoParser.java (added)
+++ maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/AsmModuleInfoParser.java Sun Apr 17 18:48:58 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/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/ModuleInfoParser.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/ModuleInfoParser.java?rev=1739635&view=auto
==============================================================================
--- maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/ModuleInfoParser.java (added)
+++ maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/ModuleInfoParser.java Sun Apr 17 18:48:58 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
Modified: maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java?rev=1739635&r1=1739634&r2=1739635&view=diff
==============================================================================
--- maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java (original)
+++ maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java Sun Apr 17 18:48:58 2016
@@ -20,6 +20,7 @@ package org.apache.maven.plugin.compiler
*/
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -186,8 +187,11 @@ public class TestCompilerMojo
private void setPaths()
throws DependencyResolutionRequiredException
{
- boolean hasMainModuleDescriptor =
- new File( getProject().getBuild().getOutputDirectory(), "module-info.class" ).exists();
+ File mainOutputDirectory = new File( getProject().getBuild().getOutputDirectory() );
+
+ File mainModuleInfo = new File( mainOutputDirectory, "module-info.class" );
+
+ boolean hasMainModuleDescriptor = mainModuleInfo.exists();
boolean hasTestModuleDescriptor = false;
for ( String sourceRoot : getProject().getTestCompileSourceRoots() )
@@ -196,8 +200,7 @@ public class TestCompilerMojo
}
List<String> compilePathElements =
- JavaMavenProjectUtils.getCompileClasspathElements( getProject(),
- new File( getProject().getBuild().getOutputDirectory() ) );
+ JavaMavenProjectUtils.getCompileClasspathElements( getProject(), mainOutputDirectory );
List<String> testPathElements =
JavaMavenProjectUtils.getTestClasspathElements( getProject(), getOutputDirectory() );
@@ -207,35 +210,57 @@ public class TestCompilerMojo
if ( hasTestModuleDescriptor )
{
+ modulepathElements = testPathElements;
+ classpathElements = Collections.emptyList();
+
if ( hasMainModuleDescriptor )
{
- modulepathElements = testPathElements;
- classpathElements = Collections.emptyList();
+ if ( compilerArgs == null )
+ {
+ compilerArgs = new ArrayList<String>();
+ }
+
+ try
+ {
+ //
+ String moduleName = new AsmModuleInfoParser().getModuleName( mainOutputDirectory );
+ compilerArgs.add( "-Xmodule:" + moduleName );
+ compilerArgs.add( "-XaddReads:" + moduleName + "=ALL-UNNAMED" );
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
else
{
- modulepathElements = testScopedElements;
- classpathElements = compilePathElements;
- // Odd, extra arguments required
+ // very odd
}
}
else
{
if ( hasMainModuleDescriptor )
{
- modulepathElements = Collections.emptyList();
- classpathElements = testPathElements;
-
-// Current options assume awareness of modulename:
-// -addmods <module>
-// -Xmodule:<module>
-// modulepathElements = compilePathElements;
-// classpathElements = testScopedElements;
-// if ( compilerArgs == null )
-// {
-// compilerArgs = new ArrayList<String>();
-// }
-// compilerArgs.add( "-addmods" );
+ modulepathElements = compilePathElements;
+ classpathElements = testScopedElements;
+ if ( compilerArgs == null )
+ {
+ compilerArgs = new ArrayList<String>();
+ }
+
+ try
+ {
+ String moduleName = new AsmModuleInfoParser().getModuleName( mainOutputDirectory );
+ compilerArgs.add( "-Xmodule:" + moduleName );
+ compilerArgs.add( "-addmods" );
+ compilerArgs.add( moduleName );
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
else
{