* 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;
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;
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,
--- /dev/null
+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