From 6b77912095c84491cbec88f7b5a67602378306ca Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 28 Sep 2011 21:37:22 +0000 Subject: move maven url calculation to NexusRepositorySearch rest services will just add baseUrl git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1177072 13f79535-47bb-0310-9956-ffa450edef68 --- .../indexer/search/NexusRepositorySearch.java | 45 ++++++++++++---------- .../archiva-rest/archiva-rest-services/pom.xml | 2 + .../rest/services/DefaultSearchService.java | 26 +++---------- 3 files changed, 31 insertions(+), 42 deletions(-) (limited to 'archiva-modules') 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 9c6432290..957b22627 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 @@ -248,27 +248,7 @@ public class NexusRepositorySearch { throw new RepositorySearchException( e ); } - /* - olamy : don't understand why this ?? it remove content from index ?? - comment until someone explain WTF ?? :-)) - finally - { - Map indexingContexts = indexer.getIndexingContexts(); - for ( Map.Entry entry : indexingContexts.entrySet() ) - { - try - { - indexer.removeIndexingContext( entry.getValue(), false ); - log.debug( "Indexing context '{}' removed from search.", entry.getKey() ); - } - catch ( IOException e ) - { - log.warn( "IOException occurred while removing indexing content '" + entry.getKey() + "'." ); - continue; - } - } - }*/ } private List getIndexingContexts( List ids ) @@ -466,7 +446,7 @@ public class NexusRepositorySearch hit.setPrefix( artifactInfo.prefix ); hit.setPackaging( artifactInfo.packaging ); hit.setClassifier( artifactInfo.classifier ); - hit.setUrl( artifactInfo.remoteUrl ); + hit.setUrl( getBaseUrl( artifactInfo ) ); } results.addHit( id, hit ); @@ -486,6 +466,29 @@ public class NexusRepositorySearch } } + /** + * calculate baseUrl without the context and base Archiva Url + * @param artifactInfo + * @return + */ + protected String getBaseUrl( ArtifactInfo artifactInfo ) + { + StringBuilder sb = new StringBuilder( ); + + sb.append( '/' ).append( StringUtils.replaceChars( artifactInfo.groupId, '.', '/' ) ); + sb.append( '/' ).append( artifactInfo.artifactId ); + sb.append( '/' ).append( artifactInfo.version ); + sb.append( '/' ).append( artifactInfo.artifactId ); + sb.append( '-' ).append( artifactInfo.version ); + if ( StringUtils.isNotBlank( artifactInfo.classifier ) ) + { + sb.append( '-' ).append( artifactInfo.classifier ); + } + sb.append( '.' ).append( artifactInfo.packaging ); + + return sb.toString(); + } + private boolean applyArtifactInfoFilters( ArtifactInfo artifactInfo, List artifactInfoFilers, Map currentResult ) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml index 6fbabbb46..120d30ead 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml @@ -31,6 +31,7 @@ 7.4.5.v20110725 + @@ -255,6 +256,7 @@ ${basedir}/target/appserver-base ${project.build.outputDirectory} ${archiva.baseRestUrl} + ${rest.admin.pwd} 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 016e816e2..78baad589 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 @@ -251,30 +251,14 @@ public class DefaultSearchService { return null; } - StringBuilder sb = new StringBuilder( getBaseUrl( httpContext.getHttpServletRequest() ) ); - - sb.append( "/repository" ); - - if ( StringUtils.startsWith( artifact.getContext(), "remote-" ) ) - { - // if context is 'remote-*' we have to set a repo which the current user can use - } - else + if (StringUtils.isEmpty( 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() ); - if ( StringUtils.isNotBlank( artifact.getClassifier() ) ) - { - sb.append( '-' ).append( artifact.getClassifier() ); + return null; } - sb.append( '-' ).append( artifact.getVersion() ); - sb.append( '.' ).append( artifact.getPackaging() ); + StringBuilder sb = new StringBuilder( getBaseUrl( httpContext.getHttpServletRequest() ) ); + sb.append( "/repository/" ); + sb.append( artifact.getUrl() ); return sb.toString(); } -- cgit v1.2.3