*/\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
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
{
deleteDocuments( getTermList( pomList ) );
}
- catch( IOException e )
+ catch ( IOException e )
{
throw new RepositoryIndexException( "Failed to delete an index document", e );
}
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() ) ) );
}
}
+ 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.
*
--- /dev/null
+<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