]> source.dussan.org Git - archiva.git/commitdiff
[MRM-369]: [Repository Scanning] Exception on update to pre-existing artifact.
authorJoakim Erdfelt <joakime@apache.org>
Sun, 17 Jun 2007 21:44:25 +0000 (21:44 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Sun, 17 Jun 2007 21:44:25 +0000 (21:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@548120 13f79535-47bb-0310-9956-ffa450edef68

archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java

index a8d5a09f832bca092527aaf0e8f0137cd3422d7b..85ac7405e9d6bad571821ccc0623406162670697 100644 (file)
@@ -83,7 +83,7 @@ public class ArtifactUpdateDatabaseConsumer
      * @plexus.requirement
      */
     private ArchivaConfiguration configuration;
-    
+
     /**
      * @plexus.requirement
      */
@@ -161,10 +161,15 @@ public class ArtifactUpdateDatabaseConsumer
     public void processFile( String path )
         throws ConsumerException
     {
-        try
+        ArchivaArtifact artifact = getLiveArtifact( path );
+
+        if ( artifact == null )
         {
-            ArchivaArtifact artifact = layout.toArtifact( path );
+            return;
+        }
 
+        try
+        {
             artifact.getModel().setRepositoryId( this.repository.getId() );
 
             // Calculate the hashcodes.
@@ -194,14 +199,41 @@ public class ArtifactUpdateDatabaseConsumer
 
             dao.getArtifactDAO().saveArtifact( artifact );
         }
+        catch ( ArchivaDatabaseException e )
+        {
+            triggerConsumerError( DB_ERROR, "Unable to save artifact to database: " + e.getMessage() );
+        }
+    }
+
+    /**
+     * Get a Live Artifact from a Path.
+     * 
+     * Will resolve the artifact details from the path, and then return a database live version
+     * of that artifact.  Suitable for modification and saving (without the need to check for
+     * existance in database prior to save.)
+     * 
+     * @param path the path to work from.
+     * @return the artifact that is suitable for database saving.
+     */
+    public ArchivaArtifact getLiveArtifact( String path )
+    {
+        try
+        {
+            ArchivaArtifact artifact = layout.toArtifact( path );
+
+            ArchivaArtifact liveArtifact = dao.getArtifactDAO().createArtifact( artifact.getGroupId(),
+                                                                                artifact.getArtifactId(),
+                                                                                artifact.getVersion(),
+                                                                                artifact.getClassifier(),
+                                                                                artifact.getType() );
+
+            return liveArtifact;
+        }
         catch ( LayoutException e )
         {
             triggerConsumerError( TYPE_NOT_ARTIFACT, "Path " + path + " cannot be converted to artifact: "
                 + e.getMessage() );
-        }
-        catch ( ArchivaDatabaseException e )
-        {
-            triggerConsumerError( DB_ERROR, "Unable to save artifact to database: " + e.getMessage() );
+            return null;
         }
     }