[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-ffa450edef68master
parent
7dd7d23ebf
commit
a44d4f1719
|
|
@ -19,6 +19,18 @@ package org.apache.maven.tools.plugin.extractor.annotations.scanner;
|
||||||
* under the License.
|
* 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.artifact.Artifact;
|
||||||
import org.apache.maven.plugins.annotations.Component;
|
import org.apache.maven.plugins.annotations.Component;
|
||||||
import org.apache.maven.plugins.annotations.Execute;
|
import org.apache.maven.plugins.annotations.Execute;
|
||||||
|
|
@ -41,17 +53,6 @@ import org.codehaus.plexus.util.reflection.ReflectorException;
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.Type;
|
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
|
* @author Olivier Lamy
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
|
|
@ -61,6 +62,9 @@ public class DefaultMojoAnnotationsScanner
|
||||||
extends AbstractLogEnabled
|
extends AbstractLogEnabled
|
||||||
implements MojoAnnotationsScanner
|
implements MojoAnnotationsScanner
|
||||||
{
|
{
|
||||||
|
// classes with a dash must be ignored
|
||||||
|
private static final Pattern SCANNABLE_CLASS = Pattern.compile( "[^-]+\\.class" );
|
||||||
|
|
||||||
private Reflector reflector = new Reflector();
|
private Reflector reflector = new Reflector();
|
||||||
|
|
||||||
public Map<String, MojoAnnotatedClass> scan( MojoAnnotationsScannerRequest request )
|
public Map<String, MojoAnnotatedClass> scan( MojoAnnotationsScannerRequest request )
|
||||||
|
|
@ -126,19 +130,28 @@ public class DefaultMojoAnnotationsScanner
|
||||||
|
|
||||||
ZipInputStream archiveStream = new ZipInputStream( new FileInputStream( archiveFile ) );
|
ZipInputStream archiveStream = new ZipInputStream( new FileInputStream( archiveFile ) );
|
||||||
|
|
||||||
|
String zipEntryName = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
for ( ZipEntry zipEntry = archiveStream.getNextEntry(); zipEntry != null;
|
for ( ZipEntry zipEntry = archiveStream.getNextEntry(); zipEntry != null;
|
||||||
zipEntry = archiveStream.getNextEntry() )
|
zipEntry = archiveStream.getNextEntry() )
|
||||||
{
|
{
|
||||||
if ( !zipEntry.getName().endsWith( ".class" ) )
|
zipEntryName = zipEntry.getName();
|
||||||
|
if ( !SCANNABLE_CLASS.matcher( zipEntryName ).matches() )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
analyzeClassStream( mojoAnnotatedClasses, archiveStream, artifact, excludeMojo );
|
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
|
finally
|
||||||
{
|
{
|
||||||
IOUtil.close( archiveStream );
|
IOUtil.close( archiveStream );
|
||||||
|
|
@ -174,7 +187,7 @@ public class DefaultMojoAnnotationsScanner
|
||||||
|
|
||||||
for ( String classFile : classFiles )
|
for ( String classFile : classFiles )
|
||||||
{
|
{
|
||||||
if ( !classFile.endsWith( ".class" ) )
|
if ( !SCANNABLE_CLASS.matcher( classFile ).matches() )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Loading…
Reference in New Issue