mirror of
https://github.com/apache/archiva.git
synced 2025-02-21 17:35:19 +00:00
[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:
parent
013ee7f312
commit
97c85abe24
@ -47,6 +47,14 @@ public interface ManagedRepositoryContent
|
|||||||
void deleteVersion( VersionedReference reference )
|
void deleteVersion( VersionedReference reference )
|
||||||
throws ContentNotFoundException;
|
throws ContentNotFoundException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete a specified artifact from the repository
|
||||||
|
* @param artifactReference
|
||||||
|
* @throws ContentNotFoundException
|
||||||
|
*/
|
||||||
|
void deleteArtifact( ArtifactReference artifactReference )
|
||||||
|
throws ContentNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Convenience method to get the repository id.
|
* Convenience method to get the repository id.
|
||||||
|
@ -20,10 +20,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.archiva.admin.model.beans.ManagedRepository;
|
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.common.utils.PathUtil;
|
||||||
import org.apache.archiva.configuration.FileTypes;
|
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.ArchivaArtifact;
|
||||||
import org.apache.archiva.model.ArtifactReference;
|
import org.apache.archiva.model.ArtifactReference;
|
||||||
import org.apache.archiva.model.ProjectReference;
|
import org.apache.archiva.model.ProjectReference;
|
||||||
@ -31,6 +30,7 @@
|
|||||||
import org.apache.archiva.repository.ContentNotFoundException;
|
import org.apache.archiva.repository.ContentNotFoundException;
|
||||||
import org.apache.archiva.repository.ManagedRepositoryContent;
|
import org.apache.archiva.repository.ManagedRepositoryContent;
|
||||||
import org.apache.archiva.repository.layout.LayoutException;
|
import org.apache.archiva.repository.layout.LayoutException;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -43,18 +43,18 @@
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManagedDefaultRepositoryContent
|
* ManagedDefaultRepositoryContent
|
||||||
*
|
*
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
@Service("managedRepositoryContent#default")
|
@Service( "managedRepositoryContent#default" )
|
||||||
@Scope("prototype")
|
@Scope( "prototype" )
|
||||||
public class ManagedDefaultRepositoryContent
|
public class ManagedDefaultRepositoryContent
|
||||||
extends AbstractDefaultRepositoryContent
|
extends AbstractDefaultRepositoryContent
|
||||||
implements ManagedRepositoryContent
|
implements ManagedRepositoryContent
|
||||||
{
|
{
|
||||||
@Inject
|
@Inject
|
||||||
@Named(value = "fileTypes" )
|
@Named( value = "fileTypes" )
|
||||||
private FileTypes filetypes;
|
private FileTypes filetypes;
|
||||||
|
|
||||||
private ManagedRepository repository;
|
private ManagedRepository repository;
|
||||||
@ -70,9 +70,9 @@ public void deleteVersion( VersionedReference reference )
|
|||||||
{
|
{
|
||||||
String path = toMetadataPath( reference );
|
String path = toMetadataPath( reference );
|
||||||
File projectPath = new File( getRepoRoot(), path );
|
File projectPath = new File( getRepoRoot(), path );
|
||||||
|
|
||||||
File projectDir = projectPath.getParentFile();
|
File projectDir = projectPath.getParentFile();
|
||||||
if( projectDir.exists() && projectDir.isDirectory() )
|
if ( projectDir.exists() && projectDir.isDirectory() )
|
||||||
{
|
{
|
||||||
FileUtils.deleteQuietly( projectDir );
|
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()
|
public String getId()
|
||||||
{
|
{
|
||||||
return repository.getId();
|
return repository.getId();
|
||||||
@ -95,14 +111,14 @@ public Set<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
|
|||||||
|
|
||||||
if ( !repoDir.exists() )
|
if ( !repoDir.exists() )
|
||||||
{
|
{
|
||||||
throw new ContentNotFoundException( "Unable to get related artifacts using a non-existant directory: "
|
throw new ContentNotFoundException(
|
||||||
+ repoDir.getAbsolutePath() );
|
"Unable to get related artifacts using a non-existant directory: " + repoDir.getAbsolutePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !repoDir.isDirectory() )
|
if ( !repoDir.isDirectory() )
|
||||||
{
|
{
|
||||||
throw new ContentNotFoundException( "Unable to get related artifacts using a non-directory: "
|
throw new ContentNotFoundException(
|
||||||
+ repoDir.getAbsolutePath() );
|
"Unable to get related artifacts using a non-directory: " + repoDir.getAbsolutePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<ArtifactReference> foundArtifacts = new HashSet<ArtifactReference>();
|
Set<ArtifactReference> foundArtifacts = new HashSet<ArtifactReference>();
|
||||||
@ -124,11 +140,10 @@ public Set<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
ArtifactReference artifact = toArtifactReference( relativePath );
|
ArtifactReference artifact = toArtifactReference( relativePath );
|
||||||
|
|
||||||
// Test for related, groupId / artifactId / version must match.
|
// Test for related, groupId / artifactId / version must match.
|
||||||
if ( artifact.getGroupId().equals( reference.getGroupId() )
|
if ( artifact.getGroupId().equals( reference.getGroupId() ) && artifact.getArtifactId().equals(
|
||||||
&& artifact.getArtifactId().equals( reference.getArtifactId() )
|
reference.getArtifactId() ) && artifact.getVersion().equals( reference.getVersion() ) )
|
||||||
&& artifact.getVersion().equals( reference.getVersion() ) )
|
|
||||||
{
|
{
|
||||||
foundArtifacts.add( artifact );
|
foundArtifacts.add( artifact );
|
||||||
}
|
}
|
||||||
@ -158,7 +173,7 @@ public ManagedRepository getRepository()
|
|||||||
* information.
|
* information.
|
||||||
*
|
*
|
||||||
* @return the Set of available versions, based on the project reference.
|
* @return the Set of available versions, based on the project reference.
|
||||||
* @throws LayoutException
|
* @throws LayoutException
|
||||||
* @throws LayoutException
|
* @throws LayoutException
|
||||||
*/
|
*/
|
||||||
public Set<String> getVersions( ProjectReference reference )
|
public Set<String> getVersions( ProjectReference reference )
|
||||||
@ -176,14 +191,14 @@ public Set<String> getVersions( ProjectReference reference )
|
|||||||
|
|
||||||
if ( !repoDir.exists() )
|
if ( !repoDir.exists() )
|
||||||
{
|
{
|
||||||
throw new ContentNotFoundException( "Unable to get Versions on a non-existant directory: "
|
throw new ContentNotFoundException(
|
||||||
+ repoDir.getAbsolutePath() );
|
"Unable to get Versions on a non-existant directory: " + repoDir.getAbsolutePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !repoDir.isDirectory() )
|
if ( !repoDir.isDirectory() )
|
||||||
{
|
{
|
||||||
throw new ContentNotFoundException( "Unable to get Versions on a non-directory: "
|
throw new ContentNotFoundException(
|
||||||
+ repoDir.getAbsolutePath() );
|
"Unable to get Versions on a non-directory: " + repoDir.getAbsolutePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> foundVersions = new HashSet<String>();
|
Set<String> foundVersions = new HashSet<String>();
|
||||||
@ -229,14 +244,14 @@ public Set<String> getVersions( VersionedReference reference )
|
|||||||
|
|
||||||
if ( !repoDir.exists() )
|
if ( !repoDir.exists() )
|
||||||
{
|
{
|
||||||
throw new ContentNotFoundException( "Unable to get versions on a non-existant directory: "
|
throw new ContentNotFoundException(
|
||||||
+ repoDir.getAbsolutePath() );
|
"Unable to get versions on a non-existant directory: " + repoDir.getAbsolutePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !repoDir.isDirectory() )
|
if ( !repoDir.isDirectory() )
|
||||||
{
|
{
|
||||||
throw new ContentNotFoundException( "Unable to get versions on a non-directory: "
|
throw new ContentNotFoundException(
|
||||||
+ repoDir.getAbsolutePath() );
|
"Unable to get versions on a non-directory: " + repoDir.getAbsolutePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> foundVersions = new HashSet<String>();
|
Set<String> foundVersions = new HashSet<String>();
|
||||||
@ -264,7 +279,7 @@ public Set<String> getVersions( VersionedReference reference )
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
ArtifactReference artifact = toArtifactReference( relativePath );
|
ArtifactReference artifact = toArtifactReference( relativePath );
|
||||||
|
|
||||||
foundVersions.add( artifact.getVersion() );
|
foundVersions.add( artifact.getVersion() );
|
||||||
}
|
}
|
||||||
catch ( LayoutException e )
|
catch ( LayoutException e )
|
||||||
@ -323,7 +338,7 @@ public void setRepository( ManagedRepository repository )
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a path to an artifact reference.
|
* Convert a path to an artifact reference.
|
||||||
*
|
*
|
||||||
* @param path the path to convert. (relative or full location path)
|
* @param path the path to convert. (relative or full location path)
|
||||||
* @throws LayoutException if the path cannot be converted to an artifact reference.
|
* @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 ) );
|
return new File( repository.getLocation(), toPath( reference ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public File toFile( ArchivaArtifact reference )
|
public File toFile( ArchivaArtifact reference )
|
||||||
{
|
{
|
||||||
return new File( repository.getLocation(), toPath( 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.
|
* 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
|
* @return the ArtifactReference to the first artifact located within the versioned reference. or null if
|
||||||
* no artifact was found within the versioned reference.
|
* 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)
|
* @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() )
|
if ( !repoDir.exists() )
|
||||||
{
|
{
|
||||||
throw new IOException( "Unable to gather the list of snapshot versions on a non-existant directory: "
|
throw new IOException( "Unable to gather the list of snapshot versions on a non-existant directory: "
|
||||||
+ repoDir.getAbsolutePath() );
|
+ repoDir.getAbsolutePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !repoDir.isDirectory() )
|
if ( !repoDir.isDirectory() )
|
||||||
{
|
{
|
||||||
throw new IOException( "Unable to gather the list of snapshot versions on a non-directory: "
|
throw new IOException(
|
||||||
+ repoDir.getAbsolutePath() );
|
"Unable to gather the list of snapshot versions on a non-directory: " + repoDir.getAbsolutePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
File repoFiles[] = repoDir.listFiles();
|
File repoFiles[] = repoDir.listFiles();
|
||||||
|
@ -459,4 +459,10 @@ public void setFileTypes( FileTypes fileTypes )
|
|||||||
{
|
{
|
||||||
this.filetypes = fileTypes;
|
this.filetypes = fileTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteArtifact( ArtifactReference artifactReference )
|
||||||
|
throws ContentNotFoundException
|
||||||
|
{
|
||||||
|
// TODO implements for legacy ??
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
import org.apache.archiva.metadata.repository.MetadataRepositoryException;
|
import org.apache.archiva.metadata.repository.MetadataRepositoryException;
|
||||||
import org.apache.archiva.metadata.repository.MetadataResolutionException;
|
import org.apache.archiva.metadata.repository.MetadataResolutionException;
|
||||||
import org.apache.archiva.metadata.repository.RepositorySession;
|
import org.apache.archiva.metadata.repository.RepositorySession;
|
||||||
|
import org.apache.archiva.model.ArtifactReference;
|
||||||
import org.apache.archiva.repository.events.RepositoryListener;
|
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;
|
||||||
@ -92,6 +93,18 @@ public class DeleteArtifactAction
|
|||||||
*/
|
*/
|
||||||
private String version;
|
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.
|
* The repository where the artifact is to be deleted.
|
||||||
*/
|
*/
|
||||||
@ -177,6 +190,26 @@ public void prepare()
|
|||||||
managedRepos = getManagableRepos();
|
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()
|
public String input()
|
||||||
{
|
{
|
||||||
return INPUT;
|
return INPUT;
|
||||||
@ -190,6 +223,8 @@ private void reset()
|
|||||||
artifactId = "";
|
artifactId = "";
|
||||||
version = "";
|
version = "";
|
||||||
repositoryId = "";
|
repositoryId = "";
|
||||||
|
classifier = "";
|
||||||
|
type = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String doDelete()
|
public String doDelete()
|
||||||
@ -209,8 +244,35 @@ public String doDelete()
|
|||||||
ref.setArtifactId( artifactId );
|
ref.setArtifactId( artifactId );
|
||||||
ref.setGroupId( groupId );
|
ref.setGroupId( groupId );
|
||||||
ref.setVersion( version );
|
ref.setVersion( version );
|
||||||
|
|
||||||
ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
|
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 );
|
String path = repository.toMetadataPath( ref );
|
||||||
int index = path.lastIndexOf( '/' );
|
int index = path.lastIndexOf( '/' );
|
||||||
path = path.substring( 0, index );
|
path = path.substring( 0, index );
|
||||||
@ -231,6 +293,7 @@ public String doDelete()
|
|||||||
updateMetadata( metadata, metadataFile, lastUpdatedTimestamp );
|
updateMetadata( metadata, metadataFile, lastUpdatedTimestamp );
|
||||||
|
|
||||||
MetadataRepository metadataRepository = repositorySession.getRepository();
|
MetadataRepository metadataRepository = repositorySession.getRepository();
|
||||||
|
|
||||||
Collection<ArtifactMetadata> artifacts =
|
Collection<ArtifactMetadata> artifacts =
|
||||||
metadataRepository.getArtifacts( repositoryId, groupId, artifactId, version );
|
metadataRepository.getArtifacts( repositoryId, groupId, artifactId, version );
|
||||||
|
|
||||||
|
@ -24,5 +24,7 @@
|
|||||||
<s:textfield name="groupId" label="Group Id" size="50" required="true"/>
|
<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="artifactId" label="Artifact Id" size="50" required="true"/>
|
||||||
<s:textfield name="version" label="Version" 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"/>
|
<s:select name="repositoryId" list="managedRepos" label="Repository Id"/>
|
||||||
|
|
@ -28,10 +28,10 @@
|
|||||||
* Listen to events on the repository. This class is a stopgap
|
* Listen to events on the repository. This class is a stopgap
|
||||||
* refactoring measure until an event bus is in place to handle
|
* refactoring measure until an event bus is in place to handle
|
||||||
* generic events such as these.
|
* 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
|
* 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.
|
* 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
|
* FIXME: this needs to be made more permanent since 3rd party plugins will depend on it heavily
|
||||||
*/
|
*/
|
||||||
public interface RepositoryListener
|
public interface RepositoryListener
|
||||||
|
Loading…
x
Reference in New Issue
Block a user