You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2011/08/17 17:35:09 UTC
svn commit: r1158770 - in /maven/indexer/trunk/indexer-core/src:
main/java/org/apache/maven/index/creator/ test/java/org/apache/maven/index/
test/java/org/apache/maven/index/creator/ test/mindexer-35/
test/mindexer-35/org/ test/mindexer-35/org/apache/ ...
Author: cstamas
Date: Wed Aug 17 15:35:08 2011
New Revision: 1158770
URL: http://svn.apache.org/viewvc?rev=1158770&view=rev
Log:
MINDEXER-35: Extended existing JarFileIndexCreator to index classes in WARs too.
Added:
maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer35NexusIndexerTest.java (with props)
maven/indexer/trunk/indexer-core/src/test/mindexer-35/
maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/
maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/
maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/
maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/
maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/
maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/
maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/
maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/maven-metadata.xml (with props)
maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.pom (with props)
maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.war
maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/maven-metadata.xml (with props)
Modified:
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java
maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java
Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java?rev=1158770&r1=1158769&r2=1158770&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java Wed Aug 17 15:35:08 2011
@@ -37,10 +37,11 @@ import org.apache.maven.index.context.In
import org.apache.maven.index.util.zip.ZipFacade;
import org.apache.maven.index.util.zip.ZipHandle;
import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.util.StringUtils;
/**
- * An index creator used to index Java class names from a Maven artifact. Will open up the JAR and collect all the class
- * names from it.
+ * 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.
*/
@Component( role = IndexCreator.class, hint = JarFileContentsIndexCreator.ID )
public class JarFileContentsIndexCreator
@@ -65,20 +66,21 @@ public class JarFileContentsIndexCreator
super( ID );
}
- public void populateArtifactInfo( ArtifactContext artifactContext )
+ public void populateArtifactInfo( final ArtifactContext artifactContext )
throws IOException
{
ArtifactInfo ai = artifactContext.getArtifactInfo();
File artifactFile = artifactContext.getArtifact();
- if ( artifactFile != null && artifactFile.isFile() && artifactFile.getName().endsWith( ".jar" ) )
+ if ( artifactFile != null && artifactFile.isFile()
+ && ( artifactFile.getName().endsWith( ".jar" ) || artifactFile.getName().endsWith( ".war" ) ) )
{
updateArtifactInfo( ai, artifactFile );
}
}
- public void updateDocument( ArtifactInfo ai, Document doc )
+ public void updateDocument( final ArtifactInfo ai, final Document doc )
{
if ( ai.classNames != null )
{
@@ -87,7 +89,7 @@ public class JarFileContentsIndexCreator
}
}
- public void updateLegacyDocument( ArtifactInfo ai, Document doc )
+ public void updateLegacyDocument( final ArtifactInfo ai, final Document doc )
{
if ( ai.classNames != null )
{
@@ -111,7 +113,7 @@ public class JarFileContentsIndexCreator
}
}
- public boolean updateArtifactInfo( Document doc, ArtifactInfo artifactInfo )
+ public boolean updateArtifactInfo( final Document doc, final ArtifactInfo artifactInfo )
{
String names = doc.get( FLD_CLASSNAMES_KW.getKey() );
@@ -139,7 +141,20 @@ public class JarFileContentsIndexCreator
return false;
}
- private void updateArtifactInfo( ArtifactInfo ai, File f )
+ private void updateArtifactInfo( final ArtifactInfo ai, final File f )
+ throws IOException
+ {
+ if ( f.getName().endsWith( ".jar" ) )
+ {
+ updateArtifactInfo( ai, f, null );
+ }
+ else if ( f.getName().endsWith( ".war" ) )
+ {
+ updateArtifactInfo( ai, f, "WEB-INF/classes/" );
+ }
+ }
+
+ private void updateArtifactInfo( final ArtifactInfo ai, final File f, final String strippedPrefix )
throws IOException
{
ZipHandle handle = null;
@@ -168,8 +183,16 @@ public class JarFileContentsIndexCreator
sb.append( '/' );
}
- // class name without ".class"
- sb.append( name.substring( 0, name.length() - 6 ) ).append( '\n' );
+ if ( StringUtils.isBlank( strippedPrefix ) )
+ {
+ // class name without ".class"
+ sb.append( name.substring( 0, name.length() - 6 ) ).append( '\n' );
+ }
+ else if ( name.startsWith( strippedPrefix ) && (name.length() > ( strippedPrefix.length() + 6 )) )
+ {
+ // class name without ".class" and stripped prefix
+ sb.append( name.substring( strippedPrefix.length(), name.length() - 6 ) ).append( '\n' );
+ }
}
}
}
Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer35NexusIndexerTest.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer35NexusIndexerTest.java?rev=1158770&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer35NexusIndexerTest.java (added)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer35NexusIndexerTest.java Wed Aug 17 15:35:08 2011
@@ -0,0 +1,70 @@
+package org.apache.maven.index;
+
+/*
+ * 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 java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.lucene.search.Query;
+import org.apache.maven.index.expr.UserInputSearchExpression;
+
+public class Mindexer35NexusIndexerTest
+ extends AbstractNexusIndexerTest
+{
+ protected File repo = new File( getBasedir(), "src/test/mindexer-35" );
+
+ @Override
+ protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
+ throws Exception
+ {
+ context =
+ nexusIndexer.addIndexingContext( "mindexer-35", "mindexer-35", repo, indexDir, null, null, FULL_CREATORS );
+ nexusIndexer.scan( context );
+ }
+
+ public void testSearchWar()
+ throws Exception
+ {
+ Query q = nexusIndexer.constructQuery( MAVEN.CLASSNAMES, new UserInputSearchExpression( "WebappClass" ) );
+
+ FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( q ) );
+
+ Collection<ArtifactInfo> r = response.getResults();
+
+ assertEquals( 1, r.size() );
+
+ List<ArtifactInfo> list = new ArrayList<ArtifactInfo>( r );
+
+ ArtifactInfo ai = null;
+
+ // g a v p c #1
+ ai = list.get( 0 );
+
+ assertEquals( "org.apache.maven.indexer.test", ai.groupId );
+ assertEquals( "sample-war", ai.artifactId );
+ assertEquals( "1.0-SNAPSHOT", ai.version );
+ assertEquals( "war", ai.packaging );
+ assertEquals( null, ai.classifier );
+ assertEquals( "mindexer-35", ai.repository );
+ assertEquals( "war", ai.fextension );
+ }
+}
Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer35NexusIndexerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer35NexusIndexerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java?rev=1158770&r1=1158769&r2=1158770&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java (original)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java Wed Aug 17 15:35:08 2011
@@ -76,4 +76,27 @@ public class JarFileContentsIndexCreator
assertNull( "Classes should be null", artifactContext.getArtifactInfo().classNames );
}
+ public void testMindexer35ScanWar()
+ throws Exception
+ {
+ File artifact =
+ new File( getBasedir(),
+ "src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.war" );
+
+ File pom =
+ new File( getBasedir(),
+ "src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.pom" );
+
+ ArtifactInfo artifactInfo =
+ new ArtifactInfo( "test", "org.apache.maven.indexer.test", "sample-war", "1.0-SNAPSHOT", null );
+
+ ArtifactContext artifactContext = new ArtifactContext( pom, artifact, null, artifactInfo, null );
+
+ indexCreator.populateArtifactInfo( artifactContext );
+
+ assertTrue( "Classes should contain WebappClass",
+ artifactContext.getArtifactInfo().classNames.contains( "WebappClass" ) );
+ assertEquals( "WebappClass should have proper package",
+ "/org/apache/maven/indexer/samples/webapp/WebappClass", artifactContext.getArtifactInfo().classNames );
+ }
}
Added: maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/maven-metadata.xml
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/maven-metadata.xml?rev=1158770&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/maven-metadata.xml (added)
+++ maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/maven-metadata.xml Wed Aug 17 15:35:08 2011
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata modelVersion="1.1.0">
+ <groupId>org.apache.maven.indexer.test</groupId>
+ <artifactId>sample-war</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <versioning>
+ <snapshot>
+ <localCopy>true</localCopy>
+ </snapshot>
+ <lastUpdated>20110817150644</lastUpdated>
+ <snapshotVersions>
+ <snapshotVersion>
+ <extension>war</extension>
+ <value>1.0-SNAPSHOT</value>
+ <updated>20110817150644</updated>
+ </snapshotVersion>
+ <snapshotVersion>
+ <extension>pom</extension>
+ <value>1.0-SNAPSHOT</value>
+ <updated>20110817150644</updated>
+ </snapshotVersion>
+ </snapshotVersions>
+ </versioning>
+</metadata>
Propchange: maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/maven-metadata.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/maven-metadata.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.pom
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.pom?rev=1158770&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.pom (added)
+++ maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.pom Wed Aug 17 15:35:08 2011
@@ -0,0 +1,21 @@
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.indexer.test</groupId>
+ <artifactId>sample-war</artifactId>
+ <packaging>war</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>sample-war Maven Webapp</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>sample-war</finalName>
+ </build>
+</project>
Propchange: maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.pom
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.pom
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.war
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.war?rev=1158770&view=auto
==============================================================================
Files maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.war (added) and maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.war Wed Aug 17 15:35:08 2011 differ
Added: maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/maven-metadata.xml
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/maven-metadata.xml?rev=1158770&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/maven-metadata.xml (added)
+++ maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/maven-metadata.xml Wed Aug 17 15:35:08 2011
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata>
+ <groupId>org.apache.maven.indexer.test</groupId>
+ <artifactId>sample-war</artifactId>
+ <versioning>
+ <versions>
+ <version>1.0-SNAPSHOT</version>
+ </versions>
+ <lastUpdated>20110817150644</lastUpdated>
+ </versioning>
+</metadata>
Propchange: maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/maven-metadata.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/indexer/trunk/indexer-core/src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/maven-metadata.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision