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
This commit is contained in:
Brett Porter 2006-07-22 14:19:12 +00:00
parent 6eb2f1d470
commit fc3ea50031
4 changed files with 132 additions and 7 deletions

View File

@ -111,10 +111,8 @@ public class ArtifactRepositoryIndex
*
* @param artifactList
* @return
* @throws RepositoryIndexException
*/
private List getDocumentList( List artifactList )
throws RepositoryIndexException
{
List list = new ArrayList();
@ -122,8 +120,16 @@ public class ArtifactRepositoryIndex
{
Artifact artifact = (Artifact) artifacts.next();
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 ) &&

View File

@ -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
*

View File

@ -0,0 +1,95 @@
<project>
<parent>
<artifactId>maven</artifactId>
<groupId>org.apache.maven</groupId>
<version>2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-corrupt-jar</artifactId>
<name>Maven Model</name>
<version>2.0</version>
<description>Maven Model</description>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<goals>
<goal>xpp3-writer</goal>
<goal>java</goal>
<goal>xpp3-reader</goal>
<goal>xsd</goal>
</goals>
</execution>
</executions>
<configuration>
<version>4.0.0</version>
<model>maven.mdo</model>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>all-models</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<executions>
<execution>
<id>v3</id>
<goals>
<goal>xpp3-writer</goal>
<goal>java</goal>
<goal>xpp3-reader</goal>
<goal>xsd</goal>
</goals>
<configuration>
<version>3.0.0</version>
<packageWithVersion>true</packageWithVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>all</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.0.5</version>
</dependency>
</dependencies>
<distributionManagement>
<status>deployed</status>
</distributionManagement>
</project>