]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1282] remove duplicated artifact population, ensuring the metadata consumer...
authorBrett Porter <brett@apache.org>
Wed, 10 Mar 2010 14:55:59 +0000 (14:55 +0000)
committerBrett Porter <brett@apache.org>
Wed, 10 Mar 2010 14:55:59 +0000 (14:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@921376 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/IncludesFilter.java [new file with mode: 0644]

index 82d9adaa87f5f5ab1ae4d8eeacf1e78b8b2d0e96..590135a2799fcb8ee0add6d07735af5e58c4a7f8 100644 (file)
@@ -19,13 +19,12 @@ package org.apache.archiva.consumers.metadata;
  * under the License.
  */
 
-import org.apache.archiva.checksum.ChecksumAlgorithm;
-import org.apache.archiva.checksum.ChecksummedFile;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.ProjectMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.MetadataResolutionException;
+import org.apache.archiva.metadata.repository.filter.IncludesFilter;
 import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver;
 import org.apache.maven.archiva.common.utils.VersionUtil;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
@@ -46,8 +45,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
-import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 
@@ -185,35 +184,15 @@ public class ArchivaMetadataCreationConsumer
             createVersionMetadata = true;
         }
 
-        // TODO: merge with storage implementation, add Maven facet        
-        ArtifactMetadata artifactMeta = new ArtifactMetadata();
-        artifactMeta.setRepositoryId( repository.getId() );
-        artifactMeta.setNamespace( artifact.getGroupId() );
-        artifactMeta.setProject( artifact.getArtifactId() );
-        artifactMeta.setId( file.getName() );
-        artifactMeta.setFileLastModified( file.lastModified() );
-        artifactMeta.setSize( file.length() );
+        // A bit weird to reconstruct the file we already have, but don't want to expose getArtifactFromFile in the
+        // storage API
+        IncludesFilter<String> filter = new IncludesFilter<String>( Arrays.asList( file.getName() ) );
+        ArtifactMetadata artifactMeta = storageResolver.getArtifacts( repository.getId(), artifact.getGroupId(),
+                                                                      artifact.getArtifactId(), projectVersion,
+                                                                      filter ).iterator().next();
         artifactMeta.setVersion( artifact.getVersion() );
         artifactMeta.setWhenGathered( whenGathered );
 
-        ChecksummedFile checksummedFile = new ChecksummedFile( file );
-        try
-        {
-            artifactMeta.setMd5( checksummedFile.calculateChecksum( ChecksumAlgorithm.MD5 ) );
-        }
-        catch ( IOException e )
-        {
-            log.error( "Error attempting to get MD5 checksum for " + file + ": " + e.getMessage() );
-        }
-        try
-        {
-            artifactMeta.setSha1( checksummedFile.calculateChecksum( ChecksumAlgorithm.SHA1 ) );
-        }
-        catch ( IOException e )
-        {
-            log.error( "Error attempting to get SHA-1 checksum for " + file + ": " + e.getMessage() );
-        }
-
         // TODO: transaction
         // read the metadata and update it if it is newer or doesn't exist
         metadataRepository.updateArtifact( repository.getId(), project.getNamespace(), project.getId(), projectVersion,
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/IncludesFilter.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/IncludesFilter.java
new file mode 100644 (file)
index 0000000..d50ebba
--- /dev/null
@@ -0,0 +1,38 @@
+package org.apache.archiva.metadata.repository.filter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+
+public class IncludesFilter<T>
+    implements Filter<T>
+{
+    private Collection<T> includes;
+
+    public IncludesFilter( Collection<T> includes )
+    {
+        this.includes = includes;
+    }
+
+    public boolean accept( T value )
+    {
+        return includes.contains( value );
+    }
+}
\ No newline at end of file