This is an automated email from the ASF dual-hosted git repository. rfscholte pushed a commit to branch MSHARED-674_Detect_Java_8_type_annotations in repository https://gitbox.apache.org/repos/asf/maven-dependency-analyzer.git
commit ae647e0fa95611c1f3036bb6f64f7d7670e662b8 Author: rfscholte <[email protected]> AuthorDate: Thu Jan 4 12:26:34 2018 +0100 [MSHARED-674] Maven Dependency Analyzer ignores Java 8 type annotations --- .../analyzer/asm/DefaultMethodVisitor.java | 8 +++++ .../DefaultProjectDependencyAnalyzerTest.java | 36 ++++++++++++++++--- .../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, 209 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..1599369 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 @@ -43,6 +43,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; /** * Tests <code>DefaultProjectDependencyAnalyzer</code>. @@ -302,17 +303,44 @@ public class DefaultProjectDependencyAnalyzerTest assertEquals( expectedAnalysis, actualAnalysis ); } + public void testTypeUseAnnotationDependency() + throws TestToolsException, ProjectDependencyAnalyzerException + { + // java.lang.annotation.ElementType.TYPE_USE introduced with Java 1.8 + Assume.assumeTrue( SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) ); + + 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..a3fa940 --- /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 { +} 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]>.
