Pārlūkot izejas kodu

[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
tags/archiva-1.4-M1
Brett Porter pirms 14 gadiem
vecāks
revīzija
49157f1525

+ 36
- 9
archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java Parādīt failu

@@ -20,14 +20,18 @@ package org.apache.archiva.consumers.metadata;
*/

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.Initializable;
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 class ArchivaMetadataCreationConsumer
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 );

// TODO: read the POM and fill in the rest of the information
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: store "whenGathered"
// TODO: read the POM and fill in the rest of the information

// 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 );
}


+ 48
- 16
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java Parādīt failu

@@ -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,38 +47,64 @@ public class ArtifactMetadata
this.id = id;
}

public Date getUpdated()
public long getSize()
{
return updated;
return size;
}

public void setUpdated( Date updated )
public void setSize( long size )
{
this.updated = updated;
this.size = size;
}

public void setUpdated( long updated )
public String getVersion()
{
this.updated = new Date( updated );
return version;
}

public long getSize()
public void setVersion( String version )
{
return size;
this.version = version;
}

public void setSize( long size )
public void setFileLastModified( long fileLastModified )
{
this.size = size;
this.fileLastModified = new Date( fileLastModified );
}

public String getVersion()
public void setWhenGathered( Date whenGathered )
{
return version;
this.whenGathered = whenGathered;
}

public void setVersion( String version )
public void setMd5( String md5 )
{
this.version = version;
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;
}
}

+ 5
- 1
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java Parādīt failu

@@ -268,8 +268,12 @@ public class FileMetadataRepository
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

Notiek ielāde…
Atcelt
Saglabāt