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 )
|
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;
|
SearchResult result;
|
||||||
Map map;
|
Map map;
|
||||||
|
|
||||||
|
@ -288,8 +298,8 @@ public class DefaultRepositoryIndexSearchLayer
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = new SearchResult();
|
result = new SearchResult();
|
||||||
result.setArtifact( factory.createBuildArtifact( model.getGroupId(), model.getArtifactId(),
|
result.setArtifact(
|
||||||
model.getVersion(), model.getPackaging() ) );
|
factory.createBuildArtifact( groupId, model.getArtifactId(), version, model.getPackaging() ) );
|
||||||
map = new HashMap();
|
map = new HashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ public class PomRepositoryIndex
|
||||||
{
|
{
|
||||||
deleteDocuments( getTermList( pomList ) );
|
deleteDocuments( getTermList( pomList ) );
|
||||||
}
|
}
|
||||||
catch( IOException e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
throw new RepositoryIndexException( "Failed to delete an index document", e );
|
throw new RepositoryIndexException( "Failed to delete an index document", e );
|
||||||
}
|
}
|
||||||
|
@ -152,15 +152,29 @@ public class PomRepositoryIndex
|
||||||
private Document createDocument( Model pom )
|
private Document createDocument( Model pom )
|
||||||
throws RepositoryIndexException
|
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();
|
Document doc = new Document();
|
||||||
doc.add( Field.Keyword( FLD_ID, POM + ":" + pom.getId() ) );
|
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_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() ) );
|
doc.add( Field.Keyword( FLD_PACKAGING, pom.getPackaging() ) );
|
||||||
|
|
||||||
Artifact artifact =
|
Artifact artifact = artifactFactory.createBuildArtifact( groupId, pom.getArtifactId(), version, "pom" );
|
||||||
artifactFactory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), "pom" );
|
|
||||||
File pomFile = new File( repository.getBasedir(), repository.pathOf( artifact ) );
|
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_SHA1, getChecksum( Digester.SHA1, pomFile.getAbsolutePath() ) ) );
|
||||||
doc.add( Field.Text( FLD_MD5, getChecksum( Digester.MD5, 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.
|
* 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