mirror of
https://github.com/apache/archiva.git
synced 2025-02-21 09:24:54 +00:00
[MRM-1025] fill out more of the information in the metadata creation consumer to make it consistent with the current database record creation consumer
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@886126 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b9d374dd09
commit
49157f1525
@ -20,14 +20,18 @@
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
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.ProjectVersionMetadata;
|
||||
import org.apache.archiva.metadata.model.ProjectMetadata;
|
||||
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
|
||||
import org.apache.archiva.metadata.repository.MetadataRepository;
|
||||
import org.apache.maven.archiva.common.utils.VersionUtil;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.ConfigurationNames;
|
||||
import org.apache.maven.archiva.configuration.FileTypes;
|
||||
@ -42,13 +46,15 @@
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||
import org.codehaus.plexus.registry.Registry;
|
||||
import org.codehaus.plexus.registry.RegistryListener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Take an artifact off of disk and put it into the metadata repository.
|
||||
*
|
||||
*
|
||||
* @version $Id: ArtifactUpdateDatabaseConsumer.java 718864 2008-11-19 06:33:35Z brett $
|
||||
* @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
|
||||
* role-hint="create-archiva-metadata" instantiation-strategy="per-lookup"
|
||||
* role-hint="create-archiva-metadata" instantiation-strategy="per-lookup"
|
||||
*/
|
||||
public class ArchivaMetadataCreationConsumer
|
||||
extends AbstractMonitoredConsumer
|
||||
@ -88,6 +94,8 @@ public class ArchivaMetadataCreationConsumer
|
||||
*/
|
||||
private MetadataRepository metadataRepository;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger( ArchivaMetadataCreationConsumer.class );
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return this.id;
|
||||
@ -143,22 +151,41 @@ public void processFile( String path )
|
||||
project.setId( artifact.getArtifactId() );
|
||||
|
||||
ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
|
||||
versionMetadata.setId( artifact.getVersion() ); // TODO: this should be the version from the POM, not the timestamped version
|
||||
versionMetadata.setId( VersionUtil.getBaseVersion( artifact.getVersion() ) );
|
||||
|
||||
ArtifactMetadata artifactMeta = new ArtifactMetadata();
|
||||
artifactMeta.setId( file.getName() );
|
||||
artifactMeta.setUpdated( file.lastModified() );
|
||||
artifactMeta.setFileLastModified( file.lastModified() );
|
||||
artifactMeta.setSize( file.length() );
|
||||
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: read the POM and fill in the rest of the information
|
||||
|
||||
// TODO: store "whenGathered"
|
||||
|
||||
// TODO: transaction
|
||||
// read the metadata and update it if it is newer or doesn't exist
|
||||
metadataRepository.updateArtifact( repository.getId(), project.getNamespace(), project.getId(), versionMetadata.getId(), artifactMeta );
|
||||
metadataRepository.updateProjectVersion( repository.getId(), project.getNamespace(), project.getId(), versionMetadata );
|
||||
metadataRepository.updateArtifact( repository.getId(), project.getNamespace(), project.getId(),
|
||||
versionMetadata.getId(), artifactMeta );
|
||||
metadataRepository.updateProjectVersion( repository.getId(), project.getNamespace(), project.getId(),
|
||||
versionMetadata );
|
||||
metadataRepository.updateProject( repository.getId(), project );
|
||||
}
|
||||
|
||||
|
@ -25,12 +25,18 @@ public class ArtifactMetadata
|
||||
{
|
||||
private String id;
|
||||
|
||||
private Date updated;
|
||||
|
||||
private long size;
|
||||
|
||||
private String version;
|
||||
|
||||
private Date fileLastModified;
|
||||
|
||||
private Date whenGathered;
|
||||
|
||||
private String md5;
|
||||
|
||||
private String sha1;
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
@ -41,21 +47,6 @@ public void setId( String id )
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getUpdated()
|
||||
{
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated( Date updated )
|
||||
{
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public void setUpdated( long updated )
|
||||
{
|
||||
this.updated = new Date( updated );
|
||||
}
|
||||
|
||||
public long getSize()
|
||||
{
|
||||
return size;
|
||||
@ -75,4 +66,45 @@ public void setVersion( String version )
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public void setFileLastModified( long fileLastModified )
|
||||
{
|
||||
this.fileLastModified = new Date( fileLastModified );
|
||||
}
|
||||
|
||||
public void setWhenGathered( Date whenGathered )
|
||||
{
|
||||
this.whenGathered = whenGathered;
|
||||
}
|
||||
|
||||
public void setMd5( String md5 )
|
||||
{
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public void setSha1( String sha1 )
|
||||
{
|
||||
this.sha1 = sha1;
|
||||
}
|
||||
|
||||
public Date getWhenGathered()
|
||||
{
|
||||
return whenGathered;
|
||||
}
|
||||
|
||||
public String getMd5()
|
||||
{
|
||||
return md5;
|
||||
}
|
||||
|
||||
public String getSha1()
|
||||
{
|
||||
return sha1;
|
||||
}
|
||||
|
||||
public Date getFileLastModified()
|
||||
{
|
||||
|
||||
return fileLastModified;
|
||||
}
|
||||
}
|
||||
|
@ -268,8 +268,12 @@ public void updateArtifact( String repoId, String namespace, String projectId, S
|
||||
Properties properties = readProperties( directory, PROJECT_VERSION_METADATA_KEY );
|
||||
|
||||
properties.setProperty( "artifact:updated:" + artifact.getId(),
|
||||
Long.toString( artifact.getUpdated().getTime() ) );
|
||||
Long.toString( artifact.getFileLastModified().getTime() ) );
|
||||
properties.setProperty( "artifact:whenGathered:" + artifact.getId(),
|
||||
Long.toString( artifact.getWhenGathered().getTime() ) );
|
||||
properties.setProperty( "artifact:size:" + artifact.getId(), Long.toString( artifact.getSize() ) );
|
||||
properties.setProperty( "artifact:md5:" + artifact.getId(), artifact.getMd5() );
|
||||
properties.setProperty( "artifact:sha1:" + artifact.getId(), artifact.getMd5() );
|
||||
properties.setProperty( "artifact:version:" + artifact.getId(), artifact.getVersion() );
|
||||
|
||||
try
|
||||
|
Loading…
x
Reference in New Issue
Block a user