]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1590] Wrong URL returned by SearchService.getArtifactVersions.
authorOlivier Lamy <olamy@apache.org>
Thu, 19 Jan 2012 10:09:47 +0000 (10:09 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 19 Jan 2012 10:09:47 +0000 (10:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1233266 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java

index 436e9df2ed03922e1c177fb875a56b708cab9df1..58cfea4cf3856c1374454dcdde90249c52582715 100644 (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
index a51de64aa969dfffd2aed356b2843f495b943c1d..3624f33c670aef73a7ab90054ea5c4237d2a2046 100644 (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( '-' ).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();
     }
 
index 088bf13d7dc36df16d8171931d2ad675739c6e4b..4f8fd620a9e6a36fd8f1c05ecc339e10fca67beb 100644 (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 );
     }