From: Brett Porter Date: Wed, 10 Mar 2010 14:55:59 +0000 (+0000) Subject: [MRM-1282] remove duplicated artifact population, ensuring the metadata consumer... X-Git-Tag: archiva-1.4-M1~986 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=17348a45ce949d306c4ebf32b7005d920813fded;p=archiva.git [MRM-1282] remove duplicated artifact population, ensuring the metadata consumer now sets facets correctly too git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@921376 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java index 82d9adaa8..590135a27 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java @@ -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 filter = new IncludesFilter( 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 index 000000000..d50ebba9b --- /dev/null +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/IncludesFilter.java @@ -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 + implements Filter +{ + private Collection includes; + + public IncludesFilter( Collection includes ) + { + this.includes = includes; + } + + public boolean accept( T value ) + { + return includes.contains( value ); + } +} \ No newline at end of file