[MPLUGIN-304] MojoAnnotationsScanner should ignore special classes
git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1753419 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java
index 8796274..f4c8301 100644
--- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java
+++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java
@@ -19,6 +19,18 @@
* under the License.
*/
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Execute;
@@ -41,17 +53,6 @@
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Type;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
/**
* @author Olivier Lamy
* @since 3.0
@@ -61,6 +62,9 @@
extends AbstractLogEnabled
implements MojoAnnotationsScanner
{
+ // classes with a dash must be ignored
+ private static final Pattern SCANNABLE_CLASS = Pattern.compile( "[^-]+\\.class" );
+
private Reflector reflector = new Reflector();
public Map<String, MojoAnnotatedClass> scan( MojoAnnotationsScannerRequest request )
@@ -126,19 +130,28 @@
ZipInputStream archiveStream = new ZipInputStream( new FileInputStream( archiveFile ) );
+ String zipEntryName = null;
try
{
+
for ( ZipEntry zipEntry = archiveStream.getNextEntry(); zipEntry != null;
zipEntry = archiveStream.getNextEntry() )
{
- if ( !zipEntry.getName().endsWith( ".class" ) )
+ zipEntryName = zipEntry.getName();
+ if ( !SCANNABLE_CLASS.matcher( zipEntryName ).matches() )
{
continue;
}
-
analyzeClassStream( mojoAnnotatedClasses, archiveStream, artifact, excludeMojo );
}
}
+ catch ( IllegalArgumentException e )
+ {
+ // In case of a class with newer specs an IllegalArgumentException can be thrown
+ getLogger().error( "Failed to analyze " + archiveFile.getAbsolutePath() + "!/" + zipEntryName );
+
+ throw e;
+ }
finally
{
IOUtil.close( archiveStream );
@@ -174,7 +187,7 @@
for ( String classFile : classFiles )
{
- if ( !classFile.endsWith( ".class" ) )
+ if ( !SCANNABLE_CLASS.matcher( classFile ).matches() )
{
continue;
}
diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java
new file mode 100644
index 0000000..6218848
--- /dev/null
+++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java
@@ -0,0 +1,35 @@
+package org.apache.maven.tools.plugin.extractor.annotations.scanner;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+public class DefaultMojoAnnotationsScannerTest
+ extends TestCase
+{
+ private DefaultMojoAnnotationsScanner scanner = new DefaultMojoAnnotationsScanner();
+
+ public void testSkipModuleInfoClassInArchive() throws Exception
+ {
+ scanner.scanArchive( new File( "src/test/resources/java9-module.jar"), null, false );
+ }
+}
diff --git a/maven-plugin-tools-annotations/src/test/resources/java9-module.jar b/maven-plugin-tools-annotations/src/test/resources/java9-module.jar
new file mode 100644
index 0000000..5a7edc0
--- /dev/null
+++ b/maven-plugin-tools-annotations/src/test/resources/java9-module.jar
Binary files differ