You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by eo...@apache.org on 2019/03/16 23:25:27 UTC
[maven-indexer] 01/01: [MINDEXER-114] Extend
JarFileContentsIndexCreator to support zip files
This is an automated email from the ASF dual-hosted git repository.
eolivelli pushed a commit to branch MINDEXER-114
in repository https://gitbox.apache.org/repos/asf/maven-indexer.git
commit b2ddbbd314fb602d4474a7f6c543f55604c0a1a3
Author: Przemyslaw Fusik <pr...@gmail.com>
AuthorDate: Thu Jan 25 00:31:14 2018 +0100
[MINDEXER-114] Extend JarFileContentsIndexCreator to support zip files
---
.../index/creator/JarFileContentsIndexCreator.java | 10 ++--
.../creator/JarFileContentsIndexCreatorTest.java | 55 +++++++++++++++++++++
.../aopalliance/1.0/aopalliance-1.0-sources.zip | Bin 0 -> 22384 bytes
.../aopalliance/1.0/aopalliance-1.0.zip | Bin 0 -> 4840 bytes
4 files changed, 61 insertions(+), 4 deletions(-)
diff --git a/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java b/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java
index 9318fbb..e1499c8 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java
@@ -40,8 +40,8 @@ import org.apache.maven.index.util.zip.ZipHandle;
import org.codehaus.plexus.util.StringUtils;
/**
- * An index creator used to index Java class names from a Maven artifact (JAR or WAR for now). Will open up the file and
- * collect all the class names from it.
+ * An index creator used to index Java class names from a Maven artifact (JAR, ZIP or WAR for now).
+ * Will open up the file and collect all the class names from it.
*/
@Singleton
@Named( JarFileContentsIndexCreator.ID )
@@ -75,7 +75,9 @@ public class JarFileContentsIndexCreator
File artifactFile = artifactContext.getArtifact();
if ( artifactFile != null && artifactFile.isFile()
- && ( artifactFile.getName().endsWith( ".jar" ) || artifactFile.getName().endsWith( ".war" ) ) )
+ && ( artifactFile.getName().endsWith( ".jar" )
+ || artifactFile.getName().endsWith( ".war" )
+ || artifactFile.getName().endsWith( ".zip" ) ) )
{
updateArtifactInfo( ai, artifactFile );
}
@@ -145,7 +147,7 @@ public class JarFileContentsIndexCreator
private void updateArtifactInfo( final ArtifactInfo ai, final File f )
throws IOException
{
- if ( f.getName().endsWith( ".jar" ) )
+ if ( f.getName().endsWith( ".jar" ) || f.getName().endsWith( ".zip" ) )
{
updateArtifactInfo( ai, f, null );
}
diff --git a/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java b/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java
index 7d559fc..8032706 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java
@@ -59,6 +59,44 @@ public class JarFileContentsIndexCreatorTest
assertNotNull( "Classes should not be null", artifactContext.getArtifactInfo().getClassNames() );
}
+ public void test_nexus_2318_indexZipWithClasses()
+ throws Exception
+ {
+ File artifact = new File( getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.zip" );
+
+ File pom = new File( getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.pom" );
+
+ ArtifactInfo artifactInfo = new ArtifactInfo( "test", "aopalliance", "aopalliance", "1.0", null, "zip" );
+
+ ArtifactContext artifactContext = new ArtifactContext( pom, artifact, null, artifactInfo, null );
+
+ indexCreator.populateArtifactInfo( artifactContext );
+
+ assertNotNull( "Classes should not be null", artifactContext.getArtifactInfo().getClassNames() );
+
+ String[] classNames = artifactContext.getArtifactInfo().getClassNames().split("\n");
+
+ assertEquals("Unexpected classes length", 9, classNames.length );
+
+ assertEquals("Advice class was expected", "/org/aopalliance/aop/Advice", classNames[0] );
+
+ assertEquals("AspectException class was expected", "/org/aopalliance/aop/AspectException", classNames[1] );
+
+ assertEquals("ConstructorInterceptor class was expected", "/org/aopalliance/intercept/ConstructorInterceptor", classNames[2] );
+
+ assertEquals("ConstructorInvocation class was expected", "/org/aopalliance/intercept/ConstructorInvocation", classNames[3] );
+
+ assertEquals("Interceptor class was expected", "/org/aopalliance/intercept/Interceptor", classNames[4] );
+
+ assertEquals("Invocation class was expected", "/org/aopalliance/intercept/Invocation", classNames[5] );
+
+ assertEquals("Joinpoint class was expected", "/org/aopalliance/intercept/Joinpoint", classNames[6] );
+
+ assertEquals("MethodInterceptor class was expected", "/org/aopalliance/intercept/MethodInterceptor", classNames[7] );
+
+ assertEquals("MethodInvocation class was expected", "/org/aopalliance/intercept/MethodInvocation", classNames[8] );
+ }
+
public void test_nexus_2318_indexJarWithSources()
throws Exception
{
@@ -76,6 +114,23 @@ public class JarFileContentsIndexCreatorTest
assertNull( "Classes should be null", artifactContext.getArtifactInfo().getClassNames() );
}
+ public void test_nexus_2318_indexZipWithSources()
+ throws Exception
+ {
+ File artifact =
+ new File( getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.zip" );
+
+ File pom = new File( getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.pom" );
+
+ ArtifactInfo artifactInfo = new ArtifactInfo( "test", "aopalliance", "aopalliance", "1.0", null, "zip" );
+
+ ArtifactContext artifactContext = new ArtifactContext( pom, artifact, null, artifactInfo, null );
+
+ indexCreator.populateArtifactInfo( artifactContext );
+
+ assertNull( "Classes should be null", artifactContext.getArtifactInfo().getClassNames() );
+ }
+
public void testMindexer35ScanWar()
throws Exception
{
diff --git a/indexer-core/src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.zip b/indexer-core/src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.zip
new file mode 100644
index 0000000..b3cb45e
Binary files /dev/null and b/indexer-core/src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.zip differ
diff --git a/indexer-core/src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.zip b/indexer-core/src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.zip
new file mode 100644
index 0000000..ea10f37
Binary files /dev/null and b/indexer-core/src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.zip differ