From 78f88941cf9ff94134ab9f103c446724e1edf175 Mon Sep 17 00:00:00 2001 From: "Edwin L. Punzalan" Date: Thu, 15 Jun 2006 10:25:38 +0000 Subject: [PATCH] Improved the indexing module * 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 --- .../indexing/AbstractRepositoryIndex.java | 181 ++++++++++-------- .../indexing/ArtifactRepositoryIndex.java | 93 ++++++--- .../indexing/EclipseRepositoryIndex.java | 94 ++++----- .../indexing/MetadataRepositoryIndex.java | 99 +++++----- .../indexing/PomRepositoryIndex.java | 90 ++++++--- .../repository/indexing/RepositoryIndex.java | 78 ++++---- .../indexing/RepositoryIndexException.java | 5 - .../RepositoryIndexSearchException.java | 10 - .../ArtifactRepositoryIndexingTest.java | 35 +--- .../indexing/EclipseRepositoryIndexTest.java | 31 +-- .../MetadataRepositoryIndexingTest.java | 57 +----- .../indexing/PomRepositoryIndexingTest.java | 23 +-- .../RepositoryIndexSearchLayerTest.java | 32 +--- ...licateArtifactFileReportProcessorTest.java | 2 - .../web/execution/DiscovererExecution.java | 43 +---- 15 files changed, 403 insertions(+), 470 deletions(-) diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java index 2c21027ad..5903cebb6 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java @@ -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 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 09b1674af..9d669af64 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 @@ -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 * diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/EclipseRepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/EclipseRepositoryIndex.java index 61d15e537..52795d84c 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/EclipseRepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/EclipseRepositoryIndex.java @@ -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 */ diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndex.java index 8e38f3070..6fad583ad 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndex.java @@ -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.repository.ArtifactRepository; import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.artifact.repository.metadata.Plugin; @@ -28,6 +29,8 @@ import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.List; +import java.util.Collections; +import java.util.ArrayList; /** * This class indexes the metadata in the repository. @@ -42,38 +45,67 @@ public class MetadataRepositoryIndex * @param repository the repository where the metadata to be indexed is located */ public MetadataRepositoryIndex( File indexPath, ArtifactRepository repository ) + throws RepositoryIndexException { super( indexPath, repository ); } /** - * Index the paramater object + * Index the contents of the specified RepositoryMetadata paramter object * - * @param obj + * @param repoMetadata the metadata object to be indexed * @throws RepositoryIndexException */ - public void index( Object obj ) + public void indexMetadata( RepositoryMetadata repoMetadata ) + throws RepositoryIndexException + { + indexMetadata( Collections.singletonList( repoMetadata ) ); + } + + public void indexMetadata( List metadataList ) throws RepositoryIndexException { - if ( obj instanceof RepositoryMetadata ) + try { - indexMetadata( (RepositoryMetadata) obj ); + deleteDocuments( getTermList( metadataList ) ); } - else + catch( IOException e ) { - throw new RepositoryIndexException( - "This instance of indexer cannot index instances of " + obj.getClass().getName() ); + throw new RepositoryIndexException( "Failed to delete an index document", e ); } + + addDocuments( getDocumentList( metadataList ) ); } - /** - * Index the contents of the specified RepositoryMetadata paramter object - * - * @param repoMetadata the metadata object to be indexed - * @throws RepositoryIndexException - */ - private void indexMetadata( RepositoryMetadata repoMetadata ) - throws RepositoryIndexException + private List getTermList( List metadataList ) + { + List terms = new ArrayList(); + + for ( Iterator metadata = metadataList.iterator(); metadata.hasNext(); ) + { + RepositoryMetadata repoMetadata = (RepositoryMetadata) metadata.next(); + + terms.add( new Term( FLD_ID, (String) repoMetadata.getKey() ) ); + } + + return terms; + } + + private List getDocumentList( List metadataList ) + { + List docs = new ArrayList(); + + for ( Iterator metadata = metadataList.iterator(); metadata.hasNext(); ) + { + RepositoryMetadata repoMetadata = (RepositoryMetadata) metadata.next(); + + docs.add( createDocument( repoMetadata ) ); + } + + return docs; + } + + private Document createDocument( RepositoryMetadata repoMetadata ) { //get lastUpdated from Versioning (specified in Metadata object) //get pluginPrefixes from Plugin (spcified in Metadata object) -----> concatenate/append??? @@ -138,40 +170,19 @@ public class MetadataRepositoryIndex doc.add( Field.Keyword( FLD_PLUGINS_BUILD, "" ) ); doc.add( Field.Keyword( FLD_PLUGINS_REPORT, "" ) ); doc.add( Field.Keyword( FLD_PLUGINS_ALL, "" ) ); - - try - { - deleteIfIndexed( repoMetadata ); - if ( !isOpen() ) - { - open(); - } - getIndexWriter().addDocument( doc ); - } - catch ( IOException e ) - { - throw new RepositoryIndexException( "Error opening index", e ); - } + return doc; } - /** - * @see org.apache.maven.repository.indexing.AbstractRepositoryIndex#deleteIfIndexed(Object) - */ - public void deleteIfIndexed( Object object ) - throws RepositoryIndexException, IOException + private void deleteIfIndexed( RepositoryMetadata repoMetadata ) + throws RepositoryIndexException { - if ( object instanceof RepositoryMetadata ) + try { - RepositoryMetadata repoMetadata = (RepositoryMetadata) object; - if ( indexExists() ) - { - validateIndex( FIELDS ); - deleteDocument( FLD_ID, (String) repoMetadata.getKey() ); - } + deleteDocument( FLD_ID, (String) repoMetadata.getKey() ); } - else + catch ( IOException e ) { - throw new RepositoryIndexException( "Object is not of type metadata." ); + throw new RepositoryIndexException( "Failed to delete document", e ); } } } diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java index 6e95e85d6..7ca9f0179 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java @@ -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; } /** diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java index 6735f864f..ecbdfd6db 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java @@ -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; } diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java index c9dd41e7f..fe16c022c 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java @@ -27,11 +27,6 @@ public class RepositoryIndexException super( message, cause ); } - public RepositoryIndexException( Throwable cause ) - { - super( cause ); - } - public RepositoryIndexException( String message ) { super( message ); diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java index f3035360f..cd84bde19 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java @@ -26,14 +26,4 @@ public class RepositoryIndexSearchException { super( message, cause ); } - - public RepositoryIndexSearchException( Throwable cause ) - { - super( cause ); - } - - public RepositoryIndexSearchException( String message ) - { - super( message ); - } } 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 b04e80433..074064504 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 @@ -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(); } /** diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/EclipseRepositoryIndexTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/EclipseRepositoryIndexTest.java index 19974cbd9..5ebff559d 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/EclipseRepositoryIndexTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/EclipseRepositoryIndexTest.java @@ -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 ); - } } /** diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java index ba3a072db..851478955 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java @@ -43,6 +43,7 @@ import java.io.FileReader; import java.io.IOException; import java.util.Iterator; import java.util.List; +import java.util.ArrayList; /** * This class tests the MetadataRepositoryIndex. @@ -100,30 +101,27 @@ public class MetadataRepositoryIndexingTest RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); + List metadataList = new ArrayList(); + RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" ); repoMetadata.setMetadata( readMetadata( repoMetadata ) ); - indexer.index( repoMetadata ); - indexer.optimize(); - indexer.close(); + metadataList.add( repoMetadata ); repoMetadata = new ArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) ); repoMetadata.setMetadata( readMetadata( repoMetadata ) ); - indexer.index( repoMetadata ); - indexer.optimize(); - indexer.close(); + metadataList.add( repoMetadata ); repoMetadata = new SnapshotArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) ); repoMetadata.setMetadata( readMetadata( repoMetadata ) ); - indexer.index( repoMetadata ); - indexer.optimize(); - indexer.close(); + metadataList.add( repoMetadata ); repoMetadata = new GroupRepositoryMetadata( "test" ); repoMetadata.setMetadata( readMetadata( repoMetadata ) ); - indexer.index( repoMetadata ); + metadataList.add( repoMetadata ); + + indexer.indexMetadata( metadataList ); indexer.optimize(); - indexer.close(); } /** @@ -207,43 +205,6 @@ public class MetadataRepositoryIndexingTest metadataList = repoSearchLayer.searchAdvanced( rQry, indexer ); assertEquals( 0, metadataList.size() ); - - indexer.close(); - } - - /** - * Test the exceptions thrown by MetadataRepositoryIndex. - * - * @throws Exception - */ - public void testExceptions() - throws Exception - { - //test when the object passed in the index(..) method is not a RepositoryMetadata instance - RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); - MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); - try - { - Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ); - indexer.index( artifact ); - fail( "Must throw exception when the passed object is not a RepositoryMetadata object." ); - indexer.optimize(); - indexer.close(); - } - catch ( RepositoryIndexException e ) - { - assertTrue( true ); - } - - try - { - indexer.deleteIfIndexed( new Object() ); - fail( "Must throw exception when the passed object is not of type metadata." ); - } - catch ( RepositoryIndexException e ) - { - assertTrue( true ); - } } /** diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java index fe0aa1d41..6c6007012 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java @@ -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(); } /** diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/RepositoryIndexSearchLayerTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/RepositoryIndexSearchLayerTest.java index 5b425a552..035239bdb 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/RepositoryIndexSearchLayerTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/RepositoryIndexSearchLayerTest.java @@ -89,74 +89,54 @@ public class RepositoryIndexSearchLayerTest 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(); 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(); artifact = getArtifact( "test", "test-artifactId", "1.0" ); artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); indexer.indexArtifact( artifact ); - indexer.optimize(); - indexer.close(); artifact = getArtifact( "test", "test-artifactId", "1.0" ); artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); indexer.indexArtifact( artifact ); - indexer.optimize(); - indexer.close(); MetadataRepositoryIndex metaIndexer = factory.createMetadataRepositoryIndex( indexPath, repository ); RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" ); repoMetadata.setMetadata( readMetadata( repoMetadata ) ); - metaIndexer.index( repoMetadata ); - metaIndexer.optimize(); - metaIndexer.close(); + metaIndexer.indexMetadata( repoMetadata ); repoMetadata = new ArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) ); repoMetadata.setMetadata( readMetadata( repoMetadata ) ); - metaIndexer.index( repoMetadata ); - metaIndexer.optimize(); - metaIndexer.close(); + metaIndexer.indexMetadata( repoMetadata ); repoMetadata = new SnapshotArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) ); repoMetadata.setMetadata( readMetadata( repoMetadata ) ); - metaIndexer.index( repoMetadata ); - metaIndexer.optimize(); - metaIndexer.close(); + metaIndexer.indexMetadata( repoMetadata ); repoMetadata = new GroupRepositoryMetadata( "test" ); repoMetadata.setMetadata( readMetadata( repoMetadata ) ); - metaIndexer.index( repoMetadata ); + metaIndexer.indexMetadata( repoMetadata ); + metaIndexer.optimize(); - metaIndexer.close(); PomRepositoryIndex pomIndexer = factory.createPomRepositoryIndex( indexPath, repository ); Model pom = getPom( "org.apache.maven", "maven-artifact", "2.0.1" ); pomIndexer.indexPom( pom ); - pomIndexer.optimize(); - pomIndexer.close(); pom = getPom( "org.apache.maven", "maven-model", "2.0" ); pomIndexer.indexPom( pom ); - pomIndexer.optimize(); - pomIndexer.close(); pom = getPom( "test", "test-artifactId", "1.0" ); pomIndexer.indexPom( pom ); - pomIndexer.optimize(); - pomIndexer.close(); pom = getPom( "test", "test-artifactId", "1.0" ); pomIndexer.indexPom( pom ); + pomIndexer.optimize(); - pomIndexer.close(); } /** diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java index b7933d152..7664cc27a 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java @@ -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" ); } diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/execution/DiscovererExecution.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/execution/DiscovererExecution.java index 4e1dfbff2..c059cd7cb 100644 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/execution/DiscovererExecution.java +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/execution/DiscovererExecution.java @@ -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(); } /** -- 2.39.5