[MRM-127] add support for archetypes

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@425943 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2006-07-27 03:42:47 +00:00
parent 25eac2b1f8
commit 60eaf42859
4 changed files with 61 additions and 40 deletions

View File

@ -18,8 +18,6 @@ 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.Metadata;
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;
@ -68,6 +66,8 @@ public class StandardArtifactIndexRecordFactory
private static final String PLUGIN_METADATA_NAME = "META-INF/maven/plugin.xml";
private static final String ARCHETYPE_METADATA_NAME = "META-INF/maven/archetype.xml";
public RepositoryIndexRecord createRecord( Artifact artifact )
throws RepositoryIndexException
{
@ -177,35 +177,6 @@ public class StandardArtifactIndexRecordFactory
}
}
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, File artifactFile )
throws RepositoryIndexException
{
@ -225,21 +196,34 @@ public class StandardArtifactIndexRecordFactory
{
classes.append( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) ).append( "\n" );
}
else
else if ( PLUGIN_METADATA_NAME.equals( name ) )
{
if ( PLUGIN_METADATA_NAME.equals( name ) )
{
populatePluginEntries( readPluginMetadata( artifactFile ), record );
}
populatePluginEntries( readXmlMetadataFileInJar( artifactFile, PLUGIN_METADATA_NAME ), record );
}
else if ( ARCHETYPE_METADATA_NAME.equals( name ) )
{
populateArchetypeEntries( record );
}
}
}
record.setClasses( classes.toString() );
record.setFiles( fileBuffer.toString() );
if ( classes.length() > 0 )
{
record.setClasses( classes.toString() );
}
if ( fileBuffer.length() > 0 )
{
record.setFiles( fileBuffer.toString() );
}
}
private Xpp3Dom readPluginMetadata( File file )
private void populateArchetypeEntries( StandardArtifactIndexRecord record )
{
// Typically discovered as a JAR
record.setType( "maven-archetype" );
}
private Xpp3Dom readXmlMetadataFileInJar( File file, String name )
throws RepositoryIndexException
{
// TODO: would be more efficient with original ZipEntry still around
@ -249,7 +233,7 @@ public class StandardArtifactIndexRecordFactory
try
{
zipFile = new ZipFile( file );
ZipEntry entry = zipFile.getEntry( PLUGIN_METADATA_NAME );
ZipEntry entry = zipFile.getEntry( name );
xpp3Dom = Xpp3DomBuilder.build( new InputStreamReader( zipFile.getInputStream( entry ) ) );
}
catch ( ZipException e )

View File

@ -169,6 +169,35 @@ public class StandardArtifactIndexRecordFactoryTest
assertEquals( "check record", expectedRecord, record );
}
public void testIndexedArchetype()
throws RepositoryIndexException, IOException, XmlPullParserException
{
Artifact artifact = createArtifact( "test-archetype" );
RepositoryIndexRecord record = factory.createRecord( artifact );
StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord();
expectedRecord.setMd5Checksum( "ecefd4674c75a175119572b19edc45f1" );
expectedRecord.setFilename( repository.pathOf( artifact ) );
expectedRecord.setLastModified( artifact.getFile().lastModified() );
expectedRecord.setSize( artifact.getFile().length() );
expectedRecord.setArtifactId( "test-archetype" );
expectedRecord.setGroupId( TEST_GROUP_ID );
expectedRecord.setVersion( "1.0" );
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.setPackaging( "jar" );
expectedRecord.setProjectName( "Archetype - test-archetype" );
assertEquals( "check record", expectedRecord, record );
}
public void testCorruptJar()
throws RepositoryIndexException
{

View File

@ -0,0 +1,8 @@
<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-archetype</artifactId>
<version>1.0</version>
<name>Archetype - test-archetype</name>
</project>