You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2021/04/09 19:45:39 UTC

[maven-dependency-analyzer] branch MDEP-679v2 updated (f83f64e -> 11ba00b)

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

slachiewicz pushed a change to branch MDEP-679v2
in repository https://gitbox.apache.org/repos/asf/maven-dependency-analyzer.git.


 discard f83f64e  [MDEP-679] Should not include string literals when parsing references
 discard 0429bf6  [MDEP-679] Refactor: extract helper functions in ConstantPoolParser
    omit 6186296  [MSHARED-785] Make ConstantPoolParser ignore classes in unnamed package
     new 1dc763f  Bump maven-project-info-reports-plugin from 3.1.0 to 3.1.1
     new e7483e7  [MSHARED-785] Make ConstantPoolParser ignore classes in unnamed package
     new e6b3fed  [MDEP-679] Refactor: extract helper functions in ConstantPoolParser
     new 11ba00b  [MDEP-679] Should not include string literals when parsing references

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (f83f64e)
            \
             N -- N -- N   refs/heads/MDEP-679v2 (11ba00b)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            |  2 +-
 .../DefaultProjectDependencyAnalyzerTest.java      | 26 +++++++---------------
 2 files changed, 9 insertions(+), 19 deletions(-)

[maven-dependency-analyzer] 04/04: [MDEP-679] Should not include string literals when parsing references

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch MDEP-679v2
in repository https://gitbox.apache.org/repos/asf/maven-dependency-analyzer.git

commit 11ba00b02cd00dac28c74a4303837a5f8c6e6187
Author: John Lin <jo...@gmail.com>
AuthorDate: Sat Mar 21 10:01:11 2020 +0800

    [MDEP-679] Should not include string literals when parsing references
    
    Closes #7
---
 .../analyzer/asm/ConstantPoolParser.java           |  9 ++-
 .../DefaultProjectDependencyAnalyzerTest.java      | 67 +++++++++++++++-------
 .../resources/jarWithClassInUnnamedPackage/pom.xml | 37 ++++++++++++
 .../jarWithClassInUnnamedPackage/project1/pom.xml  | 32 +++++++++++
 .../project1/src/main/java/coffee.java             | 26 +++++++++
 .../jarWithClassInUnnamedPackage/project2/pom.xml  | 40 +++++++++++++
 .../project2/src/main/java/project2/Project.java   | 28 +++++++++
 7 files changed, 217 insertions(+), 22 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java
index 1e30726..7bb2748 100644
--- a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java
@@ -126,7 +126,6 @@ public class ConstantPoolParser
                     stringConstants.put( ix, decodeString( buf ) );
                     continue;
                 case CONSTANT_CLASS:
-                case CONSTANT_STRING:
                 case CONSTANT_METHOD_TYPE:
                     classes.add( (int) buf.getChar() );
                     break;
@@ -150,6 +149,9 @@ public class ConstantPoolParser
                     consumeLong( buf );
                     ix++;
                     break;
+                case CONSTANT_STRING:
+                    consumeString( buf );
+                    break;
                 case CONSTANT_METHODHANDLE:
                     consumeMethodHandle( buf );
                     break;
@@ -243,6 +245,11 @@ public class ConstantPoolParser
         buf.getLong();
     }
 
+    private static void consumeString( ByteBuffer buf )
+    {
+        buf.getChar();
+    }
+
     private static void consumeMethodHandle( ByteBuffer buf )
     {
         buf.get();
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzerTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzerTest.java
index 884d734..6f3b2dd 100644
--- a/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzerTest.java
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzerTest.java
@@ -19,6 +19,7 @@ package org.apache.maven.shared.dependency.analyzer;
  */
 
 import org.apache.commons.lang3.JavaVersion;
+import org.apache.commons.lang3.SystemUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.handler.ArtifactHandler;
@@ -32,7 +33,10 @@ import org.apache.maven.shared.test.plugin.ProjectTool;
 import org.apache.maven.shared.test.plugin.RepositoryTool;
 import org.apache.maven.shared.test.plugin.TestToolsException;
 import org.codehaus.plexus.PlexusTestCase;
-import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
 
 import java.io.File;
 import java.util.Arrays;
@@ -43,6 +47,7 @@ import java.util.Properties;
 import java.util.Set;
 
 import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast;
+import static org.junit.Assume.assumeTrue;
 
 /**
  * Tests <code>DefaultProjectDependencyAnalyzer</code>.
@@ -50,6 +55,7 @@ import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast;
  * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
  * @see DefaultProjectDependencyAnalyzer
  */
+@RunWith( JUnit4.class )
 public class DefaultProjectDependencyAnalyzerTest
     extends PlexusTestCase
 {
@@ -64,7 +70,8 @@ public class DefaultProjectDependencyAnalyzerTest
     /*
      * @see org.codehaus.plexus.PlexusTestCase#setUp()
      */
-    protected void setUp()
+    @Before
+    public void setUp()
         throws Exception
     {
         super.setUp();
@@ -83,8 +90,7 @@ public class DefaultProjectDependencyAnalyzerTest
         analyzer = (ProjectDependencyAnalyzer) lookup( ProjectDependencyAnalyzer.ROLE );
     }
 
-    // tests ------------------------------------------------------------------
-
+    @Test
     public void testPom()
         throws TestToolsException, ProjectDependencyAnalyzerException
     {
@@ -99,6 +105,7 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
     public void testJarWithNoDependencies()
         throws TestToolsException, ProjectDependencyAnalyzerException
     {
@@ -113,13 +120,11 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
     public void testJava8methodRefs()
         throws TestToolsException, ProjectDependencyAnalyzerException
     {
-        if ( !isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) )
-        {
-            return;
-        }
+        assumeTrue( SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) );
 
         // Only visible through constant pool analysis (supported for JDK8+)
         compileProject( "java8methodRefs/pom.xml" );
@@ -139,13 +144,11 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
     public void testInlinedStaticReference()
         throws TestToolsException, ProjectDependencyAnalyzerException
     {
-        if ( !isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) )
-        {
-            return;
-        }
+        assumeTrue( SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) );
 
         // Only visible through constant pool analysis (supported for JDK8+)
         compileProject( "inlinedStaticReference/pom.xml" );
@@ -164,6 +167,7 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
     public void testJarWithCompileDependency()
         throws TestToolsException, ProjectDependencyAnalyzerException
     {
@@ -189,6 +193,7 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
     public void testForceDeclaredDependenciesUsage()
         throws TestToolsException, ProjectDependencyAnalyzerException
     {
@@ -223,6 +228,7 @@ public class DefaultProjectDependencyAnalyzerTest
         }
     }
 
+    @Test
     public void testJarWithTestDependency()
         throws TestToolsException, ProjectDependencyAnalyzerException
     {
@@ -254,6 +260,7 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
     public void testJarWithXmlTransitiveDependency()
         throws TestToolsException, ProjectDependencyAnalyzerException
     {
@@ -273,6 +280,7 @@ public class DefaultProjectDependencyAnalyzerTest
         // assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
     public void testJarWithCompileScopedTestDependency()
             throws TestToolsException, ProjectDependencyAnalyzerException
     {
@@ -306,6 +314,7 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
     public void testJarWithRuntimeScopedTestDependency() throws TestToolsException, ProjectDependencyAnalyzerException
     {
         // We can't effectively analyze runtime dependencies at this time
@@ -338,6 +347,7 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
     public void testMultimoduleProject()
         throws TestToolsException, ProjectDependencyAnalyzerException
     {
@@ -368,14 +378,12 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
     public void testTypeUseAnnotationDependency()
             throws TestToolsException, ProjectDependencyAnalyzerException
     {
         // java.lang.annotation.ElementType.TYPE_USE introduced with Java 1.8
-        if ( !isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) )
-        {
-            return;
-        }
+        assumeTrue( SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) );
 
         Properties properties = new Properties();
         properties.put( "maven.compiler.source", "1.8" );
@@ -395,14 +403,12 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
     public void testTypeUseAnnotationDependencyOnLocalVariable()
             throws TestToolsException, ProjectDependencyAnalyzerException
     {
         // java.lang.annotation.ElementType.TYPE_USE introduced with Java 1.8
-        if ( !isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) )
-        {
-            return;
-        }
+        assumeTrue( SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) );
 
         Properties properties = new Properties();
         properties.put( "maven.compiler.source", "1.8" );
@@ -422,10 +428,11 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
     public void testUnnamedPackageClassReference()
         throws TestToolsException, ProjectDependencyAnalyzerException
     {
-        Assume.assumeTrue( SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) );
+        assumeTrue( SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) );
 
         // Only visible through constant pool analysis (supported for JDK8+)
         compileProject( "unnamedPackageClassReference/pom.xml" );
@@ -445,6 +452,24 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    @Test
+    public void testJarWithClassInUnnamedPackage()
+            throws TestToolsException, ProjectDependencyAnalyzerException
+    {
+        compileProject( "jarWithClassInUnnamedPackage/pom.xml" );
+
+        MavenProject project2 = getProject( "jarWithClassInUnnamedPackage/project2/pom.xml" );
+
+        ProjectDependencyAnalysis actualAnalysis = analyzer.analyze( project2 );
+
+        Artifact project1 = createArtifact( "org.apache.maven.shared.dependency-analyzer.tests",
+                                            "jarWithClassInUnnamedPackage1", "jar", "1.0", "compile" );
+        Set<Artifact> unusedDeclaredArtifacts = Collections.singleton( project1 );
+        ProjectDependencyAnalysis expectedAnalysis = new ProjectDependencyAnalysis( null, null, unusedDeclaredArtifacts );
+
+        assertEquals( expectedAnalysis, actualAnalysis );
+    }
+
     // private methods --------------------------------------------------------
 
     private void compileProject( String pomPath )
diff --git a/src/test/resources/jarWithClassInUnnamedPackage/pom.xml b/src/test/resources/jarWithClassInUnnamedPackage/pom.xml
new file mode 100644
index 0000000..6fc1f26
--- /dev/null
+++ b/src/test/resources/jarWithClassInUnnamedPackage/pom.xml
@@ -0,0 +1,37 @@
+<?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.shared.dependency-analyzer.tests</groupId>
+    <artifactId>jarWithClassInUnnamedPackage</artifactId>
+    <packaging>pom</packaging>
+    <version>1.0</version>
+
+    <modules>
+        <module>project1</module>
+        <module>project2</module>
+    </modules>
+</project>
diff --git a/src/test/resources/jarWithClassInUnnamedPackage/project1/pom.xml b/src/test/resources/jarWithClassInUnnamedPackage/project1/pom.xml
new file mode 100644
index 0000000..a95a372
--- /dev/null
+++ b/src/test/resources/jarWithClassInUnnamedPackage/project1/pom.xml
@@ -0,0 +1,32 @@
+<?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.shared.dependency-analyzer.tests</groupId>
+    <artifactId>jarWithClassInUnnamedPackage1</artifactId>
+    <packaging>jar</packaging>
+    <version>1.0</version>
+</project>
diff --git a/src/test/resources/jarWithClassInUnnamedPackage/project1/src/main/java/coffee.java b/src/test/resources/jarWithClassInUnnamedPackage/project1/src/main/java/coffee.java
new file mode 100644
index 0000000..3649938
--- /dev/null
+++ b/src/test/resources/jarWithClassInUnnamedPackage/project1/src/main/java/coffee.java
@@ -0,0 +1,26 @@
+/*
+ * 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 coffee
+{
+    public coffee()
+    {
+        // no-op
+    }
+}
diff --git a/src/test/resources/jarWithClassInUnnamedPackage/project2/pom.xml b/src/test/resources/jarWithClassInUnnamedPackage/project2/pom.xml
new file mode 100644
index 0000000..c2aad12
--- /dev/null
+++ b/src/test/resources/jarWithClassInUnnamedPackage/project2/pom.xml
@@ -0,0 +1,40 @@
+<?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.shared.dependency-analyzer.tests</groupId>
+    <artifactId>jarWithClassInUnnamedPackage2</artifactId>
+    <packaging>jar</packaging>
+    <version>1.0</version>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven.shared.dependency-analyzer.tests</groupId>
+            <artifactId>jarWithClassInUnnamedPackage1</artifactId>
+            <version>1.0</version>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/src/test/resources/jarWithClassInUnnamedPackage/project2/src/main/java/project2/Project.java b/src/test/resources/jarWithClassInUnnamedPackage/project2/src/main/java/project2/Project.java
new file mode 100644
index 0000000..daea53a
--- /dev/null
+++ b/src/test/resources/jarWithClassInUnnamedPackage/project2/src/main/java/project2/Project.java
@@ -0,0 +1,28 @@
+package project2;
+
+/*
+ * 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 Project
+{
+    public Project()
+    {
+        String drink = "coffee";
+    }
+}

[maven-dependency-analyzer] 02/04: [MSHARED-785] Make ConstantPoolParser ignore classes in unnamed package

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch MDEP-679v2
in repository https://gitbox.apache.org/repos/asf/maven-dependency-analyzer.git

commit e7483e734fd5ae954f75acb5c6f8b79ef54ce8b9
Author: jhaber <jh...@hubspot.com>
AuthorDate: Mon Aug 3 10:43:38 2020 -0400

    [MSHARED-785] Make ConstantPoolParser ignore classes in unnamed package
    
    Closes #21
---
 .../analyzer/asm/ConstantPoolParser.java           | 14 +++++++-
 .../DefaultProjectDependencyAnalyzerTest.java      | 24 +++++++++++++
 .../resources/unnamedPackageClassReference/pom.xml | 41 ++++++++++++++++++++++
 .../java/unnamedPackageClassReference/Project.java | 31 ++++++++++++++++
 4 files changed, 109 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java
index 81494ed..8ff1ccd 100644
--- a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java
@@ -170,7 +170,13 @@ public class ConstantPoolParser
         Set<String> result = new HashSet<>();
         for ( Integer aClass : classes )
         {
-            result.add( stringConstants.get( aClass ) );
+            String className = stringConstants.get( aClass );
+
+            // filter out things from unnamed package, probably a false-positive
+            if ( isImportableClass( className ) )
+            {
+                result.add( className );
+            }
         }
         return result;
     }
@@ -207,4 +213,10 @@ public class ConstantPoolParser
         ( (Buffer) buf ).limit( oldLimit );
         return sb.toString();
     }
+
+    private static boolean isImportableClass( String className )
+    {
+        // without a slash, class must be in unnamed package, which can't be imported
+        return className.indexOf( '/' ) != -1;
+    }
 }
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzerTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzerTest.java
index cefd20e..884d734 100644
--- a/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzerTest.java
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzerTest.java
@@ -32,6 +32,7 @@ import org.apache.maven.shared.test.plugin.ProjectTool;
 import org.apache.maven.shared.test.plugin.RepositoryTool;
 import org.apache.maven.shared.test.plugin.TestToolsException;
 import org.codehaus.plexus.PlexusTestCase;
+import org.junit.Assume;
 
 import java.io.File;
 import java.util.Arrays;
@@ -421,6 +422,29 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    public void testUnnamedPackageClassReference()
+        throws TestToolsException, ProjectDependencyAnalyzerException
+    {
+        Assume.assumeTrue( SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) );
+
+        // Only visible through constant pool analysis (supported for JDK8+)
+        compileProject( "unnamedPackageClassReference/pom.xml" );
+
+        MavenProject project = getProject( "unnamedPackageClassReference/pom.xml" );
+
+        ProjectDependencyAnalysis actualAnalysis = analyzer.analyze( project );
+
+        Artifact dnsjava = createArtifact( "dnsjava", "dnsjava", "jar", "2.1.8", "compile" );
+        // we don't use any dnsjava classes so this should show up as an unused dep
+        Set<Artifact> unusedDeclaredArtifacts = Collections.singleton( dnsjava );
+
+        ProjectDependencyAnalysis expectedAnalysis =
+            new ProjectDependencyAnalysis( new HashSet<Artifact>(), new HashSet<Artifact>(), unusedDeclaredArtifacts,
+                new HashSet<Artifact>() );
+
+        assertEquals( expectedAnalysis, actualAnalysis );
+    }
+
     // private methods --------------------------------------------------------
 
     private void compileProject( String pomPath )
diff --git a/src/test/resources/unnamedPackageClassReference/pom.xml b/src/test/resources/unnamedPackageClassReference/pom.xml
new file mode 100644
index 0000000..bd79056
--- /dev/null
+++ b/src/test/resources/unnamedPackageClassReference/pom.xml
@@ -0,0 +1,41 @@
+<?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.shared.dependency-analyzer.tests</groupId>
+  <artifactId>unnamedPackageClassReference</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>dnsjava</groupId>
+      <artifactId>dnsjava</artifactId>
+      <version>2.1.8</version>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/src/test/resources/unnamedPackageClassReference/src/main/java/unnamedPackageClassReference/Project.java b/src/test/resources/unnamedPackageClassReference/src/main/java/unnamedPackageClassReference/Project.java
new file mode 100644
index 0000000..ff6c63a
--- /dev/null
+++ b/src/test/resources/unnamedPackageClassReference/src/main/java/unnamedPackageClassReference/Project.java
@@ -0,0 +1,31 @@
+package unnamedPackageClassReference;
+
+/*
+ * 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 Project
+{
+    // dnsjava 2.1.8 includes a class called "update"
+    public static final String UPDATE = "update";
+
+    public Project()
+    {
+        // no op
+    }
+}

[maven-dependency-analyzer] 03/04: [MDEP-679] Refactor: extract helper functions in ConstantPoolParser

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch MDEP-679v2
in repository https://gitbox.apache.org/repos/asf/maven-dependency-analyzer.git

commit e6b3fed5f174886393ed505c948753ba08957887
Author: John Lin <jo...@gmail.com>
AuthorDate: Sat Mar 21 10:00:34 2020 +0800

    [MDEP-679] Refactor: extract helper functions in ConstantPoolParser
---
 .../analyzer/asm/ConstantPoolParser.java           | 71 ++++++++++++++++++----
 1 file changed, 58 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java
index 8ff1ccd..1e30726 100644
--- a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java
@@ -134,37 +134,34 @@ public class ConstantPoolParser
                 case CONSTANT_METHODREF:
                 case CONSTANT_INTERFACEMETHODREF:
                 case CONSTANT_NAME_AND_TYPE:
-                    buf.getChar();
-                    buf.getChar();
+                    consumeReference( buf );
                     break;
                 case CONSTANT_INTEGER:
-                    buf.getInt();
+                    consumeInt( buf );
                     break;
                 case CONSTANT_FLOAT:
-                    buf.getFloat();
+                    consumeFloat( buf );
                     break;
                 case CONSTANT_DOUBLE:
-                    buf.getDouble();
+                    consumeDouble( buf );
                     ix++;
                     break;
                 case CONSTANT_LONG:
-                    buf.getLong();
+                    consumeLong( buf );
                     ix++;
                     break;
                 case CONSTANT_METHODHANDLE:
-                    buf.get();
-                    buf.getChar();
+                    consumeMethodHandle( buf );
                     break;
                 case CONSTANT_INVOKE_DYNAMIC:
-                    buf.getChar();
-                    buf.getChar();
+                    consumeInvokeDynamic( buf );
                     break;
                 case CONSTANT_MODULE:
-                    buf.getChar();
+                    consumeModule( buf );
                     break;
                 case CONSTANT_PACKAGE:
-                    buf.getChar();
-                    break;  
+                    consumePackage( buf );
+                    break;
             }
         }
         Set<String> result = new HashSet<>();
@@ -219,4 +216,52 @@ public class ConstantPoolParser
         // without a slash, class must be in unnamed package, which can't be imported
         return className.indexOf( '/' ) != -1;
     }
+
+    private static void consumeReference( ByteBuffer buf )
+    {
+        buf.getChar();
+        buf.getChar();
+    }
+
+    private static void consumeInt( ByteBuffer buf )
+    {
+        buf.getInt();
+    }
+
+    private static void consumeFloat( ByteBuffer buf )
+    {
+        buf.getFloat();
+    }
+
+    private static void consumeDouble( ByteBuffer buf )
+    {
+        buf.getDouble();
+    }
+
+    private static void consumeLong( ByteBuffer buf )
+    {
+        buf.getLong();
+    }
+
+    private static void consumeMethodHandle( ByteBuffer buf )
+    {
+        buf.get();
+        buf.getChar();
+    }
+
+    private static void consumeInvokeDynamic( ByteBuffer buf )
+    {
+        buf.getChar();
+        buf.getChar();
+    }
+
+    private static void consumeModule( ByteBuffer buf )
+    {
+        buf.getChar();
+    }
+
+    private static void consumePackage( ByteBuffer buf )
+    {
+        buf.getChar();
+    }
 }

[maven-dependency-analyzer] 01/04: Bump maven-project-info-reports-plugin from 3.1.0 to 3.1.1

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch MDEP-679v2
in repository https://gitbox.apache.org/repos/asf/maven-dependency-analyzer.git

commit 1dc763ff280566dacfb4124774ede7f088e927e9
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Fri Apr 9 21:33:52 2021 +0200

    Bump maven-project-info-reports-plugin from 3.1.0 to 3.1.1
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 1f8fd99..2d589c5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -141,7 +141,7 @@
         </plugin>
         <plugin>
           <artifactId>maven-project-info-reports-plugin</artifactId>
-          <version>3.1.0</version>
+          <version>3.1.1</version>
         </plugin>
       </plugins>
     </pluginManagement>