From: Joakim Erdfelt Date: Sun, 17 Jun 2007 21:44:25 +0000 (+0000) Subject: [MRM-369]: [Repository Scanning] Exception on update to pre-existing artifact. X-Git-Tag: archiva-1.0-alpha-2~34 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e6fc266d61e3ff72401408bbd91125b097415d19;p=archiva.git [MRM-369]: [Repository Scanning] Exception on update to pre-existing artifact. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@548120 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java b/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java index a8d5a09f8..85ac7405e 100644 --- a/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java +++ b/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java @@ -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; } }