You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/07/28 07:18:46 UTC
svn commit: r426389 - in
/maven/repository-manager/trunk/maven-repository-indexer/src:
main/java/org/apache/maven/repository/indexing/
main/java/org/apache/maven/repository/indexing/lucene/
test/java/org/apache/maven/repository/indexing/lucene/
Author: brett
Date: Thu Jul 27 22:18:45 2006
New Revision: 426389
URL: http://svn.apache.org/viewvc?rev=426389&view=rev
Log:
[MNG-127] add delete record method
Modified:
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java
Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java?rev=426389&r1=426388&r2=426389&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java Thu Jul 27 22:18:45 2006
@@ -57,4 +57,12 @@
*/
boolean exists()
throws RepositoryIndexException;
+
+ /**
+ * Delete records from the index. Simply ignore the request any did not exist.
+ *
+ * @param records the records to delete
+ */
+ void deleteRecords( Collection records )
+ throws RepositoryIndexException;
}
Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java?rev=426389&r1=426388&r2=426389&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java Thu Jul 27 22:18:45 2006
@@ -68,14 +68,7 @@
public void indexRecords( Collection records )
throws RepositoryIndexException
{
- try
- {
- deleteRecords( records );
- }
- catch ( IOException e )
- {
- throw new RepositoryIndexException( "Failed to delete an index document", e );
- }
+ deleteRecords( records );
addRecords( records );
}
@@ -141,8 +134,8 @@
return new StandardAnalyzer();
}
- private void deleteRecords( Collection records )
- throws IOException, RepositoryIndexException
+ public void deleteRecords( Collection records )
+ throws RepositoryIndexException
{
if ( exists() )
{
@@ -163,11 +156,15 @@
}
}
}
+ catch ( IOException e )
+ {
+ throw new RepositoryIndexException( "Error deleting document: " + e.getMessage(), e );
+ }
finally
{
if ( indexReader != null )
{
- indexReader.close();
+ closeQuietly( indexReader );
}
}
}
@@ -252,6 +249,21 @@
if ( searcher != null )
{
searcher.close();
+ }
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ }
+
+ private static void closeQuietly( IndexReader reader )
+ {
+ try
+ {
+ if ( reader != null )
+ {
+ reader.close();
}
}
catch ( IOException e )
Modified: maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java?rev=426389&r1=426388&r2=426389&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java Thu Jul 27 22:18:45 2006
@@ -195,6 +195,62 @@
}
}
+ public void testDeleteRecordInIndex()
+ throws IOException, RepositoryIndexException
+ {
+ createEmptyIndex();
+
+ Artifact artifact = createArtifact( "test-jar" );
+
+ RepositoryIndexRecord record = recordFactory.createRecord( artifact );
+ index.indexRecords( Collections.singletonList( record ) );
+
+ index.deleteRecords( Collections.singletonList( record ) );
+
+ IndexReader reader = IndexReader.open( indexLocation );
+ try
+ {
+ assertEquals( "No documents", 0, reader.numDocs() );
+ }
+ finally
+ {
+ reader.close();
+ }
+ }
+
+ public void testDeleteRecordNotInIndex()
+ throws IOException, RepositoryIndexException
+ {
+ createEmptyIndex();
+
+ Artifact artifact = createArtifact( "test-jar" );
+
+ RepositoryIndexRecord record = recordFactory.createRecord( artifact );
+
+ index.deleteRecords( Collections.singletonList( record ) );
+
+ IndexReader reader = IndexReader.open( indexLocation );
+ try
+ {
+ assertEquals( "No documents", 0, reader.numDocs() );
+ }
+ finally
+ {
+ reader.close();
+ }
+ }
+
+ public void testDeleteRecordNoIndex()
+ throws IOException, RepositoryIndexException
+ {
+ Artifact artifact = createArtifact( "test-jar" );
+
+ RepositoryIndexRecord record = recordFactory.createRecord( artifact );
+ index.deleteRecords( Collections.singleton( record ) );
+
+ assertFalse( index.exists() );
+ }
+
public void testAddPomRecord()
throws IOException, RepositoryIndexException
{
Modified: maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java?rev=426389&r1=426388&r2=426389&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java Thu Jul 27 22:18:45 2006
@@ -241,6 +241,62 @@
}
}
+ public void testDeleteRecordInIndex()
+ throws IOException, RepositoryIndexException
+ {
+ createEmptyIndex();
+
+ Artifact artifact = createArtifact( "test-jar" );
+
+ RepositoryIndexRecord record = recordFactory.createRecord( artifact );
+ index.indexRecords( Collections.singletonList( record ) );
+
+ index.deleteRecords( Collections.singletonList( record ) );
+
+ IndexReader reader = IndexReader.open( indexLocation );
+ try
+ {
+ assertEquals( "No documents", 0, reader.numDocs() );
+ }
+ finally
+ {
+ reader.close();
+ }
+ }
+
+ public void testDeleteRecordNotInIndex()
+ throws IOException, RepositoryIndexException
+ {
+ createEmptyIndex();
+
+ Artifact artifact = createArtifact( "test-jar" );
+
+ RepositoryIndexRecord record = recordFactory.createRecord( artifact );
+
+ index.deleteRecords( Collections.singletonList( record ) );
+
+ IndexReader reader = IndexReader.open( indexLocation );
+ try
+ {
+ assertEquals( "No documents", 0, reader.numDocs() );
+ }
+ finally
+ {
+ reader.close();
+ }
+ }
+
+ public void testDeleteRecordNoIndex()
+ throws IOException, RepositoryIndexException
+ {
+ Artifact artifact = createArtifact( "test-jar" );
+
+ RepositoryIndexRecord record = recordFactory.createRecord( artifact );
+ index.deleteRecords( Collections.singleton( record ) );
+
+ assertFalse( index.exists() );
+ }
+
private Artifact createArtifact( String artifactId )
{
return createArtifact( artifactId, "1.0", "jar" );