]> source.dussan.org Git - archiva.git/commitdiff
[MRM-127] read project using project builder to correctly handle inheritence and...
authorBrett Porter <brett@apache.org>
Thu, 27 Jul 2006 04:23:46 +0000 (04:23 +0000)
committerBrett Porter <brett@apache.org>
Thu, 27 Jul 2006 04:23:46 +0000 (04:23 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@425953 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-indexer/pom.xml
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java
maven-repository-indexer/src/site/apt/design.apt
maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java
maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/parent-pom/1/parent-pom-1.pom [new file with mode: 0644]
maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0/test-child-pom-1.0.jar [new file with mode: 0644]
maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0/test-child-pom-1.0.pom [new file with mode: 0644]

index 022932a31f42fa39284e05ee6e116d07dd1e1907..6b3479117758593e5ee0cc15f16a1f20ed860dc9 100644 (file)
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-artifact-manager</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-model</artifactId>
index e422afb71ae6e2e733026170e56ba71b28e084e6..c6a124c694eec6fbc9adbd78b14f404b4b8c11db 100644 (file)
@@ -18,21 +18,22 @@ 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.ArtifactRepository;
 import org.apache.maven.model.Model;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.repository.digest.Digester;
 import org.apache.maven.repository.indexing.RepositoryIndexException;
-import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -64,6 +65,11 @@ public class StandardArtifactIndexRecordFactory
      */
     private ArtifactFactory artifactFactory;
 
+    /**
+     * @plexus.requirement
+     */
+    private MavenProjectBuilder projectBuilder;
+
     private static final String PLUGIN_METADATA_NAME = "META-INF/maven/plugin.xml";
 
     private static final String ARCHETYPE_METADATA_NAME = "META-INF/maven/archetype.xml";
@@ -120,12 +126,12 @@ public class StandardArtifactIndexRecordFactory
                                              artifact.getRepository().pathOf( pomArtifact ) );
                     if ( pomFile.exists() )
                     {
-                        populatePomEntries( readPom( pomFile ), record );
+                        populatePomEntries( readPom( pomArtifact, artifact.getRepository() ), record );
                     }
                 }
                 else
                 {
-                    Model model = readPom( file );
+                    Model model = readPom( artifact, artifact.getRepository() );
 
                     if ( !"pom".equals( model.getPackaging() ) )
                     {
@@ -158,33 +164,21 @@ public class StandardArtifactIndexRecordFactory
 */
     }
 
-    private Model readPom( File file )
+    private Model readPom( Artifact artifact, ArtifactRepository repository )
         throws RepositoryIndexException
     {
-        MavenXpp3Reader r = new MavenXpp3Reader();
-
-        FileReader reader = null;
+        // TODO: will this pollute with local repo metadata?
+        Model model;
         try
         {
-            reader = new FileReader( file );
-            return r.read( reader );
-        }
-        catch ( FileNotFoundException e )
-        {
-            throw new RepositoryIndexException( "Unable to find requested POM: " + e.getMessage(), e );
+            MavenProject project = projectBuilder.buildFromRepository( artifact, Collections.EMPTY_LIST, repository );
+            model = project.getModel();
         }
-        catch ( IOException e )
-        {
-            throw new RepositoryIndexException( "Unable to read POM: " + e.getMessage(), e );
-        }
-        catch ( XmlPullParserException xe )
-        {
-            throw new RepositoryIndexException( "Unable to parse POM: " + xe.getMessage(), xe );
-        }
-        finally
+        catch ( ProjectBuildingException e )
         {
-            IOUtil.close( reader );
+            throw new RepositoryIndexException( "Unable to read project: " + e.getMessage(), e );
         }
+        return model;
     }
 
     private void populateArchiveEntries( List files, StandardArtifactIndexRecord record, File artifactFile )
index 5ecb476d5c572115f7b689f7949ea515c8cc6a0f..65865777e70a212c9607831caf0a7b179cd6e379 100644 (file)
@@ -67,7 +67,7 @@ Indexer Design
   dependency conflict ID, Lucene cannot delete by a combination of terms, so would require storing an additional
   field in the index where the file already exists.
 
-  The plugin prefix can be found either from inside the plugin JAR (<<<META-INF/maven/plugin.xml>>>), or from the
+  The plugin prefix could be found either from inside the plugin JAR (<<<META-INF/maven/plugin.xml>>>), or from the
   repository metadata for the plugin's group. For simplicity, the first approach will be used. This means at present
   there is no need to index the repository metadata, however that may be considered in future.
 
@@ -76,9 +76,10 @@ Indexer Design
   if found set its packaging to <<<maven-archetype>>>. In the future, this handling will be deprecated as the POMs
   can start using the appropriate packaging.
 
-  The index is shared among multiple repositories. The source repository is recorded in the index record. The indexer
-  should complain if an artifact is attempted to be updated from a different repository at a later date to avoid
-  duplicates. Ideally, the discovery/conversion mechanisms would deal with this before reaching the indexer.
+  The index is shared among multiple repositories. The source repository is recorded in the index record. The
+  discovery/conversion/reporting mechanisms are expected to deal with duplicates before reaching the indexer, so if the
+  indexer encounters an artifact from a different repository than it was already added, it will simply replace the
+  record.
 
   When indexing metadata from a POM, the POM should be loaded using the Maven project builder so that inheritance and
   interpolation are performed. This ensures that the record is as complete as possible, and that searching by
index 27219f87759283302d6b5db931ce9f162db966fc..4eb47c7005e1fd174de2a1c8807f86a44f0dea73 100644 (file)
@@ -113,6 +113,34 @@ public class StandardArtifactIndexRecordFactoryTest
         assertEquals( "check record", expectedRecord, record );
     }
 
+    public void testIndexedJarWithParentPom()
+        throws RepositoryIndexException
+    {
+        Artifact artifact = createArtifact( "test-child-pom" );
+
+        RepositoryIndexRecord record = factory.createRecord( artifact );
+
+        StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord();
+        expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" );
+        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.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.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" );
+        expectedRecord.setType( "jar" );
+        expectedRecord.setRepository( "test" );
+        expectedRecord.setPackaging( "jar" );
+        expectedRecord.setProjectName( "Child Project" );
+        expectedRecord.setProjectDescription( "Description" );
+        expectedRecord.setInceptionYear( "2005" );
+
+        assertEquals( "check record", expectedRecord, record );
+    }
+
     public void testIndexedPom()
         throws RepositoryIndexException
     {
diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/parent-pom/1/parent-pom-1.pom b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/parent-pom/1/parent-pom-1.pom
new file mode 100644 (file)
index 0000000..162f02a
--- /dev/null
@@ -0,0 +1,38 @@
+<!--
+  ~ Copyright 2005-2006 The Apache Software Foundation.
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<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>parent-pom</artifactId>
+  <version>1</version>
+  <packaging>pom</packaging>
+  <name>Test Parent POM</name>
+  <description>Description</description>
+  <inceptionYear>2005</inceptionYear>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <modules>
+    <module>test-child-pom</module>
+  </modules>
+</project>
+
diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0/test-child-pom-1.0.jar b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0/test-child-pom-1.0.jar
new file mode 100644 (file)
index 0000000..b78be2e
Binary files /dev/null and b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0/test-child-pom-1.0.jar differ
diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0/test-child-pom-1.0.pom b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0/test-child-pom-1.0.pom
new file mode 100644 (file)
index 0000000..696daf3
--- /dev/null
@@ -0,0 +1,28 @@
+<!--
+  ~ Copyright 2005-2006 The Apache Software Foundation.
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<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>
+  <parent>
+    <groupId>org.apache.maven.repository.record</groupId>
+    <artifactId>parent-pom</artifactId>
+    <version>1</version>
+  </parent>
+  <artifactId>test-child-pom</artifactId>
+  <version>1.0</version>
+  <name>Child Project</name>
+</project>