mirror of https://github.com/apache/archiva.git
[MRM-127] add more tests, bring in line with design, more consistency with original eclipse indexer in class and filename fields
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@425935 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
01cde262dd
commit
436d0b75ca
|
@ -16,7 +16,11 @@ package org.apache.maven.repository.indexing.lucene;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.document.DateTools;
|
||||
import org.apache.lucene.document.Document;
|
||||
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.RepositoryIndexRecord;
|
||||
|
||||
/**
|
||||
|
@ -27,9 +31,44 @@ import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
|
|||
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 )
|
||||
{
|
||||
// TODO: implement!
|
||||
return null;
|
||||
MinimalArtifactIndexRecord standardIndexRecord = (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, standardIndexRecord.getClasses() );
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
private static void addTokenizedField( Document document, String name, String value )
|
||||
{
|
||||
if ( value != null )
|
||||
{
|
||||
document.add( new Field( name, value, Field.Store.YES, Field.Index.TOKENIZED ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,12 +58,16 @@ public class LuceneStandardIndexRecordConverter
|
|||
|
||||
private static final String FLD_CLASSES = "classes";
|
||||
|
||||
private static final String FLD_PACKAGES = "packages";
|
||||
|
||||
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;
|
||||
|
@ -83,9 +87,11 @@ public class LuceneStandardIndexRecordConverter
|
|||
addUntokenizedField( document, FLD_MD5, standardIndexRecord.getMd5Checksum() );
|
||||
addUntokenizedField( document, FLD_SHA1, standardIndexRecord.getSha1Checksum() );
|
||||
addTokenizedField( document, FLD_CLASSES, standardIndexRecord.getClasses() );
|
||||
addTokenizedField( document, FLD_PACKAGES, standardIndexRecord.getPackages() );
|
||||
addTokenizedField( document, FLD_FILES, standardIndexRecord.getFiles() );
|
||||
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() );
|
||||
/* TODO: add later
|
||||
document.add( Field.Keyword( FLD_LICENSE_URLS, "" ) );
|
||||
document.add( Field.Keyword( FLD_DEPENDENCIES, "" ) );
|
||||
|
@ -111,5 +117,4 @@ public class LuceneStandardIndexRecordConverter
|
|||
document.add( new Field( name, value, Field.Store.YES, Field.Index.TOKENIZED ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class MinimalArtifactIndexRecord
|
|||
implements RepositoryIndexRecord
|
||||
{
|
||||
/**
|
||||
* The classes in the archive for the artifact, if it is a JAR. The package name is <b>not</b> included.
|
||||
* The classes in the archive for the artifact, if it is a JAR.
|
||||
*/
|
||||
private String classes;
|
||||
|
||||
|
|
|
@ -21,8 +21,11 @@ import org.apache.maven.repository.digest.Digester;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* An index record type for the minimal index.
|
||||
|
@ -34,12 +37,15 @@ import java.util.List;
|
|||
public class MinimalArtifactIndexRecordFactory
|
||||
extends AbstractArtifactIndexRecordFactory
|
||||
{
|
||||
/* List of types to index. */
|
||||
private static final Set INDEXED_TYPES = new HashSet( Arrays.asList( new String[]{"jar", "maven-plugin"} ) );
|
||||
|
||||
public RepositoryIndexRecord createRecord( Artifact artifact )
|
||||
{
|
||||
MinimalArtifactIndexRecord record = null;
|
||||
|
||||
File file = artifact.getFile();
|
||||
if ( file != null && "jar".equals( artifact.getType() ) && file.exists() )
|
||||
if ( file != null && INDEXED_TYPES.contains( artifact.getType() ) && file.exists() )
|
||||
{
|
||||
String md5 = readChecksum( file, Digester.MD5 );
|
||||
|
||||
|
@ -57,7 +63,7 @@ public class MinimalArtifactIndexRecordFactory
|
|||
{
|
||||
record = new MinimalArtifactIndexRecord();
|
||||
record.setMd5Checksum( md5 );
|
||||
record.setFilename( file.getName() );
|
||||
record.setFilename( artifact.getRepository().pathOf( artifact ) );
|
||||
record.setLastModified( file.lastModified() );
|
||||
record.setSize( file.length() );
|
||||
record.setClasses( getClassesFromFiles( files ) );
|
||||
|
@ -76,9 +82,7 @@ public class MinimalArtifactIndexRecordFactory
|
|||
|
||||
if ( isClass( name ) )
|
||||
{
|
||||
int idx = name.lastIndexOf( '/' );
|
||||
String classname = name.substring( idx + 1, name.length() - 6 );
|
||||
classes.append( classname ).append( "\n" );
|
||||
classes.append( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) ).append( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package org.apache.maven.repository.indexing.record;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Apache Software Foundation.
|
||||
*
|
||||
|
@ -18,6 +16,9 @@ import org.apache.maven.artifact.Artifact;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.repository.indexing.RepositoryIndexException;
|
||||
|
||||
/**
|
||||
* The layout of a record in a repository index.
|
||||
*
|
||||
|
@ -35,6 +36,9 @@ public interface RepositoryIndexRecordFactory
|
|||
*
|
||||
* @param artifact the artifact
|
||||
* @return the index record
|
||||
* @throws RepositoryIndexException if there is a problem constructing the record (due to not being able to read the artifact file as a POM)
|
||||
*/
|
||||
RepositoryIndexRecord createRecord( Artifact artifact );
|
||||
RepositoryIndexRecord createRecord( Artifact artifact )
|
||||
throws RepositoryIndexException;
|
||||
|
||||
}
|
||||
|
|
|
@ -54,11 +54,6 @@ public class StandardArtifactIndexRecord
|
|||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* A list of packages (separated by '\n') in the artifact if it contains Java classes.
|
||||
*/
|
||||
private String packages;
|
||||
|
||||
/**
|
||||
* A list of files (separated by '\n') in the artifact if it is an archive.
|
||||
*/
|
||||
|
@ -79,6 +74,21 @@ public class StandardArtifactIndexRecord
|
|||
*/
|
||||
private String pluginPrefix;
|
||||
|
||||
/**
|
||||
* The year the project was started.
|
||||
*/
|
||||
private String inceptionYear;
|
||||
|
||||
/**
|
||||
* The description of the project.
|
||||
*/
|
||||
private String projectDescription;
|
||||
|
||||
/**
|
||||
* The name of the project.
|
||||
*/
|
||||
private String projectName;
|
||||
|
||||
public void setSha1Checksum( String sha1Checksum )
|
||||
{
|
||||
this.sha1Checksum = sha1Checksum;
|
||||
|
@ -109,11 +119,6 @@ public class StandardArtifactIndexRecord
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public void setPackages( String packages )
|
||||
{
|
||||
this.packages = packages;
|
||||
}
|
||||
|
||||
public void setFiles( String files )
|
||||
{
|
||||
this.files = files;
|
||||
|
@ -160,10 +165,6 @@ public class StandardArtifactIndexRecord
|
|||
{
|
||||
return false;
|
||||
}
|
||||
if ( packages != null ? !packages.equals( that.packages ) : that.packages != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( repository != null ? !repository.equals( that.repository ) : that.repository != null )
|
||||
{
|
||||
return false;
|
||||
|
@ -188,6 +189,19 @@ public class StandardArtifactIndexRecord
|
|||
{
|
||||
return false;
|
||||
}
|
||||
if ( projectName != null ? !projectName.equals( that.projectName ) : that.projectName != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( inceptionYear != null ? !inceptionYear.equals( that.inceptionYear ) : that.inceptionYear != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( projectDescription != null ? !projectDescription.equals( that.projectDescription )
|
||||
: that.projectDescription != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -201,11 +215,13 @@ public class StandardArtifactIndexRecord
|
|||
result = 31 * result + version.hashCode();
|
||||
result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 );
|
||||
result = 31 * result + ( type != null ? type.hashCode() : 0 );
|
||||
result = 31 * result + ( packages != null ? packages.hashCode() : 0 );
|
||||
result = 31 * result + ( files != null ? files.hashCode() : 0 );
|
||||
result = 31 * result + ( repository != null ? repository.hashCode() : 0 );
|
||||
result = 31 * result + ( packaging != null ? packaging.hashCode() : 0 );
|
||||
result = 31 * result + ( pluginPrefix != null ? pluginPrefix.hashCode() : 0 );
|
||||
result = 31 * result + ( inceptionYear != null ? inceptionYear.hashCode() : 0 );
|
||||
result = 31 * result + ( projectName != null ? projectName.hashCode() : 0 );
|
||||
result = 31 * result + ( projectDescription != null ? projectDescription.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -239,11 +255,6 @@ public class StandardArtifactIndexRecord
|
|||
return type;
|
||||
}
|
||||
|
||||
public String getPackages()
|
||||
{
|
||||
return packages;
|
||||
}
|
||||
|
||||
public String getFiles()
|
||||
{
|
||||
return files;
|
||||
|
@ -273,4 +284,34 @@ public class StandardArtifactIndexRecord
|
|||
{
|
||||
this.pluginPrefix = pluginPrefix;
|
||||
}
|
||||
|
||||
public void setInceptionYear( String inceptionYear )
|
||||
{
|
||||
this.inceptionYear = inceptionYear;
|
||||
}
|
||||
|
||||
public void setProjectDescription( String description )
|
||||
{
|
||||
this.projectDescription = description;
|
||||
}
|
||||
|
||||
public void setProjectName( String projectName )
|
||||
{
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
public String getInceptionYear()
|
||||
{
|
||||
return inceptionYear;
|
||||
}
|
||||
|
||||
public String getProjectDescription()
|
||||
{
|
||||
return projectDescription;
|
||||
}
|
||||
|
||||
public String getProjectName()
|
||||
{
|
||||
return projectName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,15 +17,29 @@ package org.apache.maven.repository.indexing.record;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
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.io.xpp3.MetadataXpp3Reader;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.repository.digest.Digester;
|
||||
import org.apache.maven.repository.indexing.RepositoryIndexException;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -46,11 +60,18 @@ public class StandardArtifactIndexRecordFactory
|
|||
private static final Set ARCHIVE_TYPES =
|
||||
new HashSet( Arrays.asList( new String[]{"jar", "zip", "ejb", "par", "sar", "war", "ear"} ) );
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ArtifactFactory artifactFactory;
|
||||
|
||||
public RepositoryIndexRecord createRecord( Artifact artifact )
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
StandardArtifactIndexRecord record = null;
|
||||
|
||||
File file = artifact.getFile();
|
||||
// TODO: is this condition really a possibility?
|
||||
if ( file != null && file.exists() )
|
||||
{
|
||||
String md5 = readChecksum( file, Digester.MD5 );
|
||||
|
@ -59,21 +80,15 @@ public class StandardArtifactIndexRecordFactory
|
|||
List files = null;
|
||||
try
|
||||
{
|
||||
if ( ARCHIVE_TYPES.contains( artifact.getType() ) )
|
||||
{
|
||||
files = readFilesInArchive( file );
|
||||
}
|
||||
else
|
||||
{
|
||||
files = Collections.EMPTY_LIST;
|
||||
}
|
||||
files = readFilesInArchive( file );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
getLogger().error( "Error reading artifact file, omitting from index: " + e.getMessage() );
|
||||
}
|
||||
|
||||
if ( files != null )
|
||||
// If it's an archive with no files, don't create a record
|
||||
if ( !ARCHIVE_TYPES.contains( artifact.getType() ) || files != null )
|
||||
{
|
||||
record = new StandardArtifactIndexRecord();
|
||||
|
||||
|
@ -84,35 +99,127 @@ public class StandardArtifactIndexRecordFactory
|
|||
record.setType( artifact.getType() );
|
||||
record.setMd5Checksum( md5 );
|
||||
record.setSha1Checksum( sha1 );
|
||||
record.setFilename( file.getName() );
|
||||
record.setFilename( artifact.getRepository().pathOf( artifact ) );
|
||||
record.setLastModified( file.lastModified() );
|
||||
record.setSize( file.length() );
|
||||
record.setRepository( artifact.getRepository().getId() );
|
||||
/* TODO! these come from the POM and metadata, so probably part of an update record method instead
|
||||
// remember to test parent & inheritence
|
||||
record.setPluginPrefix( pluginPrefix );
|
||||
record.setPackaging( packaging );
|
||||
record.setProjectName( name );
|
||||
record.setProjectDescription( description );
|
||||
record.setInceptionYear( year );
|
||||
*/
|
||||
/* TODO: fields for later
|
||||
indexPlugins( doc, FLD_PLUGINS_BUILD, pom.getBuild().getPlugins().iterator() );
|
||||
indexReportPlugins( doc, FLD_PLUGINS_REPORT, pom.getReporting().getPlugins().iterator() );
|
||||
record.setDependencies( dependencies );
|
||||
record.setLicenses( licenses );
|
||||
*/
|
||||
populateArchiveEntries( files, record );
|
||||
if ( files != null )
|
||||
{
|
||||
populateArchiveEntries( files, record );
|
||||
}
|
||||
|
||||
if ( !"pom".equals( artifact.getType() ) )
|
||||
{
|
||||
Artifact pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(),
|
||||
artifact.getArtifactId(),
|
||||
artifact.getVersion() );
|
||||
File pomFile = new File( artifact.getRepository().getBasedir(),
|
||||
artifact.getRepository().pathOf( pomArtifact ) );
|
||||
if ( pomFile.exists() )
|
||||
{
|
||||
populatePomEntries( readPom( pomFile ), record );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
populatePomEntries( readPom( file ), record );
|
||||
}
|
||||
|
||||
if ( "maven-plugin".equals( record.getPackaging() ) )
|
||||
{
|
||||
// Typically discovered as a JAR
|
||||
record.setType( record.getPackaging() );
|
||||
|
||||
RepositoryMetadata metadata = new GroupRepositoryMetadata( artifact.getGroupId() );
|
||||
File metadataFile = new File( artifact.getRepository().getBasedir(),
|
||||
artifact.getRepository().pathOfRemoteRepositoryMetadata( metadata ) );
|
||||
if ( metadataFile.exists() )
|
||||
{
|
||||
populatePluginEntries( readMetadata( metadataFile ), record );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
private void populatePomEntries( Model pom, StandardArtifactIndexRecord record )
|
||||
{
|
||||
record.setPackaging( pom.getPackaging() );
|
||||
record.setProjectName( pom.getName() );
|
||||
record.setProjectDescription( pom.getDescription() );
|
||||
record.setInceptionYear( pom.getInceptionYear() );
|
||||
|
||||
/* TODO: fields for later
|
||||
indexPlugins( doc, FLD_PLUGINS_BUILD, pom.getBuild().getPlugins().iterator() );
|
||||
indexReportPlugins( doc, FLD_PLUGINS_REPORT, pom.getReporting().getPlugins().iterator() );
|
||||
record.setDependencies( dependencies );
|
||||
record.setLicenses( licenses );
|
||||
*/
|
||||
}
|
||||
|
||||
private Model readPom( File file )
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
MavenXpp3Reader r = new MavenXpp3Reader();
|
||||
|
||||
FileReader reader = null;
|
||||
try
|
||||
{
|
||||
reader = new FileReader( file );
|
||||
return r.read( reader );
|
||||
}
|
||||
catch ( FileNotFoundException e )
|
||||
{
|
||||
throw new RepositoryIndexException( "Unable to find requested POM: " + e.getMessage(), e );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new RepositoryIndexException( "Unable to read POM: " + e.getMessage(), e );
|
||||
}
|
||||
catch ( XmlPullParserException xe )
|
||||
{
|
||||
throw new RepositoryIndexException( "Unable to parse POM: " + xe.getMessage(), xe );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( reader );
|
||||
}
|
||||
}
|
||||
|
||||
private Metadata readMetadata( File file )
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
MetadataXpp3Reader r = new MetadataXpp3Reader();
|
||||
|
||||
FileReader reader = null;
|
||||
try
|
||||
{
|
||||
reader = new FileReader( file );
|
||||
return r.read( reader );
|
||||
}
|
||||
catch ( FileNotFoundException e )
|
||||
{
|
||||
throw new RepositoryIndexException( "Unable to find requested metadata: " + e.getMessage(), e );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new RepositoryIndexException( "Unable to read metadata: " + e.getMessage(), e );
|
||||
}
|
||||
catch ( XmlPullParserException xe )
|
||||
{
|
||||
throw new RepositoryIndexException( "Unable to parse metadata: " + xe.getMessage(), xe );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( reader );
|
||||
}
|
||||
}
|
||||
|
||||
private void populateArchiveEntries( List files, StandardArtifactIndexRecord record )
|
||||
{
|
||||
StringBuffer classes = new StringBuffer();
|
||||
StringBuffer packages = new StringBuffer();
|
||||
StringBuffer fileBuffer = new StringBuffer();
|
||||
|
||||
for ( Iterator i = files.iterator(); i.hasNext(); )
|
||||
|
@ -126,24 +233,32 @@ public class StandardArtifactIndexRecordFactory
|
|||
|
||||
if ( isClass( name ) )
|
||||
{
|
||||
int idx = name.lastIndexOf( '/' );
|
||||
String classname = name.substring( idx + 1, name.length() - 6 );
|
||||
classes.append( classname ).append( "\n" );
|
||||
|
||||
if ( idx > 0 )
|
||||
{
|
||||
String packageName = name.substring( 0, idx ).replace( '/', '.' );
|
||||
if ( packages.indexOf( packageName ) < 0 )
|
||||
{
|
||||
packages.append( packageName ).append( "\n" );
|
||||
}
|
||||
}
|
||||
classes.append( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) ).append( "\n" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
record.setClasses( classes.toString() );
|
||||
record.setPackages( packages.toString() );
|
||||
record.setFiles( fileBuffer.toString() );
|
||||
}
|
||||
|
||||
public void populatePluginEntries( Metadata metadata, StandardArtifactIndexRecord record )
|
||||
{
|
||||
Map prefixes = new HashMap();
|
||||
for ( Iterator i = metadata.getPlugins().iterator(); i.hasNext(); )
|
||||
{
|
||||
Plugin plugin = (Plugin) i.next();
|
||||
|
||||
prefixes.put( plugin.getArtifactId(), plugin.getPrefix() );
|
||||
}
|
||||
|
||||
if ( record.getGroupId().equals( metadata.getGroupId() ) )
|
||||
{
|
||||
String prefix = (String) prefixes.get( record.getArtifactId() );
|
||||
if ( prefix != null )
|
||||
{
|
||||
record.setPluginPrefix( prefix );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ Indexer Design
|
|||
|
||||
* plugin prefix
|
||||
|
||||
* Java classes and packages within a JAR artifact (delimited by \n)
|
||||
* Java classes within a JAR artifact (delimited by \n)
|
||||
|
||||
* filenames within an archive (delimited by \n)
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.maven.repository.indexing.lucene;
|
|||
|
||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.NumberTools;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
@ -32,19 +33,24 @@ import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
|
|||
import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Test the Lucene implementation of the artifact index.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
*/
|
||||
public class LuceneRepositoryArtifactIndexTest
|
||||
public class LuceneMinimalArtifactIndexTest
|
||||
extends PlexusTestCase
|
||||
{
|
||||
private RepositoryArtifactIndex index;
|
||||
|
@ -62,7 +68,7 @@ public class LuceneRepositoryArtifactIndexTest
|
|||
{
|
||||
super.setUp();
|
||||
|
||||
recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" );
|
||||
recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "minimal" );
|
||||
|
||||
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||
|
||||
|
@ -82,8 +88,7 @@ public class LuceneRepositoryArtifactIndexTest
|
|||
|
||||
FileUtils.deleteDirectory( indexLocation );
|
||||
|
||||
// TODO: test minimal one in same way
|
||||
index = factory.createStandardIndex( indexLocation, repository );
|
||||
index = factory.createMinimalIndex( indexLocation, repository );
|
||||
}
|
||||
|
||||
public void testIndexExists()
|
||||
|
@ -129,7 +134,7 @@ public class LuceneRepositoryArtifactIndexTest
|
|||
try
|
||||
{
|
||||
Document document = reader.document( 0 );
|
||||
assertEquals( "Check document", "test-jar", document.getField( "artifactId" ).stringValue() );
|
||||
assertEquals( "Check document", repository.pathOf( artifact ), document.get( "j" ) );
|
||||
assertEquals( "Check index size", 1, reader.numDocs() );
|
||||
}
|
||||
finally
|
||||
|
@ -152,7 +157,7 @@ public class LuceneRepositoryArtifactIndexTest
|
|||
try
|
||||
{
|
||||
Document document = reader.document( 0 );
|
||||
assertEquals( "Check document", "test-jar", document.getField( "artifactId" ).stringValue() );
|
||||
assertRecord( document, artifact, "3a0adc365f849366cd8b633cad155cb7", "A\nb.B\nb.c.C\n" );
|
||||
assertEquals( "Check index size", 1, reader.numDocs() );
|
||||
}
|
||||
finally
|
||||
|
@ -161,26 +166,27 @@ public class LuceneRepositoryArtifactIndexTest
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void testUpdateRecordWithPomMetadata()
|
||||
public void testAddRecordInIndex()
|
||||
throws IOException, RepositoryIndexException
|
||||
{
|
||||
createEmptyIndex();
|
||||
|
||||
Artifact artifact = createArtifact( "test-plugin" );
|
||||
Artifact artifact = createArtifact( "test-jar" );
|
||||
|
||||
RepositoryIndexRecord record = recordFactory.createRecord( artifact );
|
||||
index.indexRecords( Collections.singletonList( record ) );
|
||||
|
||||
// TODO: index again, with the POM metadata! Make sure a value in the first one is not present, and that is tested for
|
||||
// Do it again
|
||||
record = recordFactory.createRecord( artifact );
|
||||
index.indexRecords( Collections.singletonList( record ) );
|
||||
|
||||
IndexReader reader = IndexReader.open( indexLocation );
|
||||
try
|
||||
{
|
||||
Document document = reader.document( 0 );
|
||||
assertEquals( "Check document", "test-plugin", document.getField( "artifactId" ).stringValue() );
|
||||
assertEquals( "Check document", "jar", document.getField( "type" ).stringValue() );
|
||||
assertEquals( "Check document", "maven-plugin", document.getField( "packaging" ).stringValue() );
|
||||
String expectedChecksum = "3a0adc365f849366cd8b633cad155cb7";
|
||||
String expectedClasses = "A\nb.B\nb.c.C\n";
|
||||
assertRecord( document, artifact, expectedChecksum, expectedClasses );
|
||||
assertEquals( "Check index size", 1, reader.numDocs() );
|
||||
}
|
||||
finally
|
||||
|
@ -188,7 +194,6 @@ public class LuceneRepositoryArtifactIndexTest
|
|||
reader.close();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public void testAddPomRecord()
|
||||
throws IOException, RepositoryIndexException
|
||||
|
@ -203,11 +208,7 @@ public class LuceneRepositoryArtifactIndexTest
|
|||
IndexReader reader = IndexReader.open( indexLocation );
|
||||
try
|
||||
{
|
||||
Document document = reader.document( 0 );
|
||||
assertEquals( "Check document", "test-pom", document.getField( "artifactId" ).stringValue() );
|
||||
assertEquals( "Check document", "pom", document.getField( "type" ).stringValue() );
|
||||
// assertEquals( "Check document", "pom", document.getField( "packaging" ).stringValue() ); // TODO!
|
||||
assertEquals( "Check index size", 1, reader.numDocs() );
|
||||
assertEquals( "No documents", 0, reader.numDocs() );
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -215,26 +216,23 @@ public class LuceneRepositoryArtifactIndexTest
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void testUpdateRecordWithRepoMetadata()
|
||||
throws IOException, RepositoryIndexException
|
||||
public void testAddPlugin()
|
||||
throws IOException, RepositoryIndexException, XmlPullParserException
|
||||
{
|
||||
createEmptyIndex();
|
||||
|
||||
Artifact artifact = createArtifact( "test-plugin" );
|
||||
|
||||
RepositoryIndexRecord record = recordFactory.createRecord( artifact );
|
||||
index.indexRecords( Collections.singletonList( record ) );
|
||||
|
||||
// TODO: index again, with the repo metadata!
|
||||
index.indexRecords( Collections.singletonList( record ) );
|
||||
|
||||
IndexReader reader = IndexReader.open( indexLocation );
|
||||
try
|
||||
{
|
||||
Document document = reader.document( 0 );
|
||||
assertEquals( "Check document", "test-plugin", document.getField( "artifactId" ).stringValue() );
|
||||
assertEquals( "Check document", "maven-plugin", document.getField( "packaging" ).stringValue() );
|
||||
assertEquals( "Check document", "plugin", document.getField( "pluginPrefix" ).stringValue() );
|
||||
assertRecord( document, artifact, "06f6fe25e46c4d4fb5be4f56a9bab0ee",
|
||||
"org.apache.maven.repository.record.MyMojo\n" );
|
||||
assertEquals( "Check index size", 1, reader.numDocs() );
|
||||
}
|
||||
finally
|
||||
|
@ -243,34 +241,6 @@ public class LuceneRepositoryArtifactIndexTest
|
|||
}
|
||||
}
|
||||
|
||||
public void testUpdateRecordWithArtifactData()
|
||||
throws IOException, RepositoryIndexException
|
||||
{
|
||||
createEmptyIndex();
|
||||
|
||||
// TODO: index with the repo/POM metadata!
|
||||
|
||||
Artifact artifact = createArtifact( "test-plugin" );
|
||||
|
||||
RepositoryIndexRecord record = recordFactory.createRecord( artifact );
|
||||
index.indexRecords( Collections.singletonList( record ) );
|
||||
|
||||
IndexReader reader = IndexReader.open( indexLocation );
|
||||
try
|
||||
{
|
||||
Document document = reader.document( 0 );
|
||||
assertEquals( "Check document", "test-plugin", document.getField( "artifactId" ).stringValue() );
|
||||
assertEquals( "Check document", "maven-plugin", document.getField( "packaging" ).stringValue() );
|
||||
assertEquals( "Check document", "plugin", document.getField( "pluginPrefix" ).stringValue() );
|
||||
assertEquals( "Check index size", 1, reader.numDocs() );
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private Artifact createArtifact( String artifactId )
|
||||
{
|
||||
return createArtifact( artifactId, "1.0", "jar" );
|
||||
|
@ -303,4 +273,21 @@ public class LuceneRepositoryArtifactIndexTest
|
|||
writer.optimize();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
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 size", artifact.getFile().length(),
|
||||
NumberTools.stringToLong( document.get( "s" ) ) );
|
||||
assertEquals( "Check document classes", expectedClasses, document.get( "c" ) );
|
||||
}
|
||||
|
||||
private String getLastModified( File file )
|
||||
{
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyyMMddHHmmss", Locale.US );
|
||||
dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
|
||||
return dateFormat.format( new Date( file.lastModified() ) );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,345 @@
|
|||
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.analysis.standard.StandardAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.NumberTools;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
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.repository.indexing.RepositoryArtifactIndex;
|
||||
import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
|
||||
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.codehaus.plexus.PlexusTestCase;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Test the Lucene implementation of the artifact index.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
*/
|
||||
public class LuceneStandardArtifactIndexTest
|
||||
extends PlexusTestCase
|
||||
{
|
||||
private RepositoryArtifactIndex index;
|
||||
|
||||
private ArtifactRepository repository;
|
||||
|
||||
private ArtifactFactory artifactFactory;
|
||||
|
||||
private File indexLocation;
|
||||
|
||||
private RepositoryIndexRecordFactory recordFactory;
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
public void testIndexExists()
|
||||
throws IOException, RepositoryIndexException
|
||||
{
|
||||
assertFalse( "check index doesn't exist", index.exists() );
|
||||
|
||||
// create empty directory
|
||||
indexLocation.mkdirs();
|
||||
assertFalse( "check index doesn't exist even if directory does", index.exists() );
|
||||
|
||||
// create index, with no records
|
||||
createEmptyIndex();
|
||||
assertTrue( "check index is considered to exist", index.exists() );
|
||||
|
||||
// Test non-directory
|
||||
FileUtils.deleteDirectory( indexLocation );
|
||||
indexLocation.createNewFile();
|
||||
try
|
||||
{
|
||||
index.exists();
|
||||
fail( "Index operation should fail as the location is not valid" );
|
||||
}
|
||||
catch ( RepositoryIndexException e )
|
||||
{
|
||||
// great
|
||||
}
|
||||
finally
|
||||
{
|
||||
indexLocation.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public void testAddRecordNoIndex()
|
||||
throws IOException, RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-jar" );
|
||||
|
||||
RepositoryIndexRecord record = recordFactory.createRecord( artifact );
|
||||
index.indexRecords( Collections.singletonList( record ) );
|
||||
|
||||
IndexReader reader = IndexReader.open( indexLocation );
|
||||
try
|
||||
{
|
||||
Document document = reader.document( 0 );
|
||||
assertJarRecord( artifact, document );
|
||||
assertEquals( "Check index size", 1, reader.numDocs() );
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void testAddRecordExistingEmptyIndex()
|
||||
throws IOException, RepositoryIndexException
|
||||
{
|
||||
createEmptyIndex();
|
||||
|
||||
Artifact artifact = createArtifact( "test-jar" );
|
||||
|
||||
RepositoryIndexRecord record = recordFactory.createRecord( artifact );
|
||||
index.indexRecords( Collections.singletonList( record ) );
|
||||
|
||||
IndexReader reader = IndexReader.open( indexLocation );
|
||||
try
|
||||
{
|
||||
Document document = reader.document( 0 );
|
||||
assertJarRecord( artifact, document );
|
||||
assertEquals( "Check index size", 1, reader.numDocs() );
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void testAddRecordInIndex()
|
||||
throws IOException, RepositoryIndexException
|
||||
{
|
||||
createEmptyIndex();
|
||||
|
||||
Artifact artifact = createArtifact( "test-jar" );
|
||||
|
||||
RepositoryIndexRecord record = recordFactory.createRecord( artifact );
|
||||
index.indexRecords( Collections.singletonList( record ) );
|
||||
|
||||
// Do it again
|
||||
record = recordFactory.createRecord( artifact );
|
||||
index.indexRecords( Collections.singletonList( record ) );
|
||||
|
||||
IndexReader reader = IndexReader.open( indexLocation );
|
||||
try
|
||||
{
|
||||
Document document = reader.document( 0 );
|
||||
assertJarRecord( artifact, document );
|
||||
assertEquals( "Check index size", 1, reader.numDocs() );
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void testAddPomRecord()
|
||||
throws IOException, RepositoryIndexException
|
||||
{
|
||||
createEmptyIndex();
|
||||
|
||||
Artifact artifact = createArtifact( "test-pom", "1.0", "pom" );
|
||||
|
||||
RepositoryIndexRecord record = recordFactory.createRecord( artifact );
|
||||
index.indexRecords( Collections.singletonList( record ) );
|
||||
|
||||
IndexReader reader = IndexReader.open( indexLocation );
|
||||
try
|
||||
{
|
||||
Document document = reader.document( 0 );
|
||||
assertPomRecord( artifact, document );
|
||||
assertEquals( "Check index size", 1, reader.numDocs() );
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void testAddPlugin()
|
||||
throws IOException, RepositoryIndexException, XmlPullParserException
|
||||
{
|
||||
createEmptyIndex();
|
||||
|
||||
Artifact artifact = createArtifact( "test-plugin" );
|
||||
|
||||
RepositoryIndexRecord record = recordFactory.createRecord( artifact );
|
||||
|
||||
index.indexRecords( Collections.singletonList( record ) );
|
||||
|
||||
IndexReader reader = IndexReader.open( indexLocation );
|
||||
try
|
||||
{
|
||||
Document document = reader.document( 0 );
|
||||
assertPluginRecord( artifact, document );
|
||||
assertEquals( "Check index size", 1, reader.numDocs() );
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
private Artifact createArtifact( String artifactId )
|
||||
{
|
||||
return createArtifact( artifactId, "1.0", "jar" );
|
||||
}
|
||||
|
||||
private Artifact createArtifact( String artifactId, String version, String type )
|
||||
{
|
||||
Artifact artifact =
|
||||
artifactFactory.createBuildArtifact( "org.apache.maven.repository.record", artifactId, version, type );
|
||||
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
|
||||
artifact.setRepository( repository );
|
||||
return artifact;
|
||||
}
|
||||
|
||||
private void createEmptyIndex()
|
||||
throws IOException
|
||||
{
|
||||
createIndex( Collections.EMPTY_LIST );
|
||||
}
|
||||
|
||||
private void createIndex( List docments )
|
||||
throws IOException
|
||||
{
|
||||
IndexWriter writer = new IndexWriter( indexLocation, new StandardAnalyzer(), true );
|
||||
for ( Iterator i = docments.iterator(); i.hasNext(); )
|
||||
{
|
||||
Document document = (Document) i.next();
|
||||
writer.addDocument( document );
|
||||
}
|
||||
writer.optimize();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
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 timestamp", getLastModified( artifact.getFile() ),
|
||||
document.get( "lastModified" ) );
|
||||
assertEquals( "Check document md5", expectedMd5, document.get( "md5" ) );
|
||||
assertEquals( "Check document sha1", expectedSha1, document.get( "sha1" ) );
|
||||
assertEquals( "Check document file size", artifact.getFile().length(),
|
||||
NumberTools.stringToLong( document.get( "fileSize" ) ) );
|
||||
assertNull( "Check document classifier", document.get( "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" ) );
|
||||
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" ) );
|
||||
}
|
||||
|
||||
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\n", document.get( "classes" ) );
|
||||
assertEquals( "Check document files", "META-INF/MANIFEST.MF\nA.class\nb/B.class\nb/c/C.class\n",
|
||||
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" ) );
|
||||
}
|
||||
|
||||
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\n",
|
||||
document.get( "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\n", 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" ) );
|
||||
}
|
||||
|
||||
private String getLastModified( File file )
|
||||
{
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyyMMddHHmmss", Locale.US );
|
||||
dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
|
||||
return dateFormat.format( new Date( file.lastModified() ) );
|
||||
}
|
||||
}
|
|
@ -21,9 +21,12 @@ 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.repository.indexing.RepositoryIndexException;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Test the minimal artifact index record.
|
||||
|
@ -61,6 +64,7 @@ public class MinimalArtifactIndexRecordFactoryTest
|
|||
}
|
||||
|
||||
public void testIndexedJar()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-jar" );
|
||||
|
||||
|
@ -68,15 +72,60 @@ public class MinimalArtifactIndexRecordFactoryTest
|
|||
|
||||
MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord();
|
||||
expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" );
|
||||
expectedRecord.setFilename( "test-jar-1.0.jar" );
|
||||
expectedRecord.setFilename( repository.pathOf( artifact ) );
|
||||
expectedRecord.setLastModified( artifact.getFile().lastModified() );
|
||||
expectedRecord.setSize( artifact.getFile().length() );
|
||||
expectedRecord.setClasses( "A\nB\nC\n" );
|
||||
expectedRecord.setClasses( "A\nb.B\nb.c.C\n" );
|
||||
|
||||
assertEquals( "check record", expectedRecord, record );
|
||||
}
|
||||
|
||||
public void testIndexedJarAndPom()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-jar-and-pom" );
|
||||
|
||||
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( "A\nb.B\nb.c.C\n" );
|
||||
|
||||
assertEquals( "check record", expectedRecord, record );
|
||||
}
|
||||
|
||||
public void testIndexedPom()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-pom", "1.0", "pom" );
|
||||
|
||||
RepositoryIndexRecord record = factory.createRecord( artifact );
|
||||
|
||||
assertNull( "Check no record", record );
|
||||
}
|
||||
|
||||
public void testIndexedPlugin()
|
||||
throws RepositoryIndexException, IOException, XmlPullParserException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-plugin" );
|
||||
|
||||
RepositoryIndexRecord record = factory.createRecord( artifact );
|
||||
|
||||
MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord();
|
||||
expectedRecord.setMd5Checksum( "06f6fe25e46c4d4fb5be4f56a9bab0ee" );
|
||||
expectedRecord.setFilename( repository.pathOf( artifact ) );
|
||||
expectedRecord.setLastModified( artifact.getFile().lastModified() );
|
||||
expectedRecord.setSize( artifact.getFile().length() );
|
||||
expectedRecord.setClasses( "org.apache.maven.repository.record.MyMojo\n" );
|
||||
|
||||
assertEquals( "check record", expectedRecord, record );
|
||||
}
|
||||
|
||||
public void testCorruptJar()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-corrupt-jar" );
|
||||
|
||||
|
@ -86,6 +135,7 @@ public class MinimalArtifactIndexRecordFactoryTest
|
|||
}
|
||||
|
||||
public void testNonJar()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-dll", "1.0.1.34", "dll" );
|
||||
|
||||
|
@ -95,6 +145,7 @@ public class MinimalArtifactIndexRecordFactoryTest
|
|||
}
|
||||
|
||||
public void testMissingFile()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-foo" );
|
||||
|
||||
|
@ -112,6 +163,7 @@ public class MinimalArtifactIndexRecordFactoryTest
|
|||
{
|
||||
Artifact artifact = artifactFactory.createBuildArtifact( TEST_GROUP_ID, artifactId, version, type );
|
||||
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
|
||||
artifact.setRepository( repository );
|
||||
return artifact;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,16 +21,17 @@ 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.repository.indexing.RepositoryIndexException;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Test the minimal artifact index record.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @todo test packaging!
|
||||
* @todo test pluginPrefix!
|
||||
*/
|
||||
public class StandardArtifactIndexRecordFactoryTest
|
||||
extends PlexusTestCase
|
||||
|
@ -63,6 +64,7 @@ public class StandardArtifactIndexRecordFactoryTest
|
|||
}
|
||||
|
||||
public void testIndexedJar()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-jar" );
|
||||
|
||||
|
@ -70,15 +72,14 @@ public class StandardArtifactIndexRecordFactoryTest
|
|||
|
||||
StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord();
|
||||
expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" );
|
||||
expectedRecord.setFilename( "test-jar-1.0.jar" );
|
||||
expectedRecord.setFilename( repository.pathOf( artifact ) );
|
||||
expectedRecord.setLastModified( artifact.getFile().lastModified() );
|
||||
expectedRecord.setSize( artifact.getFile().length() );
|
||||
expectedRecord.setClasses( "A\nB\nC\n" );
|
||||
expectedRecord.setClasses( "A\nb.B\nb.c.C\n" );
|
||||
expectedRecord.setArtifactId( "test-jar" );
|
||||
expectedRecord.setGroupId( TEST_GROUP_ID );
|
||||
expectedRecord.setVersion( "1.0" );
|
||||
expectedRecord.setFiles( "META-INF/MANIFEST.MF\nA.class\nb/B.class\nb/c/C.class\n" );
|
||||
expectedRecord.setPackages( "b\nb.c\n" );
|
||||
expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" );
|
||||
expectedRecord.setType( "jar" );
|
||||
expectedRecord.setRepository( "test" );
|
||||
|
@ -86,7 +87,90 @@ public class StandardArtifactIndexRecordFactoryTest
|
|||
assertEquals( "check record", expectedRecord, record );
|
||||
}
|
||||
|
||||
public void testIndexedJarAndPom()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-jar-and-pom" );
|
||||
|
||||
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( "A\nb.B\nb.c.C\n" );
|
||||
expectedRecord.setArtifactId( "test-jar-and-pom" );
|
||||
expectedRecord.setGroupId( TEST_GROUP_ID );
|
||||
expectedRecord.setVersion( "1.0" );
|
||||
expectedRecord.setFiles( "META-INF/MANIFEST.MF\nA.class\nb/B.class\nb/c/C.class\n" );
|
||||
expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" );
|
||||
expectedRecord.setType( "jar" );
|
||||
expectedRecord.setRepository( "test" );
|
||||
expectedRecord.setPackaging( "jar" );
|
||||
expectedRecord.setProjectName( "Test JAR and POM" );
|
||||
|
||||
assertEquals( "check record", expectedRecord, record );
|
||||
}
|
||||
|
||||
public void testIndexedPom()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-pom", "1.0", "pom" );
|
||||
|
||||
RepositoryIndexRecord record = factory.createRecord( artifact );
|
||||
|
||||
StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord();
|
||||
expectedRecord.setMd5Checksum( "32dbef7ff11eb933bd8b7e7bcab85406" );
|
||||
expectedRecord.setFilename( repository.pathOf( artifact ) );
|
||||
expectedRecord.setLastModified( artifact.getFile().lastModified() );
|
||||
expectedRecord.setSize( artifact.getFile().length() );
|
||||
expectedRecord.setArtifactId( "test-pom" );
|
||||
expectedRecord.setGroupId( TEST_GROUP_ID );
|
||||
expectedRecord.setVersion( "1.0" );
|
||||
expectedRecord.setSha1Checksum( "c3b374e394607e1e705e71c227f62641e8621ebe" );
|
||||
expectedRecord.setType( "pom" );
|
||||
expectedRecord.setRepository( "test" );
|
||||
expectedRecord.setPackaging( "pom" );
|
||||
expectedRecord.setInceptionYear( "2005" );
|
||||
expectedRecord.setProjectName( "Maven Repository Manager Test POM" );
|
||||
expectedRecord.setProjectDescription( "Description" );
|
||||
|
||||
assertEquals( "check record", expectedRecord, record );
|
||||
}
|
||||
|
||||
public void testIndexedPlugin()
|
||||
throws RepositoryIndexException, IOException, XmlPullParserException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-plugin" );
|
||||
|
||||
RepositoryIndexRecord record = factory.createRecord( artifact );
|
||||
|
||||
StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord();
|
||||
expectedRecord.setMd5Checksum( "06f6fe25e46c4d4fb5be4f56a9bab0ee" );
|
||||
expectedRecord.setFilename( repository.pathOf( artifact ) );
|
||||
expectedRecord.setLastModified( artifact.getFile().lastModified() );
|
||||
expectedRecord.setSize( artifact.getFile().length() );
|
||||
expectedRecord.setArtifactId( "test-plugin" );
|
||||
expectedRecord.setGroupId( TEST_GROUP_ID );
|
||||
expectedRecord.setVersion( "1.0" );
|
||||
expectedRecord.setSha1Checksum( "382c1ebfb5d0c7d6061c2f8569fb53f8fc00fec2" );
|
||||
expectedRecord.setType( "maven-plugin" );
|
||||
expectedRecord.setRepository( "test" );
|
||||
expectedRecord.setClasses( "org.apache.maven.repository.record.MyMojo\n" );
|
||||
expectedRecord.setFiles( "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\n" );
|
||||
expectedRecord.setPackaging( "maven-plugin" );
|
||||
expectedRecord.setProjectName( "Maven Mojo Archetype" );
|
||||
expectedRecord.setPluginPrefix( "test" );
|
||||
|
||||
assertEquals( "check record", expectedRecord, record );
|
||||
}
|
||||
|
||||
public void testCorruptJar()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-corrupt-jar" );
|
||||
|
||||
|
@ -96,6 +180,7 @@ public class StandardArtifactIndexRecordFactoryTest
|
|||
}
|
||||
|
||||
public void testDll()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-dll", "1.0.1.34", "dll" );
|
||||
|
||||
|
@ -103,7 +188,7 @@ public class StandardArtifactIndexRecordFactoryTest
|
|||
|
||||
StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord();
|
||||
expectedRecord.setMd5Checksum( "d41d8cd98f00b204e9800998ecf8427e" );
|
||||
expectedRecord.setFilename( "test-dll-1.0.1.34.dll" );
|
||||
expectedRecord.setFilename( repository.pathOf( artifact ) );
|
||||
expectedRecord.setLastModified( artifact.getFile().lastModified() );
|
||||
expectedRecord.setSize( artifact.getFile().length() );
|
||||
expectedRecord.setArtifactId( "test-dll" );
|
||||
|
@ -112,14 +197,12 @@ public class StandardArtifactIndexRecordFactoryTest
|
|||
expectedRecord.setSha1Checksum( "da39a3ee5e6b4b0d3255bfef95601890afd80709" );
|
||||
expectedRecord.setType( "dll" );
|
||||
expectedRecord.setRepository( "test" );
|
||||
expectedRecord.setClasses( "" );
|
||||
expectedRecord.setPackages( "" );
|
||||
expectedRecord.setFiles( "" );
|
||||
|
||||
assertEquals( "check record", expectedRecord, record );
|
||||
}
|
||||
|
||||
public void testMissingFile()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Artifact artifact = createArtifact( "test-foo" );
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<metadata>
|
||||
<groupId>org.apache.maven.repository.record</groupId>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<prefix>test</prefix>
|
||||
<artifactId>test-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</metadata>
|
Binary file not shown.
|
@ -0,0 +1,32 @@
|
|||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.repository.record</groupId>
|
||||
<artifactId>test-jar-and-pom</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>Test JAR and POM</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
Binary file not shown.
|
@ -0,0 +1,22 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.repository.record</groupId>
|
||||
<artifactId>test-plugin</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
<version>1.0</version>
|
||||
<name>Maven Mojo Archetype</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -6,5 +6,6 @@
|
|||
<version>1.0</version>
|
||||
<name>Maven Repository Manager Test POM</name>
|
||||
<inceptionYear>2005</inceptionYear>
|
||||
<description>Description</description>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
||||
|
|
Loading…
Reference in New Issue