]> source.dussan.org Git - archiva.git/commitdiff
test and fix for inherited versions in the model causing indexing failures
authorBrett Porter <brett@apache.org>
Sat, 22 Jul 2006 15:04:41 +0000 (15:04 +0000)
committerBrett Porter <brett@apache.org>
Sat, 22 Jul 2006 15:04:41 +0000 (15:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@424590 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexSearchLayer.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java
maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java
maven-repository-indexer/src/test/repository/test/inherited/test-inherited/1.0.15/test-inherited-1.0.15.pom [new file with mode: 0644]

index da6bd6bb1413b324249b5676b77b259b06ded26c..44c5196a0b75fd7b123481e9a9ee7b26ac924fd3 100644 (file)
@@ -275,7 +275,17 @@ public class DefaultRepositoryIndexSearchLayer
      */\r
     private SearchResult createSearchResult( Model model, String field, List searchResults )\r
     {\r
-        int index = getListIndex( model.getGroupId(), model.getArtifactId(), model.getVersion(), searchResults );\r
+        String groupId = model.getGroupId();\r
+        if ( groupId == null )\r
+        {\r
+            groupId = model.getParent().getGroupId();\r
+        }\r
+        String version = model.getVersion();\r
+        if ( version == null )\r
+        {\r
+            version = model.getParent().getVersion();\r
+        }\r
+        int index = getListIndex( groupId, model.getArtifactId(), version, searchResults );\r
         SearchResult result;\r
         Map map;\r
 \r
@@ -288,8 +298,8 @@ public class DefaultRepositoryIndexSearchLayer
         else\r
         {\r
             result = new SearchResult();\r
-            result.setArtifact( factory.createBuildArtifact( model.getGroupId(), model.getArtifactId(),\r
-                                                             model.getVersion(), model.getPackaging() ) );\r
+            result.setArtifact(\r
+                factory.createBuildArtifact( groupId, model.getArtifactId(), version, model.getPackaging() ) );\r
             map = new HashMap();\r
         }\r
 \r
index 7396ecc029cc9e9a36e4e54234a855adfc56b035..81ff60492137333ec5875c26a83e1ae7a513dea1 100644 (file)
@@ -92,7 +92,7 @@ public class PomRepositoryIndex
         {
             deleteDocuments( getTermList( pomList ) );
         }
-        catch( IOException e )
+        catch ( IOException e )
         {
             throw new RepositoryIndexException( "Failed to delete an index document", e );
         }
@@ -152,15 +152,29 @@ public class PomRepositoryIndex
     private Document createDocument( Model pom )
         throws RepositoryIndexException
     {
+        String version = pom.getVersion();
+        if ( version == null )
+        {
+            // It was inherited
+            version = pom.getParent().getVersion();
+            // TODO: do we need to use the general inheritence mechanism or do we only want to search within those defined in this pom itself?
+            // I think searching just this one is adequate, and it is only necessary to inherit the version and group ID [BP]
+        }
+
+        String groupId = pom.getGroupId();
+        if ( groupId == null )
+        {
+            groupId = pom.getParent().getGroupId();
+        }
+
         Document doc = new Document();
         doc.add( Field.Keyword( FLD_ID, POM + ":" + pom.getId() ) );
-        doc.add( Field.Text( FLD_GROUPID, pom.getGroupId() ) );
+        doc.add( Field.Text( FLD_GROUPID, groupId ) );
         doc.add( Field.Text( FLD_ARTIFACTID, pom.getArtifactId() ) );
-        doc.add( Field.Text( FLD_VERSION, pom.getVersion() ) );
+        doc.add( Field.Text( FLD_VERSION, version ) );
         doc.add( Field.Keyword( FLD_PACKAGING, pom.getPackaging() ) );
 
-        Artifact artifact =
-            artifactFactory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), "pom" );
+        Artifact artifact = artifactFactory.createBuildArtifact( groupId, pom.getArtifactId(), version, "pom" );
         File pomFile = new File( repository.getBasedir(), repository.pathOf( artifact ) );
         doc.add( Field.Text( FLD_SHA1, getChecksum( Digester.SHA1, pomFile.getAbsolutePath() ) ) );
         doc.add( Field.Text( FLD_MD5, getChecksum( Digester.MD5, pomFile.getAbsolutePath() ) ) );
index 6c60070125a61df1c27b44c70fabb273cbcaea48..e89d1c3bfe45987874d1d36327cfd4a829bd8427 100644 (file)
@@ -100,6 +100,43 @@ public class PomRepositoryIndexingTest
         }
     }
 
+    public void testInheritedFields()
+        throws Exception
+    {
+        RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+        Model pom = getPom( "test.inherited", "test-inherited", "1.0.15" );
+
+        PomRepositoryIndex indexer = factory.createPomRepositoryIndex( indexPath, repository );
+        indexer.indexPom( pom );
+
+        RepositoryIndexSearchLayer repoSearchLayer =
+            (RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
+
+        // search version
+        Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0.15" );
+        List artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
+        assertEquals( 1, artifactList.size() );
+        for ( Iterator iter = artifactList.iterator(); iter.hasNext(); )
+        {
+            SearchResult result = (SearchResult) iter.next();
+            Artifact artifact = result.getArtifact();
+            assertEquals( "1.0.15", artifact.getVersion() );
+        }
+
+        // search group id
+        qry = new SinglePhraseQuery( RepositoryIndex.FLD_GROUPID, "test.inherited" );
+        artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
+        assertEquals( 1, artifactList.size() );
+        Iterator artifacts = artifactList.iterator();
+        if ( artifacts.hasNext() )
+        {
+            SearchResult result = (SearchResult) artifacts.next();
+            Artifact artifact = result.getArtifact();
+            assertEquals( "test.inherited", artifact.getGroupId() );
+        }
+
+    }
+
     /**
      * Test the PomRepositoryIndex with DefaultRepositoryIndexSearcher using a single-phrase search.
      *
diff --git a/maven-repository-indexer/src/test/repository/test/inherited/test-inherited/1.0.15/test-inherited-1.0.15.pom b/maven-repository-indexer/src/test/repository/test/inherited/test-inherited/1.0.15/test-inherited-1.0.15.pom
new file mode 100644 (file)
index 0000000..19faa79
--- /dev/null
@@ -0,0 +1,11 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>test.inherited</groupId>
+    <version>1.0.15</version>
+    <artifactId>test-inherited-parent</artifactId>
+  </parent>
+  <!-- groupID, version are inherited -->
+  <artifactId>test-inherited</artifactId>
+  <packaging>pom</packaging>
+</project>
\ No newline at end of file