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 2019/05/15 21:14:55 UTC

[maven-dependency-analyzer] branch MSHARED-792 updated (4e2fd20 -> 40fc4a6)

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

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


 discard 4e2fd20  [MSHARED-792] Detect type annotations on local variables
     new 40fc4a6  [MSHARED-792] Detect type annotations on local variables

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   (4e2fd20)
            \
             N -- N -- N   refs/heads/MSHARED-792 (40fc4a6)

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 1 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:


[maven-dependency-analyzer] 01/01: [MSHARED-792] Detect type annotations on local variables

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

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

commit 40fc4a689b92b5784a4120143540cf8db66ad63b
Author: Andreas Hubold <an...@coremedia.com>
AuthorDate: Thu Jan 3 09:56:12 2019 +0100

    [MSHARED-792] Detect type annotations on local variables
    
    by implementing DefaultMethodVisitor#visitLocalVariableAnnotation
    
    Closes #5
---
 .../analyzer/asm/DefaultMethodVisitor.java         |  9 +++++++
 .../DefaultProjectDependencyAnalyzerTest.java      | 26 +++++++++++++++++++
 .../resources/typeUseAnnotationDependency/pom.xml  |  1 +
 .../{ => usageLocalVar}/pom.xml                    | 18 +++++++------
 .../usageLocalVar/UsageLocalVar.java               | 30 ++++++++++++++++++++++
 5 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DefaultMethodVisitor.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DefaultMethodVisitor.java
index 24ca79d..2721e24 100644
--- a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DefaultMethodVisitor.java
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DefaultMethodVisitor.java
@@ -76,6 +76,15 @@ public class DefaultMethodVisitor
         return annotationVisitor;
     }
 
+    @Override
+    public AnnotationVisitor visitLocalVariableAnnotation( int typeRef, TypePath typePath, Label[] start, Label[] end,
+                                                           int[] index, String desc, boolean visible )
+    {
+        resultCollector.addDesc( desc );
+
+        return annotationVisitor;
+    }
+
     public void visitTypeInsn( final int opcode, final String desc )
     {
         if ( desc.charAt( 0 ) == '[' )
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 09fc24c..e5b90f1 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
@@ -328,6 +328,32 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    public void testTypeUseAnnotationDependencyOnLocalVariable()
+            throws TestToolsException, ProjectDependencyAnalyzerException
+    {
+        // java.lang.annotation.ElementType.TYPE_USE introduced with Java 1.8
+        if ( !SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) )
+        {
+            return;
+        }
+
+        Properties properties = new Properties();
+        properties.put( "maven.compiler.source", "1.8" );
+        properties.put( "maven.compiler.target", "1.8" );
+        compileProject( "typeUseAnnotationDependency/pom.xml", properties);
+
+        MavenProject usage = getProject( "typeUseAnnotationDependency/usageLocalVar/pom.xml" );
+
+        ProjectDependencyAnalysis actualAnalysis = analyzer.analyze( usage );
+
+        Artifact annotation = createArtifact( "org.apache.maven.shared.dependency-analyzer.tests",
+                                            "typeUseAnnotationDependencyAnnotation", "jar", "1.0", "compile" );
+        Set<Artifact> usedDeclaredArtifacts = Collections.singleton( annotation );
+        ProjectDependencyAnalysis expectedAnalysis = new ProjectDependencyAnalysis(usedDeclaredArtifacts, null, null);
+
+        assertEquals( expectedAnalysis, actualAnalysis );
+    }
+
     // private methods --------------------------------------------------------
 
     private void compileProject( String pomPath )
diff --git a/src/test/resources/typeUseAnnotationDependency/pom.xml b/src/test/resources/typeUseAnnotationDependency/pom.xml
index 62e966c..73bc5ec 100644
--- a/src/test/resources/typeUseAnnotationDependency/pom.xml
+++ b/src/test/resources/typeUseAnnotationDependency/pom.xml
@@ -33,6 +33,7 @@
 	<modules>
 		<module>annotation</module>
 		<module>usage</module>
+		<module>usageLocalVar</module>
 	</modules>
 	
 </project>
diff --git a/src/test/resources/typeUseAnnotationDependency/pom.xml b/src/test/resources/typeUseAnnotationDependency/usageLocalVar/pom.xml
similarity index 79%
copy from src/test/resources/typeUseAnnotationDependency/pom.xml
copy to src/test/resources/typeUseAnnotationDependency/usageLocalVar/pom.xml
index 62e966c..26f42b7 100644
--- a/src/test/resources/typeUseAnnotationDependency/pom.xml
+++ b/src/test/resources/typeUseAnnotationDependency/usageLocalVar/pom.xml
@@ -26,13 +26,15 @@
 >
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>org.apache.maven.shared.dependency-analyzer.tests</groupId>
-	<artifactId>typeUseAnnotationDependency</artifactId>
-	<packaging>pom</packaging>
+	<artifactId>typeUseAnnotationDependencyUsageLocalVar</artifactId>
+	<packaging>jar</packaging>
 	<version>1.0</version>
-	
-	<modules>
-		<module>annotation</module>
-		<module>usage</module>
-	</modules>
-	
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.maven.shared.dependency-analyzer.tests</groupId>
+			<artifactId>typeUseAnnotationDependencyAnnotation</artifactId>
+			<version>1.0</version>
+		</dependency>
+	</dependencies>
 </project>
diff --git a/src/test/resources/typeUseAnnotationDependency/usageLocalVar/src/main/java/typeUseAnnotationDependency/usageLocalVar/UsageLocalVar.java b/src/test/resources/typeUseAnnotationDependency/usageLocalVar/src/main/java/typeUseAnnotationDependency/usageLocalVar/UsageLocalVar.java
new file mode 100644
index 0000000..e1d8353
--- /dev/null
+++ b/src/test/resources/typeUseAnnotationDependency/usageLocalVar/src/main/java/typeUseAnnotationDependency/usageLocalVar/UsageLocalVar.java
@@ -0,0 +1,30 @@
+package typeUseAnnotationDependency.usageLocalVar;
+
+import typeUseAnnotationDependency.annotation.Annotation;
+
+/*
+ * 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 UsageLocalVar {
+
+  public void getValue() {
+    @Annotation String s = "";
+  }
+  
+}