[maven-dependency-analyzer] branch MDEP-679 created (now 154ba25)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[maven-dependency-analyzer] branch MDEP-679 created (now 154ba25)

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

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


      at 154ba25  [MDEP-679] Should not include string literals when parsing references

This branch includes the following new commits:

     new 2ba8c81  [MDEP-679] Refactor: extract helper functions in ConstantPoolParser
     new 154ba25  [MDEP-679] Should not include string literals when parsing references

The 2 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.


Reply | Threaded
Open this post in threaded view
|

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

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

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

commit 2ba8c81f8a45604c99cff77f63e2a44d7ace5799
Author: John Lin <[hidden email]>
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 c0e0cac..0d9041a 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
@@ -117,37 +117,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<String>();
@@ -189,4 +186,52 @@ public class ConstantPoolParser
         ( (Buffer) buf ).limit( oldLimit );
         return sb.toString();
     }
+
+    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();
+    }
 }

Reply | Threaded
Open this post in threaded view
|

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

slachiewicz
In reply to this post by slachiewicz
This is an automated email from the ASF dual-hosted git repository.

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

commit 154ba255cf6f70320106147aff5dbcf62183ad59
Author: John Lin <[hidden email]>
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      | 17 +++++++++
 .../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, 188 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 0d9041a..d5a2b15 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
@@ -109,7 +109,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;
@@ -133,6 +132,9 @@ public class ConstantPoolParser
                     consumeLong( buf );
                     ix++;
                     break;
+                case CONSTANT_STRING:
+                    consumeString( buf );
+                    break;
                 case CONSTANT_METHODHANDLE:
                     consumeMethodHandle( buf );
                     break;
@@ -213,6 +215,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 e5b90f1..7ff41cf 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
@@ -354,6 +354,23 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    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";
+    }
+}