[MRM-127] add search interface

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@426380 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2006-07-28 04:34:37 +00:00
parent 1c54e2df16
commit cd49d0608a
25 changed files with 1493 additions and 146 deletions

View File

@ -16,6 +16,9 @@
* limitations under the License.
*/
import org.apache.maven.repository.indexing.query.Query;
import java.util.Collection;
import java.util.List;
/**
@ -32,9 +35,20 @@ public interface RepositoryArtifactIndex
* @param records the artifacts to index
* @throws RepositoryIndexException if there is a problem indexing the records
*/
void indexRecords( List records )
void indexRecords( Collection records )
throws RepositoryIndexException;
/**
* Search the index based on the search criteria specified. Returns a list of index records.
*
* @param query The query that contains the search criteria
* @return the index records found
* @throws RepositoryIndexSearchException if there is a problem searching
* @todo should it return "SearchResult" instances that contain the index record and other search data (like score?)
*/
List search( Query query )
throws RepositoryIndexSearchException;
/**
* Check if the index already exists.
*

View File

@ -19,6 +19,8 @@
import org.apache.lucene.document.Document;
import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
import java.text.ParseException;
/**
* Converts repository records to Lucene documents.
*
@ -33,4 +35,13 @@ public interface LuceneIndexRecordConverter
* @return the document
*/
Document convert( RepositoryIndexRecord record );
/**
* Convert a Lucene document to an index record.
*
* @param document the document
* @return the record
*/
RepositoryIndexRecord convert( Document document )
throws ParseException;
}

View File

@ -21,9 +21,13 @@
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumberTools;
import org.apache.maven.repository.indexing.record.MinimalArtifactIndexRecord;
import org.apache.maven.repository.indexing.record.MinimalIndexRecordFields;
import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
import org.codehaus.plexus.util.StringUtils;
import java.text.ParseException;
import java.util.Arrays;
/**
* Convert the minimal index record to a Lucene document.
*
@ -32,37 +36,41 @@
public class LuceneMinimalIndexRecordConverter
implements LuceneIndexRecordConverter
{
private static final String FLD_FILENAME = "j";
private static final String FLD_LAST_MODIFIED = "d";
private static final String FLD_FILE_SIZE = "s";
private static final String FLD_MD5 = "m";
private static final String FLD_CLASSES = "c";
public Document convert( RepositoryIndexRecord record )
{
MinimalArtifactIndexRecord standardIndexRecord = (MinimalArtifactIndexRecord) record;
MinimalArtifactIndexRecord rec = (MinimalArtifactIndexRecord) record;
Document document = new Document();
addTokenizedField( document, FLD_FILENAME, standardIndexRecord.getFilename() );
addUntokenizedField( document, FLD_LAST_MODIFIED, DateTools.timeToString( standardIndexRecord.getLastModified(),
DateTools.Resolution.SECOND ) );
addUntokenizedField( document, FLD_FILE_SIZE, NumberTools.longToString( standardIndexRecord.getSize() ) );
addUntokenizedField( document, FLD_MD5, standardIndexRecord.getMd5Checksum() );
addTokenizedField( document, FLD_CLASSES,
StringUtils.join( standardIndexRecord.getClasses().iterator(), "\n" ) );
addTokenizedField( document, MinimalIndexRecordFields.FILENAME, rec.getFilename() );
addUntokenizedField( document, MinimalIndexRecordFields.LAST_MODIFIED,
DateTools.timeToString( rec.getLastModified(), DateTools.Resolution.SECOND ) );
addUntokenizedField( document, MinimalIndexRecordFields.FILE_SIZE, NumberTools.longToString( rec.getSize() ) );
addUntokenizedField( document, MinimalIndexRecordFields.MD5, rec.getMd5Checksum() );
addTokenizedField( document, MinimalIndexRecordFields.CLASSES,
StringUtils.join( rec.getClasses().iterator(), "\n" ) );
return document;
}
public RepositoryIndexRecord convert( Document document )
throws ParseException
{
MinimalArtifactIndexRecord record = new MinimalArtifactIndexRecord();
record.setFilename( document.get( MinimalIndexRecordFields.FILENAME ) );
record.setLastModified( DateTools.stringToTime( document.get( MinimalIndexRecordFields.LAST_MODIFIED ) ) );
record.setSize( NumberTools.stringToLong( document.get( MinimalIndexRecordFields.FILE_SIZE ) ) );
record.setMd5Checksum( document.get( MinimalIndexRecordFields.MD5 ) );
record.setClasses( Arrays.asList( document.get( MinimalIndexRecordFields.CLASSES ).split( "\n" ) ) );
return record;
}
private static void addUntokenizedField( Document document, String name, String value )
{
if ( value != null )
{
document.add( new Field( name, value, Field.Store.YES, Field.Index.TOKENIZED ) );
document.add( new Field( name, value, Field.Store.YES, Field.Index.UN_TOKENIZED ) );
}
}

View File

@ -0,0 +1,40 @@
package org.apache.maven.repository.indexing.lucene;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.repository.indexing.query.Query;
/**
* TODO [!]: Description.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public class LuceneQuery
implements Query
{
private final org.apache.lucene.search.Query query;
public LuceneQuery( org.apache.lucene.search.Query query )
{
this.query = query;
}
org.apache.lucene.search.Query getLuceneQuery()
{
return query;
}
}

View File

@ -23,13 +23,19 @@
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 org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
import org.apache.maven.repository.indexing.RepositoryIndexException;
import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
import org.apache.maven.repository.indexing.query.Query;
import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@ -53,14 +59,13 @@ public class LuceneRepositoryArtifactIndex
private static final String FLD_PK = "pk";
public LuceneRepositoryArtifactIndex( File indexPath, ArtifactRepository repository,
LuceneIndexRecordConverter converter )
public LuceneRepositoryArtifactIndex( File indexPath, LuceneIndexRecordConverter converter )
{
this.indexLocation = indexPath;
this.converter = converter;
}
public void indexRecords( List records )
public void indexRecords( Collection records )
throws RepositoryIndexException
{
try
@ -75,7 +80,7 @@ public void indexRecords( List records )
addRecords( records );
}
private void addRecords( List records )
private void addRecords( Collection records )
throws RepositoryIndexException
{
IndexWriter indexWriter;
@ -136,7 +141,7 @@ private Analyzer getAnalyzer()
return new StandardAnalyzer();
}
private void deleteRecords( List records )
private void deleteRecords( Collection records )
throws IOException, RepositoryIndexException
{
if ( exists() )
@ -195,4 +200,63 @@ else if ( indexLocation.isDirectory() )
throw new RepositoryIndexException( indexLocation + " is not a directory." );
}
}
public List search( Query query )
throws RepositoryIndexSearchException
{
LuceneQuery lQuery = (LuceneQuery) query;
org.apache.lucene.search.Query luceneQuery = lQuery.getLuceneQuery();
IndexSearcher searcher;
try
{
searcher = new IndexSearcher( indexLocation.getAbsolutePath() );
}
catch ( IOException e )
{
throw new RepositoryIndexSearchException( "Unable to open index: " + e.getMessage(), e );
}
List records = new ArrayList();
try
{
Hits hits = searcher.search( luceneQuery );
for ( int i = 0; i < hits.length(); i++ )
{
Document doc = hits.doc( i );
records.add( converter.convert( doc ) );
}
}
catch ( IOException e )
{
throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e );
}
catch ( ParseException e )
{
throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e );
}
finally
{
closeQuietly( searcher );
}
return records;
}
private static void closeQuietly( IndexSearcher searcher )
{
try
{
if ( searcher != null )
{
searcher.close();
}
}
catch ( IOException e )
{
// ignore
}
}
}

View File

@ -33,11 +33,11 @@ public class LuceneRepositoryArtifactIndexFactory
{
public RepositoryArtifactIndex createStandardIndex( File indexPath, ArtifactRepository repository )
{
return new LuceneRepositoryArtifactIndex( indexPath, repository, new LuceneStandardIndexRecordConverter() );
return new LuceneRepositoryArtifactIndex( indexPath, new LuceneStandardIndexRecordConverter() );
}
public RepositoryArtifactIndex createMinimalIndex( File indexPath, ArtifactRepository repository )
{
return new LuceneRepositoryArtifactIndex( indexPath, repository, new LuceneMinimalIndexRecordConverter() );
return new LuceneRepositoryArtifactIndex( indexPath, new LuceneMinimalIndexRecordConverter() );
}
}

View File

@ -22,100 +22,116 @@
import org.apache.lucene.document.NumberTools;
import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
import org.apache.maven.repository.indexing.record.StandardArtifactIndexRecord;
import org.apache.maven.repository.indexing.record.StandardIndexRecordFields;
import org.codehaus.plexus.util.StringUtils;
import java.text.ParseException;
import java.util.Arrays;
/**
* Convert the standard index record to a Lucene document.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @todo use enum for field names
*/
public class LuceneStandardIndexRecordConverter
implements LuceneIndexRecordConverter
{
private static final String FLD_FILENAME = "filename";
private static final String FLD_GROUPID = "groupId";
private static final String FLD_ARTIFACTID = "artifactId";
private static final String FLD_VERSION = "version";
private static final String FLD_TYPE = "type";
private static final String FLD_CLASSIFIER = "classifier";
private static final String FLD_PACKAGING = "packaging";
private static final String FLD_REPOSITORY = "repo";
private static final String FLD_LAST_MODIFIED = "lastModified";
private static final String FLD_FILE_SIZE = "fileSize";
private static final String FLD_MD5 = "md5";
private static final String FLD_SHA1 = "sha1";
private static final String FLD_CLASSES = "classes";
private static final String FLD_PLUGINPREFIX = "pluginPrefix";
private static final String FLD_FILES = "files";
private static final String FLD_INCEPTION_YEAR = "inceptionYear";
private static final String FLD_PROJECT_NAME = "projectName";
private static final String FLD_PROJECT_DESCRIPTION = "projectDesc";
public Document convert( RepositoryIndexRecord record )
{
StandardArtifactIndexRecord standardIndexRecord = (StandardArtifactIndexRecord) record;
StandardArtifactIndexRecord rec = (StandardArtifactIndexRecord) record;
Document document = new Document();
addTokenizedField( document, FLD_FILENAME, standardIndexRecord.getFilename() );
addTokenizedField( document, FLD_GROUPID, standardIndexRecord.getGroupId() );
addTokenizedField( document, FLD_ARTIFACTID, standardIndexRecord.getArtifactId() );
addTokenizedField( document, FLD_VERSION, standardIndexRecord.getVersion() );
addUntokenizedField( document, FLD_TYPE, standardIndexRecord.getType() );
addTokenizedField( document, FLD_CLASSIFIER, standardIndexRecord.getClassifier() );
addUntokenizedField( document, FLD_PACKAGING, standardIndexRecord.getPackaging() );
addTokenizedField( document, FLD_REPOSITORY, standardIndexRecord.getRepository() );
addUntokenizedField( document, FLD_LAST_MODIFIED, DateTools.timeToString( standardIndexRecord.getLastModified(),
DateTools.Resolution.SECOND ) );
addUntokenizedField( document, FLD_FILE_SIZE, NumberTools.longToString( standardIndexRecord.getSize() ) );
addUntokenizedField( document, FLD_MD5, standardIndexRecord.getMd5Checksum() );
addUntokenizedField( document, FLD_SHA1, standardIndexRecord.getSha1Checksum() );
if ( standardIndexRecord.getClasses() != null )
addTokenizedField( document, StandardIndexRecordFields.FILENAME, rec.getFilename() );
addTokenizedField( document, StandardIndexRecordFields.GROUPID, rec.getGroupId() );
addExactField( document, StandardIndexRecordFields.GROUPID_EXACT, rec.getGroupId() );
addTokenizedField( document, StandardIndexRecordFields.ARTIFACTID, rec.getArtifactId() );
addExactField( document, StandardIndexRecordFields.ARTIFACTID_EXACT, rec.getArtifactId() );
addTokenizedField( document, StandardIndexRecordFields.VERSION, rec.getVersion() );
addExactField( document, StandardIndexRecordFields.VERSION_EXACT, rec.getVersion() );
addTokenizedField( document, StandardIndexRecordFields.BASE_VERSION, rec.getBaseVersion() );
addExactField( document, StandardIndexRecordFields.BASE_VERSION_EXACT, rec.getBaseVersion() );
addUntokenizedField( document, StandardIndexRecordFields.TYPE, rec.getType() );
addTokenizedField( document, StandardIndexRecordFields.CLASSIFIER, rec.getClassifier() );
addUntokenizedField( document, StandardIndexRecordFields.PACKAGING, rec.getPackaging() );
addUntokenizedField( document, StandardIndexRecordFields.REPOSITORY, rec.getRepository() );
addUntokenizedField( document, StandardIndexRecordFields.LAST_MODIFIED,
DateTools.timeToString( rec.getLastModified(), DateTools.Resolution.SECOND ) );
addUntokenizedField( document, StandardIndexRecordFields.FILE_SIZE, NumberTools.longToString( rec.getSize() ) );
addUntokenizedField( document, StandardIndexRecordFields.MD5, rec.getMd5Checksum() );
addUntokenizedField( document, StandardIndexRecordFields.SHA1, rec.getSha1Checksum() );
if ( rec.getClasses() != null )
{
addTokenizedField( document, FLD_CLASSES,
StringUtils.join( standardIndexRecord.getClasses().iterator(), "\n" ) );
addTokenizedField( document, StandardIndexRecordFields.CLASSES,
StringUtils.join( rec.getClasses().iterator(), "\n" ) );
}
if ( standardIndexRecord.getFiles() != null )
if ( rec.getFiles() != null )
{
addTokenizedField( document, FLD_FILES,
StringUtils.join( standardIndexRecord.getFiles().iterator(), "\n" ) );
addTokenizedField( document, StandardIndexRecordFields.FILES,
StringUtils.join( rec.getFiles().iterator(), "\n" ) );
}
addTokenizedField( document, FLD_PLUGINPREFIX, standardIndexRecord.getPluginPrefix() );
addUntokenizedField( document, FLD_INCEPTION_YEAR, standardIndexRecord.getInceptionYear() );
addTokenizedField( document, FLD_PROJECT_NAME, standardIndexRecord.getProjectName() );
addTokenizedField( document, FLD_PROJECT_DESCRIPTION, standardIndexRecord.getProjectDescription() );
addUntokenizedField( document, StandardIndexRecordFields.PLUGIN_PREFIX, rec.getPluginPrefix() );
addUntokenizedField( document, StandardIndexRecordFields.INCEPTION_YEAR, rec.getInceptionYear() );
addTokenizedField( document, StandardIndexRecordFields.PROJECT_NAME, rec.getProjectName() );
addTokenizedField( document, StandardIndexRecordFields.PROJECT_DESCRIPTION, rec.getProjectDescription() );
/* TODO: add later
document.add( Field.Keyword( FLD_LICENSE_URLS, "" ) );
document.add( Field.Keyword( FLD_DEPENDENCIES, "" ) );
document.add( Field.Keyword( FLD_PLUGINS_REPORT, "" ) );
document.add( Field.Keyword( FLD_PLUGINS_BUILD, "" ) );
document.add( Field.Keyword( StandardIndexRecordFields.FLD_LICENSE_URLS, "" ) );
document.add( Field.Keyword( StandardIndexRecordFields.FLD_DEPENDENCIES, "" ) );
document.add( Field.Keyword( StandardIndexRecordFields.FLD_PLUGINS_REPORT, "" ) );
document.add( Field.Keyword( StandardIndexRecordFields.FLD_PLUGINS_BUILD, "" ) );
*/
return document;
}
public RepositoryIndexRecord convert( Document document )
throws ParseException
{
StandardArtifactIndexRecord record = new StandardArtifactIndexRecord();
record.setFilename( document.get( StandardIndexRecordFields.FILENAME ) );
record.setGroupId( document.get( StandardIndexRecordFields.GROUPID ) );
record.setArtifactId( document.get( StandardIndexRecordFields.ARTIFACTID ) );
record.setVersion( document.get( StandardIndexRecordFields.VERSION ) );
record.setBaseVersion( document.get( StandardIndexRecordFields.BASE_VERSION ) );
record.setType( document.get( StandardIndexRecordFields.TYPE ) );
record.setClassifier( document.get( StandardIndexRecordFields.CLASSIFIER ) );
record.setPackaging( document.get( StandardIndexRecordFields.PACKAGING ) );
record.setRepository( document.get( StandardIndexRecordFields.REPOSITORY ) );
record.setLastModified( DateTools.stringToTime( document.get( StandardIndexRecordFields.LAST_MODIFIED ) ) );
record.setSize( NumberTools.stringToLong( document.get( StandardIndexRecordFields.FILE_SIZE ) ) );
record.setMd5Checksum( document.get( StandardIndexRecordFields.MD5 ) );
record.setSha1Checksum( document.get( StandardIndexRecordFields.SHA1 ) );
String classes = document.get( StandardIndexRecordFields.CLASSES );
if ( classes != null )
{
record.setClasses( Arrays.asList( classes.split( "\n" ) ) );
}
String files = document.get( StandardIndexRecordFields.FILES );
if ( files != null )
{
record.setFiles( Arrays.asList( files.split( "\n" ) ) );
}
record.setPluginPrefix( document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) );
record.setInceptionYear( document.get( StandardIndexRecordFields.INCEPTION_YEAR ) );
record.setProjectName( document.get( StandardIndexRecordFields.PROJECT_NAME ) );
record.setProjectDescription( document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) );
return record;
}
private static void addUntokenizedField( Document document, String name, String value )
{
if ( value != null )
{
document.add( new Field( name, value, Field.Store.YES, Field.Index.TOKENIZED ) );
document.add( new Field( name, value, Field.Store.YES, Field.Index.UN_TOKENIZED ) );
}
}
private static void addExactField( Document document, String name, String value )
{
if ( value != null )
{
document.add( new Field( name, value, Field.Store.NO, Field.Index.UN_TOKENIZED ) );
}
}

View File

@ -43,7 +43,7 @@ public class MinimalArtifactIndexRecord
private String filename;
/**
* The timestamp that the artifact file was last modified.
* The timestamp that the artifact file was last modified. Granularity is seconds.
*/
private long lastModified;
@ -52,6 +52,8 @@ public class MinimalArtifactIndexRecord
*/
private long size;
private static final int MS_PER_SEC = 1000;
public void setClasses( List classes )
{
this.classes = classes;
@ -69,7 +71,7 @@ public void setFilename( String filename )
public void setLastModified( long lastModified )
{
this.lastModified = lastModified;
this.lastModified = lastModified - lastModified % MS_PER_SEC;
}
public void setSize( long size )

View File

@ -0,0 +1,41 @@
package org.apache.maven.repository.indexing.record;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* The fields in a minimal artifact index record.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @todo should be an enum
*/
public class MinimalIndexRecordFields
{
public static final String FILENAME = "j";
public static final String LAST_MODIFIED = "d";
public static final String FILE_SIZE = "s";
public static final String MD5 = "m";
public static final String CLASSES = "c";
private MinimalIndexRecordFields()
{
// No touchy!
}
}

View File

@ -91,6 +91,11 @@ public class StandardArtifactIndexRecord
*/
private String projectName;
/**
* The base version (before the snapshot is determined).
*/
private String baseVersion;
public void setSha1Checksum( String sha1Checksum )
{
this.sha1Checksum = sha1Checksum;
@ -183,6 +188,10 @@ public boolean equals( Object obj )
{
return false;
}
if ( !baseVersion.equals( that.baseVersion ) )
{
return false;
}
if ( packaging != null ? !packaging.equals( that.packaging ) : that.packaging != null )
{
return false;
@ -215,6 +224,7 @@ public int hashCode()
result = 31 * result + groupId.hashCode();
result = 31 * result + artifactId.hashCode();
result = 31 * result + version.hashCode();
result = 31 * result + baseVersion.hashCode();
result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 );
result = 31 * result + ( type != null ? type.hashCode() : 0 );
result = 31 * result + ( files != null ? files.hashCode() : 0 );
@ -316,4 +326,14 @@ public String getProjectName()
{
return projectName;
}
public void setBaseVersion( String baseVersion )
{
this.baseVersion = baseVersion;
}
public String getBaseVersion()
{
return baseVersion;
}
}

View File

@ -88,9 +88,13 @@ public RepositoryIndexRecord createRecord( Artifact artifact )
String sha1 = readChecksum( file, Digester.SHA1 );
List files = null;
boolean archive = ARCHIVE_TYPES.contains( artifact.getType() );
try
{
files = readFilesInArchive( file );
if ( archive )
{
files = readFilesInArchive( file );
}
}
catch ( IOException e )
{
@ -98,12 +102,13 @@ public RepositoryIndexRecord createRecord( Artifact artifact )
}
// If it's an archive with no files, don't create a record
if ( !ARCHIVE_TYPES.contains( artifact.getType() ) || files != null )
if ( !archive || files != null )
{
record = new StandardArtifactIndexRecord();
record.setGroupId( artifact.getGroupId() );
record.setArtifactId( artifact.getArtifactId() );
record.setBaseVersion( artifact.getBaseVersion() );
record.setVersion( artifact.getVersion() );
record.setClassifier( artifact.getClassifier() );
record.setType( artifact.getType() );
@ -123,6 +128,7 @@ record = new StandardArtifactIndexRecord();
Artifact pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getVersion() );
pomArtifact.isSnapshot(); // gross hack around bug in maven-artifact
File pomFile = new File( artifact.getRepository().getBasedir(),
artifact.getRepository().pathOf( pomArtifact ) );
if ( pomFile.exists() )

View File

@ -0,0 +1,77 @@
package org.apache.maven.repository.indexing.record;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* The fields in a minimal artifact index record.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @todo should be an enum
*/
public class StandardIndexRecordFields
{
public static final String FILENAME = "filename";
public static final String GROUPID = "groupId";
public static final String GROUPID_EXACT = GROUPID + "_u";
public static final String ARTIFACTID = "artifactId";
public static final String ARTIFACTID_EXACT = ARTIFACTID + "_u";
public static final String VERSION = "version";
public static final String VERSION_EXACT = VERSION + "_u";
public static final String BASE_VERSION = "baseVersion";
public static final String BASE_VERSION_EXACT = BASE_VERSION + "_u";
public static final String TYPE = "type";
public static final String CLASSIFIER = "classifier";
public static final String PACKAGING = "packaging";
public static final String REPOSITORY = "repo";
public static final String LAST_MODIFIED = "lastModified";
public static final String FILE_SIZE = "fileSize";
public static final String MD5 = "md5";
public static final String SHA1 = "sha1";
public static final String CLASSES = "classes";
public static final String PLUGIN_PREFIX = "pluginPrefix";
public static final String FILES = "files";
public static final String INCEPTION_YEAR = "inceptionYear";
public static final String PROJECT_NAME = "projectName";
public static final String PROJECT_DESCRIPTION = "projectDesc";
private StandardIndexRecordFields()
{
// No touchy!
}
}

View File

@ -105,6 +105,8 @@ Indexer Design
* <<<m>>>: md5 checksum of the JAR
* <<<pk>>>: the primary key of the artifact
Only JARs are indexed at present. The JAR filename is used as the key for later deleting entries.
* Searching
@ -128,3 +130,7 @@ Indexer Design
reasons. It should not have to read any metadata files or properties of files such as size and checksum from the disk.
This enables searching a repository remotely without having the physical repository available, which is useful for
IDE integration among other things.
Note that to be able to do an exact match search, a field must be stored untokenized. For fields where it makes sense
to search both tokenized and untokenized, they will be stored twice. This currently includes: artifact ID, group ID,
and version.

View File

@ -0,0 +1,218 @@
package org.apache.maven.repository.indexing.lucene;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
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.versioning.VersionRange;
import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
import org.apache.maven.repository.indexing.record.MinimalIndexRecordFields;
import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Test the Lucene implementation of the artifact index search.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @todo would be nice to abstract some of the query away, but for now passing in a Lucene query directly is good enough
*/
public class LuceneMinimalArtifactIndexSearchTest
extends PlexusTestCase
{
private RepositoryArtifactIndex index;
private ArtifactRepository repository;
private ArtifactFactory artifactFactory;
private File indexLocation;
private RepositoryIndexRecordFactory recordFactory;
private Map records = new HashMap();
protected void setUp()
throws Exception
{
super.setUp();
recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "minimal" );
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
ArtifactRepositoryFactory repositoryFactory =
(ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
File file = getTestFile( "src/test/managed-repository" );
repository =
repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null );
RepositoryArtifactIndexFactory factory =
(RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" );
indexLocation = getTestFile( "target/test-index" );
FileUtils.deleteDirectory( indexLocation );
index = factory.createMinimalIndex( indexLocation, repository );
records.put( "test-jar", recordFactory.createRecord( createArtifact( "test-jar" ) ) );
records.put( "test-jar-jdk14",
recordFactory.createRecord( createArtifact( "test-jar", "1.0", "jar", "jdk14" ) ) );
records.put( "test-jar-and-pom",
recordFactory.createRecord( createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" ) ) );
records.put( "test-jar-and-pom-jdk14", recordFactory.createRecord(
createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" ) ) );
records.put( "test-child-pom",
recordFactory.createRecord( createArtifact( "test-child-pom", "1.0-20060728.121314-1", "jar" ) ) );
records.put( "test-archetype", recordFactory.createRecord( createArtifact( "test-archetype" ) ) );
records.put( "test-plugin", recordFactory.createRecord( createArtifact( "test-plugin" ) ) );
records.put( "test-pom", recordFactory.createRecord( createArtifact( "test-pom", "1.0", "pom" ) ) );
records.put( "parent-pom", recordFactory.createRecord( createArtifact( "parent-pom", "1", "pom" ) ) );
records.put( "test-dll", recordFactory.createRecord( createArtifact( "test-dll", "1.0.1.34", "dll" ) ) );
index.indexRecords( records.values() );
}
public void testExactMatchMd5()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( MinimalIndexRecordFields.MD5, "3a0adc365f849366cd8b633cad155cb7" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertEquals( "Check results size", 5, results.size() );
// test non-match fails
query = new TermQuery( new Term( MinimalIndexRecordFields.MD5, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testMatchFilename()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "maven" ) );
List results = index.search( new LuceneQuery( query ) );
assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) );
assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) );
assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) );
assertEquals( "Check results size", 7, results.size() );
/* TODO: if this is a result we want, we need to change the analyzer. Currently, it is tokenizing it as plugin-1.0 and plugin/1.0 in the path
query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "plugin" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertEquals( "Check results size", 1, results.size() );
*/
query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "test" ) );
results = index.search( new LuceneQuery( query ) );
assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) );
assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) );
assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) );
assertEquals( "Check results size", 7, results.size() );
// test non-match fails
query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testMatchClass()
throws RepositoryIndexSearchException
{
// TODO: should be preserving case!
Query query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "b.c.c" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertEquals( "Check results size", 5, results.size() );
/* TODO!: need to change the analyzer if we want partial classes (split on '.')
query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "C" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertEquals( "Check results size", 4, results.size() );
query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "MyMojo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertEquals( "Check results size", 1, results.size() );
*/
// test non-match fails
query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
private Artifact createArtifact( String artifactId )
{
return createArtifact( artifactId, "1.0", "jar", null );
}
private Artifact createArtifact( String artifactId, String version, String type )
{
return createArtifact( artifactId, version, type, null );
}
private Artifact createArtifact( String artifactId, String version, String type, String classifier )
{
Artifact artifact = artifactFactory.createDependencyArtifact( "org.apache.maven.repository.record", artifactId,
VersionRange.createFromVersion( version ), type,
classifier, Artifact.SCOPE_RUNTIME );
artifact.isSnapshot();
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
artifact.setRepository( repository );
return artifact;
}
}

View File

@ -29,6 +29,7 @@
import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
import org.apache.maven.repository.indexing.RepositoryIndexException;
import org.apache.maven.repository.indexing.record.MinimalIndexRecordFields;
import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory;
import org.codehaus.plexus.PlexusTestCase;
@ -134,7 +135,8 @@ public void testAddRecordNoIndex()
try
{
Document document = reader.document( 0 );
assertEquals( "Check document", repository.pathOf( artifact ), document.get( "j" ) );
assertEquals( "Check document", repository.pathOf( artifact ),
document.get( MinimalIndexRecordFields.FILENAME ) );
assertEquals( "Check index size", 1, reader.numDocs() );
}
finally
@ -274,12 +276,14 @@ private void createIndex( List docments )
private void assertRecord( Document document, Artifact artifact, String expectedChecksum, String expectedClasses )
{
assertEquals( "Check document filename", repository.pathOf( artifact ), document.get( "j" ) );
assertEquals( "Check document timestamp", getLastModified( artifact.getFile() ), document.get( "d" ) );
assertEquals( "Check document checksum", expectedChecksum, document.get( "m" ) );
assertEquals( "Check document filename", repository.pathOf( artifact ),
document.get( MinimalIndexRecordFields.FILENAME ) );
assertEquals( "Check document timestamp", getLastModified( artifact.getFile() ),
document.get( MinimalIndexRecordFields.LAST_MODIFIED ) );
assertEquals( "Check document checksum", expectedChecksum, document.get( MinimalIndexRecordFields.MD5 ) );
assertEquals( "Check document size", artifact.getFile().length(),
NumberTools.stringToLong( document.get( "s" ) ) );
assertEquals( "Check document classes", expectedClasses, document.get( "c" ) );
NumberTools.stringToLong( document.get( MinimalIndexRecordFields.FILE_SIZE ) ) );
assertEquals( "Check document classes", expectedClasses, document.get( MinimalIndexRecordFields.CLASSES ) );
}
private String getLastModified( File file )

View File

@ -0,0 +1,700 @@
package org.apache.maven.repository.indexing.lucene;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
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.versioning.VersionRange;
import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory;
import org.apache.maven.repository.indexing.record.StandardIndexRecordFields;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Test the Lucene implementation of the artifact index search.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @todo would be nice to abstract some of the query away, but for now passing in a Lucene query directly is good enough
*/
public class LuceneStandardArtifactIndexSearchTest
extends PlexusTestCase
{
private RepositoryArtifactIndex index;
private ArtifactRepository repository;
private ArtifactFactory artifactFactory;
private File indexLocation;
private RepositoryIndexRecordFactory recordFactory;
private Map records = new HashMap();
protected void setUp()
throws Exception
{
super.setUp();
recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" );
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
ArtifactRepositoryFactory repositoryFactory =
(ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
File file = getTestFile( "src/test/managed-repository" );
repository =
repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null );
RepositoryArtifactIndexFactory factory =
(RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" );
indexLocation = getTestFile( "target/test-index" );
FileUtils.deleteDirectory( indexLocation );
index = factory.createStandardIndex( indexLocation, repository );
records.put( "test-jar", recordFactory.createRecord( createArtifact( "test-jar" ) ) );
records.put( "test-jar-jdk14",
recordFactory.createRecord( createArtifact( "test-jar", "1.0", "jar", "jdk14" ) ) );
records.put( "test-jar-and-pom",
recordFactory.createRecord( createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" ) ) );
records.put( "test-jar-and-pom-jdk14", recordFactory.createRecord(
createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" ) ) );
records.put( "test-child-pom",
recordFactory.createRecord( createArtifact( "test-child-pom", "1.0-20060728.121314-1", "jar" ) ) );
records.put( "test-archetype", recordFactory.createRecord( createArtifact( "test-archetype" ) ) );
records.put( "test-plugin", recordFactory.createRecord( createArtifact( "test-plugin" ) ) );
records.put( "test-pom", recordFactory.createRecord( createArtifact( "test-pom", "1.0", "pom" ) ) );
records.put( "parent-pom", recordFactory.createRecord( createArtifact( "parent-pom", "1", "pom" ) ) );
records.put( "test-dll", recordFactory.createRecord( createArtifact( "test-dll", "1.0.1.34", "dll" ) ) );
index.indexRecords( records.values() );
}
public void testExactMatchVersion()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.VERSION_EXACT, "1.0" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) );
assertEquals( "Check results size", 5, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.VERSION_EXACT, "1.0-SNAPSHOT" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
query = new TermQuery( new Term( StandardIndexRecordFields.VERSION_EXACT, "1.0-20060728.121314-1" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertEquals( "Check results size", 1, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.VERSION_EXACT, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testExactMatchBaseVersion()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION_EXACT, "1.0" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) );
assertEquals( "Check results size", 5, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION_EXACT, "1.0-SNAPSHOT" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertEquals( "Check results size", 1, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION_EXACT, "1.0-20060728.121314-1" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION_EXACT, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testExactMatchGroupId()
throws RepositoryIndexSearchException
{
Query query =
new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, "org.apache.maven.repository.record" ) );
List results = index.search( new LuceneQuery( query ) );
assertEquals( "Check results size", 10, results.size() );
// test partial match fails
query = new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, "org.apache.maven" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testExactMatchArtifactId()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, "test-jar" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertEquals( "Check results size", 2, results.size() );
// test partial match fails
query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, "test" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testExactMatchType()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "maven-plugin" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertEquals( "Check results size", 1, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "jar" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertEquals( "Check results size", 5, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "dll" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-dll" ) ) );
assertEquals( "Check results size", 1, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "maven-archetype" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) );
assertEquals( "Check results size", 1, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testExactMatchPackaging()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "maven-plugin" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertEquals( "Check results size", 1, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "jar" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertEquals( "Check results size", 4, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "dll" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "maven-archetype" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testExactMatchPluginPrefix()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.PLUGIN_PREFIX, "test" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertEquals( "Check results size", 1, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.PLUGIN_PREFIX, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testExactMatchRepository()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.REPOSITORY, "test" ) );
List results = index.search( new LuceneQuery( query ) );
assertEquals( "Check results size", 10, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.REPOSITORY, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testExactMatchMd5()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.MD5, "3a0adc365f849366cd8b633cad155cb7" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertEquals( "Check results size", 5, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.MD5, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testExactMatchSha1()
throws RepositoryIndexSearchException
{
Query query =
new TermQuery( new Term( StandardIndexRecordFields.SHA1, "c66f18bf192cb613fc2febb4da541a34133eedc2" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertEquals( "Check results size", 5, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.SHA1, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testExactMatchInceptionYear()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.INCEPTION_YEAR, "2005" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "parent-pom" ) ) );
assertEquals( "Check results size", 3, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.INCEPTION_YEAR, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testMatchFilename()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.FILENAME, "maven" ) );
List results = index.search( new LuceneQuery( query ) );
assertEquals( "Check results size", 10, results.size() );
/* TODO: if this is a result we want, we need to change the analyzer. Currently, it is tokenizing it as plugin-1.0 and plugin/1.0 in the path
query = new TermQuery( new Term( StandardIndexRecordFields.FILENAME, "plugin" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertEquals( "Check results size", 1, results.size() );
*/
query = new TermQuery( new Term( StandardIndexRecordFields.FILENAME, "test" ) );
results = index.search( new LuceneQuery( query ) );
assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) );
assertEquals( "Check results size", 9, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.FILENAME, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testMatchGroupId()
throws RepositoryIndexSearchException
{
Query query =
new TermQuery( new Term( StandardIndexRecordFields.GROUPID, "org.apache.maven.repository.record" ) );
List results = index.search( new LuceneQuery( query ) );
assertEquals( "Check results size", 10, results.size() );
/* TODO: if we want this result, must change the analyzer to split on '.'
query = new TermQuery( new Term( StandardIndexRecordFields.GROUPID, "maven" ) );
results = index.search( new LuceneQuery( query ) );
assertEquals( "Check results size", 10, results.size() );
*/
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.GROUPID, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testMatchArtifactId()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID, "plugin" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertEquals( "Check results size", 1, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID, "test" ) );
results = index.search( new LuceneQuery( query ) );
assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) );
assertEquals( "Check results size", 9, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID, "maven" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testMatchVersion()
throws RepositoryIndexSearchException
{
// If partial matches are desired, need to change the analyzer for versions to split on '.'
Query query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "1" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "parent-pom" ) ) );
assertEquals( "Check results size", 1, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "1.0" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) );
assertEquals( "Check results size", 5, results.size() );
/* TODO: need to change analyzer to split on - if we want this
query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "snapshot" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "alpha" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertEquals( "Check results size", 2, results.size() );
*/
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testMatchBaseVersion()
throws RepositoryIndexSearchException
{
// If partial matches are desired, need to change the analyzer for versions to split on '.'
Query query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "1" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "parent-pom" ) ) );
assertEquals( "Check results size", 1, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "1.0" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) );
assertEquals( "Check results size", 5, results.size() );
/* TODO: need to change analyzer to split on - if we want this
query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "snapshot" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertEquals( "Check results size", 1, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "alpha" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertEquals( "Check results size", 2, results.size() );
*/
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testMatchClassifier()
throws RepositoryIndexSearchException
{
BooleanQuery bQuery = new BooleanQuery();
bQuery.add( new MatchAllDocsQuery(), BooleanClause.Occur.MUST );
bQuery.add( new TermQuery( new Term( StandardIndexRecordFields.CLASSIFIER, "jdk14" ) ),
BooleanClause.Occur.MUST_NOT );
List results = index.search( new LuceneQuery( bQuery ) );
assertFalse( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertFalse( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertEquals( "Check results size", 8, results.size() );
// TODO: can we search for "anything with no classifier" ?
Query query = new TermQuery( new Term( StandardIndexRecordFields.CLASSIFIER, "jdk14" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertEquals( "Check results size", 2, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.CLASSIFIER, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testMatchClass()
throws RepositoryIndexSearchException
{
// TODO: should be preserving case!
Query query = new TermQuery( new Term( StandardIndexRecordFields.CLASSES, "b.c.c" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertEquals( "Check results size", 5, results.size() );
/* TODO!: need to change the analyzer if we want partial classes (split on '.')
query = new TermQuery( new Term( StandardIndexRecordFields.CLASSES, "C" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
assertEquals( "Check results size", 4, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.CLASSES, "MyMojo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertEquals( "Check results size", 1, results.size() );
*/
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.CLASSES, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testMatchFiles()
throws RepositoryIndexSearchException
{
// TODO: should be preserving case!
Query query = new TermQuery( new Term( StandardIndexRecordFields.FILES, "manifest.mf" ) );
List results = index.search( new LuceneQuery( query ) );
assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) );
assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) );
assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) );
assertEquals( "Check results size", 7, results.size() );
/*
// TODO: should be preserving case, and '-inf'!
query = new TermQuery( new Term( StandardIndexRecordFields.FILES, "meta-inf" ) );
results = index.search( new LuceneQuery( query ) );
assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) );
assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) );
assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) );
assertEquals( "Check results size", 7, results.size() );
*/
query = new TermQuery( new Term( StandardIndexRecordFields.FILES, "plugin.xml" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertEquals( "Check results size", 1, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.FILES, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testMatchProjectName()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_NAME, "mojo" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
assertEquals( "Check results size", 1, results.size() );
query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_NAME, "maven" ) );
results = index.search( new LuceneQuery( query ) );
assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) );
assertFalse( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertEquals( "Check results size", 2, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_NAME, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
public void testMatchProjectDescription()
throws RepositoryIndexSearchException
{
Query query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_DESCRIPTION, "description" ) );
List results = index.search( new LuceneQuery( query ) );
assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "parent-pom" ) ) );
assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) );
assertEquals( "Check results size", 3, results.size() );
// test non-match fails
query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_DESCRIPTION, "foo" ) );
results = index.search( new LuceneQuery( query ) );
assertTrue( "Check results size", results.isEmpty() );
}
private Artifact createArtifact( String artifactId )
{
return createArtifact( artifactId, "1.0", "jar", null );
}
private Artifact createArtifact( String artifactId, String version, String type )
{
return createArtifact( artifactId, version, type, null );
}
private Artifact createArtifact( String artifactId, String version, String type, String classifier )
{
Artifact artifact = artifactFactory.createDependencyArtifact( "org.apache.maven.repository.record", artifactId,
VersionRange.createFromVersion( version ), type,
classifier, Artifact.SCOPE_RUNTIME );
artifact.isSnapshot();
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
artifact.setRepository( repository );
return artifact;
}
}

View File

@ -31,6 +31,7 @@
import org.apache.maven.repository.indexing.RepositoryIndexException;
import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory;
import org.apache.maven.repository.indexing.record.StandardIndexRecordFields;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@ -276,47 +277,51 @@ private void createIndex( List docments )
private void assertRecord( Artifact artifact, Document document, String expectedArtifactId, String expectedType,
String expectedMd5, String expectedSha1 )
{
assertEquals( "Check document filename", repository.pathOf( artifact ), document.get( "filename" ) );
assertEquals( "Check document groupId", "org.apache.maven.repository.record", document.get( "groupId" ) );
assertEquals( "Check document artifactId", expectedArtifactId, document.get( "artifactId" ) );
assertEquals( "Check document version", "1.0", document.get( "version" ) );
assertEquals( "Check document type", expectedType, document.get( "type" ) );
assertEquals( "Check document repository", "test", document.get( "repo" ) );
assertEquals( "Check document filename", repository.pathOf( artifact ),
document.get( StandardIndexRecordFields.FILENAME ) );
assertEquals( "Check document groupId", "org.apache.maven.repository.record",
document.get( StandardIndexRecordFields.GROUPID ) );
assertEquals( "Check document artifactId", expectedArtifactId,
document.get( StandardIndexRecordFields.ARTIFACTID ) );
assertEquals( "Check document version", "1.0", document.get( StandardIndexRecordFields.VERSION ) );
assertEquals( "Check document type", expectedType, document.get( StandardIndexRecordFields.TYPE ) );
assertEquals( "Check document repository", "test", document.get( StandardIndexRecordFields.REPOSITORY ) );
assertEquals( "Check document timestamp", getLastModified( artifact.getFile() ),
document.get( "lastModified" ) );
assertEquals( "Check document md5", expectedMd5, document.get( "md5" ) );
assertEquals( "Check document sha1", expectedSha1, document.get( "sha1" ) );
document.get( StandardIndexRecordFields.LAST_MODIFIED ) );
assertEquals( "Check document md5", expectedMd5, document.get( StandardIndexRecordFields.MD5 ) );
assertEquals( "Check document sha1", expectedSha1, document.get( StandardIndexRecordFields.SHA1 ) );
assertEquals( "Check document file size", artifact.getFile().length(),
NumberTools.stringToLong( document.get( "fileSize" ) ) );
assertNull( "Check document classifier", document.get( "classifier" ) );
NumberTools.stringToLong( document.get( StandardIndexRecordFields.FILE_SIZE ) ) );
assertNull( "Check document classifier", document.get( StandardIndexRecordFields.CLASSIFIER ) );
}
private void assertPomRecord( Artifact artifact, Document document )
{
assertRecord( artifact, document, "test-pom", "pom", "32dbef7ff11eb933bd8b7e7bcab85406",
"c3b374e394607e1e705e71c227f62641e8621ebe" );
assertNull( "Check document classes", document.get( "classes" ) );
assertNull( "Check document files", document.get( "files" ) );
assertNull( "Check document pluginPrefix", document.get( "pluginPrefix" ) );
assertEquals( "Check document year", "2005", document.get( "inceptionYear" ) );
assertNull( "Check document classes", document.get( StandardIndexRecordFields.CLASSES ) );
assertNull( "Check document files", document.get( StandardIndexRecordFields.FILES ) );
assertNull( "Check document pluginPrefix", document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) );
assertEquals( "Check document year", "2005", document.get( StandardIndexRecordFields.INCEPTION_YEAR ) );
assertEquals( "Check document project name", "Maven Repository Manager Test POM",
document.get( "projectName" ) );
assertEquals( "Check document project description", "Description", document.get( "projectDesc" ) );
assertEquals( "Check document packaging", "pom", document.get( "packaging" ) );
document.get( StandardIndexRecordFields.PROJECT_NAME ) );
assertEquals( "Check document project description", "Description",
document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) );
assertEquals( "Check document packaging", "pom", document.get( StandardIndexRecordFields.PACKAGING ) );
}
private void assertJarRecord( Artifact artifact, Document document )
{
assertRecord( artifact, document, "test-jar", "jar", "3a0adc365f849366cd8b633cad155cb7",
"c66f18bf192cb613fc2febb4da541a34133eedc2" );
assertEquals( "Check document classes", "A\nb.B\nb.c.C", document.get( "classes" ) );
assertEquals( "Check document classes", "A\nb.B\nb.c.C", document.get( StandardIndexRecordFields.CLASSES ) );
assertEquals( "Check document files", "META-INF/MANIFEST.MF\nA.class\nb/B.class\nb/c/C.class",
document.get( "files" ) );
assertNull( "Check document inceptionYear", document.get( "inceptionYear" ) );
assertNull( "Check document projectName", document.get( "projectName" ) );
assertNull( "Check document projectDesc", document.get( "projectDesc" ) );
assertNull( "Check document pluginPrefix", document.get( "pluginPrefix" ) );
assertNull( "Check document packaging", document.get( "packaging" ) );
document.get( StandardIndexRecordFields.FILES ) );
assertNull( "Check document inceptionYear", document.get( StandardIndexRecordFields.INCEPTION_YEAR ) );
assertNull( "Check document projectName", document.get( StandardIndexRecordFields.PROJECT_NAME ) );
assertNull( "Check document projectDesc", document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) );
assertNull( "Check document pluginPrefix", document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) );
assertNull( "Check document packaging", document.get( StandardIndexRecordFields.PACKAGING ) );
}
private void assertPluginRecord( Artifact artifact, Document document )
@ -324,16 +329,18 @@ private void assertPluginRecord( Artifact artifact, Document document )
assertRecord( artifact, document, "test-plugin", "maven-plugin", "06f6fe25e46c4d4fb5be4f56a9bab0ee",
"382c1ebfb5d0c7d6061c2f8569fb53f8fc00fec2" );
assertEquals( "Check document classes", "org.apache.maven.repository.record.MyMojo",
document.get( "classes" ) );
document.get( StandardIndexRecordFields.CLASSES ) );
assertEquals( "Check document files", "META-INF/MANIFEST.MF\n" + "META-INF/maven/plugin.xml\n" +
"org/apache/maven/repository/record/MyMojo.class\n" +
"META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.xml\n" +
"META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.properties", document.get( "files" ) );
assertEquals( "Check document pluginPrefix", "test", document.get( "pluginPrefix" ) );
assertEquals( "Check document packaging", "maven-plugin", document.get( "packaging" ) );
assertNull( "Check document inceptionYear", document.get( "inceptionYear" ) );
assertEquals( "Check document project name", "Maven Mojo Archetype", document.get( "projectName" ) );
assertNull( "Check document projectDesc", document.get( "projectDesc" ) );
"META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.properties",
document.get( StandardIndexRecordFields.FILES ) );
assertEquals( "Check document pluginPrefix", "test", document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) );
assertEquals( "Check document packaging", "maven-plugin", document.get( StandardIndexRecordFields.PACKAGING ) );
assertNull( "Check document inceptionYear", document.get( StandardIndexRecordFields.INCEPTION_YEAR ) );
assertEquals( "Check document project name", "Maven Mojo Archetype",
document.get( StandardIndexRecordFields.PROJECT_NAME ) );
assertNull( "Check document projectDesc", document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) );
}
private String getLastModified( File file )

View File

@ -21,6 +21,7 @@
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.versioning.VersionRange;
import org.apache.maven.repository.indexing.RepositoryIndexException;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@ -85,10 +86,44 @@ public void testIndexedJar()
assertEquals( "check record", expectedRecord, record );
}
public void testIndexedJarWithClassifier()
throws RepositoryIndexException
{
Artifact artifact = createArtifact( "test-jar", "1.0", "jar", "jdk14" );
RepositoryIndexRecord record = factory.createRecord( artifact );
MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord();
expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" );
expectedRecord.setFilename( repository.pathOf( artifact ) );
expectedRecord.setLastModified( artifact.getFile().lastModified() );
expectedRecord.setSize( artifact.getFile().length() );
expectedRecord.setClasses( JAR_CLASS_LIST );
assertEquals( "check record", expectedRecord, record );
}
public void testIndexedJarAndPom()
throws RepositoryIndexException
{
Artifact artifact = createArtifact( "test-jar-and-pom" );
Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" );
RepositoryIndexRecord record = factory.createRecord( artifact );
MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord();
expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" );
expectedRecord.setFilename( repository.pathOf( artifact ) );
expectedRecord.setLastModified( artifact.getFile().lastModified() );
expectedRecord.setSize( artifact.getFile().length() );
expectedRecord.setClasses( JAR_CLASS_LIST );
assertEquals( "check record", expectedRecord, record );
}
public void testIndexedJarAndPomWithClassifier()
throws RepositoryIndexException
{
Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" );
RepositoryIndexRecord record = factory.createRecord( artifact );
@ -116,7 +151,7 @@ public void testNonIndexedPom()
throws RepositoryIndexException
{
// If we pass in only the POM that belongs to a JAR, then expect null not the POM
Artifact artifact = createArtifact( "test-jar-and-pom", "1.0", "pom" );
Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "pom" );
RepositoryIndexRecord record = factory.createRecord( artifact );
@ -189,7 +224,15 @@ private Artifact createArtifact( String artifactId )
private Artifact createArtifact( String artifactId, String version, String type )
{
Artifact artifact = artifactFactory.createBuildArtifact( TEST_GROUP_ID, artifactId, version, type );
return createArtifact( artifactId, version, type, null );
}
private Artifact createArtifact( String artifactId, String version, String type, String classifier )
{
Artifact artifact = artifactFactory.createDependencyArtifact( TEST_GROUP_ID, artifactId,
VersionRange.createFromVersion( version ), type,
classifier, Artifact.SCOPE_RUNTIME );
artifact.isSnapshot();
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
artifact.setRepository( repository );
return artifact;

View File

@ -21,6 +21,7 @@
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.versioning.VersionRange;
import org.apache.maven.repository.indexing.RepositoryIndexException;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@ -85,6 +86,7 @@ public void testIndexedJar()
expectedRecord.setClasses( JAR_CLASS_LIST );
expectedRecord.setArtifactId( "test-jar" );
expectedRecord.setGroupId( TEST_GROUP_ID );
expectedRecord.setBaseVersion( "1.0" );
expectedRecord.setVersion( "1.0" );
expectedRecord.setFiles( JAR_FILE_LIST );
expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" );
@ -94,10 +96,36 @@ public void testIndexedJar()
assertEquals( "check record", expectedRecord, record );
}
public void testIndexedJarWithClassifier()
throws RepositoryIndexException
{
Artifact artifact = createArtifact( "test-jar", "1.0", "jar", "jdk14" );
RepositoryIndexRecord record = factory.createRecord( artifact );
StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord();
expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" );
expectedRecord.setFilename( repository.pathOf( artifact ) );
expectedRecord.setLastModified( artifact.getFile().lastModified() );
expectedRecord.setSize( artifact.getFile().length() );
expectedRecord.setClasses( JAR_CLASS_LIST );
expectedRecord.setArtifactId( "test-jar" );
expectedRecord.setGroupId( TEST_GROUP_ID );
expectedRecord.setBaseVersion( "1.0" );
expectedRecord.setVersion( "1.0" );
expectedRecord.setFiles( JAR_FILE_LIST );
expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" );
expectedRecord.setType( "jar" );
expectedRecord.setRepository( "test" );
expectedRecord.setClassifier( "jdk14" );
assertEquals( "check record", expectedRecord, record );
}
public void testIndexedJarAndPom()
throws RepositoryIndexException
{
Artifact artifact = createArtifact( "test-jar-and-pom" );
Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" );
RepositoryIndexRecord record = factory.createRecord( artifact );
@ -109,7 +137,8 @@ public void testIndexedJarAndPom()
expectedRecord.setClasses( JAR_CLASS_LIST );
expectedRecord.setArtifactId( "test-jar-and-pom" );
expectedRecord.setGroupId( TEST_GROUP_ID );
expectedRecord.setVersion( "1.0" );
expectedRecord.setBaseVersion( "1.0-alpha-1" );
expectedRecord.setVersion( "1.0-alpha-1" );
expectedRecord.setFiles( JAR_FILE_LIST );
expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" );
expectedRecord.setType( "jar" );
@ -120,10 +149,38 @@ public void testIndexedJarAndPom()
assertEquals( "check record", expectedRecord, record );
}
public void testIndexedJarAndPomWithClassifier()
throws RepositoryIndexException
{
Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" );
RepositoryIndexRecord record = factory.createRecord( artifact );
StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord();
expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" );
expectedRecord.setFilename( repository.pathOf( artifact ) );
expectedRecord.setLastModified( artifact.getFile().lastModified() );
expectedRecord.setSize( artifact.getFile().length() );
expectedRecord.setClasses( JAR_CLASS_LIST );
expectedRecord.setArtifactId( "test-jar-and-pom" );
expectedRecord.setGroupId( TEST_GROUP_ID );
expectedRecord.setBaseVersion( "1.0-alpha-1" );
expectedRecord.setVersion( "1.0-alpha-1" );
expectedRecord.setFiles( JAR_FILE_LIST );
expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" );
expectedRecord.setType( "jar" );
expectedRecord.setRepository( "test" );
expectedRecord.setPackaging( "jar" );
expectedRecord.setProjectName( "Test JAR and POM" );
expectedRecord.setClassifier( "jdk14" );
assertEquals( "check record", expectedRecord, record );
}
public void testIndexedJarWithParentPom()
throws RepositoryIndexException
{
Artifact artifact = createArtifact( "test-child-pom" );
Artifact artifact = createArtifact( "test-child-pom", "1.0-20060728.121314-1", "jar" );
RepositoryIndexRecord record = factory.createRecord( artifact );
@ -135,7 +192,8 @@ public void testIndexedJarWithParentPom()
expectedRecord.setClasses( JAR_CLASS_LIST );
expectedRecord.setArtifactId( "test-child-pom" );
expectedRecord.setGroupId( TEST_GROUP_ID );
expectedRecord.setVersion( "1.0" );
expectedRecord.setBaseVersion( "1.0-SNAPSHOT" );
expectedRecord.setVersion( "1.0-20060728.121314-1" );
expectedRecord.setFiles( JAR_FILE_LIST );
expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" );
expectedRecord.setType( "jar" );
@ -162,6 +220,7 @@ public void testIndexedPom()
expectedRecord.setSize( artifact.getFile().length() );
expectedRecord.setArtifactId( "test-pom" );
expectedRecord.setGroupId( TEST_GROUP_ID );
expectedRecord.setBaseVersion( "1.0" );
expectedRecord.setVersion( "1.0" );
expectedRecord.setSha1Checksum( "c3b374e394607e1e705e71c227f62641e8621ebe" );
expectedRecord.setType( "pom" );
@ -211,6 +270,7 @@ public void testIndexedPlugin()
expectedRecord.setSize( artifact.getFile().length() );
expectedRecord.setArtifactId( "test-plugin" );
expectedRecord.setGroupId( TEST_GROUP_ID );
expectedRecord.setBaseVersion( "1.0" );
expectedRecord.setVersion( "1.0" );
expectedRecord.setSha1Checksum( "382c1ebfb5d0c7d6061c2f8569fb53f8fc00fec2" );
expectedRecord.setType( "maven-plugin" );
@ -241,6 +301,7 @@ public void testIndexedArchetype()
expectedRecord.setSize( artifact.getFile().length() );
expectedRecord.setArtifactId( "test-archetype" );
expectedRecord.setGroupId( TEST_GROUP_ID );
expectedRecord.setBaseVersion( "1.0" );
expectedRecord.setVersion( "1.0" );
expectedRecord.setSha1Checksum( "5ebabafdbcd6684ae434c06e22c32844df284b05" );
expectedRecord.setType( "maven-archetype" );
@ -279,6 +340,7 @@ public void testDll()
expectedRecord.setSize( artifact.getFile().length() );
expectedRecord.setArtifactId( "test-dll" );
expectedRecord.setGroupId( TEST_GROUP_ID );
expectedRecord.setBaseVersion( "1.0.1.34" );
expectedRecord.setVersion( "1.0.1.34" );
expectedRecord.setSha1Checksum( "da39a3ee5e6b4b0d3255bfef95601890afd80709" );
expectedRecord.setType( "dll" );
@ -304,7 +366,15 @@ private Artifact createArtifact( String artifactId )
private Artifact createArtifact( String artifactId, String version, String type )
{
Artifact artifact = artifactFactory.createBuildArtifact( TEST_GROUP_ID, artifactId, version, type );
return createArtifact( artifactId, version, type, null );
}
private Artifact createArtifact( String artifactId, String version, String type, String classifier )
{
Artifact artifact = artifactFactory.createDependencyArtifact( TEST_GROUP_ID, artifactId,
VersionRange.createFromVersion( version ), type,
classifier, Artifact.SCOPE_RUNTIME );
artifact.isSnapshot();
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
artifact.setRepository( repository );
return artifact;

View File

@ -23,6 +23,6 @@
<version>1</version>
</parent>
<artifactId>test-child-pom</artifactId>
<version>1.0</version>
<version>1.0-20060731-121314-1</version>
<name>Child Project</name>
</project>

View File

@ -19,7 +19,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.repository.record</groupId>
<artifactId>test-jar-and-pom</artifactId>
<version>1.0</version>
<version>1.0-alpha-1</version>
<name>Test JAR and POM</name>
<dependencies>
<dependency>