[MRM-1542] missing classifier field in the delete artifact web page

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1188328 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-10-24 19:36:20 +00:00
parent 013ee7f312
commit 97c85abe24
6 changed files with 128 additions and 34 deletions

View File

@ -47,6 +47,14 @@ public interface ManagedRepositoryContent
void deleteVersion( VersionedReference reference )
throws ContentNotFoundException;
/**
* delete a specified artifact from the repository
* @param artifactReference
* @throws ContentNotFoundException
*/
void deleteArtifact( ArtifactReference artifactReference )
throws ContentNotFoundException;
/**
* <p>
* Convenience method to get the repository id.

View File

@ -20,10 +20,9 @@
*/
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
import org.apache.commons.io.FileUtils;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
import org.apache.archiva.model.ArchivaArtifact;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.ProjectReference;
@ -31,6 +30,7 @@
import org.apache.archiva.repository.ContentNotFoundException;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.commons.io.FileUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
@ -43,18 +43,18 @@
import java.util.Set;
/**
* ManagedDefaultRepositoryContent
* ManagedDefaultRepositoryContent
*
* @version $Id$
*/
@Service("managedRepositoryContent#default")
@Scope("prototype")
@Service( "managedRepositoryContent#default" )
@Scope( "prototype" )
public class ManagedDefaultRepositoryContent
extends AbstractDefaultRepositoryContent
implements ManagedRepositoryContent
{
@Inject
@Named(value = "fileTypes" )
@Named( value = "fileTypes" )
private FileTypes filetypes;
private ManagedRepository repository;
@ -70,9 +70,9 @@ public void deleteVersion( VersionedReference reference )
{
String path = toMetadataPath( reference );
File projectPath = new File( getRepoRoot(), path );
File projectDir = projectPath.getParentFile();
if( projectDir.exists() && projectDir.isDirectory() )
if ( projectDir.exists() && projectDir.isDirectory() )
{
FileUtils.deleteQuietly( projectDir );
}
@ -82,6 +82,22 @@ public void deleteVersion( VersionedReference reference )
}
}
public void deleteArtifact( ArtifactReference artifactReference )
throws ContentNotFoundException
{
String path = toPath( artifactReference );
File filePath = new File( getRepoRoot(), path );
if ( filePath.exists() )
{
FileUtils.deleteQuietly( filePath );
}
else
{
throw new ContentNotFoundException( "Unable to delete non-existing project artifact: " + filePath );
}
}
public String getId()
{
return repository.getId();
@ -95,14 +111,14 @@ public Set<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
if ( !repoDir.exists() )
{
throw new ContentNotFoundException( "Unable to get related artifacts using a non-existant directory: "
+ repoDir.getAbsolutePath() );
throw new ContentNotFoundException(
"Unable to get related artifacts using a non-existant directory: " + repoDir.getAbsolutePath() );
}
if ( !repoDir.isDirectory() )
{
throw new ContentNotFoundException( "Unable to get related artifacts using a non-directory: "
+ repoDir.getAbsolutePath() );
throw new ContentNotFoundException(
"Unable to get related artifacts using a non-directory: " + repoDir.getAbsolutePath() );
}
Set<ArtifactReference> foundArtifacts = new HashSet<ArtifactReference>();
@ -124,11 +140,10 @@ public Set<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
try
{
ArtifactReference artifact = toArtifactReference( relativePath );
// Test for related, groupId / artifactId / version must match.
if ( artifact.getGroupId().equals( reference.getGroupId() )
&& artifact.getArtifactId().equals( reference.getArtifactId() )
&& artifact.getVersion().equals( reference.getVersion() ) )
if ( artifact.getGroupId().equals( reference.getGroupId() ) && artifact.getArtifactId().equals(
reference.getArtifactId() ) && artifact.getVersion().equals( reference.getVersion() ) )
{
foundArtifacts.add( artifact );
}
@ -158,7 +173,7 @@ public ManagedRepository getRepository()
* information.
*
* @return the Set of available versions, based on the project reference.
* @throws LayoutException
* @throws LayoutException
* @throws LayoutException
*/
public Set<String> getVersions( ProjectReference reference )
@ -176,14 +191,14 @@ public Set<String> getVersions( ProjectReference reference )
if ( !repoDir.exists() )
{
throw new ContentNotFoundException( "Unable to get Versions on a non-existant directory: "
+ repoDir.getAbsolutePath() );
throw new ContentNotFoundException(
"Unable to get Versions on a non-existant directory: " + repoDir.getAbsolutePath() );
}
if ( !repoDir.isDirectory() )
{
throw new ContentNotFoundException( "Unable to get Versions on a non-directory: "
+ repoDir.getAbsolutePath() );
throw new ContentNotFoundException(
"Unable to get Versions on a non-directory: " + repoDir.getAbsolutePath() );
}
Set<String> foundVersions = new HashSet<String>();
@ -229,14 +244,14 @@ public Set<String> getVersions( VersionedReference reference )
if ( !repoDir.exists() )
{
throw new ContentNotFoundException( "Unable to get versions on a non-existant directory: "
+ repoDir.getAbsolutePath() );
throw new ContentNotFoundException(
"Unable to get versions on a non-existant directory: " + repoDir.getAbsolutePath() );
}
if ( !repoDir.isDirectory() )
{
throw new ContentNotFoundException( "Unable to get versions on a non-directory: "
+ repoDir.getAbsolutePath() );
throw new ContentNotFoundException(
"Unable to get versions on a non-directory: " + repoDir.getAbsolutePath() );
}
Set<String> foundVersions = new HashSet<String>();
@ -264,7 +279,7 @@ public Set<String> getVersions( VersionedReference reference )
try
{
ArtifactReference artifact = toArtifactReference( relativePath );
foundVersions.add( artifact.getVersion() );
}
catch ( LayoutException e )
@ -323,7 +338,7 @@ public void setRepository( ManagedRepository repository )
/**
* Convert a path to an artifact reference.
*
*
* @param path the path to convert. (relative or full location path)
* @throws LayoutException if the path cannot be converted to an artifact reference.
*/
@ -343,7 +358,7 @@ public File toFile( ArtifactReference reference )
{
return new File( repository.getLocation(), toPath( reference ) );
}
public File toFile( ArchivaArtifact reference )
{
return new File( repository.getLocation(), toPath( reference ) );
@ -352,7 +367,7 @@ public File toFile( ArchivaArtifact reference )
/**
* Get the first Artifact found in the provided VersionedReference location.
*
* @param reference the reference to the versioned reference to search within
* @param reference the reference to the versioned reference to search within
* @return the ArtifactReference to the first artifact located within the versioned reference. or null if
* no artifact was found within the versioned reference.
* @throws IOException if the versioned reference is invalid (example: doesn't exist, or isn't a directory)
@ -374,13 +389,13 @@ private ArtifactReference getFirstArtifact( VersionedReference reference )
if ( !repoDir.exists() )
{
throw new IOException( "Unable to gather the list of snapshot versions on a non-existant directory: "
+ repoDir.getAbsolutePath() );
+ repoDir.getAbsolutePath() );
}
if ( !repoDir.isDirectory() )
{
throw new IOException( "Unable to gather the list of snapshot versions on a non-directory: "
+ repoDir.getAbsolutePath() );
throw new IOException(
"Unable to gather the list of snapshot versions on a non-directory: " + repoDir.getAbsolutePath() );
}
File repoFiles[] = repoDir.listFiles();

View File

@ -459,4 +459,10 @@ public void setFileTypes( FileTypes fileTypes )
{
this.filetypes = fileTypes;
}
public void deleteArtifact( ArtifactReference artifactReference )
throws ContentNotFoundException
{
// TODO implements for legacy ??
}
}

View File

@ -33,6 +33,7 @@
import org.apache.archiva.metadata.repository.MetadataRepositoryException;
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.ArchivaSecurityException;
@ -92,6 +93,18 @@ public class DeleteArtifactAction
*/
private String version;
/**
* @since 1.4-M2
* The classifier of the artifact to be deleted (optionnal)
*/
private String classifier;
/**
* @since 1.4-M2
* The type of the artifact to be deleted (optionnal) (default jar)
*/
private String type;
/**
* The repository where the artifact is to be deleted.
*/
@ -177,6 +190,26 @@ public void prepare()
managedRepos = getManagableRepos();
}
public String getClassifier()
{
return classifier;
}
public void setClassifier( String classifier )
{
this.classifier = classifier;
}
public String getType()
{
return type;
}
public void setType( String type )
{
this.type = type;
}
public String input()
{
return INPUT;
@ -190,6 +223,8 @@ private void reset()
artifactId = "";
version = "";
repositoryId = "";
classifier = "";
type = "";
}
public String doDelete()
@ -209,8 +244,35 @@ public String doDelete()
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();
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();
// as metadatarepository doesn't contains any informations regarding classifier we are free to return
// TODO when metadatarepository will contains such informations we will have to cleanup that !!
return SUCCESS;
}
String path = repository.toMetadataPath( ref );
int index = path.lastIndexOf( '/' );
path = path.substring( 0, index );
@ -231,6 +293,7 @@ public String doDelete()
updateMetadata( metadata, metadataFile, lastUpdatedTimestamp );
MetadataRepository metadataRepository = repositorySession.getRepository();
Collection<ArtifactMetadata> artifacts =
metadataRepository.getArtifacts( repositoryId, groupId, artifactId, version );

View File

@ -24,5 +24,7 @@
<s:textfield name="groupId" label="Group Id" size="50" required="true"/>
<s:textfield name="artifactId" label="Artifact Id" size="50" required="true"/>
<s:textfield name="version" label="Version" size="50" required="true"/>
<s:textfield name="classifier" label="Classifier" size="60" required="false"/>
<s:textfield name="type" label="Type (manadatory when using classifier)" size="60" required="false" />
<s:select name="repositoryId" list="managedRepos" label="Repository Id"/>

View File

@ -28,10 +28,10 @@
* Listen to events on the repository. This class is a stopgap
* refactoring measure until an event bus is in place to handle
* generic events such as these.
*
* <p/>
* This assumes that the events occur before the action has completed, though they don't currently offer any mechanism
* to prevent an event from occurring or guarantee that it will happen.
*
* <p/>
* FIXME: this needs to be made more permanent since 3rd party plugins will depend on it heavily
*/
public interface RepositoryListener