From 436d0b75cabf9229097560860a5a03f79c979a54 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 27 Jul 2006 03:01:41 +0000 Subject: [PATCH] [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 --- .../LuceneMinimalIndexRecordConverter.java | 43 ++- .../LuceneStandardIndexRecordConverter.java | 13 +- .../record/MinimalArtifactIndexRecord.java | 2 +- .../MinimalArtifactIndexRecordFactory.java | 14 +- .../record/RepositoryIndexRecordFactory.java | 10 +- .../record/StandardArtifactIndexRecord.java | 81 +++- .../StandardArtifactIndexRecordFactory.java | 187 ++++++++-- .../src/site/apt/design.apt | 2 +- ...va => LuceneMinimalArtifactIndexTest.java} | 95 +++-- .../LuceneStandardArtifactIndexTest.java | 345 ++++++++++++++++++ ...MinimalArtifactIndexRecordFactoryTest.java | 56 ++- ...tandardArtifactIndexRecordFactoryTest.java | 101 ++++- .../repository/record/maven-metadata.xml | 25 ++ .../1.0/test-jar-and-pom-1.0.jar | Bin 0 -> 1408 bytes .../1.0/test-jar-and-pom-1.0.pom | 32 ++ .../test-plugin/1.0/test-plugin-1.0.jar | Bin 0 -> 4416 bytes .../test-plugin/1.0/test-plugin-1.0.pom | 22 ++ .../record/test-pom/1.0/test-pom-1.0.pom | 1 + 18 files changed, 892 insertions(+), 137 deletions(-) rename maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/{LuceneRepositoryArtifactIndexTest.java => LuceneMinimalArtifactIndexTest.java} (73%) create mode 100644 maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java create mode 100644 maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/maven-metadata.xml create mode 100644 maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0/test-jar-and-pom-1.0.jar create mode 100644 maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0/test-jar-and-pom-1.0.pom create mode 100644 maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.jar create mode 100644 maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.pom diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java index 2631151eb..70db48091 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java @@ -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 ) ); + } } } diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java index 0ce7ea418..a8e813c14 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java @@ -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 ) ); } } - } diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java index 8513f807e..806f05a4d 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java @@ -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 not included. + * The classes in the archive for the artifact, if it is a JAR. */ private String classes; diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactory.java index 5f9509e26..2f6fc40ca 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactory.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactory.java @@ -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" ); } } diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecordFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecordFactory.java index b1c9fb090..2dde9674d 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecordFactory.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecordFactory.java @@ -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; + } diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java index 10ffc3132..ee922fb5f 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java @@ -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; + } } diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java index 22a8689e3..ac93097fb 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java @@ -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 ); - */ + 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 ); */ - populateArchiveEntries( files, record ); - } + } + + 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 ); + } + } - return record; + 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 ); + } + } + } } diff --git a/maven-repository-indexer/src/site/apt/design.apt b/maven-repository-indexer/src/site/apt/design.apt index 15b446809..5ecb476d5 100644 --- a/maven-repository-indexer/src/site/apt/design.apt +++ b/maven-repository-indexer/src/site/apt/design.apt @@ -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) diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java similarity index 73% rename from maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexTest.java rename to maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java index 4d9a87224..873c79fed 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java @@ -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 Brett Porter */ -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,53 +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! - - 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(); - } - } - - 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() ); + assertRecord( document, artifact, "06f6fe25e46c4d4fb5be4f56a9bab0ee", + "org.apache.maven.repository.record.MyMojo\n" ); assertEquals( "Check index size", 1, reader.numDocs() ); } finally @@ -269,7 +240,6 @@ public class LuceneRepositoryArtifactIndexTest reader.close(); } } -*/ private Artifact createArtifact( String artifactId ) { @@ -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() ) ); + } } diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java new file mode 100644 index 000000000..deaafb48e --- /dev/null +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java @@ -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 Brett Porter + */ +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() ) ); + } +} diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java index 0ec38f86a..bffd0ca15 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java @@ -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; } } diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java index f48a6949d..2413a58c0 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java @@ -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 Brett Porter - * @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" ); diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/maven-metadata.xml b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/maven-metadata.xml new file mode 100644 index 000000000..afbc79b86 --- /dev/null +++ b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/maven-metadata.xml @@ -0,0 +1,25 @@ + + + + org.apache.maven.repository.record + + + test + test-plugin + + + \ No newline at end of file diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0/test-jar-and-pom-1.0.jar b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0/test-jar-and-pom-1.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..b78be2eb81b2dae5b108881937300447b7d9ce7e GIT binary patch literal 1408 zcmWIWW@Zs#-~hrSYk!(BAOTJW76xC}5Jz24KR5kbe@5RzpESxi5 zO1@BAI!#4NGlOONGtD1qYT{4D!^NgAc_yY^@l5q~=BJ{MMT}s#?5<2%?FF<6gb{Ap zh~^P?psb@_a!z7#v8&%%zJmz@b8=TN?OG-N;K_4`M_wvQg+hEs{%XtrToSeNQyiaC z;RgmeuQ$&h8CmbPo;maT^Pfx?+|Ro5J+;wdjrbrNBFn-e)RIsp5Pq@SWzT!v%^^pB zGai&%6_KjkbTex`=QWj^UQVgYk}UVjIL}g-b-*&8CYx5*fVanB= z`@AphvY4w>nOCvlVZoyr5B@WYKXlA9GT9N*S1rV&``hr6S&v@6?>^!4NzWNyu^f|q z_EufXXxE=BcbZPVFf(%*>1g= z=kwpa_6*lJY9lyodTe?)rwHzG>GC-u-L(7a(!4U3?0q`~-t5?=l3 zRH|T_{)NkX*nO_g5WD>R?%@yoAn)5UoZ7bn==c*r4Dud!@3Vltmy9O>xS=YXVQIvg z>rjBe9N#n7e{`#F_!KO$AvA|6Y*A~{|G1h{!oCVF?^6|AYJW}gD%4faXc=zX@ z`|dHQz4*1^LdnHX0nWD_k2`u8@JG6FOjj=yz8JaWct-FOD_cL#Z$8U+&Dfk~a7Qq! za9eoGwV>r$rF%W5=C|5>K5{?hx=kQ=tdOYYRH<6Mp zC~qRbNgxxNQ$d=z7_dhv%;gY`Cm12=8{tflCCG^bl)@3<1z0^az2mb6HCT=VZB5b# kr6W{}kb@bNk`Uk}R0lL&1$eWvfh5_1um$LbXUrfT0LLw<`v3p{ literal 0 HcmV?d00001 diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0/test-jar-and-pom-1.0.pom b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0/test-jar-and-pom-1.0.pom new file mode 100644 index 000000000..e002bb0a7 --- /dev/null +++ b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0/test-jar-and-pom-1.0.pom @@ -0,0 +1,32 @@ + + + + 4.0.0 + org.apache.maven.repository.record + test-jar-and-pom + 1.0 + Test JAR and POM + + + junit + junit + 3.8.1 + test + + + diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.jar b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..a7f3a67a8ef901f5c23736491797df120d1eb4ae GIT binary patch literal 4416 zcmb_f2{_d0A0PL9gix;J2;*LAY;I=AteeJ>+ql9otRqZ0!xBc$9K}?&Ou271$&q71 zuG~3t6v`4x{AUtVTW$O7{@;0i$Mekh`}rR4?|nb-#{f!3P75Fm!%OevKE8aq(cquD zU=uZoGkOpygHLAE00X?4MNF1$68`T|{KfXUnXa1N83@?eL{b+LnNUpoP?|GhLv@^A zD$$6CyQF;Tx`8+I#veCDm*ftRcgT@d31;8dt##H~`+ zha7y|FF<$nk2U{%i4!Zi0y#`3&tn2+tz(0iU9qWSv_*xVT^T-Ka=+x5!NEugDJCOV`lRVYChixUth9ysW)QPbL5pG$ppH>d#$XePHtp7Ee%{outizj{r*AMB z|L(tTiCeY1cV0~;z`g%ZZvDqn4`yJEZqY-E$LH0`u9G1vD4a7FdVpcdasETsGHM(R@0PTbe+pX7ESQP_;1Y7PP6PBMP$Z7I5HRweB#8ZQFpptvlDV`XD zyAJ_|zrPC1e7viWrqHs^Yyd(CMR`%543q^~PWntWx^j0vx~a5lJ@O7!cU#SP*27V+ zpwXA+XErSmiSyhvn1*3cQ(i0Nx16{4xgs?#b`PNRJ<)3{07UW3{A!i=9(yaVEt;(q` zsmgP???gq%`gE_n?|LTrbQWPP(q)b^WCs>Lxv%l`dJ-)e>nV&wVCF7hf2C1>+*81m zf=~@I0H6i`9ZCJO4^cNz7vYAGba1!x@rgI_FlL3Zp**!q?5v73F_G`WOwUsbT4J$B zt-(c?Xk5I#yttiDb})!XjCFQF-rQef+I*IwCu{7qc8zb_Fk9K5<4~yIJG&=JbJcSS zbE7^_#`Q1muJc-nOvc2J%+z}G<_jBfKFzbeo*s(r&!r!gOKOy0Rhh1cv3Y$r^fcx2 z(JJRWjxBnf3p|7N>c5>~RZ5qY_OOLax_8rZVZCt1y$odQkn5FoOLa(hsUp4$zbZ&3 z=DZG;%3_&sk1wPVuvmy>nZyTu;!F@!ai(7b5y2RJO9CtC^(vv#K7$ zdQIMynEID>=mxB#fXjuSPne!E;PRW*6&hkp?@0{m^@zmKq2`$AEY4+2_`n6$NOP_8 zgcE7QQ)|H=%2jt^kt)X4B8SI1H5gw?!@^UMH~pAFtS7|XG9%UK%{SR6%&QX2>6oN} zwmk77-8^t$RL~8--038Jr@qsFQu11CGSE@7ONiTPPmYQ@GmGTR>*S9QuLWBU%Ja#G zqO_>V4AX0-5yN+HtZsKbJBt-Q%%pPPuCZ(e{hqqa_ZQOJTRZp$S^NDvp$_%ANmY02 z76vVz%gyL9$*yG-u`tN_V@iXx{a&gi&y+oN(Y~l*`>IUj#PzD`>DE!$osn(WPKOdJ zrOd;i$JuN7T02*_wGyQqluM$3+Z$8>YQeQ&BdEb#l@Ut6v$`FNqXp^h)pqm++w(nqKZMe!&6I{<2DC~S7~^8i#{y)_C{ z@lZQ1SRh$g2FyF&BJ8xj7mvy+wm~gHaO1+}Y+jAl4$1y{{F=;UzuwpJ+$OolT#_FN zNs`Dg_}4FZ;%hwRe}(4@_wkk3~FqgH^ev=>o+3G0d``6R|sk&D|X%+rt%@DoEFIHGuWC}1YFU1 zu#0zPpM@2xKki62&&(D)RxK8B&MIen`_0zc)Qs5e;Q|J)v_H~V1tmL7nPeSgwj4(8AV8Wp#MrfK5Of`_bSYl0c z<_u=TY5vWrrf}2ofTb?V`bu1DbnRV@yrmn=2VxD4U)DvJ7A6EtZ>Z=+T9v^|S+7X4O zyN_&yo(~zxdT;~>bdM!F&|Ih%0?i5o3WgVkm2lM#P86OvsFQ>(pjMf3aUyrQ-f*4S z7)Kfxni#@0qy1FWz*G@iQ;*Pzl@Wg@=#ZsWVMyw^G1NTlEaToDl>S_Kz-&+^ggZc_ zoA;O%?c;Vt!^ZKKPj78R<=Y;`MPbMlbhPAH9x_h~NpC%PfH*t{DRYW8((5xNZrENh?Y%+# zJ~iZ2UWi9~@KV-}YV_^QvzH`1k2Twb%f&R!1YJY*Hb2)ya(P=uk9^R4#ZA8;eTl)7 z9|ytGy_kfggiXw`6me=F9{?u@1aI}DgPumP&Ta++-qRNByDBsiz!Xn_SLW)?BC0&Wg({1JDAl283_34>rp~*I; zR9j$VTA+&U05Er8VucRwFPk%6FOe_klfL1{r5&1mo9KB>wv4|FX8c zkO(h0($^L4b2z@3w&@rf*uU{2vn(u*F7vmHX0#W+VMT59PH#_za*Vq-kPe7xAMo1}W*-t0 zN{=U%gE`!*izsM_d42l?ON24OPYpo~e(LNV&}S8X%Iov + 4.0.0 + org.apache.maven.repository.record + test-plugin + maven-plugin + 1.0 + Maven Mojo Archetype + + + org.apache.maven + maven-plugin-api + 2.0 + + + junit + junit + 3.8.1 + test + + + diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-pom/1.0/test-pom-1.0.pom b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-pom/1.0/test-pom-1.0.pom index 9ffc00b52..34b9e1f3f 100644 --- a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-pom/1.0/test-pom-1.0.pom +++ b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-pom/1.0/test-pom-1.0.pom @@ -6,5 +6,6 @@ 1.0 Maven Repository Manager Test POM 2005 + Description pom -- 2.39.5