aboutsummaryrefslogtreecommitdiffstats
path: root/maven-repository-indexer
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2006-07-27 03:42:47 +0000
committerBrett Porter <brett@apache.org>2006-07-27 03:42:47 +0000
commit60eaf428594d4e5b198d405da5896d8ac2173ccf (patch)
tree8e9c89494d6b4df47948de45b89301ac983929a7 /maven-repository-indexer
parent25eac2b1f80ff04f5085a853dd6e9d6a0da7f037 (diff)
downloadarchiva-60eaf428594d4e5b198d405da5896d8ac2173ccf.tar.gz
archiva-60eaf428594d4e5b198d405da5896d8ac2173ccf.zip
[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
Diffstat (limited to 'maven-repository-indexer')
-rw-r--r--maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java64
-rw-r--r--maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java29
-rw-r--r--maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.jarbin0 -> 4338 bytes
-rw-r--r--maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.pom8
4 files changed, 61 insertions, 40 deletions
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
--- /dev/null
+++ b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.jar
Binary files 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 @@
+<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>