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;
/**
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;
* @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;
}
/**
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 )
{
}
/**
- * @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
indexWriter.close();
indexWriter = null;
}
-
- indexOpen = false;
}
catch ( IOException e )
{
* @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();
+ }
}
}
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();
}
}
}
}
- /**
- * 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()
*/
return isAdded;
}
+ /**
+ * Inner class used as the default IndexAnalyzer
+ */
private static class ArtifactRepositoryIndexAnalyzer
extends Analyzer
{
}
/**
- * Class used to tokenize an artifact's version.
+ * Inner class used to tokenize an artifact's version.
*/
private static class VersionTokenizer
extends CharTokenizer
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;
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;
* @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;
}
/**
*/
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();
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
*
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;
* @param digester the digester object to generate the checksum strings
*/
public EclipseRepositoryIndex( File indexPath, ArtifactRepository repository, Digester digester )
+ throws RepositoryIndexException
{
super( indexPath, repository );
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
*
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() )
{
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;
}
/**
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
*/
\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
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
* @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
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
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;
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;
*/
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 );
}
-
}
/**
*/
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() ) );
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;
}
/**
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.io.File;
+import java.io.IOException;
import java.util.Arrays;
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();
* @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;
}
super( message, cause );
}
- public RepositoryIndexException( Throwable cause )
- {
- super( cause );
- }
-
public RepositoryIndexException( String message )
{
super( message );
{
super( message, cause );
}
-
- public RepositoryIndexSearchException( Throwable cause )
- {
- super( cause );
- }
-
- public RepositoryIndexSearchException( String message )
- {
- super( message );
- }
}
import java.io.File;
import java.util.Iterator;
import java.util.List;
+import java.util.ArrayList;
/**
* @author Edwin Punzalan
{
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 );
- }
}
/**
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();
}
/**
String md5Tmp = digester.createChecksum( artifact2.getFile(), Digester.MD5 );
assertEquals( md5, md5Tmp );
}
-
- indexer.close();
}
/**
assertEquals( "maven-artifact", artifact.getArtifactId() );
assertEquals( "org.apache.maven", artifact.getGroupId() );
}
-
- indexer.close();
}
/**
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
+import java.util.List;
+import java.util.ArrayList;
/**
* @author Edwin Punzalan
{
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;
}
{
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 );
- }
}
/**
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
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
\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
{
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 );
- }
}
/**
String md5Tmp = digester.createChecksum( getPomFile( artifact2 ), Digester.MD5 );
assertEquals( md5, md5Tmp );
}
-
- indexer.close();
}
/**
assertEquals( "maven-artifact", artifact.getArtifactId() );
assertEquals( "org.apache.maven", artifact.getGroupId() );
}
-
- indexer.close();
}
/**
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();
}
/**
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
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;
ArtifactRepositoryIndex index = new ArtifactRepositoryIndex( indexDirectory, repository, digester );
index.indexArtifact( artifact );
index.optimize();
- index.close();
processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate" );
}
*/
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;
import java.io.File;
import java.net.MalformedURLException;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
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();
}
/**
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();
}
/**
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();
}
/**