*/
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;
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;
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;
{
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 );
}
}
}
+ 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();
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>();
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 );
}
* information.
*
* @return the Set of available versions, based on the project reference.
- * @throws LayoutException
+ * @throws LayoutException
* @throws LayoutException
*/
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>();
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>();
try
{
ArtifactReference artifact = toArtifactReference( relativePath );
-
+
foundVersions.add( artifact.getVersion() );
}
catch ( LayoutException e )
/**
* 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.
*/
{
return new File( repository.getLocation(), toPath( reference ) );
}
-
+
public File toFile( ArchivaArtifact reference )
{
return new File( repository.getLocation(), toPath( 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)
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();
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;
*/
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.
*/
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;
artifactId = "";
version = "";
repositoryId = "";
+ classifier = "";
+ type = "";
}
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 );
updateMetadata( metadata, metadataFile, lastUpdatedTimestamp );
MetadataRepository metadataRepository = repositorySession.getRepository();
+
Collection<ArtifactMetadata> artifacts =
metadataRepository.getArtifacts( repositoryId, groupId, artifactId, version );