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
This commit is contained in:
Olivier Lamy 2011-09-28 21:37:22 +00:00
parent 45ff9153bf
commit 6b77912095
3 changed files with 32 additions and 43 deletions

View File

@ -248,27 +248,7 @@ private SearchResults search( SearchResultLimits limits, BooleanQuery q, List<St
{
throw new RepositorySearchException( e );
}
/*
olamy : don't understand why this ?? it remove content from index ??
comment until someone explain WTF ?? :-))
finally
{
Map<String, IndexingContext> indexingContexts = indexer.getIndexingContexts();
for ( Map.Entry<String, IndexingContext> 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<IndexingContext> getIndexingContexts( List<String> ids )
@ -466,7 +446,7 @@ private SearchResults convertToSearchResults( FlatSearchResponse response, Searc
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 @@ private SearchResults convertToSearchResults( FlatSearchResponse response, Searc
}
}
/**
* 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<? extends ArtifactInfoFiler> artifactInfoFilers,
Map<String, SearchResultHit> currentResult )

View File

@ -31,6 +31,7 @@
<properties>
<jettyVersion>7.4.5.v20110725</jettyVersion>
<archiva.baseRestUrl></archiva.baseRestUrl>
<rest.admin.pwd></rest.admin.pwd>
</properties>
<dependencies>
@ -255,6 +256,7 @@
<appserver.base>${basedir}/target/appserver-base</appserver.base>
<java.io.tmpdir>${project.build.outputDirectory}</java.io.tmpdir>
<archiva.baseRestUrl>${archiva.baseRestUrl}</archiva.baseRestUrl>
<rest.admin.pwd>${rest.admin.pwd}</rest.admin.pwd>
</systemPropertyVariables>
</configuration>
</plugin>

View File

@ -251,30 +251,14 @@ private String getArtifactUrl( HttpContext httpContext, Artifact artifact )
{
return null;
}
if (StringUtils.isEmpty( artifact.getUrl() ))
{
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
{
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() );
}
sb.append( '-' ).append( artifact.getVersion() );
sb.append( '.' ).append( artifact.getPackaging() );
sb.append( "/repository/" );
sb.append( artifact.getUrl() );
return sb.toString();
}