mirror of https://github.com/apache/archiva.git
use configured applicationUrl for download urls
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1342819 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
23bd07d564
commit
eccbf5b9c1
|
@ -19,18 +19,20 @@ package org.apache.archiva.rest.services;
|
|||
*/
|
||||
|
||||
import org.apache.archiva.admin.model.AuditInformation;
|
||||
import org.apache.archiva.admin.model.RepositoryAdminException;
|
||||
import org.apache.archiva.admin.model.admin.ArchivaAdministration;
|
||||
import org.apache.archiva.audit.AuditEvent;
|
||||
import org.apache.archiva.audit.AuditListener;
|
||||
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
|
||||
import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal;
|
||||
import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
|
||||
import org.apache.archiva.redback.users.User;
|
||||
import org.apache.archiva.redback.users.UserManager;
|
||||
import org.apache.archiva.security.AccessDeniedException;
|
||||
import org.apache.archiva.security.ArchivaSecurityException;
|
||||
import org.apache.archiva.security.PrincipalNotFoundException;
|
||||
import org.apache.archiva.security.UserRepositories;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.archiva.redback.users.User;
|
||||
import org.apache.archiva.redback.users.UserManager;
|
||||
import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal;
|
||||
import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
@ -67,6 +69,9 @@ public abstract class AbstractRestService
|
|||
@Named( value = "repositorySessionFactory" )
|
||||
protected RepositorySessionFactory repositorySessionFactory;
|
||||
|
||||
@Inject
|
||||
protected ArchivaAdministration archivaAdministration;
|
||||
|
||||
@Context
|
||||
protected HttpServletRequest httpServletRequest;
|
||||
|
||||
|
@ -122,7 +127,13 @@ public abstract class AbstractRestService
|
|||
}
|
||||
|
||||
protected String getBaseUrl( HttpServletRequest req )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
String applicationUrl = archivaAdministration.getUiConfiguration().getApplicationUrl();
|
||||
if ( StringUtils.isNotBlank( applicationUrl ) )
|
||||
{
|
||||
return applicationUrl;
|
||||
}
|
||||
return req.getScheme() + "://" + req.getServerName() + ( req.getServerPort() == 80
|
||||
? ""
|
||||
: ":" + req.getServerPort() ) + req.getContextPath();
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.apache.commons.lang.StringUtils;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
|
@ -199,85 +200,98 @@ public class DefaultManagedRepositoriesService
|
|||
}
|
||||
|
||||
private String createSnippet( ManagedRepository repo )
|
||||
throws ArchivaRestServiceException
|
||||
{
|
||||
StringBuilder snippet = new StringBuilder();
|
||||
snippet.append( "<project>\n" );
|
||||
snippet.append( " ...\n" );
|
||||
snippet.append( " <distributionManagement>\n" );
|
||||
|
||||
String distRepoName = "repository";
|
||||
if ( repo.isSnapshots() )
|
||||
try
|
||||
{
|
||||
distRepoName = "snapshotRepository";
|
||||
StringBuilder snippet = new StringBuilder();
|
||||
snippet.append( "<project>\n" );
|
||||
snippet.append( " ...\n" );
|
||||
snippet.append( " <distributionManagement>\n" );
|
||||
|
||||
String distRepoName = "repository";
|
||||
if ( repo.isSnapshots() )
|
||||
{
|
||||
distRepoName = "snapshotRepository";
|
||||
}
|
||||
|
||||
snippet.append( " <" ).append( distRepoName ).append( ">\n" );
|
||||
snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" );
|
||||
snippet.append( " <url>" );
|
||||
snippet.append( getBaseUrl( httpServletRequest ) + "/repository" );
|
||||
snippet.append( "/" ).append( repo.getId() ).append( "/" ).append( "</url>\n" );
|
||||
|
||||
if ( !"default".equals( repo.getLayout() ) )
|
||||
{
|
||||
snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>" );
|
||||
}
|
||||
|
||||
snippet.append( " </" ).append( distRepoName ).append( ">\n" );
|
||||
snippet.append( " </distributionManagement>\n" );
|
||||
snippet.append( "\n" );
|
||||
|
||||
snippet.append( " <repositories>\n" );
|
||||
snippet.append( " <repository>\n" );
|
||||
snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" );
|
||||
snippet.append( " <name>" ).append( repo.getName() ).append( "</name>\n" );
|
||||
|
||||
snippet.append( " <url>" );
|
||||
snippet.append( getBaseUrl( httpServletRequest ) + "/repository" );
|
||||
snippet.append( "/" ).append( repo.getId() ).append( "/" );
|
||||
|
||||
snippet.append( "</url>\n" );
|
||||
|
||||
if ( !"default".equals( repo.getLayout() ) )
|
||||
{
|
||||
snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>\n" );
|
||||
}
|
||||
|
||||
snippet.append( " <releases>\n" );
|
||||
snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isReleases() ) ).append(
|
||||
"</enabled>\n" );
|
||||
snippet.append( " </releases>\n" );
|
||||
snippet.append( " <snapshots>\n" );
|
||||
snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isSnapshots() ) ).append(
|
||||
"</enabled>\n" );
|
||||
snippet.append( " </snapshots>\n" );
|
||||
snippet.append( " </repository>\n" );
|
||||
snippet.append( " </repositories>\n" );
|
||||
snippet.append( " <pluginRepositories>\n" );
|
||||
snippet.append( " <pluginRepository>\n" );
|
||||
snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" );
|
||||
snippet.append( " <name>" ).append( repo.getName() ).append( "</name>\n" );
|
||||
|
||||
snippet.append( " <url>" );
|
||||
snippet.append( getBaseUrl( httpServletRequest ) + "/repository" );
|
||||
snippet.append( "/" ).append( repo.getId() ).append( "/" );
|
||||
|
||||
snippet.append( "</url>\n" );
|
||||
|
||||
if ( !"default".equals( repo.getLayout() ) )
|
||||
{
|
||||
snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>\n" );
|
||||
}
|
||||
|
||||
snippet.append( " <releases>\n" );
|
||||
snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isReleases() ) ).append(
|
||||
"</enabled>\n" );
|
||||
snippet.append( " </releases>\n" );
|
||||
snippet.append( " <snapshots>\n" );
|
||||
snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isSnapshots() ) ).append(
|
||||
"</enabled>\n" );
|
||||
snippet.append( " </snapshots>\n" );
|
||||
snippet.append( " </pluginRepository>\n" );
|
||||
snippet.append( " </pluginRepositories>\n" );
|
||||
|
||||
snippet.append( " ...\n" );
|
||||
snippet.append( "</project>\n" );
|
||||
|
||||
return StringEscapeUtils.escapeXml( snippet.toString() );
|
||||
}
|
||||
|
||||
snippet.append( " <" ).append( distRepoName ).append( ">\n" );
|
||||
snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" );
|
||||
snippet.append( " <url>" );
|
||||
snippet.append( getBaseUrl( httpServletRequest ) + "/repository" );
|
||||
snippet.append( "/" ).append( repo.getId() ).append( "/" ).append( "</url>\n" );
|
||||
|
||||
if ( !"default".equals( repo.getLayout() ) )
|
||||
catch ( RepositoryAdminException e )
|
||||
{
|
||||
snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>" );
|
||||
throw new ArchivaRestServiceException( e.getMessage(),
|
||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
|
||||
}
|
||||
|
||||
snippet.append( " </" ).append( distRepoName ).append( ">\n" );
|
||||
snippet.append( " </distributionManagement>\n" );
|
||||
snippet.append( "\n" );
|
||||
|
||||
snippet.append( " <repositories>\n" );
|
||||
snippet.append( " <repository>\n" );
|
||||
snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" );
|
||||
snippet.append( " <name>" ).append( repo.getName() ).append( "</name>\n" );
|
||||
|
||||
snippet.append( " <url>" );
|
||||
snippet.append( getBaseUrl( httpServletRequest ) + "/repository" );
|
||||
snippet.append( "/" ).append( repo.getId() ).append( "/" );
|
||||
|
||||
snippet.append( "</url>\n" );
|
||||
|
||||
if ( !"default".equals( repo.getLayout() ) )
|
||||
{
|
||||
snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>\n" );
|
||||
}
|
||||
|
||||
snippet.append( " <releases>\n" );
|
||||
snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isReleases() ) ).append( "</enabled>\n" );
|
||||
snippet.append( " </releases>\n" );
|
||||
snippet.append( " <snapshots>\n" );
|
||||
snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isSnapshots() ) ).append( "</enabled>\n" );
|
||||
snippet.append( " </snapshots>\n" );
|
||||
snippet.append( " </repository>\n" );
|
||||
snippet.append( " </repositories>\n" );
|
||||
snippet.append( " <pluginRepositories>\n" );
|
||||
snippet.append( " <pluginRepository>\n" );
|
||||
snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" );
|
||||
snippet.append( " <name>" ).append( repo.getName() ).append( "</name>\n" );
|
||||
|
||||
snippet.append( " <url>" );
|
||||
snippet.append( getBaseUrl( httpServletRequest ) + "/repository" );
|
||||
snippet.append( "/" ).append( repo.getId() ).append( "/" );
|
||||
|
||||
snippet.append( "</url>\n" );
|
||||
|
||||
if ( !"default".equals( repo.getLayout() ) )
|
||||
{
|
||||
snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>\n" );
|
||||
}
|
||||
|
||||
snippet.append( " <releases>\n" );
|
||||
snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isReleases() ) ).append( "</enabled>\n" );
|
||||
snippet.append( " </releases>\n" );
|
||||
snippet.append( " <snapshots>\n" );
|
||||
snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isSnapshots() ) ).append( "</enabled>\n" );
|
||||
snippet.append( " </snapshots>\n" );
|
||||
snippet.append( " </pluginRepository>\n" );
|
||||
snippet.append( " </pluginRepositories>\n" );
|
||||
|
||||
snippet.append( " ...\n" );
|
||||
snippet.append( "</project>\n" );
|
||||
|
||||
return StringEscapeUtils.escapeXml( snippet.toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,9 +133,6 @@ public class DefaultRepositoriesService
|
|||
@Inject
|
||||
private RepositoryContentFactory repositoryFactory;
|
||||
|
||||
@Inject
|
||||
private ArchivaAdministration archivaAdministration;
|
||||
|
||||
@Inject
|
||||
@Named( value = "archivaTaskScheduler#repository" )
|
||||
private ArchivaTaskScheduler scheduler;
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.archiva.rest.services;
|
|||
*/
|
||||
|
||||
import net.sf.beanlib.provider.replicator.BeanReplicator;
|
||||
import org.apache.archiva.admin.model.RepositoryAdminException;
|
||||
import org.apache.archiva.indexer.search.RepositorySearch;
|
||||
import org.apache.archiva.indexer.search.RepositorySearchException;
|
||||
import org.apache.archiva.indexer.search.SearchFields;
|
||||
|
@ -38,6 +39,7 @@ import org.apache.commons.lang.StringUtils;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -202,6 +204,7 @@ public class DefaultSearchService
|
|||
// internal
|
||||
//-------------------------------------
|
||||
protected List<Artifact> getArtifacts( SearchResults searchResults )
|
||||
throws ArchivaRestServiceException
|
||||
{
|
||||
|
||||
if ( searchResults == null || searchResults.isEmpty() )
|
||||
|
@ -240,42 +243,51 @@ public class DefaultSearchService
|
|||
* @return
|
||||
*/
|
||||
private String getArtifactUrl( Artifact artifact, String version )
|
||||
throws ArchivaRestServiceException
|
||||
{
|
||||
|
||||
if ( httpServletRequest == null )
|
||||
try
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if ( StringUtils.isEmpty( artifact.getUrl() ) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder( getBaseUrl( httpServletRequest ) );
|
||||
|
||||
sb.append( "/repository" );
|
||||
if ( httpServletRequest == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if ( StringUtils.isEmpty( artifact.getUrl() ) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder( getBaseUrl( httpServletRequest ) );
|
||||
|
||||
sb.append( '/' ).append( artifact.getContext() );
|
||||
sb.append( "/repository" );
|
||||
|
||||
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( "jar" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append( '.' ).append( artifact.getPackaging() );
|
||||
}
|
||||
sb.append( '/' ).append( artifact.getContext() );
|
||||
|
||||
return sb.toString();
|
||||
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( "jar" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append( '.' ).append( artifact.getPackaging() );
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
catch ( RepositoryAdminException e )
|
||||
{
|
||||
throw new ArchivaRestServiceException( e.getMessage(),
|
||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue