From: Olivier Lamy Date: Thu, 19 Jan 2012 10:09:47 +0000 (+0000) Subject: [MRM-1590] Wrong URL returned by SearchService.getArtifactVersions. X-Git-Tag: archiva-1.4-M3~1552 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=883900fa2a0523146e336a89e86b131280f10046;p=archiva.git [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 --- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java index 436e9df2e..58cfea4cf 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java @@ -240,8 +240,8 @@ public class NexusRepositorySearch } private SearchResults search( SearchResultLimits limits, BooleanQuery q, List indexingContextIds, - List filters, - List selectedRepos, boolean includePoms) + List filters, List selectedRepos, + boolean includePoms ) throws RepositorySearchException { @@ -449,7 +449,7 @@ public class NexusRepositorySearch private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits, List artifactInfoFilters, - ListselectedRepos, boolean includePoms) + List 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 diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java index a51de64aa..3624f33c6 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java @@ -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( '-' ).append( artifact.getClassifier() ); + } + // maven-plugin packaging is a jar + if ( StringUtils.equals( "maven-plugin", artifact.getPackaging() ) ) { - sb.append( '/' ); + sb.append( "jar" ); } - sb.append( artifact.getUrl() ); + else + { + sb.append( '.' ).append( artifact.getPackaging() ); + } + return sb.toString(); } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java index 088bf13d7..4f8fd620a 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java @@ -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 ); }