*/
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;
@Named( value = "repositorySessionFactory" )
protected RepositorySessionFactory repositorySessionFactory;
+ @Inject
+ protected ArchivaAdministration archivaAdministration;
+
@Context
protected HttpServletRequest httpServletRequest;
}
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();
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;
}
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" );
- 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" );
+ String distRepoName = "repository";
+ if ( repo.isSnapshots() )
+ {
+ distRepoName = "snapshotRepository";
+ }
- if ( !"default".equals( repo.getLayout() ) )
- {
- snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>" );
- }
+ 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" );
- snippet.append( " </" ).append( distRepoName ).append( ">\n" );
- snippet.append( " </distributionManagement>\n" );
- snippet.append( "\n" );
+ if ( !"default".equals( repo.getLayout() ) )
+ {
+ snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>" );
+ }
- 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( " </" ).append( distRepoName ).append( ">\n" );
+ snippet.append( " </distributionManagement>\n" );
+ snippet.append( "\n" );
- snippet.append( " <url>" );
- snippet.append( getBaseUrl( httpServletRequest ) + "/repository" );
- snippet.append( "/" ).append( repo.getId() ).append( "/" );
+ 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>\n" );
+ snippet.append( " <url>" );
+ snippet.append( getBaseUrl( httpServletRequest ) + "/repository" );
+ snippet.append( "/" ).append( repo.getId() ).append( "/" );
- if ( !"default".equals( repo.getLayout() ) )
- {
- snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>\n" );
- }
+ snippet.append( "</url>\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" );
+ if ( !"default".equals( repo.getLayout() ) )
+ {
+ snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>\n" );
+ }
- snippet.append( " ...\n" );
- snippet.append( "</project>\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" );
+ }
- return StringEscapeUtils.escapeXml( snippet.toString() );
+ 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() );
+ }
+ catch ( RepositoryAdminException e )
+ {
+ throw new ArchivaRestServiceException( e.getMessage(),
+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
+ }
}
}
*/
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;
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;
// internal
//-------------------------------------
protected List<Artifact> getArtifacts( SearchResults searchResults )
+ throws ArchivaRestServiceException
{
if ( searchResults == null || searchResults.isEmpty() )
* @return
*/
private String getArtifactUrl( Artifact artifact, String version )
+ throws ArchivaRestServiceException
{
-
- if ( httpServletRequest == null )
- {
- return null;
- }
- if ( StringUtils.isEmpty( artifact.getUrl() ) )
+ try
{
- 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" );
+ 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( "jar" );
+ }
+ else
+ {
+ sb.append( '.' ).append( artifact.getPackaging() );
+ }
+
+ return sb.toString();
}
- else
+ catch ( RepositoryAdminException e )
{
- sb.append( '.' ).append( artifact.getPackaging() );
+ throw new ArchivaRestServiceException( e.getMessage(),
+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
}
-
- return sb.toString();
}