]> source.dussan.org Git - archiva.git/commitdiff
Improved the indexing module
authorEdwin L. Punzalan <epunzalan@apache.org>
Thu, 15 Jun 2006 10:25:38 +0000 (10:25 +0000)
committerEdwin L. Punzalan <epunzalan@apache.org>
Thu, 15 Jun 2006 10:25:38 +0000 (10:25 +0000)
* added addDocuments and deleteDocuments methods
* hid some unused methods
* did some performance optimization
* made validate to be called only in the class constructor

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@414538 13f79535-47bb-0310-9956-ffa450edef68

15 files changed:
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/EclipseRepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java
maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java
maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/EclipseRepositoryIndexTest.java
maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java
maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java
maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/RepositoryIndexSearchLayerTest.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/execution/DiscovererExecution.java

index 2c21027adaa621330a63089241ee05d7b3efc177..5903cebb69b2b79f80f882acd943f31b88bde1be 100644 (file)
@@ -23,12 +23,16 @@ import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.document.Document;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 
 import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
 import java.util.Collection;
+import java.util.List;
+import java.util.Iterator;
+import java.util.Collections;
 import java.util.zip.ZipEntry;
 
 /**
@@ -40,12 +44,9 @@ import java.util.zip.ZipEntry;
 public abstract class AbstractRepositoryIndex
     implements RepositoryIndex
 {
-    // TODO: can this be derived from the repository? -- probably a sensible default, but still should be configurable, but this could just be on the call to open()
+    // TODO: can this be derived from the repository? -- probably a sensible default, but still should be configurable
     private File indexPath;
 
-    private boolean indexOpen;
-
-    // TODO: why is the writer open for the life, but not the reader? why keep them open that length of time anyway? investigate best practices in Lucene
     private IndexWriter indexWriter;
 
     protected ArtifactRepository repository;
@@ -59,35 +60,20 @@ public abstract class AbstractRepositoryIndex
      * @param repository
      */
     protected AbstractRepositoryIndex( File indexPath, ArtifactRepository repository )
+        throws RepositoryIndexException
     {
         this.repository = repository;
         this.indexPath = indexPath;
-    }
 
-    /**
-     * Method to open the IndexWriter
-     *
-     * @throws RepositoryIndexException
-     */
-    public void open()
-        throws RepositoryIndexException
-    {
         try
         {
-            if ( indexExists() )
-            {
-                indexWriter = new IndexWriter( indexPath, getAnalyzer(), false );
-            }
-            else
-            {
-                indexWriter = new IndexWriter( indexPath, getAnalyzer(), true );
-            }
+            validate();
         }
-        catch ( IOException ie )
+        catch ( IOException e )
         {
-            throw new RepositoryIndexException( ie );
+            throw new RepositoryIndexException( "Failed to validate index path: " +
+                                                getIndexPath().getAbsolutePath(), e );
         }
-        indexOpen = true;
     }
 
     /**
@@ -96,14 +82,10 @@ public abstract class AbstractRepositoryIndex
     public void optimize()
         throws RepositoryIndexException
     {
-        if ( !indexOpen )
-        {
-            throw new RepositoryIndexException( "Unable to optimize index on a closed index" );
-        }
-
         try
         {
-            indexWriter.optimize();
+            getIndexWriter().optimize();
+            close();
         }
         catch ( IOException ioe )
         {
@@ -112,17 +94,9 @@ public abstract class AbstractRepositoryIndex
     }
 
     /**
-     * @see org.apache.maven.repository.indexing.RepositoryIndex#isOpen()
+     * closes the current index from writing thus removing lock files
      */
-    public boolean isOpen()
-    {
-        return indexOpen;
-    }
-
-    /**
-     * @see org.apache.maven.repository.indexing.RepositoryIndex#close()
-     */
-    public void close()
+    private void close()
         throws RepositoryIndexException
     {
         try
@@ -132,8 +106,6 @@ public abstract class AbstractRepositoryIndex
                 indexWriter.close();
                 indexWriter = null;
             }
-
-            indexOpen = false;
         }
         catch ( IOException e )
         {
@@ -155,45 +127,52 @@ public abstract class AbstractRepositoryIndex
      * @return the lucene IndexWriter object used to update the index
      * @throws IOException
      */
-    protected IndexWriter getIndexWriter()
-        throws IOException
+    private IndexWriter getIndexWriter()
+        throws IOException, RepositoryIndexException
     {
-        // TODO: why is this allowed to be called before open()?
         if ( indexWriter == null )
         {
-            indexWriter = new IndexWriter( indexPath, getAnalyzer(), false );
+            if ( indexExists() )
+            {
+                indexWriter = new IndexWriter( indexPath, getAnalyzer(), false );
+            }
+            else
+            {
+                indexWriter = new IndexWriter( indexPath, getAnalyzer(), true );
+            }
         }
+
         return indexWriter;
     }
 
     /**
-     * method for validating an index directory
-     *
-     * @param indexFields
-     * @throws RepositoryIndexException if the given indexPath is not valid for this type of RepositoryIndex
+     * @see RepositoryIndex#validate()
      */
-    protected void validateIndex( String[] indexFields )
+    public void validate()
         throws RepositoryIndexException, IOException
     {
-        IndexReader indexReader = IndexReader.open( indexPath );
-        try
+        if ( indexExists() )
         {
-            if ( indexReader.numDocs() > 0 )
+            IndexReader indexReader = IndexReader.open( indexPath );
+            try
             {
-                Collection fields = indexReader.getFieldNames();
-                for ( int idx = 0; idx < indexFields.length; idx++ )
+                if ( indexReader.numDocs() > 0 )
                 {
-                    if ( !fields.contains( indexFields[idx] ) )
+                    Collection fields = indexReader.getFieldNames();
+                    for ( int idx = 0; idx < FIELDS.length; idx++ )
                     {
-                        throw new RepositoryIndexException(
-                            "The Field " + indexFields[idx] + " does not exist in index " + indexPath + "." );
+                        if ( !fields.contains( FIELDS[idx] ) )
+                        {
+                            throw new RepositoryIndexException(
+                                "The Field " + FIELDS[idx] + " does not exist in index " + indexPath + "." );
+                        }
                     }
                 }
             }
-        }
-        finally
-        {
-            indexReader.close();
+            finally
+            {
+                indexReader.close();
+            }
         }
     }
 
@@ -216,22 +195,65 @@ public abstract class AbstractRepositoryIndex
     protected void deleteDocument( String field, String value )
         throws RepositoryIndexException, IOException
     {
-        IndexReader indexReader = null;
+        Term term = new Term( field, value );
+
+        deleteDocuments( Collections.singletonList( term ) );
+    }
+
+    public void deleteDocuments( List termList )
+        throws RepositoryIndexException, IOException
+    {
+        if ( indexExists() )
+        {
+            IndexReader indexReader = null;
+            try
+            {
+                indexReader = IndexReader.open( indexPath );
+
+                for ( Iterator terms = termList.iterator(); terms.hasNext(); )
+                {
+                    Term term = (Term) terms.next();
+
+                    indexReader.delete( term );
+                }
+            }
+            finally
+            {
+                if ( indexReader != null )
+                {
+                    indexReader.close();
+                }
+            }
+        }
+    }
+
+    /**
+     * Opens the lucene index and add all the lucene documents inside the list into the index.
+     * Closes the index at the end.
+     *
+     * @param docList List of Lucene Documents
+     * @throws RepositoryIndexException when an error occurred during the indexing of the documents
+     */
+    public void addDocuments( List docList )
+        throws RepositoryIndexException
+    {
         try
         {
-            indexReader = IndexReader.open( indexPath );
-            indexReader.delete( new Term( field, value ) );
+            IndexWriter indexWriter = getIndexWriter();
+
+            for ( Iterator docs = docList.iterator(); docs.hasNext(); )
+            {
+                Document doc = (Document) docs.next();
+                indexWriter.addDocument( doc );
+            }
         }
-        catch ( IOException ie )
+        catch ( IOException e )
         {
-            throw new RepositoryIndexException( indexPath + " is not a valid directory." );
+            throw new RepositoryIndexException( "Failed to add an index document", e );
         }
         finally
         {
-            if ( indexReader != null )
-            {
-                indexReader.close();
-            }
+            close();
         }
     }
 
@@ -269,16 +291,6 @@ public abstract class AbstractRepositoryIndex
         }
     }
 
-    /**
-     * Checks if the object has already been indexed and deletes it if it is.
-     *
-     * @param object the object to be indexed.
-     * @throws RepositoryIndexException
-     * @throws IOException
-     */
-    abstract void deleteIfIndexed( Object object )
-        throws RepositoryIndexException, IOException;
-
     /**
      * @see org.apache.maven.repository.indexing.RepositoryIndex#getAnalyzer()
      */
@@ -331,6 +343,9 @@ public abstract class AbstractRepositoryIndex
         return isAdded;
     }
 
+    /**
+     * Inner class used as the default IndexAnalyzer
+     */
     private static class ArtifactRepositoryIndexAnalyzer
         extends Analyzer
     {
@@ -371,7 +386,7 @@ public abstract class AbstractRepositoryIndex
     }
 
     /**
-     * Class used to tokenize an artifact's version.
+     * Inner class used to tokenize an artifact's version.
      */
     private static class VersionTokenizer
         extends CharTokenizer
index 09b1674af7aca42ca20e9d2119b9d7b9a58ec7f8..9d669af64d54b2c6084317c115914bf64502bc90 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.maven.repository.indexing;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
+import org.apache.lucene.index.Term;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.repository.digest.Digester;
@@ -26,7 +27,11 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
@@ -50,30 +55,73 @@ public class ArtifactRepositoryIndex
      * @param digester   the digester object to generate the checksum strings
      */
     public ArtifactRepositoryIndex( File indexPath, ArtifactRepository repository, Digester digester )
+        throws RepositoryIndexException
     {
         super( indexPath, repository );
         this.digester = digester;
     }
 
     /**
-     * @see AbstractRepositoryIndex#deleteIfIndexed(Object)
+     * Checks if the artifact has already been indexed and deletes it if it is.
+     *
+     * @param artifact the object to be indexed.
+     * @throws RepositoryIndexException
      */
-    public void deleteIfIndexed( Object object )
-        throws RepositoryIndexException, IOException
+    private void deleteIfIndexed( Artifact artifact )
+        throws RepositoryIndexException
     {
-        if ( object instanceof Artifact )
+        try
         {
-            Artifact artifact = (Artifact) object;
-            if ( indexExists() )
-            {
-                validateIndex( FIELDS );
-                deleteDocument( FLD_ID, ARTIFACT + ":" + artifact.getId() );
-            }
+            deleteDocument( FLD_ID, ARTIFACT + ":" + artifact.getId() );
+        }
+        catch ( IOException e )
+        {
+            throw new RepositoryIndexException( "Failed to delete a document", e );
+        }
+    }
+
+    public void indexArtifacts( List artifactList )
+        throws RepositoryIndexException
+    {
+        try
+        {
+            deleteDocuments( getTermList( artifactList ) );
+        }
+        catch( IOException e )
+        {
+            throw new RepositoryIndexException( "Failed to delete an index document", e );
+        }
+
+        addDocuments( getDocumentList( artifactList ) );
+    }
+
+    private List getTermList( List artifactList )
+    {
+        List list = new ArrayList();
+
+        for ( Iterator artifacts = artifactList.iterator(); artifacts.hasNext(); )
+        {
+            Artifact artifact = (Artifact) artifacts.next();
+
+            list.add( new Term( FLD_ID, ARTIFACT + ":" + artifact.getId() ) );
         }
-        else
+
+        return list;
+    }
+
+    private List getDocumentList( List artifactList )
+        throws RepositoryIndexException
+    {
+        List list = new ArrayList();
+
+        for ( Iterator artifacts = artifactList.iterator(); artifacts.hasNext(); )
         {
-            throw new RepositoryIndexException( "Object is not of type artifact." );
+            Artifact artifact = (Artifact) artifacts.next();
+
+            list.add( createDocument( artifact ) );
         }
+
+        return list;
     }
 
     /**
@@ -84,6 +132,12 @@ public class ArtifactRepositoryIndex
      */
     public void indexArtifact( Artifact artifact )
         throws RepositoryIndexException
+    {
+        indexArtifacts( Collections.singletonList( artifact ) );
+    }
+
+    private Document createDocument( Artifact artifact )
+        throws RepositoryIndexException
     {
         StringBuffer classes = new StringBuffer();
         StringBuffer packages = new StringBuffer();
@@ -158,21 +212,10 @@ public class ArtifactRepositoryIndex
         int i = artifact.getFile().getName().lastIndexOf( '.' );
         doc.add( Field.Text( FLD_PACKAGING, artifact.getFile().getName().substring( i + 1 ) ) );
 
-        try
-        {
-            deleteIfIndexed( artifact );
-            if ( !isOpen() )
-            {
-                open();
-            }
-            getIndexWriter().addDocument( doc );
-        }
-        catch ( IOException e )
-        {
-            throw new RepositoryIndexException( "Error opening index", e );
-        }
+        return doc;
     }
 
+
     /**
      * Method to add a class package to the buffer of packages
      *
index 61d15e537be69f09bcb0e0fff95cc68e40073641..52795d84ccdae52acee4132b99fafb5fdfbb91ea 100644 (file)
@@ -37,6 +37,10 @@ import java.io.IOException;
 import java.io.Reader;
 import java.security.NoSuchAlgorithmException;
 import java.util.Enumeration;
+import java.util.Collections;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
@@ -69,6 +73,7 @@ public class EclipseRepositoryIndex
      * @param digester   the digester object to generate the checksum strings
      */
     public EclipseRepositoryIndex( File indexPath, ArtifactRepository repository, Digester digester )
+        throws RepositoryIndexException
     {
         super( indexPath, repository );
 
@@ -83,6 +88,26 @@ public class EclipseRepositoryIndex
         return new EclipseIndexAnalyzer( new SimpleAnalyzer() );
     }
 
+    public void indexArtifacts( List artifactList )
+        throws RepositoryIndexException
+    {
+        List docs = new ArrayList();
+
+        for ( Iterator artifacts = artifactList.iterator(); artifacts.hasNext(); )
+        {
+            Artifact artifact = (Artifact) artifacts.next();
+
+            Document doc = createDocument( artifact );
+
+            if ( doc != null )
+            {
+                docs.add( doc );
+            }
+        }
+
+        addDocuments( docs );
+    }
+
     /**
      * Method to index a given artifact for use with the eclipse plugin
      *
@@ -92,6 +117,18 @@ public class EclipseRepositoryIndex
     public void indexArtifact( Artifact artifact )
         throws RepositoryIndexException
     {
+        Document doc = createDocument( artifact );
+        if ( doc != null )
+        {
+            addDocuments( Collections.singletonList( doc ) );
+        }
+    }
+
+    private Document createDocument( Artifact artifact )
+        throws RepositoryIndexException
+    {
+        Document doc = null;
+
         File artifactFile = artifact.getFile();
         if ( artifactFile != null && artifactFile.getName().endsWith( ".jar" ) && artifactFile.exists() )
         {
@@ -138,26 +175,15 @@ public class EclipseRepositoryIndex
                 throw new RepositoryIndexException( "Error reading from artifact file", e );
             }
 
-            Document doc = new Document();
+            doc = new Document();
             doc.add( Field.Text( MD5, md5 ) );
             doc.add( Field.Text( JAR_NAME, artifactFile.getName() ) );
             doc.add( Field.Text( JAR_DATE, DateField.timeToString( artifactFile.lastModified() ) ) );
             doc.add( Field.Text( JAR_SIZE, Long.toString( artifactFile.length() ) ) );
             doc.add( Field.Text( NAMES, classes.toString() ) );
-
-            try
-            {
-                if ( !isOpen() )
-                {
-                    open();
-                }
-                getIndexWriter().addDocument( doc );
-            }
-            catch ( IOException e )
-            {
-                throw new RepositoryIndexException( "Error opening index.", e );
-            }
         }
+
+        return doc;
     }
 
     /**
@@ -214,46 +240,6 @@ public class EclipseRepositoryIndex
         zos.closeEntry();
     }
 
-    /**
-     * @see AbstractRepositoryIndex#deleteIfIndexed(Object)
-     */
-    public void deleteIfIndexed( Object object )
-        throws RepositoryIndexException, IOException
-    {
-        if ( object instanceof Artifact )
-        {
-            Artifact artifact = (Artifact) object;
-            if ( indexExists() )
-            {
-                validateIndex( FIELDS );
-
-                String md5;
-                try
-                {
-                    md5 = digester.createChecksum( artifact.getFile(), "MD5" );
-                }
-                catch ( FileNotFoundException e )
-                {
-                    throw new RepositoryIndexException( "Unable to create index.", e );
-                }
-                catch ( NoSuchAlgorithmException e )
-                {
-                    throw new RepositoryIndexException( "Unable to create index.", e );
-                }
-                catch ( IOException e )
-                {
-                    throw new RepositoryIndexException( "Unable to create index.", e );
-                }
-
-                deleteDocument( MD5, md5 );
-            }
-        }
-        else
-        {
-            throw new RepositoryIndexException( "Object is not of type artifact." );
-        }
-    }
-
     /**
      * Class used to analyze the lucene index
      */
index 8e38f3070c851a74f0e8178bd3c9169170ecc7b5..6fad583adcba017b951dac62d0362e7b93d2df91 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.maven.repository.indexing;
 \r
 import org.apache.lucene.document.Document;\r
 import org.apache.lucene.document.Field;\r
+import org.apache.lucene.index.Term;\r
 import org.apache.maven.artifact.repository.ArtifactRepository;\r
 import org.apache.maven.artifact.repository.metadata.Metadata;\r
 import org.apache.maven.artifact.repository.metadata.Plugin;\r
@@ -28,6 +29,8 @@ import java.io.File;
 import java.io.IOException;\r
 import java.util.Iterator;\r
 import java.util.List;\r
+import java.util.Collections;\r
+import java.util.ArrayList;\r
 \r
 /**\r
  * This class indexes the metadata in the repository.\r
@@ -42,38 +45,67 @@ public class MetadataRepositoryIndex
      * @param repository the repository where the metadata to be indexed is located\r
      */\r
     public MetadataRepositoryIndex( File indexPath, ArtifactRepository repository )\r
+        throws RepositoryIndexException\r
     {\r
         super( indexPath, repository );\r
     }\r
 \r
     /**\r
-     * Index the paramater object\r
+     * Index the contents of the specified RepositoryMetadata paramter object\r
      *\r
-     * @param obj\r
+     * @param repoMetadata the metadata object to be indexed\r
      * @throws RepositoryIndexException\r
      */\r
-    public void index( Object obj )\r
+    public void indexMetadata( RepositoryMetadata repoMetadata )\r
+        throws RepositoryIndexException\r
+    {\r
+        indexMetadata( Collections.singletonList( repoMetadata ) );\r
+    }\r
+\r
+    public void indexMetadata( List metadataList )\r
         throws RepositoryIndexException\r
     {\r
-        if ( obj instanceof RepositoryMetadata )\r
+        try\r
         {\r
-            indexMetadata( (RepositoryMetadata) obj );\r
+            deleteDocuments( getTermList( metadataList ) );\r
         }\r
-        else\r
+        catch( IOException e )\r
         {\r
-            throw new RepositoryIndexException(\r
-                "This instance of indexer cannot index instances of " + obj.getClass().getName() );\r
+            throw new RepositoryIndexException( "Failed to delete an index document", e );\r
         }\r
+\r
+        addDocuments( getDocumentList( metadataList ) );\r
     }\r
 \r
-    /**\r
-     * Index the contents of the specified RepositoryMetadata paramter object\r
-     *\r
-     * @param repoMetadata the metadata object to be indexed\r
-     * @throws RepositoryIndexException\r
-     */\r
-    private void indexMetadata( RepositoryMetadata repoMetadata )\r
-        throws RepositoryIndexException\r
+    private List getTermList( List metadataList )\r
+    {\r
+        List terms = new ArrayList();\r
+\r
+        for ( Iterator metadata = metadataList.iterator(); metadata.hasNext(); )\r
+        {\r
+            RepositoryMetadata repoMetadata = (RepositoryMetadata) metadata.next();\r
+\r
+            terms.add( new Term( FLD_ID, (String) repoMetadata.getKey() ) );\r
+        }\r
+\r
+        return terms;\r
+    }\r
+\r
+    private List getDocumentList( List metadataList )\r
+    {\r
+        List docs = new ArrayList();\r
+\r
+        for ( Iterator metadata = metadataList.iterator(); metadata.hasNext(); )\r
+        {\r
+            RepositoryMetadata repoMetadata = (RepositoryMetadata) metadata.next();\r
+\r
+            docs.add( createDocument( repoMetadata ) );\r
+        }\r
+\r
+        return docs;\r
+    }\r
+\r
+    private Document createDocument( RepositoryMetadata repoMetadata )\r
     {\r
         //get lastUpdated from Versioning (specified in Metadata object)\r
         //get pluginPrefixes from Plugin (spcified in Metadata object) -----> concatenate/append???\r
@@ -138,40 +170,19 @@ public class MetadataRepositoryIndex
         doc.add( Field.Keyword( FLD_PLUGINS_BUILD, "" ) );\r
         doc.add( Field.Keyword( FLD_PLUGINS_REPORT, "" ) );\r
         doc.add( Field.Keyword( FLD_PLUGINS_ALL, "" ) );\r
-\r
-        try\r
-        {\r
-            deleteIfIndexed( repoMetadata );\r
-            if ( !isOpen() )\r
-            {\r
-                open();\r
-            }\r
-            getIndexWriter().addDocument( doc );\r
-        }\r
-        catch ( IOException e )\r
-        {\r
-            throw new RepositoryIndexException( "Error opening index", e );\r
-        }\r
+        return doc;\r
     }\r
 \r
-    /**\r
-     * @see org.apache.maven.repository.indexing.AbstractRepositoryIndex#deleteIfIndexed(Object)\r
-     */\r
-    public void deleteIfIndexed( Object object )\r
-        throws RepositoryIndexException, IOException\r
+    private void deleteIfIndexed( RepositoryMetadata repoMetadata )\r
+        throws RepositoryIndexException\r
     {\r
-        if ( object instanceof RepositoryMetadata )\r
+        try\r
         {\r
-            RepositoryMetadata repoMetadata = (RepositoryMetadata) object;\r
-            if ( indexExists() )\r
-            {\r
-                validateIndex( FIELDS );\r
-                deleteDocument( FLD_ID, (String) repoMetadata.getKey() );\r
-            }\r
+            deleteDocument( FLD_ID, (String) repoMetadata.getKey() );\r
         }\r
-        else\r
+        catch ( IOException e )\r
         {\r
-            throw new RepositoryIndexException( "Object is not of type metadata." );\r
+            throw new RepositoryIndexException( "Failed to delete document", e );\r
         }\r
     }\r
 }\r
index 6e95e85d64bc09676985d5d17d7f457f92563df7..7ca9f017918bc181fe123b79abf5bd42b07a7ef2 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.maven.repository.indexing;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
+import org.apache.lucene.index.Term;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -33,6 +34,8 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
@@ -58,32 +61,24 @@ public class PomRepositoryIndex
      */
     public PomRepositoryIndex( File indexPath, ArtifactRepository repository, Digester digester,
                                ArtifactFactory artifactFactory )
+        throws RepositoryIndexException
     {
         super( indexPath, repository );
         this.digester = digester;
         this.artifactFactory = artifactFactory;
     }
 
-    /**
-     * @see org.apache.maven.repository.indexing.AbstractRepositoryIndex#deleteIfIndexed(Object)
-     */
-    public void deleteIfIndexed( Object object )
-        throws RepositoryIndexException, IOException
+    private void deleteIfIndexed( Model pom )
+        throws RepositoryIndexException
     {
-        if ( object instanceof Model )
+        try
         {
-            Model pom = (Model) object;
-            if ( indexExists() )
-            {
-                validateIndex( FIELDS );
-                deleteDocument( FLD_ID, POM + ":" + pom.getId() );
-            }
+            deleteDocument( FLD_ID, POM + ":" + pom.getId() );
         }
-        else
+        catch ( IOException e )
         {
-            throw new RepositoryIndexException( "Object is not of type model." );
+            throw new RepositoryIndexException( "Failed to delete document", e  );
         }
-
     }
 
     /**
@@ -94,6 +89,56 @@ public class PomRepositoryIndex
      */
     public void indexPom( Model pom )
         throws RepositoryIndexException
+    {
+        indexPoms( Collections.singletonList( pom ) );
+    }
+
+    public void indexPoms( List pomList )
+        throws RepositoryIndexException
+    {
+        try
+        {
+            deleteDocuments( getTermList( pomList ) );
+        }
+        catch( IOException e )
+        {
+            throw new RepositoryIndexException( "Failed to delete an index document", e );
+        }
+
+        addDocuments( getDocumentList( pomList ) );
+    }
+
+    private List getTermList( List pomList )
+    {
+        List terms = new ArrayList();
+
+        for ( Iterator poms = pomList.iterator(); poms.hasNext(); )
+        {
+            Model pom = (Model) poms.next();
+
+            terms.add( new Term( FLD_ID, POM + ":" + pom.getId() ) );
+        }
+
+        return terms;
+    }
+
+    private List getDocumentList( List pomList )
+        throws RepositoryIndexException
+    {
+        List docs = new ArrayList();
+
+        for ( Iterator poms = pomList.iterator(); poms.hasNext(); )
+        {
+            Model pom = (Model) poms.next();
+
+            docs.add( createDocument( pom ) );
+        }
+
+        return docs;
+    }
+
+    private Document createDocument( Model pom )
+        throws RepositoryIndexException
     {
         Document doc = new Document();
         doc.add( Field.Keyword( FLD_ID, POM + ":" + pom.getId() ) );
@@ -147,20 +192,7 @@ public class PomRepositoryIndex
         doc.add( Field.Text( FLD_CLASSES, "" ) );
         doc.add( Field.Keyword( FLD_PACKAGES, "" ) );
         doc.add( Field.Text( FLD_FILES, "" ) );
-
-        try
-        {
-            deleteIfIndexed( pom );
-            if ( !isOpen() )
-            {
-                open();
-            }
-            getIndexWriter().addDocument( doc );
-        }
-        catch ( IOException e )
-        {
-            throw new RepositoryIndexException( "Error opening index", e );
-        }
+        return doc;
     }
 
     /**
index 6735f864f4f5578cf7c23f284eab8e4ab7922131..ecbdfd6dbe905119858f1c34510c669f945ef0f9 100644 (file)
@@ -20,6 +20,7 @@ import org.apache.lucene.analysis.Analyzer;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 
@@ -28,71 +29,58 @@ import java.util.List;
  */
 public interface RepositoryIndex
 {
-    String POM = "POM";
+    static final String POM = "POM";
 
-    String METADATA = "METADATA";
+    static final String METADATA = "METADATA";
 
-    String ARTIFACT = "ARTIFACT";
+    static final String ARTIFACT = "ARTIFACT";
 
-    String FLD_ID = "id";
+    static final String FLD_ID = "id";
 
-    String FLD_NAME = "name";
+    static final String FLD_NAME = "name";
 
-    String FLD_DOCTYPE = "doctype";
+    static final String FLD_DOCTYPE = "doctype";
 
-    String FLD_GROUPID = "groupId";
+    static final String FLD_GROUPID = "groupId";
 
-    String FLD_ARTIFACTID = "artifactId";
+    static final String FLD_ARTIFACTID = "artifactId";
 
-    String FLD_VERSION = "version";
+    static final String FLD_VERSION = "version";
 
-    String FLD_PACKAGING = "packaging";
+    static final String FLD_PACKAGING = "packaging";
 
-    String FLD_SHA1 = "sha1";
+    static final String FLD_SHA1 = "sha1";
 
-    String FLD_MD5 = "md5";
+    static final String FLD_MD5 = "md5";
 
-    String FLD_LASTUPDATE = "last update";
+    static final String FLD_LASTUPDATE = "last update";
 
-    String FLD_PLUGINPREFIX = "plugin prefix";
+    static final String FLD_PLUGINPREFIX = "plugin prefix";
 
-    String FLD_CLASSES = "class";
+    static final String FLD_CLASSES = "class";
 
-    String FLD_PACKAGES = "package";
+    static final String FLD_PACKAGES = "package";
 
-    String FLD_FILES = "file";
+    static final String FLD_FILES = "file";
 
-    String FLD_LICENSE_URLS = "license url";
+    static final String FLD_LICENSE_URLS = "license url";
 
-    String FLD_DEPENDENCIES = "dependency";
+    static final String FLD_DEPENDENCIES = "dependency";
 
-    String FLD_PLUGINS_BUILD = "build plugin";
+    static final String FLD_PLUGINS_BUILD = "build plugin";
 
-    String FLD_PLUGINS_REPORT = "report plugin";
+    static final String FLD_PLUGINS_REPORT = "report plugin";
 
-    String FLD_PLUGINS_ALL = "plugins_all";
+    static final String FLD_PLUGINS_ALL = "plugins_all";
 
-    String[] FIELDS = {FLD_ID, FLD_NAME, FLD_DOCTYPE, FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION, FLD_PACKAGING, FLD_SHA1,
+    static final String[] FIELDS = {FLD_ID, FLD_NAME, FLD_DOCTYPE, FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION, FLD_PACKAGING, FLD_SHA1,
         FLD_MD5, FLD_LASTUPDATE, FLD_PLUGINPREFIX, FLD_CLASSES, FLD_PACKAGES, FLD_FILES, FLD_LICENSE_URLS,
         FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL};
 
-    List KEYWORD_FIELDS = Arrays.asList( new String[]{FLD_ID, FLD_PACKAGING, FLD_LICENSE_URLS, FLD_DEPENDENCIES,
+    static final List KEYWORD_FIELDS = Arrays.asList( new String[]{FLD_ID, FLD_PACKAGING, FLD_LICENSE_URLS, FLD_DEPENDENCIES,
         FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL} );
 
-    String[] MODEL_FIELDS = {FLD_PACKAGING, FLD_LICENSE_URLS, FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT};
-
-    /**
-     * Method used to query the index status
-     *
-     * @return true if the index is open.
-     */
-    boolean isOpen();
-
-    /**
-     * Method to close open streams to the index directory
-     */
-    void close()
-        throws RepositoryIndexException;
+    static final String[] MODEL_FIELDS = {FLD_PACKAGING, FLD_LICENSE_URLS, FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT};
 
     ArtifactRepository getRepository();
 
@@ -123,4 +111,18 @@ public interface RepositoryIndex
      * @return true if the index field passed is a keyword, otherwise its false
      */
     boolean isKeywordField( String field );
+
+    /**
+     * method for validating an index directory
+     *
+     * @throws RepositoryIndexException if the given indexPath is not valid for this type of RepositoryIndex
+     */
+    public void validate()
+        throws RepositoryIndexException, IOException;
+
+    public void addDocuments( List docList )
+        throws RepositoryIndexException;
+
+    public void deleteDocuments( List termList )
+        throws RepositoryIndexException, IOException;
 }
index c9dd41e7fd8fa10b08802ee13c9dfd787f564517..fe16c022c3c4856385990916b075f26a046fa5a4 100644 (file)
@@ -27,11 +27,6 @@ public class RepositoryIndexException
         super( message, cause );
     }
 
-    public RepositoryIndexException( Throwable cause )
-    {
-        super( cause );
-    }
-
     public RepositoryIndexException( String message )
     {
         super( message );
index f3035360f63e251e9a36bcc20cd555e1f8659c73..cd84bde19fbd0f5a796f1e1eaeaa069cf3fa9fdd 100644 (file)
@@ -26,14 +26,4 @@ public class RepositoryIndexSearchException
     {
         super( message, cause );
     }
-
-    public RepositoryIndexSearchException( Throwable cause )
-    {
-        super( cause );
-    }
-
-    public RepositoryIndexSearchException( String message )
-    {
-        super( message );
-    }
 }
index b04e804334f50fa7f0bee5c995acc1dbf75e8eec..07406450459db76053c8b9b91acd604d00bb1b24 100644 (file)
@@ -32,6 +32,7 @@ import org.codehaus.plexus.util.FileUtils;
 import java.io.File;
 import java.util.Iterator;
 import java.util.List;
+import java.util.ArrayList;
 
 /**
  * @author Edwin Punzalan
@@ -98,17 +99,6 @@ public class ArtifactRepositoryIndexingTest
         {
             assertTrue( true );
         }
-
-        ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
-        try
-        {
-            indexer.deleteIfIndexed( new Object() );
-            fail( "Must throw exception on object not of type artifact." );
-        }
-        catch ( RepositoryIndexException e )
-        {
-            assertTrue( true );
-        }
     }
 
     /**
@@ -124,30 +114,27 @@ public class ArtifactRepositoryIndexingTest
         RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
         ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
 
+        List artifacts = new ArrayList();
+
         Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" );
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
-        indexer.indexArtifact( artifact );
-        indexer.optimize();
-        indexer.close();
+        artifacts.add( artifact );
 
         artifact = getArtifact( "org.apache.maven", "maven-model", "2.0" );
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
-        indexer.indexArtifact( artifact );
-        indexer.optimize();
-        indexer.close();
+        artifacts.add( artifact );
 
         artifact = getArtifact( "test", "test-artifactId", "1.0" );
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
-        indexer.indexArtifact( artifact );
-        indexer.optimize();
-        indexer.close();
+        artifacts.add( artifact );
+
+        indexer.indexArtifacts( artifacts );
 
         artifact = getArtifact( "test", "test-artifactId", "1.0" );
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
         indexer.indexArtifact( artifact );
-        indexer.optimize();
-        indexer.close();
 
+        indexer.optimize();
     }
 
     /**
@@ -274,8 +261,6 @@ public class ArtifactRepositoryIndexingTest
             String md5Tmp = digester.createChecksum( artifact2.getFile(), Digester.MD5 );
             assertEquals( md5, md5Tmp );
         }
-
-        indexer.close();
     }
 
     /**
@@ -402,8 +387,6 @@ public class ArtifactRepositoryIndexingTest
             assertEquals( "maven-artifact", artifact.getArtifactId() );
             assertEquals( "org.apache.maven", artifact.getGroupId() );
         }
-
-        indexer.close();
     }
 
     /**
index 19974cbd932fc4634e91c1449c20814b36f992b6..5ebff559dfbbb4f3aee3730f50b12443df4ff0d8 100644 (file)
@@ -32,6 +32,8 @@ import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * @author Edwin Punzalan
@@ -79,35 +81,33 @@ public class EclipseRepositoryIndexTest
     {
         EclipseRepositoryIndex indexer = new EclipseRepositoryIndex( indexPath, repository, new DefaultDigester() );
 
+        List artifacts = new ArrayList();
+
         Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" );
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
         artifactFileTime = artifact.getFile().lastModified();
-        indexer.indexArtifact( artifact );
-        indexer.optimize();
-        indexer.close();
+        artifacts.add( artifact );
 
         long historicTime = artifactFileTime - TIME_DIFFERENCE;
 
         artifact = getArtifact( "org.apache.maven", "maven-model", "2.0" );
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
         artifact.getFile().setLastModified( historicTime );
-        indexer.indexArtifact( artifact );
-        indexer.optimize();
-        indexer.close();
+        artifacts.add( artifact );
 
         artifact = getArtifact( "test", "test-artifactId", "1.0" );
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
         artifact.getFile().setLastModified( historicTime );
-        indexer.indexArtifact( artifact );
-        indexer.optimize();
-        indexer.close();
+        artifacts.add( artifact );
+
+        indexer.indexArtifacts( artifacts );
 
         artifact = getArtifact( "test", "test-artifactId", "1.0" );
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
         artifact.getFile().setLastModified( historicTime );
         indexer.indexArtifact( artifact );
+
         indexer.optimize();
-        indexer.close();
 
         return indexer;
     }
@@ -146,17 +146,6 @@ public class EclipseRepositoryIndexTest
         {
             assertTrue( true );
         }
-
-        EclipseRepositoryIndex indexer = new EclipseRepositoryIndex( indexPath, repository, digester );
-        try
-        {
-            indexer.deleteIfIndexed( new Object() );
-            fail( "Must throw exception on object not of type artifact." );
-        }
-        catch ( RepositoryIndexException e )
-        {
-            assertTrue( true );
-        }
     }
 
     /**
index ba3a072db20451fc05b45b7cddee32dec0caae38..85147895563aa130260d3cbfabd9f3cd53102d24 100644 (file)
@@ -43,6 +43,7 @@ import java.io.FileReader;
 import java.io.IOException;\r
 import java.util.Iterator;\r
 import java.util.List;\r
+import java.util.ArrayList;\r
 \r
 /**\r
  * This class tests the MetadataRepositoryIndex.\r
@@ -100,30 +101,27 @@ public class MetadataRepositoryIndexingTest
         RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );\r
         MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );\r
 \r
+        List metadataList = new ArrayList();\r
+\r
         RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" );\r
         repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
-        indexer.index( repoMetadata );\r
-        indexer.optimize();\r
-        indexer.close();\r
+        metadataList.add( repoMetadata );\r
 \r
         repoMetadata = new ArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) );\r
         repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
-        indexer.index( repoMetadata );\r
-        indexer.optimize();\r
-        indexer.close();\r
+        metadataList.add( repoMetadata );\r
 \r
         repoMetadata =\r
             new SnapshotArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) );\r
         repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
-        indexer.index( repoMetadata );\r
-        indexer.optimize();\r
-        indexer.close();\r
+        metadataList.add( repoMetadata );\r
 \r
         repoMetadata = new GroupRepositoryMetadata( "test" );\r
         repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
-        indexer.index( repoMetadata );\r
+        metadataList.add( repoMetadata );\r
+\r
+        indexer.indexMetadata( metadataList );\r
         indexer.optimize();\r
-        indexer.close();\r
     }\r
 \r
     /**\r
@@ -207,43 +205,6 @@ public class MetadataRepositoryIndexingTest
 \r
         metadataList = repoSearchLayer.searchAdvanced( rQry, indexer );\r
         assertEquals( 0, metadataList.size() );\r
-\r
-        indexer.close();\r
-    }\r
-\r
-    /**\r
-     * Test the exceptions thrown by MetadataRepositoryIndex.\r
-     *\r
-     * @throws Exception\r
-     */\r
-    public void testExceptions()\r
-        throws Exception\r
-    {\r
-        //test when the object passed in the index(..) method is not a RepositoryMetadata instance\r
-        RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );\r
-        MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );\r
-        try\r
-        {\r
-            Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" );\r
-            indexer.index( artifact );\r
-            fail( "Must throw exception when the passed object is not a RepositoryMetadata object." );\r
-            indexer.optimize();\r
-            indexer.close();\r
-        }\r
-        catch ( RepositoryIndexException e )\r
-        {\r
-            assertTrue( true );\r
-        }\r
-\r
-        try\r
-        {\r
-            indexer.deleteIfIndexed( new Object() );\r
-            fail( "Must throw exception when the passed object is not of type metadata." );\r
-        }\r
-        catch ( RepositoryIndexException e )\r
-        {\r
-            assertTrue( true );\r
-        }\r
     }\r
 \r
     /**\r
index fe0aa1d41e2cb91b193548c86060671a35930575..6c60070125a61df1c27b44c70fabb273cbcaea48 100644 (file)
@@ -98,17 +98,6 @@ public class PomRepositoryIndexingTest
         {
             assertTrue( true );
         }
-
-        PomRepositoryIndex indexer = factory.createPomRepositoryIndex( indexPath, repository );
-        try
-        {
-            indexer.deleteIfIndexed( new Object() );
-            fail( "Must throw exception when the passed object is not of type model." );
-        }
-        catch ( RepositoryIndexException e )
-        {
-            assertTrue( true );
-        }
     }
 
     /**
@@ -299,8 +288,6 @@ public class PomRepositoryIndexingTest
             String md5Tmp = digester.createChecksum( getPomFile( artifact2 ), Digester.MD5 );
             assertEquals( md5, md5Tmp );
         }
-
-        indexer.close();
     }
 
     /**
@@ -430,8 +417,6 @@ public class PomRepositoryIndexingTest
             assertEquals( "maven-artifact", artifact.getArtifactId() );
             assertEquals( "org.apache.maven", artifact.getGroupId() );
         }
-
-        indexer.close();
     }
 
     /**
@@ -449,23 +434,17 @@ public class PomRepositoryIndexingTest
 
         Model pom = getPom( "org.apache.maven", "maven-artifact", "2.0.1" );
         indexer.indexPom( pom );
-        indexer.optimize();
-        indexer.close();
 
         pom = getPom( "org.apache.maven", "maven-model", "2.0" );
         indexer.indexPom( pom );
-        indexer.optimize();
-        indexer.close();
 
         pom = getPom( "test", "test-artifactId", "1.0" );
         indexer.indexPom( pom );
-        indexer.optimize();
-        indexer.close();
 
         pom = getPom( "test", "test-artifactId", "1.0" );
         indexer.indexPom( pom );
+
         indexer.optimize();
-        indexer.close();
     }
 
     /**
index 5b425a5525b5a472af8f799ffdafd5557c1bbee1..035239bdb3c55f5aba35236501b69f415780eb47 100644 (file)
@@ -89,74 +89,54 @@ public class RepositoryIndexSearchLayerTest
         Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" );\r
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );\r
         indexer.indexArtifact( artifact );\r
-        indexer.optimize();\r
-        indexer.close();\r
 \r
         artifact = getArtifact( "org.apache.maven", "maven-model", "2.0" );\r
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );\r
         indexer.indexArtifact( artifact );\r
-        indexer.optimize();\r
-        indexer.close();\r
 \r
         artifact = getArtifact( "test", "test-artifactId", "1.0" );\r
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );\r
         indexer.indexArtifact( artifact );\r
-        indexer.optimize();\r
-        indexer.close();\r
 \r
         artifact = getArtifact( "test", "test-artifactId", "1.0" );\r
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );\r
         indexer.indexArtifact( artifact );\r
-        indexer.optimize();\r
-        indexer.close();\r
 \r
         MetadataRepositoryIndex metaIndexer = factory.createMetadataRepositoryIndex( indexPath, repository );\r
         RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" );\r
         repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
-        metaIndexer.index( repoMetadata );\r
-        metaIndexer.optimize();\r
-        metaIndexer.close();\r
+        metaIndexer.indexMetadata( repoMetadata );\r
 \r
         repoMetadata = new ArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) );\r
         repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
-        metaIndexer.index( repoMetadata );\r
-        metaIndexer.optimize();\r
-        metaIndexer.close();\r
+        metaIndexer.indexMetadata( repoMetadata );\r
 \r
         repoMetadata =\r
             new SnapshotArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) );\r
         repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
-        metaIndexer.index( repoMetadata );\r
-        metaIndexer.optimize();\r
-        metaIndexer.close();\r
+        metaIndexer.indexMetadata( repoMetadata );\r
 \r
         repoMetadata = new GroupRepositoryMetadata( "test" );\r
         repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
-        metaIndexer.index( repoMetadata );\r
+        metaIndexer.indexMetadata( repoMetadata );\r
+\r
         metaIndexer.optimize();\r
-        metaIndexer.close();\r
 \r
         PomRepositoryIndex pomIndexer = factory.createPomRepositoryIndex( indexPath, repository );\r
 \r
         Model pom = getPom( "org.apache.maven", "maven-artifact", "2.0.1" );\r
         pomIndexer.indexPom( pom );\r
-        pomIndexer.optimize();\r
-        pomIndexer.close();\r
 \r
         pom = getPom( "org.apache.maven", "maven-model", "2.0" );\r
         pomIndexer.indexPom( pom );\r
-        pomIndexer.optimize();\r
-        pomIndexer.close();\r
 \r
         pom = getPom( "test", "test-artifactId", "1.0" );\r
         pomIndexer.indexPom( pom );\r
-        pomIndexer.optimize();\r
-        pomIndexer.close();\r
 \r
         pom = getPom( "test", "test-artifactId", "1.0" );\r
         pomIndexer.indexPom( pom );\r
+\r
         pomIndexer.optimize();\r
-        pomIndexer.close();\r
     }\r
 \r
     /**\r
index b7933d152af7c53fb390ecd6e7b0a7e2dafd6788..7664cc27ae6f6a812e4491084b07e4d01067de2b 100644 (file)
@@ -21,7 +21,6 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.model.Model;
 import org.apache.maven.repository.digest.Digester;
 import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
-import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
 
@@ -65,7 +64,6 @@ public class DuplicateArtifactFileReportProcessorTest
         ArtifactRepositoryIndex index = new ArtifactRepositoryIndex( indexDirectory, repository, digester );
         index.indexArtifact( artifact );
         index.optimize();
-        index.close();
 
         processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate" );
     }
index 4e1dfbff21308f48946980df8760cc27e2d8341d..c059cd7cb5514022652aa490f7c18c0ac1bf7ee4 100644 (file)
@@ -17,13 +17,10 @@ package org.apache.maven.repository.manager.web.execution;
  */
 
 import org.apache.lucene.index.IndexReader;
-import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
 import org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
-import org.apache.maven.model.Model;
 import org.apache.maven.repository.configuration.Configuration;
 import org.apache.maven.repository.discovery.ArtifactDiscoverer;
 import org.apache.maven.repository.discovery.MetadataDiscoverer;
@@ -36,7 +33,6 @@ import org.codehaus.plexus.logging.AbstractLogEnabled;
 
 import java.io.File;
 import java.net.MalformedURLException;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -138,17 +134,8 @@ public class DiscovererExecution
         throws RepositoryIndexException
     {
         ArtifactRepositoryIndex artifactIndex = indexFactory.createArtifactRepositoryIndex( indexPath, repository );
-        for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
-        {
-            Artifact artifact = (Artifact) iter.next();
-            artifactIndex.indexArtifact( artifact );
-
-            if ( artifactIndex.isOpen() )
-            {
-                artifactIndex.optimize();
-                artifactIndex.close();
-            }
-        }
+        artifactIndex.indexArtifacts( artifacts );
+        artifactIndex.optimize();
     }
 
     /**
@@ -161,17 +148,8 @@ public class DiscovererExecution
         throws RepositoryIndexException, MalformedURLException
     {
         MetadataRepositoryIndex metadataIndex = indexFactory.createMetadataRepositoryIndex( indexPath, repository );
-        for ( Iterator iter = metadataList.iterator(); iter.hasNext(); )
-        {
-            RepositoryMetadata repoMetadata = (RepositoryMetadata) iter.next();
-            metadataIndex.index( repoMetadata );
-
-            if ( metadataIndex.isOpen() )
-            {
-                metadataIndex.optimize();
-                metadataIndex.close();
-            }
-        }
+        metadataIndex.indexMetadata( metadataList );
+        metadataIndex.optimize();
     }
 
     /**
@@ -185,17 +163,8 @@ public class DiscovererExecution
         throws RepositoryIndexException
     {
         PomRepositoryIndex pomIndex = indexFactory.createPomRepositoryIndex( indexPath, repository );
-        for ( Iterator iter = models.iterator(); iter.hasNext(); )
-        {
-            Model model = (Model) iter.next();
-            pomIndex.indexPom( model );
-
-            if ( pomIndex.isOpen() )
-            {
-                pomIndex.optimize();
-                pomIndex.close();
-            }
-        }
+        pomIndex.indexPoms( models );
+        pomIndex.optimize();
     }
 
     /**