You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2011/10/24 21:36:20 UTC

svn commit: r1188328 - in /archiva/trunk/archiva-modules: archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ archiva-web/archiva-...

Author: olamy
Date: Mon Oct 24 19:36:20 2011
New Revision: 1188328

URL: http://svn.apache.org/viewvc?rev=1188328&view=rev
Log:
[MRM-1542] missing classifier field in the delete artifact web page

Modified:
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/deleteArtifactForm.jspf
    archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java?rev=1188328&r1=1188327&r2=1188328&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java (original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java Mon Oct 24 19:36:20 2011
@@ -48,6 +48,14 @@ public interface ManagedRepositoryConten
         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.
      * </p>

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java?rev=1188328&r1=1188327&r2=1188328&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java (original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java Mon Oct 24 19:36:20 2011
@@ -20,10 +20,9 @@ package org.apache.archiva.repository.co
  */
 
 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.Versione
 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 ManagedDefaultRepositoryCon
     {
         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 ManagedDefaultRepositoryCon
         }
     }
 
+    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 ManagedDefaultRepositoryCon
 
         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 class ManagedDefaultRepositoryCon
                 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 ManagedDefaultRepositoryCon
      * 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 class ManagedDefaultRepositoryCon
 
         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 class ManagedDefaultRepositoryCon
 
         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 class ManagedDefaultRepositoryCon
                 try
                 {
                     ArtifactReference artifact = toArtifactReference( relativePath );
-    
+
                     foundVersions.add( artifact.getVersion() );
                 }
                 catch ( LayoutException e )
@@ -323,7 +338,7 @@ public class ManagedDefaultRepositoryCon
 
     /**
      * 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 ManagedDefaultRepositoryCon
     {
         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 ManagedDefaultRepositoryCon
     /**
      * 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 ManagedDefaultRepositoryCon
         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();

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java?rev=1188328&r1=1188327&r2=1188328&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java (original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java Mon Oct 24 19:36:20 2011
@@ -459,4 +459,10 @@ public class ManagedLegacyRepositoryCont
     {
         this.filetypes = fileTypes;
     }
+
+    public void deleteArtifact( ArtifactReference artifactReference )
+        throws ContentNotFoundException
+    {
+        // TODO implements for legacy ??
+    }
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java?rev=1188328&r1=1188327&r2=1188328&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/DeleteArtifactAction.java Mon Oct 24 19:36:20 2011
@@ -33,6 +33,7 @@ import org.apache.archiva.metadata.repos
 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;
@@ -93,6 +94,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.
      */
     private String repositoryId;
@@ -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<ArtifactMetadata> artifacts =
                 metadataRepository.getArtifacts( repositoryId, groupId, artifactId, version );
 

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/deleteArtifactForm.jspf
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/deleteArtifactForm.jspf?rev=1188328&r1=1188327&r2=1188328&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/deleteArtifactForm.jspf (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/deleteArtifactForm.jspf Mon Oct 24 19:36:20 2011
@@ -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"/>
 	
\ No newline at end of file

Modified: archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java?rev=1188328&r1=1188327&r2=1188328&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java (original)
+++ archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java Mon Oct 24 19:36:20 2011
@@ -28,10 +28,10 @@ import org.apache.archiva.metadata.repos
  * 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