mirror of https://github.com/apache/archiva.git
test and fix for inherited versions in the model causing indexing failures
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@424590 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a1f72ea29b
commit
1c018926a6
|
@ -275,7 +275,17 @@ public class DefaultRepositoryIndexSearchLayer
|
|||
*/
|
||||
private SearchResult createSearchResult( Model model, String field, List searchResults )
|
||||
{
|
||||
int index = getListIndex( model.getGroupId(), model.getArtifactId(), model.getVersion(), searchResults );
|
||||
String groupId = model.getGroupId();
|
||||
if ( groupId == null )
|
||||
{
|
||||
groupId = model.getParent().getGroupId();
|
||||
}
|
||||
String version = model.getVersion();
|
||||
if ( version == null )
|
||||
{
|
||||
version = model.getParent().getVersion();
|
||||
}
|
||||
int index = getListIndex( groupId, model.getArtifactId(), version, searchResults );
|
||||
SearchResult result;
|
||||
Map map;
|
||||
|
||||
|
@ -288,8 +298,8 @@ public class DefaultRepositoryIndexSearchLayer
|
|||
else
|
||||
{
|
||||
result = new SearchResult();
|
||||
result.setArtifact( factory.createBuildArtifact( model.getGroupId(), model.getArtifactId(),
|
||||
model.getVersion(), model.getPackaging() ) );
|
||||
result.setArtifact(
|
||||
factory.createBuildArtifact( groupId, model.getArtifactId(), version, model.getPackaging() ) );
|
||||
map = new HashMap();
|
||||
}
|
||||
|
||||
|
|
|
@ -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() ) ) );
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue