From: Brett Porter Date: Thu, 27 Jul 2006 03:42:47 +0000 (+0000) Subject: [MRM-127] add support for archetypes X-Git-Tag: archiva-0.9-alpha-1~739 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=60eaf428594d4e5b198d405da5896d8ac2173ccf;p=archiva.git [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 --- 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 eb706d4f0..cab0b91fd 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 @@ -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 void populateArchetypeEntries( StandardArtifactIndexRecord record ) + { + // Typically discovered as a JAR + record.setType( "maven-archetype" ); } - private Xpp3Dom readPluginMetadata( File file ) + 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 ) 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 2413a58c0..8c345752b 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 @@ -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 { diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.jar b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.jar new file mode 100644 index 000000000..e1686a206 Binary files /dev/null and b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.jar differ diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.pom b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.pom new file mode 100644 index 000000000..7b9d7c7f7 --- /dev/null +++ b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.pom @@ -0,0 +1,8 @@ + + 4.0.0 + org.apache.maven.repository.record + test-archetype + 1.0 + Archetype - test-archetype +