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/02/27 12:05:12 UTC

svn commit: r1732622 - in /maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler: CompilerMojo.java JavaMavenProjectUtils.java TestCompilerMojo.java

Author: rfscholte
Date: Sat Feb 27 11:05:12 2016
New Revision: 1732622

URL: http://svn.apache.org/viewvc?rev=1732622&view=rev
Log:
Split main and test pathElements to detect if artifact must be added to -cp or -mp

Added:
    maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/JavaMavenProjectUtils.java
Modified:
    maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
    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/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java?rev=1732622&r1=1732621&r2=1732622&view=diff
==============================================================================
--- maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java (original)
+++ maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java Sat Feb 27 11:05:12 2016
@@ -151,9 +151,15 @@ public class CompilerMojo
     
     private void setPaths() throws DependencyResolutionRequiredException
     {
+        boolean hasModuleDescriptor = false;
+        for ( String sourceRoot : getProject().getCompileSourceRoots() )
+        {
+            hasModuleDescriptor |= new File( sourceRoot, "module-info.java" ).exists();
+        }
+
         List<String> pathElements =
             JavaMavenProjectUtils.getCompileClasspathElements( getProject(), getOutputDirectory() );
-        if ( hasModuleDescriptor( pathElements ) )
+        if ( hasModuleDescriptor )
         {
             modulepathElements = pathElements;
             classpathElements = Collections.emptyList();

Added: maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/JavaMavenProjectUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/JavaMavenProjectUtils.java?rev=1732622&view=auto
==============================================================================
--- maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/JavaMavenProjectUtils.java (added)
+++ maven/plugins/branches/maven-compiler-plugin_jigsaw-ea/src/main/java/org/apache/maven/plugin/compiler/JavaMavenProjectUtils.java Sat Feb 27 11:05:12 2016
@@ -0,0 +1,99 @@
+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.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * MavenProject should be clean from language specific properties.
+ * ClassPath is Java specific, so that kind of code should be moved to here.
+ * Other projects should simply use the Artifacts instead
+ * 
+ * @author Robert Scholte
+ * @since 3.6
+ */
+public final class JavaMavenProjectUtils
+{
+    private JavaMavenProjectUtils()
+    {
+    }
+
+    public static List<String> getCompileClasspathElements( MavenProject project, File outputDirectory )
+        throws DependencyResolutionRequiredException
+    {
+        List<String> list = new ArrayList<String>( project.getArtifacts().size() + 1 );
+
+        // Would be nice if this one wasn't required
+        list.add( outputDirectory.getAbsolutePath() );
+
+        for ( Artifact a : project.getArtifacts() )
+        {
+            if ( a.getArtifactHandler().isAddedToClasspath() )
+            {
+                // TODO: let the scope handler deal with this
+                if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
+                    || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
+                {
+                    addArtifactPath( a, list );
+                }
+            }
+        }
+
+        return list;
+    }
+    
+    //TODO: this checking for file == null happens because the resolver has been confused about the root
+    // artifact or not. things like the stupid dummy artifact coming from surefire.
+    public static List<String> getTestClasspathElements( MavenProject project, File outputDirectory )
+        throws DependencyResolutionRequiredException
+    {
+        List<String> list = new ArrayList<String>( project.getArtifacts().size() + 2 );
+
+        // Would be nice if this one wasn't required
+        list.add( outputDirectory.getAbsolutePath() );
+
+        list.add( project.getBuild().getOutputDirectory() );
+        
+        for ( Artifact a : project.getArtifacts() )
+        {            
+            if ( a.getArtifactHandler().isAddedToClasspath() )
+            {                
+                addArtifactPath( a, list );
+            }
+        }
+
+        return list;
+    }
+
+    private static void addArtifactPath( Artifact artifact, List<String> classpath )
+    {
+        File file = artifact.getFile();
+        if ( file != null )
+        {
+            classpath.add( file.getPath() );
+        }
+    }
+}

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=1732622&r1=1732621&r2=1732622&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 Sat Feb 27 11:05:12 2016
@@ -223,14 +223,19 @@ public class TestCompilerMojo
         {
             if ( hasMainModuleDescriptor )
             {
-                modulepathElements = compilePathElements;
-                classpathElements = testScopedElements;
-                
-                if ( compilerArgs == null )
-                {
-                    compilerArgs = new ArrayList<String>();
-                }
-                compilerArgs.add( "-addmods" );
+                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" );
             }
             else
             {