From: Olivier Lamy Date: Mon, 24 Oct 2011 19:36:20 +0000 (+0000) Subject: [MRM-1542] missing classifier field in the delete artifact web page X-Git-Tag: archiva-1.4-M2~223 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=97c85abe24abda8a6eda548251b1512ec51a53d4;p=archiva.git [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 --- diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java index 533381de0..a23415ed9 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java @@ -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; + /** *

* Convenience method to get the repository id. diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java index 2479aa90d..f9b5bb13b 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java @@ -20,10 +20,9 @@ package org.apache.archiva.repository.content; */ 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.model.VersionedReference; 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.HashSet; 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 class ManagedDefaultRepositoryContent { 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 class ManagedDefaultRepositoryContent } } + 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 class ManagedDefaultRepositoryContent 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 foundArtifacts = new HashSet(); @@ -124,11 +140,10 @@ public class ManagedDefaultRepositoryContent 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 class ManagedDefaultRepositoryContent * information. * * @return the Set of available versions, based on the project reference. - * @throws LayoutException + * @throws LayoutException * @throws LayoutException */ public Set getVersions( ProjectReference reference ) @@ -176,14 +191,14 @@ public class ManagedDefaultRepositoryContent 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 foundVersions = new HashSet(); @@ -229,14 +244,14 @@ public class ManagedDefaultRepositoryContent 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 foundVersions = new HashSet(); @@ -264,7 +279,7 @@ public class ManagedDefaultRepositoryContent try { ArtifactReference artifact = toArtifactReference( relativePath ); - + foundVersions.add( artifact.getVersion() ); } catch ( LayoutException e ) @@ -323,7 +338,7 @@ public class ManagedDefaultRepositoryContent /** * 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 class ManagedDefaultRepositoryContent { return new File( repository.getLocation(), toPath( reference ) ); } - + public File toFile( ArchivaArtifact reference ) { return new File( repository.getLocation(), toPath( reference ) ); @@ -352,7 +367,7 @@ public class ManagedDefaultRepositoryContent /** * 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 @@ public class ManagedDefaultRepositoryContent 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(); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java index ab4b1c0a1..56690c7b6 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java @@ -459,4 +459,10 @@ public class ManagedLegacyRepositoryContent { this.filetypes = fileTypes; } + + public void deleteArtifact( ArtifactReference artifactReference ) + throws ContentNotFoundException + { + // TODO implements for legacy ?? + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java index 09a332eb3..938079844 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java @@ -33,6 +33,7 @@ import org.apache.archiva.metadata.repository.MetadataRepository; 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 class DeleteArtifactAction 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 @@ public class DeleteArtifactAction artifactId = ""; version = ""; repositoryId = ""; + classifier = ""; + type = ""; } public String doDelete() @@ -209,8 +244,35 @@ public class DeleteArtifactAction 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 class DeleteArtifactAction updateMetadata( metadata, metadataFile, lastUpdatedTimestamp ); MetadataRepository metadataRepository = repositorySession.getRepository(); + Collection artifacts = metadataRepository.getArtifacts( repositoryId, groupId, artifactId, version ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/deleteArtifactForm.jspf b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/deleteArtifactForm.jspf index eca6ece57..5e96c5706 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/deleteArtifactForm.jspf +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/deleteArtifactForm.jspf @@ -24,5 +24,7 @@ + + \ No newline at end of file diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java index 580a577f7..a68c0f171 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java @@ -28,10 +28,10 @@ import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataE * 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. - * + *

* 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. - * + *

* FIXME: this needs to be made more permanent since 3rd party plugins will depend on it heavily */ public interface RepositoryListener