From fc3ea50031ac8248d808c52108845f4dcbd07b00 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Sat, 22 Jul 2006 14:19:12 +0000 Subject: [PATCH] test and better handling for corrupt JARs when indexing git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@424579 13f79535-47bb-0310-9956-ffa450edef68 --- .../indexing/ArtifactRepositoryIndex.java | 18 ++-- .../ArtifactRepositoryIndexingTest.java | 26 ++++- .../2.0/maven-corrupt-jar-2.0.jar | 0 .../2.0/maven-corrupt-jar-2.0.pom | 95 +++++++++++++++++++ 4 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 maven-repository-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.jar create mode 100644 maven-repository-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.pom diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java index 6e3a08527..1913770bf 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java @@ -111,10 +111,8 @@ public class ArtifactRepositoryIndex * * @param artifactList * @return - * @throws RepositoryIndexException */ private List getDocumentList( List artifactList ) - throws RepositoryIndexException { List list = new ArrayList(); @@ -122,7 +120,15 @@ public class ArtifactRepositoryIndex { Artifact artifact = (Artifact) artifacts.next(); - list.add( createDocument( artifact ) ); + try + { + list.add( createDocument( artifact ) ); + } + catch ( RepositoryIndexException e ) + { + // TODO: log the problem and record it as a repository error + // We log the problem, but do not add the document to the list to be added to the index + } } return list; @@ -268,7 +274,7 @@ public class ArtifactRepositoryIndex try { - for ( int i = 0; i < indexReader.numDocs(); i ++ ) + for ( int i = 0; i < indexReader.numDocs(); i++ ) { Document doc = indexReader.document( i ); groups.add( doc.getField( FLD_GROUPID ).stringValue() ); @@ -293,7 +299,7 @@ public class ArtifactRepositoryIndex try { - for ( int i = 0; i < indexReader.numDocs(); i ++ ) + for ( int i = 0; i < indexReader.numDocs(); i++ ) { Document doc = indexReader.document( i ); if ( doc.getField( FLD_GROUPID ).stringValue().equals( groupId ) ) @@ -321,7 +327,7 @@ public class ArtifactRepositoryIndex try { - for ( int i = 0; i < indexReader.numDocs(); i ++ ) + for ( int i = 0; i < indexReader.numDocs(); i++ ) { Document doc = indexReader.document( i ); if ( doc.getField( FLD_GROUPID ).stringValue().equals( groupId ) && diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java index 074064504..83c78b586 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java @@ -30,9 +30,9 @@ import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.FileUtils; import java.io.File; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.ArrayList; /** * @author Edwin Punzalan @@ -455,6 +455,30 @@ public class ArtifactRepositoryIndexingTest assertEquals( 0, artifacts.size() ); } + /** + * Test delete of document from the artifact index. + * + * @throws Exception + */ + public void testCorruptJar() + throws Exception + { + createTestIndex(); + + RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); + RepositoryIndexSearcher repoSearcher = (RepositoryIndexSearcher) lookup( RepositoryIndexSearcher.ROLE ); + + ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository ); + + Artifact artifact = getArtifact( "org.apache.maven", "maven-corrupt-jar", "2.0" ); + artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); + indexer.indexArtifact( artifact ); + + Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + artifact.getId() ); + List artifacts = repoSearcher.search( qry, indexer ); + assertEquals( 0, artifacts.size() ); + } + /** * Method for creating artifact object * diff --git a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.jar b/maven-repository-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.pom b/maven-repository-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.pom new file mode 100644 index 000000000..e5dc3f3a8 --- /dev/null +++ b/maven-repository-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.pom @@ -0,0 +1,95 @@ + + + maven + org.apache.maven + 2.0 + + 4.0.0 + org.apache.maven + maven-corrupt-jar + Maven Model + 2.0 + Maven Model + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + org.codehaus.modello + modello-maven-plugin + 2.0 + + + + xpp3-writer + java + xpp3-reader + xsd + + + + + 4.0.0 + maven.mdo + + + + + + + all-models + + + + org.codehaus.modello + modello-maven-plugin + + + v3 + + xpp3-writer + java + xpp3-reader + xsd + + + 3.0.0 + true + + + + + + maven-jar-plugin + + + package + + jar + + + all + + + + + + + + + + + org.codehaus.plexus + plexus-utils + 1.0.5 + + + + deployed + + \ No newline at end of file