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 2019/10/25 09:37:37 UTC

[maven-jdeps-plugin] 01/02: jdeps now verifies transitive dependencies

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MJDEPS-16
in repository https://gitbox.apache.org/repos/asf/maven-jdeps-plugin.git

commit 670f249c930694d0104e80959fecf6baa83eb73b
Author: Mihail Stoynov, STY <mi...@sty.bz>
AuthorDate: Fri Jul 19 12:40:57 2019 +0300

    jdeps now verifies transitive dependencies
---
 src/it/dependenciesToAnalyze/pom.xml               |   3 +
 src/it/includeClasspath/invoker.properties         |  20 ++++
 .../pom.xml                                        | 117 +++++++++++----------
 src/it/includeClasspath/src/main/java/Main.java    |  25 +++++
 src/it/includeClasspath/verify.groovy              |  34 ++++++
 .../maven/plugins/jdeps/AbstractJDepsMojo.java     |  36 +++++--
 6 files changed, 170 insertions(+), 65 deletions(-)

diff --git a/src/it/dependenciesToAnalyze/pom.xml b/src/it/dependenciesToAnalyze/pom.xml
index c6ef9c5..7a39404 100644
--- a/src/it/dependenciesToAnalyze/pom.xml
+++ b/src/it/dependenciesToAnalyze/pom.xml
@@ -43,6 +43,9 @@ under the License.
             <goals>
               <goal>jdkinternals</goal>
             </goals>
+            <configuration>
+              <includeClasspath>false</includeClasspath>
+            </configuration>
           </execution>
         </executions>
       </plugin>
diff --git a/src/it/includeClasspath/invoker.properties b/src/it/includeClasspath/invoker.properties
new file mode 100644
index 0000000..f5d8d2d
--- /dev/null
+++ b/src/it/includeClasspath/invoker.properties
@@ -0,0 +1,20 @@
+# 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
+invoker.buildResult=failure
\ No newline at end of file
diff --git a/src/it/dependenciesToAnalyze/pom.xml b/src/it/includeClasspath/pom.xml
similarity index 90%
copy from src/it/dependenciesToAnalyze/pom.xml
copy to src/it/includeClasspath/pom.xml
index c6ef9c5..05e945e 100644
--- a/src/it/dependenciesToAnalyze/pom.xml
+++ b/src/it/includeClasspath/pom.xml
@@ -1,59 +1,60 @@
-<?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>
+<?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>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <version>25.1-jre</version>
+    </dependency>
+  </dependencies>
 </project>
\ No newline at end of file
diff --git a/src/it/includeClasspath/src/main/java/Main.java b/src/it/includeClasspath/src/main/java/Main.java
new file mode 100644
index 0000000..5a677ab
--- /dev/null
+++ b/src/it/includeClasspath/src/main/java/Main.java
@@ -0,0 +1,25 @@
+/*
+ * 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 )
+   {
+   }    
+}
\ No newline at end of file
diff --git a/src/it/includeClasspath/verify.groovy b/src/it/includeClasspath/verify.groovy
new file mode 100644
index 0000000..96aed52
--- /dev/null
+++ b/src/it/includeClasspath/verify.groovy
@@ -0,0 +1,34 @@
+
+/*
+ * 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;
+
+buildLog.readLines().each { String line ->
+
+  if ( line.contains( 'Found offending packages' ) )
+  {
+    System.out.println(line);
+    found = true;
+  }
+}
+
+assert found : "No offending packages"
diff --git a/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java b/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java
index 0140e82..c22bab6 100644
--- a/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java
@@ -79,15 +79,23 @@ public abstract class AbstractJDepsMojo
      */
     @Parameter( defaultValue = "true", property = "jdeps.failOnWarning" )
     private boolean failOnWarning;
-    
+
     /**
      * Specifies the version when processing multi-release JAR files version should be an integer >=9 or base.
-     * 
+     *
      * @since 3.1.1
      */
     @Parameter( property = "jdeps.multiRelease" )
     private String multiRelease;
-    
+
+    /**
+     * Specifies the version when processing multi-release JAR files version should be an integer >=9 or base.
+     *
+     * @since 3.1.3
+     */
+    @Parameter( defaultValue = "true", property = "jdeps.includeClasspath" )
+    private boolean includeClasspath;
+
     /**
      * Additional dependencies which should be analyzed besides the classes.
      * Specify as {@code groupId:artifactId}, allowing ant-pattern.
@@ -227,8 +235,16 @@ public abstract class AbstractJDepsMojo
 //      jdeps [options] classes ...
         Commandline cmd = new Commandline();
         cmd.setExecutable( jExecutable );
-        
-        Set<Path> dependenciesToAnalyze = getDependenciesToAnalyze();
+
+        Set<Path> dependenciesToAnalyze = null;
+        try
+        {
+            dependenciesToAnalyze = getDependenciesToAnalyze( includeClasspath );
+        }
+        catch ( DependencyResolutionRequiredException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
         addJDepsOptions( cmd, dependenciesToAnalyze );
         addJDepsClasses( cmd, dependenciesToAnalyze );
         
@@ -370,12 +386,18 @@ public abstract class AbstractJDepsMojo
         // cmd.createArg().setValue( "-version" );
     }
     
-    protected Set<Path> getDependenciesToAnalyze()
+    protected Set<Path> getDependenciesToAnalyze( boolean includeClasspath )
+            throws DependencyResolutionRequiredException
     {
         Set<Path> jdepsClasses = new LinkedHashSet<>();
         
         jdepsClasses.add( Paths.get( getClassesDirectory() ) );
-        
+
+        if ( includeClasspath )
+        {
+            jdepsClasses.addAll( getClassPath() );
+        }
+
         if ( dependenciesToAnalyzeIncludes != null )
         {
             MatchPatterns includes = MatchPatterns.from( dependenciesToAnalyzeIncludes );