You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2016/07/19 19:27:24 UTC

svn commit: r1753419 - in /maven/plugin-tools/trunk/maven-plugin-tools-annotations/src: main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/ test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/ test/resources/

Author: rfscholte
Date: Tue Jul 19 19:27:24 2016
New Revision: 1753419

URL: http://svn.apache.org/viewvc?rev=1753419&view=rev
Log:
[MPLUGIN-304] MojoAnnotationsScanner should ignore special classes

Added:
    maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/
    maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java
    maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/test/resources/
    maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/test/resources/java9-module.jar   (with props)
Modified:
    maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

Modified: maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java?rev=1753419&r1=1753418&r2=1753419&view=diff
==============================================================================
--- maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java (original)
+++ maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java Tue Jul 19 19:27:24 2016
@@ -19,6 +19,18 @@ package org.apache.maven.tools.plugin.ex
  * 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.codehaus.plexus.util.reflecti
 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 @@ public class DefaultMojoAnnotationsScann
     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 @@ public class DefaultMojoAnnotationsScann
 
         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 @@ public class DefaultMojoAnnotationsScann
 
         for ( String classFile : classFiles )
         {
-            if ( !classFile.endsWith( ".class" ) )
+            if ( !SCANNABLE_CLASS.matcher( classFile ).matches() )
             {
                 continue;
             }

Added: maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java?rev=1753419&view=auto
==============================================================================
--- maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java (added)
+++ maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java Tue Jul 19 19:27:24 2016
@@ -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 );
+    }
+}

Added: maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/test/resources/java9-module.jar
URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/test/resources/java9-module.jar?rev=1753419&view=auto
==============================================================================
Binary file - no diff available.

Propchange: maven/plugin-tools/trunk/maven-plugin-tools-annotations/src/test/resources/java9-module.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream