[MRM-1590] Wrong URL returned by SearchService.getArtifactVersions.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1233266 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-01-19 10:09:47 +00:00
parent cd7744eb28
commit 883900fa2a
3 changed files with 38 additions and 8 deletions

View File

@ -240,8 +240,8 @@ public class NexusRepositorySearch
}
private SearchResults search( SearchResultLimits limits, BooleanQuery q, List<String> indexingContextIds,
List<? extends ArtifactInfoFilter> filters,
List<String> selectedRepos, boolean includePoms)
List<? extends ArtifactInfoFilter> filters, List<String> selectedRepos,
boolean includePoms )
throws RepositorySearchException
{
@ -449,7 +449,7 @@ public class NexusRepositorySearch
private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits,
List<? extends ArtifactInfoFilter> artifactInfoFilters,
List<String>selectedRepos, boolean includePoms)
List<String> selectedRepos, boolean includePoms )
throws RepositoryAdminException
{
SearchResults results = new SearchResults();
@ -541,6 +541,7 @@ public class NexusRepositorySearch
if ( managedRepoId != null )
{
sb.append( '/' ).append( managedRepoId );
artifactInfo.context = managedRepoId;
}
}
else

View File

@ -237,7 +237,7 @@ public class DefaultSearchService
if ( StringUtils.isNotBlank( version ) )
{
versionned.setVersion( version );
versionned.setUrl( getArtifactUrl( versionned ) );
versionned.setUrl( getArtifactUrl( versionned, version ) );
artifacts.add( versionned );
@ -250,10 +250,11 @@ public class DefaultSearchService
/**
* TODO add a configuration mechanism to have configured the base archiva url
*
* @param artifact
* @return
*/
private String getArtifactUrl( Artifact artifact )
private String getArtifactUrl( Artifact artifact, String version )
{
if ( httpServletRequest == null )
@ -267,11 +268,28 @@ public class DefaultSearchService
StringBuilder sb = new StringBuilder( getBaseUrl( httpServletRequest ) );
sb.append( "/repository" );
if ( !StringUtils.startsWith( artifact.getUrl(), "/" ) )
sb.append( '/' ).append( artifact.getContext() );
sb.append( '/' ).append( StringUtils.replaceChars( artifact.getGroupId(), '.', '/' ) );
sb.append( '/' ).append( artifact.getArtifactId() );
sb.append( '/' ).append( artifact.getVersion() );
sb.append( '/' ).append( artifact.getArtifactId() );
sb.append( '-' ).append( artifact.getVersion() );
if ( StringUtils.isNotBlank( artifact.getClassifier() ) )
{
sb.append( '/' );
sb.append( '-' ).append( artifact.getClassifier() );
}
sb.append( artifact.getUrl() );
// maven-plugin packaging is a jar
if ( StringUtils.equals( "maven-plugin", artifact.getPackaging() ) )
{
sb.append( "jar" );
}
else
{
sb.append( '.' ).append( artifact.getPackaging() );
}
return sb.toString();
}

View File

@ -189,6 +189,17 @@ public class SearchServiceTest
" not 2 results for Bundle Symbolic Name org.apache.karaf.features.core but " + artifacts.size() + ":"
+ artifacts, artifacts.size() == 2 );
for ( Artifact artifact : artifacts )
{
log.info( "url:" + artifact.getUrl() );
String version = artifact.getVersion();
assertEquals( "http://localhost:" + port
+ "/repository/test-repo/org/apache/karaf/features/org.apache.karaf.features.core/"
+ version + "/org.apache.karaf.features.core-" + version + ".bundle", artifact.getUrl() );
}
deleteTestRepo( testRepoId );
}