[MRM-127] change record to use lists instead of concatenated strings (index representation is the same, except that the trailing \n is removed)

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@425965 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2006-07-27 05:25:49 +00:00
parent 071eb2dced
commit f187c34612
10 changed files with 74 additions and 49 deletions

View File

@ -22,6 +22,7 @@ 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;
import org.codehaus.plexus.util.StringUtils;
/**
* Convert the minimal index record to a Lucene document.
@ -51,7 +52,8 @@ public class LuceneMinimalIndexRecordConverter
DateTools.Resolution.SECOND ) );
addUntokenizedField( document, FLD_FILE_SIZE, NumberTools.longToString( standardIndexRecord.getSize() ) );
addUntokenizedField( document, FLD_MD5, standardIndexRecord.getMd5Checksum() );
addTokenizedField( document, FLD_CLASSES, standardIndexRecord.getClasses() );
addTokenizedField( document, FLD_CLASSES,
StringUtils.join( standardIndexRecord.getClasses().iterator(), "\n" ) );
return document;
}

View File

@ -22,6 +22,7 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumberTools;
import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
import org.apache.maven.repository.indexing.record.StandardArtifactIndexRecord;
import org.codehaus.plexus.util.StringUtils;
/**
* Convert the standard index record to a Lucene document.
@ -86,8 +87,16 @@ public class LuceneStandardIndexRecordConverter
addUntokenizedField( document, FLD_FILE_SIZE, NumberTools.longToString( standardIndexRecord.getSize() ) );
addUntokenizedField( document, FLD_MD5, standardIndexRecord.getMd5Checksum() );
addUntokenizedField( document, FLD_SHA1, standardIndexRecord.getSha1Checksum() );
addTokenizedField( document, FLD_CLASSES, standardIndexRecord.getClasses() );
addTokenizedField( document, FLD_FILES, standardIndexRecord.getFiles() );
if ( standardIndexRecord.getClasses() != null )
{
addTokenizedField( document, FLD_CLASSES,
StringUtils.join( standardIndexRecord.getClasses().iterator(), "\n" ) );
}
if ( standardIndexRecord.getFiles() != null )
{
addTokenizedField( document, FLD_FILES,
StringUtils.join( standardIndexRecord.getFiles().iterator(), "\n" ) );
}
addTokenizedField( document, FLD_PLUGINPREFIX, standardIndexRecord.getPluginPrefix() );
addUntokenizedField( document, FLD_INCEPTION_YEAR, standardIndexRecord.getInceptionYear() );
addTokenizedField( document, FLD_PROJECT_NAME, standardIndexRecord.getProjectName() );

View File

@ -1,6 +1,7 @@
package org.apache.maven.repository.indexing.record;
import java.util.Date;
import java.util.List;
/*
* Copyright 2005-2006 The Apache Software Foundation.
@ -29,7 +30,7 @@ public class MinimalArtifactIndexRecord
/**
* The classes in the archive for the artifact, if it is a JAR.
*/
private String classes;
private List classes;
/**
* The MD5 checksum of the artifact file.
@ -51,7 +52,7 @@ public class MinimalArtifactIndexRecord
*/
private long size;
public void setClasses( String classes )
public void setClasses( List classes )
{
this.classes = classes;
}
@ -76,7 +77,7 @@ public class MinimalArtifactIndexRecord
this.size = size;
}
public String getClasses()
public List getClasses()
{
return classes;
}

View File

@ -21,6 +21,7 @@ import org.apache.maven.repository.digest.Digester;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
@ -72,9 +73,9 @@ public class MinimalArtifactIndexRecordFactory
return record;
}
private String getClassesFromFiles( List files )
private List getClassesFromFiles( List files )
{
StringBuffer classes = new StringBuffer();
List classes = new ArrayList();
for ( Iterator i = files.iterator(); i.hasNext(); )
{
@ -82,10 +83,10 @@ public class MinimalArtifactIndexRecordFactory
if ( isClass( name ) )
{
classes.append( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) ).append( "\n" );
classes.add( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) );
}
}
return classes.toString();
return classes;
}
}

View File

@ -1,5 +1,7 @@
package org.apache.maven.repository.indexing.record;
import java.util.List;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
@ -57,7 +59,7 @@ public class StandardArtifactIndexRecord
/**
* A list of files (separated by '\n') in the artifact if it is an archive.
*/
private String files;
private List files;
/**
* The identifier of the repository that the artifact came from.
@ -119,7 +121,7 @@ public class StandardArtifactIndexRecord
this.type = type;
}
public void setFiles( String files )
public void setFiles( List files )
{
this.files = files;
}
@ -255,7 +257,7 @@ public class StandardArtifactIndexRecord
return type;
}
public String getFiles()
public List getFiles()
{
return files;
}

View File

@ -32,6 +32,7 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
@ -184,8 +185,8 @@ public class StandardArtifactIndexRecordFactory
private void populateArchiveEntries( List files, StandardArtifactIndexRecord record, File artifactFile )
throws RepositoryIndexException
{
StringBuffer classes = new StringBuffer();
StringBuffer fileBuffer = new StringBuffer();
List classes = new ArrayList();
List fileList = new ArrayList();
for ( Iterator i = files.iterator(); i.hasNext(); )
{
@ -194,11 +195,11 @@ public class StandardArtifactIndexRecordFactory
// ignore directories
if ( !name.endsWith( "/" ) )
{
fileBuffer.append( name ).append( "\n" );
fileList.add( name );
if ( isClass( name ) )
{
classes.append( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) ).append( "\n" );
classes.add( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) );
}
else if ( PLUGIN_METADATA_NAME.equals( name ) )
{
@ -211,13 +212,13 @@ public class StandardArtifactIndexRecordFactory
}
}
if ( classes.length() > 0 )
if ( !classes.isEmpty() )
{
record.setClasses( classes.toString() );
record.setClasses( classes );
}
if ( fileBuffer.length() > 0 )
if ( !fileList.isEmpty() )
{
record.setFiles( fileBuffer.toString() );
record.setFiles( fileList );
}
}

View File

@ -157,7 +157,7 @@ public class LuceneMinimalArtifactIndexTest
try
{
Document document = reader.document( 0 );
assertRecord( document, artifact, "3a0adc365f849366cd8b633cad155cb7", "A\nb.B\nb.c.C\n" );
assertRecord( document, artifact, "3a0adc365f849366cd8b633cad155cb7", "A\nb.B\nb.c.C" );
assertEquals( "Check index size", 1, reader.numDocs() );
}
finally
@ -184,9 +184,7 @@ public class LuceneMinimalArtifactIndexTest
try
{
Document document = reader.document( 0 );
String expectedChecksum = "3a0adc365f849366cd8b633cad155cb7";
String expectedClasses = "A\nb.B\nb.c.C\n";
assertRecord( document, artifact, expectedChecksum, expectedClasses );
assertRecord( document, artifact, "3a0adc365f849366cd8b633cad155cb7", "A\nb.B\nb.c.C" );
assertEquals( "Check index size", 1, reader.numDocs() );
}
finally
@ -232,7 +230,7 @@ public class LuceneMinimalArtifactIndexTest
{
Document document = reader.document( 0 );
assertRecord( document, artifact, "06f6fe25e46c4d4fb5be4f56a9bab0ee",
"org.apache.maven.repository.record.MyMojo\n" );
"org.apache.maven.repository.record.MyMojo" );
assertEquals( "Check index size", 1, reader.numDocs() );
}
finally

View File

@ -309,8 +309,8 @@ public class LuceneStandardArtifactIndexTest
{
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",
assertEquals( "Check document classes", "A\nb.B\nb.c.C", document.get( "classes" ) );
assertEquals( "Check document files", "META-INF/MANIFEST.MF\nA.class\nb/B.class\nb/c/C.class",
document.get( "files" ) );
assertNull( "Check document inceptionYear", document.get( "inceptionYear" ) );
assertNull( "Check document projectName", document.get( "projectName" ) );
@ -323,12 +323,12 @@ public class LuceneStandardArtifactIndexTest
{
assertRecord( artifact, document, "test-plugin", "maven-plugin", "06f6fe25e46c4d4fb5be4f56a9bab0ee",
"382c1ebfb5d0c7d6061c2f8569fb53f8fc00fec2" );
assertEquals( "Check document classes", "org.apache.maven.repository.record.MyMojo\n",
assertEquals( "Check document classes", "org.apache.maven.repository.record.MyMojo",
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" ) );
"META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.properties", document.get( "files" ) );
assertEquals( "Check document pluginPrefix", "test", document.get( "pluginPrefix" ) );
assertEquals( "Check document packaging", "maven-plugin", document.get( "packaging" ) );
assertNull( "Check document inceptionYear", document.get( "inceptionYear" ) );

View File

@ -27,6 +27,9 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Test the minimal artifact index record.
@ -44,6 +47,8 @@ public class MinimalArtifactIndexRecordFactoryTest
private static final String TEST_GROUP_ID = "org.apache.maven.repository.record";
private static final List JAR_CLASS_LIST = Arrays.asList( new String[]{"A", "b.B", "b.c.C"} );
protected void setUp()
throws Exception
{
@ -75,7 +80,7 @@ public class MinimalArtifactIndexRecordFactoryTest
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.setClasses( JAR_CLASS_LIST );
assertEquals( "check record", expectedRecord, record );
}
@ -92,7 +97,7 @@ public class MinimalArtifactIndexRecordFactoryTest
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.setClasses( JAR_CLASS_LIST );
assertEquals( "check record", expectedRecord, record );
}
@ -142,7 +147,7 @@ public class MinimalArtifactIndexRecordFactoryTest
expectedRecord.setFilename( repository.pathOf( artifact ) );
expectedRecord.setLastModified( artifact.getFile().lastModified() );
expectedRecord.setSize( artifact.getFile().length() );
expectedRecord.setClasses( "org.apache.maven.repository.record.MyMojo\n" );
expectedRecord.setClasses( Collections.singletonList( "org.apache.maven.repository.record.MyMojo" ) );
assertEquals( "check record", expectedRecord, record );
}

View File

@ -27,6 +27,8 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
/**
* Test the minimal artifact index record.
@ -44,6 +46,11 @@ public class StandardArtifactIndexRecordFactoryTest
private static final String TEST_GROUP_ID = "org.apache.maven.repository.record";
private static final List JAR_CLASS_LIST = Arrays.asList( new String[]{"A", "b.B", "b.c.C"} );
private static final List JAR_FILE_LIST =
Arrays.asList( new String[]{"META-INF/MANIFEST.MF", "A.class", "b/B.class", "b/c/C.class"} );
protected void setUp()
throws Exception
{
@ -75,11 +82,11 @@ public class StandardArtifactIndexRecordFactoryTest
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.setClasses( JAR_CLASS_LIST );
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.setFiles( JAR_FILE_LIST );
expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" );
expectedRecord.setType( "jar" );
expectedRecord.setRepository( "test" );
@ -99,11 +106,11 @@ public class StandardArtifactIndexRecordFactoryTest
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.setClasses( JAR_CLASS_LIST );
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.setFiles( JAR_FILE_LIST );
expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" );
expectedRecord.setType( "jar" );
expectedRecord.setRepository( "test" );
@ -125,11 +132,11 @@ public class StandardArtifactIndexRecordFactoryTest
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.setClasses( JAR_CLASS_LIST );
expectedRecord.setArtifactId( "test-child-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.setFiles( JAR_FILE_LIST );
expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" );
expectedRecord.setType( "jar" );
expectedRecord.setRepository( "test" );
@ -208,11 +215,11 @@ public class StandardArtifactIndexRecordFactoryTest
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.setClasses( Arrays.asList( new String[]{"org.apache.maven.repository.record.MyMojo"} ) );
expectedRecord.setFiles( Arrays.asList( new String[]{"META-INF/MANIFEST.MF", "META-INF/maven/plugin.xml",
"org/apache/maven/repository/record/MyMojo.class",
"META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.xml",
"META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.properties"} ) );
expectedRecord.setPackaging( "maven-plugin" );
expectedRecord.setProjectName( "Maven Mojo Archetype" );
expectedRecord.setPluginPrefix( "test" );
@ -238,11 +245,10 @@ public class StandardArtifactIndexRecordFactoryTest
expectedRecord.setSha1Checksum( "5ebabafdbcd6684ae434c06e22c32844df284b05" );
expectedRecord.setType( "maven-archetype" );
expectedRecord.setRepository( "test" );
expectedRecord.setFiles( "META-INF/MANIFEST.MF\n" + "archetype-resources/pom.xml\n" +
"archetype-resources/src/main/java/App.java\n" + "archetype-resources/src/test/java/AppTest.java\n" +
"META-INF/maven/archetype.xml\n" +
"META-INF/maven/org.apache.maven.repository.record/test-archetype/pom.xml\n" +
"META-INF/maven/org.apache.maven.repository.record/test-archetype/pom.properties\n" );
expectedRecord.setFiles( Arrays.asList( new String[]{"META-INF/MANIFEST.MF", "archetype-resources/pom.xml",
"archetype-resources/src/main/java/App.java", "archetype-resources/src/test/java/AppTest.java",
"META-INF/maven/archetype.xml", "META-INF/maven/org.apache.maven.repository.record/test-archetype/pom.xml",
"META-INF/maven/org.apache.maven.repository.record/test-archetype/pom.properties"} ) );
expectedRecord.setPackaging( "jar" );
expectedRecord.setProjectName( "Archetype - test-archetype" );