maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1806510 - in /maven/plugins/trunk/maven-jdeps-plugin/src: it/dependenciesToAnalyze/ it/dependenciesToAnalyze/src/ it/dependenciesToAnalyze/src/main/ it/dependenciesToAnalyze/src/main/java/ main/java/org/apache/maven/plugin/jdeps/
Date Mon, 28 Aug 2017 21:15:37 GMT
Author: rfscholte
Date: Mon Aug 28 21:15:37 2017
New Revision: 1806510

URL: http://svn.apache.org/viewvc?rev=1806510&view=rev
Log:
[MJDEPS-6] -cp should not duplicated classes/files to analyze

Added:
    maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/
    maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/invoker.properties
    maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/pom.xml
    maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/src/
    maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/src/main/
    maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/src/main/java/
    maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/src/main/java/Main.java
    maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/verify.groovy
Modified:
    maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDKInternalsMojo.java
    maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDepsMojo.java
    maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/JDKInternalsMojo.java
    maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/TestJDKInternalsMojo.java

Added: maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/invoker.properties?rev=1806510&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/invoker.properties
(added)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/invoker.properties
Mon Aug 28 21:15:37 2017
@@ -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=1.8+
+invoker.goals=process-classes

Added: maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/pom.xml?rev=1806510&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/pom.xml (added)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/pom.xml Mon Aug 28
21:15:37 2017
@@ -0,0 +1,59 @@
+<?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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  
+  <groupId>org.apache.maven.plugins.jdeps.its</groupId>
+  <artifactId>basic</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  
+  <properties>
+    <maven.compiler.source>1.6</maven.compiler.source>
+    <maven.compiler.target>1.6</maven.compiler.target>
+  </properties>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>@project.groupId@</groupId>
+        <artifactId>@project.artifactId@</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>jdkinternals</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  
+  <dependencies>
+    <dependency>
+       <groupId>org.codehaus.plexus</groupId>
+       <artifactId>plexus-utils</artifactId>
+       <version>3.0.24</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Added: maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/src/main/java/Main.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/src/main/java/Main.java?rev=1806510&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/src/main/java/Main.java
(added)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/src/main/java/Main.java
Mon Aug 28 21:15:37 2017
@@ -0,0 +1,29 @@
+/*
+ * 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 Main
+{
+   public static void main( String[] args )
+   {
+       for ( String validFamily : org.codehaus.plexus.util.Os.getValidFamilies() )
+       {
+           System.out.println( validFamily ); 
+       }
+   }    
+}
\ No newline at end of file

Added: maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/verify.groovy?rev=1806510&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/verify.groovy (added)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/it/dependenciesToAnalyze/verify.groovy Mon
Aug 28 21:15:37 2017
@@ -0,0 +1,37 @@
+
+/*
+ * 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.
+ */
+ 
+def buildLog = new File( basedir, 'build.log' )
+
+def found = false;
+
+assert buildLog.readLines().each { String line -> 
+
+  if ( line.startsWith( '[DEBUG] Executing: ' ) )
+  {
+    assert line.count( "classes" ) == 1 : "invalid classes count: " + line.count( "classes"
)
+
+    assert line.count( "plexus-utils-3.0.24.jar" ) == 1 : "invalid plexus-utils-3.0.24.jar
count: " + line.count( "plexus-utils-3.0.24.jar" )
+    
+    found = true;
+  }
+}
+
+assert found == true : "Executing line not found"

Modified: maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDKInternalsMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDKInternalsMojo.java?rev=1806510&r1=1806509&r2=1806510&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDKInternalsMojo.java
(original)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDKInternalsMojo.java
Mon Aug 28 21:15:37 2017
@@ -19,6 +19,9 @@ package org.apache.maven.plugin.jdeps;
  * under the License.
  */
 
+import java.nio.file.Path;
+import java.util.Set;
+
 import org.apache.maven.plugin.MojoFailureException;
 import org.codehaus.plexus.util.cli.Commandline;
 
@@ -31,10 +34,10 @@ public abstract class AbstractJDKInterna
 {
 
     @Override
-    protected void addJDepsOptions( Commandline cmd )
+    protected void addJDepsOptions( Commandline cmd, Set<Path> dependenciesToAnalyze
)
         throws MojoFailureException
     {
-        super.addJDepsOptions( cmd );
+        super.addJDepsOptions( cmd, dependenciesToAnalyze );
         cmd.createArg().setValue( "-jdkinternals" );
     }
 }

Modified: maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDepsMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDepsMojo.java?rev=1806510&r1=1806509&r2=1806510&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDepsMojo.java
(original)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDepsMojo.java
Mon Aug 28 21:15:37 2017
@@ -23,10 +23,16 @@ import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 import java.util.StringTokenizer;
 
 import org.apache.commons.lang3.SystemUtils;
@@ -204,8 +210,10 @@ public abstract class AbstractJDepsMojo
 //      jdeps [options] classes ...
         Commandline cmd = new Commandline();
         cmd.setExecutable( jExecutable );
-        addJDepsOptions( cmd );
-        addJDepsClasses( cmd );
+        
+        Set<Path> dependenciesToAnalyze = getDependenciesToAnalyze();
+        addJDepsOptions( cmd, dependenciesToAnalyze );
+        addJDepsClasses( cmd, dependenciesToAnalyze );
         
         JDepsConsumer consumer = new JDepsConsumer();
         executeJDepsCommandLine( cmd, outputDirectory, consumer );
@@ -230,7 +238,7 @@ public abstract class AbstractJDepsMojo
         }
     }
 
-    protected void addJDepsOptions( Commandline cmd )
+    protected void addJDepsOptions( Commandline cmd, Set<Path> dependenciesToAnalyze
)
         throws MojoFailureException
     {
         if ( dotOutput != null )
@@ -262,8 +270,23 @@ public abstract class AbstractJDepsMojo
         
         try
         {
-            cmd.createArg().setValue( "-cp" );
-            cmd.createArg().setValue( getClassPath() );
+            Collection<Path> cp = new ArrayList<>();
+            
+            for ( Path path : getClassPath() )
+            {
+                if ( !dependenciesToAnalyze.contains( path ) )
+                {
+                    cp.add( path );
+                }
+            }
+            
+            if ( !cp.isEmpty() )
+            {
+                cmd.createArg().setValue( "-cp" );
+
+                cmd.createArg().setValue( StringUtils.join( cp.iterator(), File.pathSeparator
) );
+            }
+            
         }
         catch ( DependencyResolutionRequiredException e )
         {
@@ -314,11 +337,12 @@ public abstract class AbstractJDepsMojo
         // cmd.createArg().setValue( "-version" );
     }
     
-    protected void addJDepsClasses( Commandline cmd )
+    protected Set<Path> getDependenciesToAnalyze()
     {
-        // <classes> can be a pathname to a .class file, a directory, a JAR file, or
a fully-qualified class name.
-        cmd.createArg().setFile( new File( getClassesDirectory() ) );
-
+        Set<Path> jdepsClasses = new LinkedHashSet<>();
+        
+        jdepsClasses.add( Paths.get( getClassesDirectory() ) );
+        
         if ( dependenciesToAnalyzeIncludes != null )
         {
             MatchPatterns includes = MatchPatterns.from( dependenciesToAnalyzeIncludes );
@@ -340,10 +364,21 @@ public abstract class AbstractJDepsMojo
                 if ( includes.matchesPatternStart( versionlessKey, true ) 
                     && !excludes.matchesPatternStart( versionlessKey, true ) )
                 {
-                    cmd.createArg().setFile( artifact.getFile() );
+                    jdepsClasses.add( artifact.getFile().toPath() );
                 }
             }
         }
+        
+        return jdepsClasses;
+    }
+    
+    protected void addJDepsClasses( Commandline cmd, Set<Path> dependenciesToAnalyze
)
+    {
+        // <classes> can be a pathname to a .class file, a directory, a JAR file, or
a fully-qualified class name.
+        for ( Path dependencyToAnalyze : dependenciesToAnalyze )
+        {
+            cmd.createArg().setFile( dependencyToAnalyze.toFile() );
+        }
     }
 
     private String getJDepsExecutable() throws IOException
@@ -421,7 +456,7 @@ public abstract class AbstractJDepsMojo
         if ( getLog().isDebugEnabled() )
         {
             // no quoted arguments
-            getLog().debug( CommandLineUtils.toString( cmd.getCommandline() ).replaceAll(
"'", "" ) );
+            getLog().debug( "Executing: " + CommandLineUtils.toString( cmd.getCommandline()
).replaceAll( "'", "" ) );
         }
 
         
@@ -544,5 +579,5 @@ public abstract class AbstractJDepsMojo
 
     protected abstract String getClassesDirectory();
     
-    protected abstract String getClassPath() throws DependencyResolutionRequiredException;
+    protected abstract Collection<Path> getClassPath() throws DependencyResolutionRequiredException;
 }

Modified: maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/JDKInternalsMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/JDKInternalsMojo.java?rev=1806510&r1=1806509&r2=1806510&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/JDKInternalsMojo.java
(original)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/JDKInternalsMojo.java
Mon Aug 28 21:15:37 2017
@@ -19,13 +19,16 @@ package org.apache.maven.plugin.jdeps;
  * under the License.
  */
 
-import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.Set;
 
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.ResolutionScope;
-import org.codehaus.plexus.util.StringUtils;
 
 /**
  * Check if main classes depend on internal JDK classes
@@ -47,9 +50,16 @@ public class JDKInternalsMojo
     }
     
     @Override
-    protected String getClassPath() throws DependencyResolutionRequiredException
+    protected Collection<Path> getClassPath()
+        throws DependencyResolutionRequiredException
     {
-        return StringUtils.join( getProject().getCompileClasspathElements().iterator(), File.pathSeparator
);
-    }
+        Set<Path> classPath = new LinkedHashSet<>( getProject().getCompileClasspathElements().size()
);
+
+        for ( String elm : getProject().getCompileClasspathElements() )
+        {
+            classPath.add( Paths.get( elm ) );
+        }
 
+        return classPath;
+    }
 }

Modified: maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/TestJDKInternalsMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/TestJDKInternalsMojo.java?rev=1806510&r1=1806509&r2=1806510&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/TestJDKInternalsMojo.java
(original)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/TestJDKInternalsMojo.java
Mon Aug 28 21:15:37 2017
@@ -19,13 +19,16 @@ package org.apache.maven.plugin.jdeps;
  * under the License.
  */
 
-import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.Set;
 
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.ResolutionScope;
-import org.codehaus.plexus.util.StringUtils;
 
 /**
  * Check if test classes depend on internal JDK classes
@@ -47,8 +50,16 @@ public class TestJDKInternalsMojo
     }
     
     @Override
-    protected String getClassPath() throws DependencyResolutionRequiredException
+    protected Collection<Path> getClassPath()
+        throws DependencyResolutionRequiredException
     {
-        return StringUtils.join( getProject().getTestClasspathElements().iterator(), File.pathSeparator
);
+        Set<Path> classPath = new LinkedHashSet<>( getProject().getTestClasspathElements().size()
);
+
+        for ( String elm : getProject().getTestClasspathElements() )
+        {
+            classPath.add( Paths.get( elm ) );
+        }
+
+        return classPath;
     }
 }



Mime
View raw message