From e6fc266d61e3ff72401408bbd91125b097415d19 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sun, 17 Jun 2007 21:44:25 +0000 Subject: [PATCH] [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 --- .../ArtifactUpdateDatabaseConsumer.java | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) 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; } } -- 2.39.5