Author: epunzalan Date: Sun Jan 22 23:27:58 2006 New Revision: 371476 URL: http://svn.apache.org/viewcvs?rev=371476&view=rev Log: PR: MRM-56 Submitted by: Maria Odea Ching
Enabled Index delete document. Also did some refractoring and code formatting. Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndex.java maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexSearcher.java maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java?rev=371476&r1=371475&r2=371476&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java (original) +++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java Sun Jan 22 23:27:58 2006 @@ -18,6 +18,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.Term; import org.apache.maven.artifact.repository.ArtifactRepository; import java.io.File; @@ -194,5 +195,27 @@ public ArtifactRepository getRepository() { return repository; + } + + /** + * @see org.apache.maven.repository.indexing.RepositoryIndex#deleteDocument(String, String) + */ + public void deleteDocument( String field, String value ) + throws RepositoryIndexException, IOException + { + IndexReader indexReader = null; + try + { + indexReader = IndexReader.open( indexPath ); + indexReader.delete( new Term( field, value ) ); + } + catch ( IOException ie ) + { + throw new RepositoryIndexException( indexPath + "is not a valid directory." ); + } + finally + { + indexReader.close(); + } } } Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java?rev=371476&r1=371475&r2=371476&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java (original) +++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java Sun Jan 22 23:27:58 2006 @@ -27,8 +27,8 @@ import org.apache.maven.repository.indexing.query.CompoundQuery; import org.apache.maven.repository.indexing.query.CompoundQueryTerm; import org.apache.maven.repository.indexing.query.Query; -import org.apache.maven.repository.indexing.query.SinglePhraseQuery; import org.apache.maven.repository.indexing.query.RangeQuery; +import org.apache.maven.repository.indexing.query.SinglePhraseQuery; import org.codehaus.plexus.logging.AbstractLogEnabled; import java.io.IOException; @@ -159,19 +159,19 @@ } retVal = booleanQuery; } - else if( query instanceof RangeQuery ) + else if ( query instanceof RangeQuery ) { RangeQuery rq = (RangeQuery) query; List queries = rq.getQueries(); Iterator iter = queries.iterator(); Term begin = null, end = null; - if(queries.size() == 2) + if ( queries.size() == 2 ) { SinglePhraseQuery qry = (SinglePhraseQuery) iter.next(); begin = new Term( qry.getField(), qry.getValue() ); - qry = ( SinglePhraseQuery ) iter.next(); + qry = (SinglePhraseQuery) iter.next(); end = new Term( qry.getField(), qry.getValue() ); - } + } retVal = new org.apache.lucene.search.RangeQuery( begin, end, rq.isInclusive() ); } else Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java?rev=371476&r1=371475&r2=371476&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java (original) +++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java Sun Jan 22 23:27:58 2006 @@ -41,6 +41,8 @@ public class ArtifactRepositoryIndex extends AbstractRepositoryIndex { + protected static final String FLD_ID = "id"; + protected static final String FLD_NAME = "name"; protected static final String FLD_GROUPID = "groupId"; @@ -59,13 +61,15 @@ protected static final String FLD_FILES = "files"; - private static final String[] FIELDS = - {FLD_NAME, FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION, FLD_SHA1, FLD_MD5, FLD_CLASSES, FLD_PACKAGES, FLD_FILES}; + private static final String[] FIELDS = {FLD_ID, FLD_NAME, FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION, FLD_SHA1, + FLD_MD5, FLD_CLASSES, FLD_PACKAGES, FLD_FILES}; private Analyzer analyzer; private Digester digester; + protected static final String ARTIFACT_TYPE = "ARTIFACT"; + /** * Class constructor * @@ -161,6 +165,7 @@ //@todo should some of these fields be Keyword instead of Text ? Document doc = new Document(); + doc.add( Field.Keyword( FLD_ID, ARTIFACT_TYPE + artifact.getId() ) ); doc.add( Field.Text( FLD_NAME, artifact.getFile().getName() ) ); doc.add( Field.Text( FLD_GROUPID, artifact.getGroupId() ) ); doc.add( Field.Text( FLD_ARTIFACTID, artifact.getArtifactId() ) ); Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java?rev=371476&r1=371475&r2=371476&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java (original) +++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java Sun Jan 22 23:27:58 2006 @@ -8,7 +8,7 @@ * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 - + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -72,9 +72,10 @@ return new PomRepositoryIndexSearcher( index, artifactFactory ); } - public MetadataRepositoryIndex createMetadataRepositoryIndex( String indexPath, ArtifactRepository repository) - throws RepositoryIndexException{ - return new MetadataRepositoryIndex(indexPath, repository); + public MetadataRepositoryIndex createMetadataRepositoryIndex( String indexPath, ArtifactRepository repository ) + throws RepositoryIndexException + { + return new MetadataRepositoryIndex( indexPath, repository ); } public MetadataRepositoryIndexSearcher createMetadataRepositoryIndexSearcher( MetadataRepositoryIndex index ) Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndex.java URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndex.java?rev=371476&r1=371475&r2=371476&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndex.java (original) +++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndex.java Sun Jan 22 23:27:58 2006 @@ -21,50 +21,54 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; import org.apache.maven.artifact.repository.metadata.Metadata; -import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.artifact.repository.metadata.Plugin; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Versioning; -import java.util.List; -import java.util.Iterator; import java.io.IOException; +import java.util.Iterator; +import java.util.List; /** * This class indexes the metadata in the repository. */ public class MetadataRepositoryIndex - extends AbstractRepositoryIndex + extends AbstractRepositoryIndex { - private static final String FLD_LASTUPDATE = "lastUpdate"; + protected static final String FLD_ID = "id"; - private static final String FLD_PLUGINPREFIX = "pluginPrefix"; + protected static final String FLD_LASTUPDATE = "lastUpdate"; - private static final String FLD_METADATAPATH = "path"; + protected static final String FLD_PLUGINPREFIX = "pluginPrefix"; - private static final String FLD_GROUPID = "groupId"; + protected static final String FLD_METADATAPATH = "path"; - private static final String FLD_ARTIFACTID = "artifactId"; + protected static final String FLD_GROUPID = "groupId"; - private static final String FLD_VERSION = "version"; + protected static final String FLD_ARTIFACTID = "artifactId"; - private static final String[] FIELDS = {FLD_METADATAPATH, FLD_PLUGINPREFIX, FLD_LASTUPDATE, - FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION}; + protected static final String FLD_VERSION = "version"; + + private static final String[] FIELDS = + {FLD_ID, FLD_METADATAPATH, FLD_PLUGINPREFIX, FLD_LASTUPDATE, FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION}; /** * Constructor - * @param indexPath the path to the index + * + * @param indexPath the path to the index * @param repository the repository where the metadata to be indexed is located * @throws RepositoryIndexException */ public MetadataRepositoryIndex( String indexPath, ArtifactRepository repository ) - throws RepositoryIndexException + throws RepositoryIndexException { super( indexPath, repository, FIELDS ); } /** * Get the field names to be used in the index + * * @return array of strings */ public String[] getIndexFields() @@ -74,6 +78,7 @@ /** * Returns the analyzer used for indexing + * * @return Analyzer object */ public Analyzer getAnalyzer() @@ -83,12 +88,14 @@ /** * Index the paramater object + * * @param obj * @throws RepositoryIndexException */ - public void index( Object obj ) throws RepositoryIndexException + public void index( Object obj ) + throws RepositoryIndexException { - if ( obj instanceof RepositoryMetadata ) + if ( obj instanceof RepositoryMetadata ) { indexMetadata( (RepositoryMetadata) obj ); } @@ -101,12 +108,14 @@ /** * 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 void indexMetadata( RepositoryMetadata repoMetadata ) + throws RepositoryIndexException { - if ( !isOpen() ) + if ( !isOpen() ) { throw new RepositoryIndexException( "Unable to add artifact index on a closed index" ); } @@ -116,38 +125,40 @@ //get the metadatapath: check where metadata is located, then concatenate the groupId, // artifactId, version based on its location Document doc = new Document(); + doc.add( Field.Keyword( FLD_ID, (String) repoMetadata.getKey() ) ); String path = ""; - if( repoMetadata.storedInGroupDirectory() && !repoMetadata.storedInArtifactVersionDirectory()) + if ( repoMetadata.storedInGroupDirectory() && !repoMetadata.storedInArtifactVersionDirectory() ) { path = repoMetadata.getGroupId() + "/"; } - else if(!repoMetadata.storedInGroupDirectory() && !repoMetadata.storedInArtifactVersionDirectory()) + else if ( !repoMetadata.storedInGroupDirectory() && !repoMetadata.storedInArtifactVersionDirectory() ) { - path = repoMetadata.getGroupId() + "/" + repoMetadata.getArtifactId() + "/"; + path = repoMetadata.getGroupId() + "/" + repoMetadata.getArtifactId() + "/"; } - else if(!repoMetadata.storedInGroupDirectory() && repoMetadata.storedInArtifactVersionDirectory()) + else if ( !repoMetadata.storedInGroupDirectory() && repoMetadata.storedInArtifactVersionDirectory() ) { - path = repoMetadata.getGroupId() + "/" + repoMetadata.getArtifactId() + "/" + repoMetadata.getBaseVersion() + "/"; + path = repoMetadata.getGroupId() + "/" + repoMetadata.getArtifactId() + "/" + + repoMetadata.getBaseVersion() + "/"; } //@todo use localfilename or remotefilename to get the path??? path = path + repoMetadata.getRemoteFilename(); - doc.add( Field.Text( FLD_METADATAPATH, path) ); + doc.add( Field.Text( FLD_METADATAPATH, path ) ); Metadata metadata = repoMetadata.getMetadata(); Versioning versioning = metadata.getVersioning(); - if( versioning != null ) + if ( versioning != null ) { doc.add( Field.Text( FLD_LASTUPDATE, versioning.getLastUpdated() ) ); } List plugins = metadata.getPlugins(); String pluginAppended = ""; - for( Iterator iter = plugins.iterator(); iter.hasNext(); ) + for ( Iterator iter = plugins.iterator(); iter.hasNext(); ) { Plugin plugin = (Plugin) iter.next(); - if( plugin.getPrefix() != null && !plugin.getPrefix().equals("") ) + if ( plugin.getPrefix() != null && !plugin.getPrefix().equals( "" ) ) { pluginAppended = plugin.getPrefix() + " "; } @@ -155,11 +166,11 @@ doc.add( Field.Text( FLD_PLUGINPREFIX, pluginAppended ) ); doc.add( Field.UnIndexed( FLD_GROUPID, metadata.getGroupId() ) ); - if( metadata.getArtifactId() != null && !metadata.getArtifactId().equals("") ) + if ( metadata.getArtifactId() != null && !metadata.getArtifactId().equals( "" ) ) { doc.add( Field.UnIndexed( FLD_ARTIFACTID, metadata.getArtifactId() ) ); } - if( metadata.getVersion() != null && !metadata.getVersion().equals("") ) + if ( metadata.getVersion() != null && !metadata.getVersion().equals( "" ) ) { doc.add( Field.UnIndexed( FLD_VERSION, metadata.getVersion() ) ); } @@ -174,7 +185,8 @@ } } - public boolean isKeywordField( String field ){ - return false; + public boolean isKeywordField( String field ) + { + return false; } } Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexSearcher.java URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexSearcher.java?rev=371476&r1=371475&r2=371476&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexSearcher.java (original) +++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexSearcher.java Sun Jan 22 23:27:58 2006 @@ -17,26 +17,29 @@ */ import org.apache.lucene.document.Document; +import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; -import org.apache.maven.artifact.Artifact; -import java.net.URL; -import java.io.InputStream; import java.io.File; +import java.io.InputStream; import java.io.InputStreamReader; -import java.util.*; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; /** * This class searches the specified index given the search/query criteria. - * */ public class MetadataRepositoryIndexSearcher - extends AbstractRepositoryIndexSearcher + extends AbstractRepositoryIndexSearcher { private ArtifactFactory artifactFactory; @@ -56,17 +59,19 @@ /** * Constructor - * @param index the index object to be set + * + * @param index the index object to be set * @param factory */ - public MetadataRepositoryIndexSearcher( MetadataRepositoryIndex index, ArtifactFactory factory) + public MetadataRepositoryIndexSearcher( MetadataRepositoryIndex index, ArtifactFactory factory ) { - super(index); + super( index ); artifactFactory = factory; } /** * Create object to be returned by the search based on the document + * * @param doc * @return Object */ @@ -85,11 +90,11 @@ String tmpDir = (String) it.next(); String metadataType = ""; - if( tmpDir.equals( doc.get( FLD_GROUPID ) ) ) + if ( tmpDir.equals( doc.get( FLD_GROUPID ) ) ) { metadataType = GROUP_TYPE; } - else if( tmpDir.equals( doc.get( FLD_ARTIFACTID ) ) ) + else if ( tmpDir.equals( doc.get( FLD_ARTIFACTID ) ) ) { metadataType = ARTIFACT_TYPE; } @@ -100,10 +105,12 @@ RepositoryMetadata repoMetadata = null; - try{ - repoMetadata = getMetadata(doc.get( FLD_GROUPID ), doc.get( FLD_ARTIFACTID ), doc.get( FLD_VERSION ), metadataFile, metadataType ); + try + { + repoMetadata = getMetadata( doc.get( FLD_GROUPID ), doc.get( FLD_ARTIFACTID ), doc.get( FLD_VERSION ), + metadataFile, metadataType ); } - catch(Exception e) + catch ( Exception e ) { //@todo } @@ -114,15 +121,16 @@ /** * Create RepositoryMetadata object. * - * @param groupId the groupId to be set - * @param artifactId the artifactId to be set - * @param version the version to be set - * @param filename the name of the metadata file + * @param groupId the groupId to be set + * @param artifactId the artifactId to be set + * @param version the version to be set + * @param filename the name of the metadata file * @param metadataType the type of RepositoryMetadata object to be created (GROUP, ARTIFACT or SNAPSHOT) * @return RepositoryMetadata * @throws Exception */ - private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename, String metadataType) + private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename, + String metadataType ) throws Exception { RepositoryMetadata repoMetadata = null; @@ -131,25 +139,27 @@ MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); //group metadata - if( metadataType.equals( GROUP_TYPE ) ) + if ( metadataType.equals( GROUP_TYPE ) ) { - url = new File( index.getRepository().getBasedir() + groupId.replace('.', '/') + "/" + filename ).toURL(); + url = new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" + filename ).toURL(); is = url.openStream(); - repoMetadata = new GroupRepositoryMetadata(groupId); + repoMetadata = new GroupRepositoryMetadata( groupId ); repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) ); } //artifact metadata - else if( metadataType.equals( ARTIFACT_TYPE ) ) + else if ( metadataType.equals( ARTIFACT_TYPE ) ) { - url = new File( index.getRepository().getBasedir() + groupId.replace('.', '/') + "/" + artifactId + "/" + filename ).toURL(); + url = new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" + artifactId + "/" + + filename ).toURL(); is = url.openStream(); repoMetadata = new ArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) ); repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) ); } //snapshot/version metadata - else if( metadataType.equals( SNAPSHOT_TYPE ) ) + else if ( metadataType.equals( SNAPSHOT_TYPE ) ) { - url = new File( index.getRepository().getBasedir() + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + filename ).toURL(); + url = new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" + artifactId + "/" + + version + "/" + filename ).toURL(); is = url.openStream(); repoMetadata = new SnapshotArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) ); repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) ); @@ -160,9 +170,10 @@ /** * Create artifact object. - * @param groupId the groupId of the artifact + * + * @param groupId the groupId of the artifact * @param artifactId the artifactId of the artifact - * @param version the version of the artifact + * @param version the version of the artifact * @return Artifact * @throws Exception */ Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java?rev=371476&r1=371475&r2=371476&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java (original) +++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java Sun Jan 22 23:27:58 2006 @@ -8,7 +8,7 @@ * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 - + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -47,6 +47,8 @@ public class PomRepositoryIndex extends AbstractRepositoryIndex { + protected static final String FLD_ID = "id"; + protected static final String FLD_GROUPID = "groupId"; protected static final String FLD_ARTIFACTID = "artifactId"; @@ -69,8 +71,8 @@ protected static final String FLD_MD5 = "md5"; - private static final String[] FIELDS = {FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION, FLD_PACKAGING, FLD_LICENSE_URLS, - FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL}; + private static final String[] FIELDS = {FLD_ID, FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION, FLD_PACKAGING, + FLD_LICENSE_URLS, FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL}; private Analyzer analyzer; @@ -78,8 +80,10 @@ private ArtifactFactory artifactFactory; - private static final List KEYWORD_FIELDS = Arrays.asList( - new String[]{FLD_LICENSE_URLS, FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL} ); + private static final List KEYWORD_FIELDS = Arrays.asList( new String[]{FLD_ID, FLD_LICENSE_URLS, FLD_DEPENDENCIES, + FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL} ); + + protected static final String POM_TYPE = "POM"; /** * Class Constructor @@ -127,6 +131,7 @@ } Document doc = new Document(); + doc.add( Field.Keyword( FLD_ID, POM_TYPE + pom.getId() ) ); doc.add( Field.Text( FLD_GROUPID, pom.getGroupId() ) ); doc.add( Field.Text( FLD_ARTIFACTID, pom.getArtifactId() ) ); doc.add( Field.Text( FLD_VERSION, pom.getVersion() ) ); Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java?rev=371476&r1=371475&r2=371476&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java (original) +++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java Sun Jan 22 23:27:58 2006 @@ -8,7 +8,7 @@ * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 - + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -65,8 +65,8 @@ */ PomRepositoryIndexSearcher createPomRepositoryIndexSearcher( PomRepositoryIndex index ); - MetadataRepositoryIndex createMetadataRepositoryIndex( String indexPath, ArtifactRepository repository) - throws RepositoryIndexException; + MetadataRepositoryIndex createMetadataRepositoryIndex( String indexPath, ArtifactRepository repository ) + throws RepositoryIndexException; MetadataRepositoryIndexSearcher createMetadataRepositoryIndexSearcher( MetadataRepositoryIndex index ); Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java?rev=371476&r1=371475&r2=371476&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java (original) +++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java Sun Jan 22 23:27:58 2006 @@ -16,11 +16,12 @@ * limitations under the License. */ -import java.util.List; import java.util.ArrayList; +import java.util.List; /** * Query object that handles range queries for dates. + * * @author Maria Odea Ching */ public class RangeQuery @@ -30,7 +31,7 @@ private boolean inclusive; - public RangeQuery( boolean inclusive) + public RangeQuery( boolean inclusive ) { this.inclusive = inclusive; } Modified: maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java?rev=371476&r1=371475&r2=371476&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java (original) +++ maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java Sun Jan 22 23:27:58 2006 @@ -39,18 +39,6 @@ public class ArtifactRepositoryIndexingTest extends PlexusTestCase { - private static final String GROUPID = "groupId"; - - private static final String ARTIFACTID = "artifactId"; - - private static final String VERSION = "version"; - - private static final String CLASSES = "classes"; - - private static final String PACKAGES = "packages"; - - private static final String FILES = "files"; - private ArtifactFactory artifactFactory; private ArtifactRepository repository; @@ -59,11 +47,7 @@ private Digester digester; - private static final String SHA1 = "sha1"; - - private static final String MD5 = "md5"; - - private static final String NAME = "name"; + private static final String ARTIFACT_TYPE = "ARTIFACT"; protected void setUp() throws Exception @@ -181,7 +165,7 @@ RepositoryIndexSearcher repoSearcher = factory.createArtifactRepositoryIndexSearcher( indexer ); // search version - Query qry = new SinglePhraseQuery( VERSION, "1.0" ); + Query qry = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_VERSION, "1.0" ); List artifacts = repoSearcher.search( qry ); assertEquals( 1, artifacts.size() ); for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) @@ -191,7 +175,7 @@ } // search classes - qry = new SinglePhraseQuery( CLASSES, "App" ); + qry = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_CLASSES, "App" ); artifacts = repoSearcher.search( qry ); assertEquals( 1, artifacts.size() ); for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) @@ -201,7 +185,7 @@ } // search packages - qry = new SinglePhraseQuery( PACKAGES, "groupId" ); + qry = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_PACKAGES, "groupId" ); artifacts = repoSearcher.search( qry ); assertEquals( 1, artifacts.size() ); for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) @@ -211,7 +195,7 @@ } // search files - qry = new SinglePhraseQuery( FILES, "pom.xml" ); + qry = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_FILES, "pom.xml" ); artifacts = repoSearcher.search( qry ); assertEquals( 3, artifacts.size() ); Iterator iter = artifacts.iterator(); @@ -222,7 +206,7 @@ } // search group id - qry = new SinglePhraseQuery( GROUPID, "org.apache.maven" ); + qry = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_GROUPID, "org.apache.maven" ); artifacts = repoSearcher.search( qry ); assertEquals( 2, artifacts.size() ); iter = artifacts.iterator(); @@ -233,7 +217,7 @@ } // search artifact id - qry = new SinglePhraseQuery( ARTIFACTID, "maven-artifact" ); + qry = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_ARTIFACTID, "maven-artifact" ); artifacts = repoSearcher.search( qry ); assertEquals( 1, artifacts.size() ); for ( iter = artifacts.iterator(); iter.hasNext(); ) @@ -243,7 +227,7 @@ } // search version - qry = new SinglePhraseQuery( VERSION, "2" ); + qry = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_VERSION, "2" ); artifacts = repoSearcher.search( qry ); assertEquals( 2, artifacts.size() ); for ( iter = artifacts.iterator(); iter.hasNext(); ) @@ -258,7 +242,7 @@ String sha1 = digester.createChecksum( artifact.getFile(), Digester.SHA1 ); - qry = new SinglePhraseQuery( SHA1, sha1.trim() ); + qry = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_SHA1, sha1.trim() ); artifacts = repoSearcher.search( qry ); assertEquals( 1, artifacts.size() ); for ( iter = artifacts.iterator(); iter.hasNext(); ) @@ -270,7 +254,7 @@ // search md5 checksum String md5 = digester.createChecksum( artifact.getFile(), Digester.MD5 ); - qry = new SinglePhraseQuery( MD5, md5.trim() ); + qry = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_MD5, md5.trim() ); artifacts = repoSearcher.search( qry ); assertEquals( 1, artifacts.size() ); for ( iter = artifacts.iterator(); iter.hasNext(); ) @@ -300,8 +284,8 @@ // Criteria 1: required query // ex. artifactId=maven-artifact AND groupId=org.apache.maven - Query qry1 = new SinglePhraseQuery( ARTIFACTID, "maven-artifact" ); - Query qry2 = new SinglePhraseQuery( GROUPID, "org.apache.maven" ); + Query qry1 = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_ARTIFACTID, "maven-artifact" ); + Query qry2 = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_GROUPID, "org.apache.maven" ); CompoundQuery rQry = new CompoundQuery(); rQry.and( qry1 ); rQry.and( qry2 ); @@ -317,7 +301,7 @@ // Criteria 2: nested required query // ex. (artifactId=maven-artifact AND groupId=org.apache.maven) OR // version=2.0.3 - Query qry3 = new SinglePhraseQuery( VERSION, "2.0.3" ); + Query qry3 = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_VERSION, "2.0.3" ); CompoundQuery oQry = new CompoundQuery(); oQry.or( rQry ); oQry.or( qry3 ); @@ -334,14 +318,14 @@ // ex. (artifactId=maven-artifact AND groupId=org.apache.maven) AND // (version=2.0.3 OR version=2.0.1) // AND (name=maven-artifact-2.0.1.jar OR name=maven-artifact) - Query qry4 = new SinglePhraseQuery( VERSION, "2.0.1" ); + Query qry4 = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_VERSION, "2.0.1" ); oQry = new CompoundQuery(); oQry.or( qry3 ); oQry.or( qry4 ); CompoundQuery oQry5 = new CompoundQuery(); - Query qry9 = new SinglePhraseQuery( NAME, "maven-artifact-2.0.1.jar" ); - Query qry10 = new SinglePhraseQuery( NAME, "maven-artifact" ); + Query qry9 = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_NAME, "maven-artifact-2.0.1.jar" ); + Query qry10 = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_NAME, "maven-artifact" ); oQry5.or( qry9 ); oQry5.or( qry10 ); @@ -365,8 +349,8 @@ // AND (name=maven-artifact-2.0.1.jar OR name=maven-artifact)] // OR [(artifactId=sample AND groupId=test)] CompoundQuery rQry3 = new CompoundQuery(); - Query qry5 = new SinglePhraseQuery( ARTIFACTID, "sample" ); - Query qry6 = new SinglePhraseQuery( GROUPID, "test" ); + Query qry5 = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_ARTIFACTID, "sample" ); + Query qry6 = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_GROUPID, "test" ); rQry3.and( qry5 ); rQry3.and( qry6 ); CompoundQuery oQry2 = new CompoundQuery(); @@ -389,8 +373,8 @@ // [(artifactId=sample AND groupId=test)] OR // [(artifactId=sample2 AND groupId=test)] CompoundQuery rQry4 = new CompoundQuery(); - Query qry7 = new SinglePhraseQuery( ARTIFACTID, "sample2" ); - Query qry8 = new SinglePhraseQuery( GROUPID, "test" ); + Query qry7 = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_ARTIFACTID, "sample2" ); + Query qry8 = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_GROUPID, "test" ); rQry4.and( qry7 ); rQry4.and( qry8 ); oQry2.and( rQry4 ); @@ -404,6 +388,24 @@ } indexer.close(); + } + + public void testDeleteArtifactDocument() + throws Exception + { + createTestIndex(); + + RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); + ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository ); + + Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ); + artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); + indexer.deleteDocument( ArtifactRepositoryIndex.FLD_ID, ARTIFACT_TYPE + artifact.getId() ); + + RepositoryIndexSearcher repoSearcher = factory.createArtifactRepositoryIndexSearcher( indexer ); + Query qry = new SinglePhraseQuery( ArtifactRepositoryIndex.FLD_ID, ARTIFACT_TYPE + artifact.getId() ); + List artifacts = repoSearcher.search( qry ); + assertEquals( artifacts.size(), 0 ); } private Artifact getArtifact( String groupId, String artifactId, String version ) Modified: maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java?rev=371476&r1=371475&r2=371476&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java (original) +++ maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java Sun Jan 22 23:27:58 2006 @@ -21,7 +21,13 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.repository.metadata.*; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Metadata; +import org.apache.maven.artifact.repository.metadata.Plugin; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; import org.apache.maven.repository.indexing.query.Query; import org.apache.maven.repository.indexing.query.RangeQuery; @@ -40,16 +46,12 @@ * This class tests the MetadataRepositoryIndex. */ public class MetadataRepositoryIndexingTest - extends PlexusTestCase + extends PlexusTestCase { private ArtifactRepository repository; private String indexPath; - private static final String FLD_LASTUPDATE = "lastUpdate"; - - private static final String FLD_PLUGINPREFIX = "pluginPrefix"; - private static final String GROUP_TYPE = "GROUP"; private static final String ARTIFACT_TYPE = "ARTIFACT"; @@ -62,15 +64,17 @@ /** * Set up. + * * @throws Exception */ - public void setUp() throws Exception + public void setUp() + throws Exception { super.setUp(); File repositoryDirectory = getTestFile( "src/test/repository" ); String repoDir = repositoryDirectory.toURL().toString(); - ArtifactRepositoryLayout layout = ( ArtifactRepositoryLayout ) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - ArtifactRepositoryFactory repoFactory = ( ArtifactRepositoryFactory ) lookup( ArtifactRepositoryFactory.ROLE ); + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + ArtifactRepositoryFactory repoFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); repository = repoFactory.createArtifactRepository( "test", repoDir, layout, null, null ); indexPath = "target/index/metadata"; @@ -79,9 +83,11 @@ /** * Tear down. + * * @throws Exception */ - public void tearDown() throws Exception + public void tearDown() + throws Exception { repository = null; super.tearDown(); @@ -89,20 +95,25 @@ /** * Create the test index. + * * @throws Exception */ - private void createTestIndex() throws Exception + private void createTestIndex() + throws Exception { - RepositoryIndexingFactory factory = ( RepositoryIndexingFactory ) lookup( RepositoryIndexingFactory.ROLE ); + RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); - RepositoryMetadata repoMetadata = getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", GROUP_TYPE ); + RepositoryMetadata repoMetadata = + getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", GROUP_TYPE ); indexer.index( repoMetadata ); - repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml", ARTIFACT_TYPE ); + repoMetadata = + getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml", ARTIFACT_TYPE ); indexer.index( repoMetadata ); - repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml", SNAPSHOT_TYPE ); + repoMetadata = + getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml", SNAPSHOT_TYPE ); indexer.index( repoMetadata ); indexer.optimize(); @@ -114,9 +125,9 @@ * * @throws Exception */ - public void testSearch() - throws Exception - { + public void testSearch() + throws Exception + { createTestIndex(); RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); @@ -124,7 +135,8 @@ RepositoryIndexSearcher repoSearcher = factory.createMetadataRepositoryIndexSearcher( indexer ); // search last update - org.apache.maven.repository.indexing.query.Query qry = new SinglePhraseQuery( FLD_LASTUPDATE, "20051212044643" ); + org.apache.maven.repository.indexing.query.Query qry = + new SinglePhraseQuery( MetadataRepositoryIndex.FLD_LASTUPDATE, "20051212044643" ); List metadataList = repoSearcher.search( qry ); assertEquals( 1, metadataList.size() ); for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) @@ -137,7 +149,7 @@ } // search plugin prefix - qry = new SinglePhraseQuery( FLD_PLUGINPREFIX, "org.apache.maven" ); + qry = new SinglePhraseQuery( MetadataRepositoryIndex.FLD_PLUGINPREFIX, "org.apache.maven" ); metadataList = repoSearcher.search( qry ); assertEquals( 1, metadataList.size() ); for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) @@ -145,7 +157,7 @@ RepositoryMetadata repoMetadata = (RepositoryMetadata) iter.next(); Metadata metadata = repoMetadata.getMetadata(); List plugins = metadata.getPlugins(); - for( Iterator it = plugins.iterator(); it.hasNext(); ) + for ( Iterator it = plugins.iterator(); it.hasNext(); ) { Plugin plugin = (Plugin) it.next(); assertEquals( "org.apache.maven", plugin.getPrefix() ); @@ -153,8 +165,8 @@ } // search last update using INCLUSIVE Range Query - Query qry1 = new SinglePhraseQuery( FLD_LASTUPDATE, "20051212000000" ); - Query qry2 = new SinglePhraseQuery( FLD_LASTUPDATE, "20051212235959"); + Query qry1 = new SinglePhraseQuery( MetadataRepositoryIndex.FLD_LASTUPDATE, "20051212000000" ); + Query qry2 = new SinglePhraseQuery( MetadataRepositoryIndex.FLD_LASTUPDATE, "20051212235959" ); RangeQuery rQry = new RangeQuery( true ); rQry.addQuery( qry1 ); rQry.addQuery( qry2 ); @@ -169,8 +181,8 @@ } // search last update using EXCLUSIVE Range Query - qry1 = new SinglePhraseQuery( FLD_LASTUPDATE, "20051212000000" ); - qry2 = new SinglePhraseQuery( FLD_LASTUPDATE, "20051212044643"); + qry1 = new SinglePhraseQuery( MetadataRepositoryIndex.FLD_LASTUPDATE, "20051212000000" ); + qry2 = new SinglePhraseQuery( MetadataRepositoryIndex.FLD_LASTUPDATE, "20051212044643" ); rQry = new RangeQuery( false ); rQry.addQuery( qry1 ); rQry.addQuery( qry2 ); @@ -179,64 +191,95 @@ assertEquals( metadataList.size(), 0 ); indexer.close(); - } + } + /** + * Test the exceptions thrown by MetadataRepositoryIndex. + * + * @throws Exception + */ public void testExceptions() - throws Exception + throws Exception { //test when the object passed in the index(..) method is not a RepositoryMetadat instance - RepositoryIndexingFactory factory = ( RepositoryIndexingFactory ) lookup( RepositoryIndexingFactory.ROLE ); + RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); try { - Artifact artifact = getArtifact("org.apache.maven", "maven-artifact", "2.0.1"); + 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." ); } - catch( Exception e ) + catch ( Exception e ) { } indexer.optimize(); indexer.close(); //test when the plugin prefix is blank - factory = ( RepositoryIndexingFactory ) lookup( RepositoryIndexingFactory.ROLE ); + factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); try { RepositoryMetadata repoMetadata = getMetadata( "test", null, null, "maven-metadata.xml", GROUP_TYPE ); indexer.index( repoMetadata ); } - catch( Exception e ) + catch ( Exception e ) { } indexer.optimize(); indexer.close(); - //test when the index is closed + //test when the index is closed try { - RepositoryMetadata repoMetadata = getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", GROUP_TYPE ); + RepositoryMetadata repoMetadata = + getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", GROUP_TYPE ); indexer.index( repoMetadata ); fail( "Must throw exception when a metadata is added to the index while the indexer is still closed." ); } - catch( Exception e ) + catch ( Exception e ) { } } /** + * Test delete of document from metadata index. + * + * @throws Exception + */ + public void testDeleteMetadataDocument() + throws Exception + { + createTestIndex(); + + RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); + indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); + + RepositoryMetadata repoMetadata = + getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", GROUP_TYPE ); + indexer.deleteDocument( MetadataRepositoryIndex.FLD_ID, (String) repoMetadata.getKey() ); + + RepositoryIndexSearcher repoSearcher = factory.createMetadataRepositoryIndexSearcher( indexer ); + org.apache.maven.repository.indexing.query.Query qry = + new SinglePhraseQuery( MetadataRepositoryIndex.FLD_ID, (String) repoMetadata.getKey() ); + List metadataList = repoSearcher.search( qry ); + assertEquals( metadataList.size(), 0 ); + } + + /** * Create RepositoryMetadata object. * - * @param groupId the groupId to be set - * @param artifactId the artifactId to be set - * @param version the version to be set - * @param filename the name of the metadata file + * @param groupId the groupId to be set + * @param artifactId the artifactId to be set + * @param version the version to be set + * @param filename the name of the metadata file * @param metadataType the type of RepositoryMetadata object to be created (GROUP, ARTIFACT or SNAPSHOT) * @return RepositoryMetadata * @throws Exception */ - private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename, String metadataType) + private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename, + String metadataType ) throws Exception { RepositoryMetadata repoMetadata = null; @@ -245,25 +288,27 @@ MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); //group metadata - if( metadataType.equals( GROUP_TYPE ) ) + if ( metadataType.equals( GROUP_TYPE ) ) { - url = new File( repository.getBasedir() + groupId.replace('.', '/') + "/" + filename ).toURL(); + url = new File( repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + filename ).toURL(); is = url.openStream(); - repoMetadata = new GroupRepositoryMetadata(groupId); + repoMetadata = new GroupRepositoryMetadata( groupId ); repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) ); } //artifact metadata - else if( metadataType.equals( ARTIFACT_TYPE ) ) + else if ( metadataType.equals( ARTIFACT_TYPE ) ) { - url = new File( repository.getBasedir() + groupId.replace('.', '/') + "/" + artifactId + "/" + filename ).toURL(); + url = new File( + repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + artifactId + "/" + filename ).toURL(); is = url.openStream(); repoMetadata = new ArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) ); repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) ); } //snapshot/version metadata - else if( metadataType.equals( SNAPSHOT_TYPE ) ) + else if ( metadataType.equals( SNAPSHOT_TYPE ) ) { - url = new File( repository.getBasedir() + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + filename ).toURL(); + url = new File( repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + artifactId + "/" + version + + "/" + filename ).toURL(); is = url.openStream(); repoMetadata = new SnapshotArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) ); repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) ); @@ -275,9 +320,10 @@ /** * Create artifact object. - * @param groupId the groupId of the artifact + * + * @param groupId the groupId of the artifact * @param artifactId the artifactId of the artifact - * @param version the version of the artifact + * @param version the version of the artifact * @return Artifact * @throws Exception */ Modified: maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java?rev=371476&r1=371475&r2=371476&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java (original) +++ maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java Sun Jan 22 23:27:58 2006 @@ -450,6 +450,27 @@ indexer.close(); } + /** + * Test delete of pom document from index. + * + * @throws Exception + */ + public void testDeletePomDocument() + throws Exception + { + createTestIndex(); + + RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); + PomRepositoryIndex indexer = factory.createPomRepositoryIndex( indexPath, repository ); + Model pom = getPom( "org.apache.maven", "maven-artifact", "2.0.1" ); + indexer.deleteDocument( PomRepositoryIndex.FLD_ID, PomRepositoryIndex.POM_TYPE + pom.getId() ); + + RepositoryIndexSearcher repoSearcher = factory.createPomRepositoryIndexSearcher( indexer ); + Query qry = new SinglePhraseQuery( PomRepositoryIndex.FLD_ID, PomRepositoryIndex.POM_TYPE + pom.getId() ); + List artifactList = repoSearcher.search( qry ); + assertEquals( artifactList.size(), 0 ); + } + private Model getPom( String groupId, String artifactId, String version ) throws Exception {