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

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


The following commit(s) were added to refs/heads/master by this push:
     new 51ff6e8  [MSHARED-674] Detect Java 8 type annotations (#1)
51ff6e8 is described below

commit 51ff6e801a4b9d206ddb42645658355b43540bba
Author: Andreas Hubold <[email protected]>
AuthorDate: Thu Jan 4 13:36:25 2018 +0100

    [MSHARED-674] Detect Java 8 type annotations (#1)
    
    * [MSHARED-674] Detect Java 8 type annotations
    
    by implementing DefaultMethodVisitor#visitTypeAnnotation
    
    * [MSHARED-674] Do not use assumeTrue in junit test
    
    assumptions do not work in old methodName based junit tests
---
 .../analyzer/asm/DefaultMethodVisitor.java         |  8 +++++
 .../DefaultProjectDependencyAnalyzerTest.java      | 38 +++++++++++++++++---
 .../typeUseAnnotationDependency/annotation/pom.xml | 33 ++++++++++++++++++
 .../annotation/Annotation.java                     | 30 ++++++++++++++++
 .../resources/typeUseAnnotationDependency/pom.xml  | 38 ++++++++++++++++++++
 .../typeUseAnnotationDependency/usage/pom.xml      | 40 ++++++++++++++++++++++
 .../typeUseAnnotationDependency/usage/Usage.java   | 28 +++++++++++++++
 7 files changed, 211 insertions(+), 4 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 795398c..bde6173 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
@@ -24,6 +24,7 @@ import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.Type;
+import org.objectweb.asm.TypePath;
 import org.objectweb.asm.signature.SignatureReader;
 import org.objectweb.asm.signature.SignatureVisitor;
 
@@ -60,6 +61,13 @@ public class DefaultMethodVisitor
         return annotationVisitor;
     }
 
+    @Override
+    public AnnotationVisitor visitTypeAnnotation( int typeRef, TypePath 
typePath, String desc, boolean visible )
+    {
+        resultCollector.addDesc( desc );
+
+        return annotationVisitor;
+    }
 
     public AnnotationVisitor visitParameterAnnotation( final int parameter, 
final String desc, final boolean visible )
     {
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 1e2466b..9e412f2 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
@@ -302,17 +302,47 @@ public class DefaultProjectDependencyAnalyzerTest
         assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    public void testTypeUseAnnotationDependency()
+            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/usage/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 )
         throws TestToolsException
     {
+        compileProject( pomPath, new Properties() );
+    }
+
+    private void compileProject(String pomPath, Properties properties) throws 
TestToolsException {
         File pom = getTestFile( "target/test-classes/", pomPath );
-        Properties properties = new Properties();
-        if ( SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_9 ) )
+        if ( SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_9 )
+             && !properties.containsKey( "maven.compiler.source" ) )
         {
-          properties.put( "maven.compiler.source", "1.6" );   
-          properties.put( "maven.compiler.target", "1.6" );   
+          properties.put( "maven.compiler.source", "1.6" );
+          properties.put( "maven.compiler.target", "1.6" );
         }
 
         List<String> goals = Arrays.asList( "clean", "install" );
diff --git a/src/test/resources/typeUseAnnotationDependency/annotation/pom.xml 
b/src/test/resources/typeUseAnnotationDependency/annotation/pom.xml
new file mode 100644
index 0000000..6eaf2ca
--- /dev/null
+++ b/src/test/resources/typeUseAnnotationDependency/annotation/pom.xml
@@ -0,0 +1,33 @@
+<?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>typeUseAnnotationDependencyAnnotation</artifactId>
+       <packaging>jar</packaging>
+       <version>1.0</version>
+       
+</project>
diff --git 
a/src/test/resources/typeUseAnnotationDependency/annotation/src/main/java/typeUseAnnotationDependency/annotation/Annotation.java
 
b/src/test/resources/typeUseAnnotationDependency/annotation/src/main/java/typeUseAnnotationDependency/annotation/Annotation.java
new file mode 100644
index 0000000..5a7675f
--- /dev/null
+++ 
b/src/test/resources/typeUseAnnotationDependency/annotation/src/main/java/typeUseAnnotationDependency/annotation/Annotation.java
@@ -0,0 +1,30 @@
+package typeUseAnnotationDependency.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/*
+ * 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.
+ */
+
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Annotation {
+}
\ No newline at end of file
diff --git a/src/test/resources/typeUseAnnotationDependency/pom.xml 
b/src/test/resources/typeUseAnnotationDependency/pom.xml
new file mode 100644
index 0000000..62e966c
--- /dev/null
+++ b/src/test/resources/typeUseAnnotationDependency/pom.xml
@@ -0,0 +1,38 @@
+<?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>typeUseAnnotationDependency</artifactId>
+       <packaging>pom</packaging>
+       <version>1.0</version>
+       
+       <modules>
+               <module>annotation</module>
+               <module>usage</module>
+       </modules>
+       
+</project>
diff --git a/src/test/resources/typeUseAnnotationDependency/usage/pom.xml 
b/src/test/resources/typeUseAnnotationDependency/usage/pom.xml
new file mode 100644
index 0000000..6c46e6b
--- /dev/null
+++ b/src/test/resources/typeUseAnnotationDependency/usage/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>typeUseAnnotationDependencyUsage</artifactId>
+       <packaging>jar</packaging>
+       <version>1.0</version>
+
+       <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/usage/src/main/java/typeUseAnnotationDependency/usage/Usage.java
 
b/src/test/resources/typeUseAnnotationDependency/usage/src/main/java/typeUseAnnotationDependency/usage/Usage.java
new file mode 100644
index 0000000..3d1ad16
--- /dev/null
+++ 
b/src/test/resources/typeUseAnnotationDependency/usage/src/main/java/typeUseAnnotationDependency/usage/Usage.java
@@ -0,0 +1,28 @@
+package typeUseAnnotationDependency.usage;
+
+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 interface Usage {
+
+  @Annotation String getValue();
+  
+}

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to