mirror of https://github.com/apache/archiva.git
[MRM-1551] add rest method to delete artifact.
reuse service in webapp action to avoid too much duplicate code. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1200019 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
397e88dac8
commit
609cdaabe9
|
@ -606,11 +606,10 @@ public class DefaultRepositoriesService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Boolean deleteArtifact( Artifact artifact, String repositoryId )
|
public Boolean deleteArtifact( Artifact artifact, String repositoryId )
|
||||||
throws ArchivaRestServiceException
|
throws ArchivaRestServiceException
|
||||||
{
|
{
|
||||||
String userName = getAuditInformation().getUser().getUsername();
|
String userName = (String) getAuditInformation().getUser().getPrincipal();
|
||||||
if ( StringUtils.isBlank( userName ) )
|
if ( StringUtils.isBlank( userName ) )
|
||||||
{
|
{
|
||||||
// TODO use constants from a class instead of magic number
|
// TODO use constants from a class instead of magic number
|
||||||
|
@ -821,6 +820,56 @@ public class DefaultRepositoriesService
|
||||||
auditListener.auditEvent( auditEvent );
|
auditListener.auditEvent( auditEvent );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ManagedRepositoryAdmin getManagedRepositoryAdmin()
|
||||||
|
{
|
||||||
|
return managedRepositoryAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
|
||||||
|
{
|
||||||
|
this.managedRepositoryAdmin = managedRepositoryAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RepositoryContentFactory getRepositoryFactory()
|
||||||
|
{
|
||||||
|
return repositoryFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepositoryFactory( RepositoryContentFactory repositoryFactory )
|
||||||
|
{
|
||||||
|
this.repositoryFactory = repositoryFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RepositorySessionFactory getRepositorySessionFactory()
|
||||||
|
{
|
||||||
|
return repositorySessionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepositorySessionFactory( RepositorySessionFactory repositorySessionFactory )
|
||||||
|
{
|
||||||
|
this.repositorySessionFactory = repositorySessionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RepositoryListener> getListeners()
|
||||||
|
{
|
||||||
|
return listeners;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListeners( List<RepositoryListener> listeners )
|
||||||
|
{
|
||||||
|
this.listeners = listeners;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArchivaAdministration getArchivaAdministration()
|
||||||
|
{
|
||||||
|
return archivaAdministration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArchivaAdministration( ArchivaAdministration archivaAdministration )
|
||||||
|
{
|
||||||
|
this.archivaAdministration = archivaAdministration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.apache.commons.lang.math.NumberUtils;
|
||||||
import org.apache.struts2.ServletActionContext;
|
import org.apache.struts2.ServletActionContext;
|
||||||
import org.apache.struts2.interceptor.SessionAware;
|
import org.apache.struts2.interceptor.SessionAware;
|
||||||
import org.codehaus.plexus.redback.users.User;
|
import org.codehaus.plexus.redback.users.User;
|
||||||
|
import org.codehaus.redback.rest.services.RedbackRequestInformation;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
@ -192,6 +193,11 @@ public abstract class AbstractActionSupport
|
||||||
return auditInformation;
|
return auditInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected RedbackRequestInformation getRedbackRequestInformation()
|
||||||
|
{
|
||||||
|
return new RedbackRequestInformation( new SimpleUser( getPrincipal() ), getRemoteAddr() );
|
||||||
|
}
|
||||||
|
|
||||||
public String getArchivaVersion()
|
public String getArchivaVersion()
|
||||||
{
|
{
|
||||||
return (String) archivaRuntimeProperties.get( "archiva.version" );
|
return (String) archivaRuntimeProperties.get( "archiva.version" );
|
||||||
|
|
|
@ -21,53 +21,26 @@ package org.apache.archiva.web.action;
|
||||||
|
|
||||||
import com.opensymphony.xwork2.Preparable;
|
import com.opensymphony.xwork2.Preparable;
|
||||||
import com.opensymphony.xwork2.Validateable;
|
import com.opensymphony.xwork2.Validateable;
|
||||||
import org.apache.archiva.admin.model.RepositoryAdminException;
|
|
||||||
import org.apache.archiva.admin.model.beans.ManagedRepository;
|
|
||||||
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
|
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
|
||||||
import org.apache.archiva.audit.AuditEvent;
|
|
||||||
import org.apache.archiva.audit.Auditable;
|
import org.apache.archiva.audit.Auditable;
|
||||||
import org.apache.archiva.checksum.ChecksumAlgorithm;
|
import org.apache.archiva.checksum.ChecksumAlgorithm;
|
||||||
import org.apache.archiva.checksum.ChecksummedFile;
|
import org.apache.archiva.common.utils.VersionUtil;
|
||||||
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
import org.apache.archiva.rest.api.model.Artifact;
|
||||||
import org.apache.archiva.metadata.repository.MetadataRepository;
|
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
|
||||||
import org.apache.archiva.metadata.repository.MetadataRepositoryException;
|
import org.apache.archiva.rest.api.services.RepositoriesService;
|
||||||
import org.apache.archiva.metadata.repository.MetadataResolutionException;
|
|
||||||
import org.apache.archiva.metadata.repository.RepositorySession;
|
|
||||||
import org.apache.archiva.model.ArtifactReference;
|
|
||||||
import org.apache.archiva.repository.events.RepositoryListener;
|
|
||||||
import org.apache.archiva.security.AccessDeniedException;
|
import org.apache.archiva.security.AccessDeniedException;
|
||||||
import org.apache.archiva.security.ArchivaSecurityException;
|
import org.apache.archiva.security.ArchivaSecurityException;
|
||||||
import org.apache.archiva.security.PrincipalNotFoundException;
|
import org.apache.archiva.security.PrincipalNotFoundException;
|
||||||
import org.apache.archiva.security.UserRepositories;
|
import org.apache.archiva.security.UserRepositories;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.archiva.common.utils.VersionComparator;
|
import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal;
|
||||||
import org.apache.archiva.common.utils.VersionUtil;
|
|
||||||
import org.apache.archiva.model.ArchivaRepositoryMetadata;
|
|
||||||
import org.apache.archiva.model.VersionedReference;
|
|
||||||
import org.apache.archiva.repository.ContentNotFoundException;
|
|
||||||
import org.apache.archiva.repository.ManagedRepositoryContent;
|
|
||||||
import org.apache.archiva.repository.RepositoryContentFactory;
|
|
||||||
import org.apache.archiva.repository.RepositoryException;
|
|
||||||
import org.apache.archiva.repository.RepositoryNotFoundException;
|
|
||||||
import org.apache.archiva.repository.metadata.MetadataTools;
|
|
||||||
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
|
|
||||||
import org.apache.archiva.repository.metadata.RepositoryMetadataReader;
|
|
||||||
import org.apache.archiva.repository.metadata.RepositoryMetadataWriter;
|
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.io.File;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an artifact. Metadata will be updated if one exists, otherwise it would be created.
|
* Delete an artifact. Metadata will be updated if one exists, otherwise it would be created.
|
||||||
|
@ -118,15 +91,12 @@ public class DeleteArtifactAction
|
||||||
@Inject
|
@Inject
|
||||||
private UserRepositories userRepositories;
|
private UserRepositories userRepositories;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private RepositoryContentFactory repositoryFactory;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private List<RepositoryListener> listeners;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ManagedRepositoryAdmin managedRepositoryAdmin;
|
private ManagedRepositoryAdmin managedRepositoryAdmin;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private RepositoriesService repositoriesService;
|
||||||
|
|
||||||
private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 };
|
private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 };
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
|
@ -229,128 +199,27 @@ public class DeleteArtifactAction
|
||||||
|
|
||||||
public String doDelete()
|
public String doDelete()
|
||||||
{
|
{
|
||||||
|
// services need a ThreadLocal variable to test karma
|
||||||
RepositorySession repositorySession = repositorySessionFactory.createSession();
|
RedbackAuthenticationThreadLocal.set( getRedbackRequestInformation() );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Date lastUpdatedTimestamp = Calendar.getInstance().getTime();
|
Artifact artifact = new Artifact();
|
||||||
|
artifact.setGroupId( groupId );
|
||||||
|
artifact.setArtifactId( artifactId );
|
||||||
|
artifact.setVersion( version );
|
||||||
|
artifact.setClassifier( classifier );
|
||||||
|
artifact.setPackaging( type );
|
||||||
|
|
||||||
TimeZone timezone = TimeZone.getTimeZone( "UTC" );
|
repositoriesService.deleteArtifact( artifact, repositoryId );
|
||||||
DateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
|
|
||||||
fmt.setTimeZone( timezone );
|
|
||||||
ManagedRepository repoConfig = getManagedRepositoryAdmin().getManagedRepository( repositoryId );
|
|
||||||
|
|
||||||
VersionedReference ref = new VersionedReference();
|
|
||||||
ref.setArtifactId( artifactId );
|
|
||||||
ref.setGroupId( groupId );
|
|
||||||
ref.setVersion( version );
|
|
||||||
|
|
||||||
ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
|
|
||||||
|
|
||||||
if ( StringUtils.isNotBlank( classifier ) )
|
|
||||||
{
|
|
||||||
if (StringUtils.isBlank( type ))
|
|
||||||
{
|
|
||||||
addFieldError( "type", "You must configure a type when using classifier" );
|
|
||||||
return INPUT;
|
|
||||||
}
|
}
|
||||||
ArtifactReference artifactReference = new ArtifactReference();
|
catch ( ArchivaRestServiceException e )
|
||||||
artifactReference.setArtifactId( artifactId );
|
|
||||||
artifactReference.setGroupId( groupId );
|
|
||||||
artifactReference.setVersion( version );
|
|
||||||
artifactReference.setClassifier( classifier );
|
|
||||||
artifactReference.setType( type );
|
|
||||||
repository.deleteArtifact( artifactReference );
|
|
||||||
|
|
||||||
String msg = "Artifact \'" + groupId + ":" + artifactId + ":" + classifier + ":" + version
|
|
||||||
+ "\' was successfully deleted from repository \'" + repositoryId + "\'";
|
|
||||||
|
|
||||||
addActionMessage( msg );
|
|
||||||
|
|
||||||
reset();
|
|
||||||
// TODO cleanup facet which contains classifier information
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
String path = repository.toMetadataPath( ref );
|
|
||||||
int index = path.lastIndexOf( '/' );
|
|
||||||
path = path.substring( 0, index );
|
|
||||||
File targetPath = new File( repoConfig.getLocation(), path );
|
|
||||||
|
|
||||||
if ( !targetPath.exists() )
|
|
||||||
{
|
{
|
||||||
throw new ContentNotFoundException( groupId + ":" + artifactId + ":" + version );
|
addActionError( "ArchivaRestServiceException exception: " + e.getMessage() );
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: this should be in the storage mechanism so that it is all tied together
|
|
||||||
// delete from file system
|
|
||||||
repository.deleteVersion( ref );
|
|
||||||
|
|
||||||
File metadataFile = getMetadata( targetPath.getAbsolutePath() );
|
|
||||||
ArchivaRepositoryMetadata metadata = getMetadata( metadataFile );
|
|
||||||
|
|
||||||
updateMetadata( metadata, metadataFile, lastUpdatedTimestamp );
|
|
||||||
|
|
||||||
MetadataRepository metadataRepository = repositorySession.getRepository();
|
|
||||||
|
|
||||||
Collection<ArtifactMetadata> artifacts =
|
|
||||||
metadataRepository.getArtifacts( repositoryId, groupId, artifactId, version );
|
|
||||||
|
|
||||||
for ( ArtifactMetadata artifact : artifacts )
|
|
||||||
{
|
|
||||||
// TODO: mismatch between artifact (snapshot) version and project (base) version here
|
|
||||||
if ( artifact.getVersion().equals( version ) )
|
|
||||||
{
|
|
||||||
metadataRepository.removeArtifact( artifact.getRepositoryId(), artifact.getNamespace(),
|
|
||||||
artifact.getProject(), artifact.getVersion(), artifact.getId() );
|
|
||||||
|
|
||||||
// TODO: move into the metadata repository proper - need to differentiate attachment of
|
|
||||||
// repository metadata to an artifact
|
|
||||||
for ( RepositoryListener listener : listeners )
|
|
||||||
{
|
|
||||||
listener.deleteArtifact( metadataRepository, repository.getId(), artifact.getNamespace(),
|
|
||||||
artifact.getProject(), artifact.getVersion(), artifact.getId() );
|
|
||||||
}
|
|
||||||
|
|
||||||
triggerAuditEvent( repositoryId, path, AuditEvent.REMOVE_FILE );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
repositorySession.save();
|
|
||||||
}
|
|
||||||
catch ( ContentNotFoundException e )
|
|
||||||
{
|
|
||||||
addActionError( "Artifact does not exist: " + e.getMessage() );
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
catch ( RepositoryNotFoundException e )
|
|
||||||
{
|
|
||||||
addActionError( "Target repository cannot be found: " + e.getMessage() );
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
catch ( RepositoryException e )
|
|
||||||
{
|
|
||||||
addActionError( "Repository exception: " + e.getMessage() );
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
catch ( MetadataResolutionException e )
|
|
||||||
{
|
|
||||||
addActionError( "Repository exception: " + e.getMessage() );
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
catch ( MetadataRepositoryException e )
|
|
||||||
{
|
|
||||||
addActionError( "Repository exception: " + e.getMessage() );
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
catch ( RepositoryAdminException e )
|
|
||||||
{
|
|
||||||
addActionError( "RepositoryAdmin exception: " + e.getMessage() );
|
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
repositorySession.close();
|
RedbackAuthenticationThreadLocal.set( null );
|
||||||
}
|
}
|
||||||
|
|
||||||
String msg = "Artifact \'" + groupId + ":" + artifactId + ":" + version
|
String msg = "Artifact \'" + groupId + ":" + artifactId + ":" + version
|
||||||
|
@ -362,83 +231,6 @@ public class DeleteArtifactAction
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getMetadata( String targetPath )
|
|
||||||
{
|
|
||||||
String artifactPath = targetPath.substring( 0, targetPath.lastIndexOf( File.separatorChar ) );
|
|
||||||
|
|
||||||
return new File( artifactPath, MetadataTools.MAVEN_METADATA );
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArchivaRepositoryMetadata getMetadata( File metadataFile )
|
|
||||||
throws RepositoryMetadataException
|
|
||||||
{
|
|
||||||
ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
|
|
||||||
if ( metadataFile.exists() )
|
|
||||||
{
|
|
||||||
metadata = RepositoryMetadataReader.read( metadataFile );
|
|
||||||
}
|
|
||||||
return metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update artifact level metadata. Creates one if metadata does not exist after artifact deletion.
|
|
||||||
*
|
|
||||||
* @param metadata
|
|
||||||
*/
|
|
||||||
private void updateMetadata( ArchivaRepositoryMetadata metadata, File metadataFile, Date lastUpdatedTimestamp )
|
|
||||||
throws RepositoryMetadataException
|
|
||||||
{
|
|
||||||
List<String> availableVersions = new ArrayList<String>();
|
|
||||||
String latestVersion = "";
|
|
||||||
|
|
||||||
if ( metadataFile.exists() )
|
|
||||||
{
|
|
||||||
if ( metadata.getAvailableVersions() != null )
|
|
||||||
{
|
|
||||||
availableVersions = metadata.getAvailableVersions();
|
|
||||||
|
|
||||||
if ( availableVersions.size() > 0 )
|
|
||||||
{
|
|
||||||
Collections.sort( availableVersions, VersionComparator.getInstance() );
|
|
||||||
|
|
||||||
if ( availableVersions.contains( version ) )
|
|
||||||
{
|
|
||||||
availableVersions.remove( availableVersions.indexOf( version ) );
|
|
||||||
}
|
|
||||||
if ( availableVersions.size() > 0 )
|
|
||||||
{
|
|
||||||
latestVersion = availableVersions.get( availableVersions.size() - 1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( metadata.getGroupId() == null )
|
|
||||||
{
|
|
||||||
metadata.setGroupId( groupId );
|
|
||||||
}
|
|
||||||
if ( metadata.getArtifactId() == null )
|
|
||||||
{
|
|
||||||
metadata.setArtifactId( artifactId );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !VersionUtil.isSnapshot( version ) )
|
|
||||||
{
|
|
||||||
if ( metadata.getReleasedVersion() != null && metadata.getReleasedVersion().equals( version ) )
|
|
||||||
{
|
|
||||||
metadata.setReleasedVersion( latestVersion );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
metadata.setLatestVersion( latestVersion );
|
|
||||||
metadata.setLastUpdatedTimestamp( lastUpdatedTimestamp );
|
|
||||||
metadata.setAvailableVersions( availableVersions );
|
|
||||||
|
|
||||||
RepositoryMetadataWriter.write( metadata, metadataFile );
|
|
||||||
ChecksummedFile checksum = new ChecksummedFile( metadataFile );
|
|
||||||
checksum.fixChecksums( algorithms );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validate()
|
public void validate()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -511,16 +303,6 @@ public class DeleteArtifactAction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RepositoryListener> getListeners()
|
|
||||||
{
|
|
||||||
return listeners;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRepositoryFactory( RepositoryContentFactory repositoryFactory )
|
|
||||||
{
|
|
||||||
this.repositoryFactory = repositoryFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ManagedRepositoryAdmin getManagedRepositoryAdmin()
|
public ManagedRepositoryAdmin getManagedRepositoryAdmin()
|
||||||
{
|
{
|
||||||
return managedRepositoryAdmin;
|
return managedRepositoryAdmin;
|
||||||
|
@ -530,4 +312,14 @@ public class DeleteArtifactAction
|
||||||
{
|
{
|
||||||
this.managedRepositoryAdmin = managedRepositoryAdmin;
|
this.managedRepositoryAdmin = managedRepositoryAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RepositoriesService getRepositoriesService()
|
||||||
|
{
|
||||||
|
return repositoriesService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepositoriesService( RepositoriesService repositoriesService )
|
||||||
|
{
|
||||||
|
this.repositoriesService = repositoriesService;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,25 +22,32 @@ package org.apache.archiva.web.action;
|
||||||
import net.sf.beanlib.provider.replicator.BeanReplicator;
|
import net.sf.beanlib.provider.replicator.BeanReplicator;
|
||||||
import org.apache.archiva.admin.model.beans.ManagedRepository;
|
import org.apache.archiva.admin.model.beans.ManagedRepository;
|
||||||
import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
|
import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
|
||||||
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
|
||||||
import org.apache.archiva.metadata.repository.MetadataRepository;
|
|
||||||
import org.apache.archiva.metadata.repository.RepositorySession;
|
|
||||||
import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.archiva.configuration.ArchivaConfiguration;
|
import org.apache.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.archiva.configuration.Configuration;
|
import org.apache.archiva.configuration.Configuration;
|
||||||
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
|
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
|
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
||||||
|
import org.apache.archiva.metadata.repository.MetadataRepository;
|
||||||
|
import org.apache.archiva.metadata.repository.RepositorySession;
|
||||||
import org.apache.archiva.repository.ManagedRepositoryContent;
|
import org.apache.archiva.repository.ManagedRepositoryContent;
|
||||||
import org.apache.archiva.repository.RepositoryContentFactory;
|
import org.apache.archiva.repository.RepositoryContentFactory;
|
||||||
import org.apache.archiva.repository.content.ManagedDefaultRepositoryContent;
|
import org.apache.archiva.repository.content.ManagedDefaultRepositoryContent;
|
||||||
|
import org.apache.archiva.rest.services.DefaultRepositoriesService;
|
||||||
|
import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.struts2.StrutsSpringTestCase;
|
import org.apache.struts2.StrutsSpringTestCase;
|
||||||
|
import org.codehaus.plexus.redback.users.User;
|
||||||
|
import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal;
|
||||||
|
import org.codehaus.redback.rest.services.RedbackRequestInformation;
|
||||||
import org.easymock.MockControl;
|
import org.easymock.MockControl;
|
||||||
import org.easymock.classextension.MockClassControl;
|
import org.easymock.classextension.MockClassControl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class DeleteArtifactActionTest
|
public class DeleteArtifactActionTest
|
||||||
|
@ -82,8 +89,8 @@ public class DeleteArtifactActionTest
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
//action = (DeleteArtifactAction) lookup( Action.class.getName(), "deleteArtifactAction" );
|
|
||||||
action = (DeleteArtifactAction) getActionProxy( "/deleteArtifact.action" ).getAction();
|
action = (DeleteArtifactAction) getActionProxy( "/deleteArtifact.action" ).getAction();
|
||||||
|
action.setPrincipal( "admin" );
|
||||||
assertNotNull( action );
|
assertNotNull( action );
|
||||||
|
|
||||||
configurationControl = MockControl.createControl( ArchivaConfiguration.class );
|
configurationControl = MockControl.createControl( ArchivaConfiguration.class );
|
||||||
|
@ -103,8 +110,9 @@ public class DeleteArtifactActionTest
|
||||||
|
|
||||||
repositorySessionFactory.setRepositorySession( repositorySession );
|
repositorySessionFactory.setRepositorySession( repositorySession );
|
||||||
|
|
||||||
(( DefaultManagedRepositoryAdmin)action.getManagedRepositoryAdmin()).setArchivaConfiguration( configuration );
|
( (DefaultManagedRepositoryAdmin) ( (DefaultRepositoriesService) action.getRepositoriesService() ).getManagedRepositoryAdmin() ).setArchivaConfiguration(
|
||||||
action.setRepositoryFactory( repositoryFactory );
|
configuration );
|
||||||
|
( (DefaultRepositoriesService) action.getRepositoriesService() ).setRepositoryFactory( repositoryFactory );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -116,12 +124,6 @@ public class DeleteArtifactActionTest
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetListeners()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
assertNotNull( action.getListeners() );
|
|
||||||
assertFalse( action.getListeners().isEmpty() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNPEInDeleteArtifact()
|
public void testNPEInDeleteArtifact()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -151,8 +153,10 @@ public class DeleteArtifactActionTest
|
||||||
|
|
||||||
action.doDelete();
|
action.doDelete();
|
||||||
|
|
||||||
String artifactPath = REPO_LOCATION + "/" + StringUtils.replace( GROUP_ID, ".", "/" ) + "/"
|
String artifactPath =
|
||||||
+ StringUtils.replace( ARTIFACT_ID, ".", "/" ) + "/" + VERSION + "/" + ARTIFACT_ID + "-" + VERSION;
|
REPO_LOCATION + "/" + StringUtils.replace( GROUP_ID, ".", "/" ) + "/" + StringUtils.replace( ARTIFACT_ID,
|
||||||
|
".", "/" )
|
||||||
|
+ "/" + VERSION + "/" + ARTIFACT_ID + "-" + VERSION;
|
||||||
|
|
||||||
assertFalse( new File( artifactPath + ".jar" ).exists() );
|
assertFalse( new File( artifactPath + ".jar" ).exists() );
|
||||||
assertFalse( new File( artifactPath + ".jar.sha1" ).exists() );
|
assertFalse( new File( artifactPath + ".jar.sha1" ).exists() );
|
||||||
|
|
Loading…
Reference in New Issue