From 60eaf428594d4e5b198d405da5896d8ac2173ccf Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 27 Jul 2006 03:42:47 +0000 Subject: [PATCH] [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 --- .../StandardArtifactIndexRecordFactory.java | 64 +++++++----------- ...tandardArtifactIndexRecordFactoryTest.java | 29 ++++++++ .../test-archetype/1.0/test-archetype-1.0.jar | Bin 0 -> 4338 bytes .../test-archetype/1.0/test-archetype-1.0.pom | 8 +++ 4 files changed, 61 insertions(+), 40 deletions(-) create mode 100644 maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.jar create mode 100644 maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.pom 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 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 ) 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 0000000000000000000000000000000000000000..e1686a206c4d0aefd9007986e94be8ab80ab51b3 GIT binary patch literal 4338 zcmb_e3tWrs8(x%^l+rLdp_EjsSd79}$~vspq)_OzT2#wgC3J3dn2xm0qCzJfi1t-< z_;f<&gU*RaB8m*I?Cdgb5E5ACC6^5f2mbB@CgjIu7?hrtrp7@-7)Fy4Qnb8O5keV9 zc5hS&#fggK=Jh3FPYaB9jG=vP<*Mv$dyXghBj_Hl9X+;=j0INy<0J5{OE|BZBokOi zc2S$?izrjo{4ALKY?(k(bH9b561EX_2wtLN5Zv-HsFmXhv2IZPoX(qAxmM+<7Tl2a z1^tizp!ZPw;C=~wy?8Ik7Z1mQ=h2Ahn#eBC)?q;zu{jQlsWLd2lPn2%vYR7bo`iQI zI+HB%PV=l6TR>S@IFT&bSc$T+vNyMNU}L)Jccv%JUCi0ovvWT$)RiYma zj}-|t;48`tg>%pvOaw-D82E4AC^O~ur8@Um95V4fek?X#(EntTUh%OeBOBWjeMwHc z%knLh(SO5V96(l!d~hfzk=-v40N!>gb0R7B2I}cHM}5EKiF0>gg*g@hp)E>P8$HhZ zZz5LN)wKq0m%jYM%t{}7>M>$?J0V3I;pv?-bzTgHJ)gogXx60hkTzL* zA|{xhXW8A{QklldFxi7R)sm7bs?a`aLHAJcUw-R|F7e9(Z3>E8EMIQYkd)bb-1Sk% zSVZ61?qp8BT+S-4XNgbp91N{5>93XPbiSE=6(3TGiA7@Sbv{uW-b$Gh=?$Ud!`IJ5 zRcKG#Xw-!U9#ox@-1mLST#3)*)oE0GV*-%RMqqAbkyl2+PM6;FCZZf2VT>1fj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