mirror of https://github.com/apache/archiva.git
[MRM-1282] remove use of repository layer in favour of storage API
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@921423 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
17348a45ce
commit
d6c33feff1
|
@ -18,7 +18,8 @@
|
||||||
~ under the License.
|
~ under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>archiva-consumers</artifactId>
|
<artifactId>archiva-consumers</artifactId>
|
||||||
|
@ -32,6 +33,14 @@
|
||||||
<groupId>org.apache.archiva</groupId>
|
<groupId>org.apache.archiva</groupId>
|
||||||
<artifactId>archiva-consumer-api</artifactId>
|
<artifactId>archiva-consumer-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.archiva</groupId>
|
||||||
|
<artifactId>archiva-configuration</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.archiva</groupId>
|
||||||
|
<artifactId>archiva-common</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.archiva</groupId>
|
<groupId>org.apache.archiva</groupId>
|
||||||
<artifactId>metadata-model</artifactId>
|
<artifactId>metadata-model</artifactId>
|
||||||
|
@ -41,8 +50,16 @@
|
||||||
<artifactId>metadata-repository-api</artifactId>
|
<artifactId>metadata-repository-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.archiva</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>archiva-repository-layer</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-component-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus.registry</groupId>
|
||||||
|
<artifactId>plexus-registry-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.apache.archiva.metadata.model.ProjectMetadata;
|
||||||
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
|
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
|
||||||
import org.apache.archiva.metadata.repository.MetadataRepository;
|
import org.apache.archiva.metadata.repository.MetadataRepository;
|
||||||
import org.apache.archiva.metadata.repository.MetadataResolutionException;
|
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.archiva.metadata.repository.storage.StorageMetadataResolver;
|
||||||
import org.apache.maven.archiva.common.utils.VersionUtil;
|
import org.apache.maven.archiva.common.utils.VersionUtil;
|
||||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
|
@ -34,9 +33,6 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
|
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
|
||||||
import org.apache.maven.archiva.consumers.ConsumerException;
|
import org.apache.maven.archiva.consumers.ConsumerException;
|
||||||
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
|
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
|
||||||
import org.apache.maven.archiva.model.ArtifactReference;
|
|
||||||
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
|
|
||||||
import org.apache.maven.archiva.repository.layout.LayoutException;
|
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||||
import org.codehaus.plexus.registry.Registry;
|
import org.codehaus.plexus.registry.Registry;
|
||||||
|
@ -44,9 +40,7 @@ import org.codehaus.plexus.registry.RegistryListener;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -83,11 +77,6 @@ public class ArchivaMetadataCreationConsumer
|
||||||
|
|
||||||
private Date whenGathered;
|
private Date whenGathered;
|
||||||
|
|
||||||
/**
|
|
||||||
* @plexus.requirement
|
|
||||||
*/
|
|
||||||
private ManagedRepositoryContent repository;
|
|
||||||
|
|
||||||
private List<String> includes = new ArrayList<String>();
|
private List<String> includes = new ArrayList<String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,9 +85,7 @@ public class ArchivaMetadataCreationConsumer
|
||||||
private MetadataRepository metadataRepository;
|
private MetadataRepository metadataRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXME: this needs to be configurable based on storage type, and availability of proxy module
|
* FIXME: this needs to be configurable based on storage type
|
||||||
* ... could be a different type since we need methods to modify the storage metadata, which would also allow more
|
|
||||||
* appropriate methods to pass in the already determined repository configuration, for example, instead of the ID
|
|
||||||
*
|
*
|
||||||
* @plexus.requirement role-hint="maven2"
|
* @plexus.requirement role-hint="maven2"
|
||||||
*/
|
*/
|
||||||
|
@ -106,6 +93,8 @@ public class ArchivaMetadataCreationConsumer
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger( ArchivaMetadataCreationConsumer.class );
|
private static final Logger log = LoggerFactory.getLogger( ArchivaMetadataCreationConsumer.class );
|
||||||
|
|
||||||
|
private String repoId;
|
||||||
|
|
||||||
public String getId()
|
public String getId()
|
||||||
{
|
{
|
||||||
return this.id;
|
return this.id;
|
||||||
|
@ -134,7 +123,7 @@ public class ArchivaMetadataCreationConsumer
|
||||||
public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered )
|
public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered )
|
||||||
throws ConsumerException
|
throws ConsumerException
|
||||||
{
|
{
|
||||||
this.repository.setRepository( repo );
|
repoId = repo.getId();
|
||||||
this.whenGathered = whenGathered;
|
this.whenGathered = whenGathered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,29 +133,19 @@ public class ArchivaMetadataCreationConsumer
|
||||||
// note that we do minimal processing including checksums and POM information for performance of
|
// note that we do minimal processing including checksums and POM information for performance of
|
||||||
// the initial scan. Any request for this information will be intercepted and populated on-demand
|
// the initial scan. Any request for this information will be intercepted and populated on-demand
|
||||||
// or picked up by subsequent scans
|
// or picked up by subsequent scans
|
||||||
ArtifactReference artifact;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
artifact = repository.toArtifactReference( path );
|
|
||||||
}
|
|
||||||
catch ( LayoutException e )
|
|
||||||
{
|
|
||||||
throw new ConsumerException( e.getMessage(), e );
|
|
||||||
}
|
|
||||||
|
|
||||||
File file = new File( repository.getRepoRoot(), path );
|
ArtifactMetadata artifact = storageResolver.getArtifactForPath( repoId, path );
|
||||||
|
|
||||||
ProjectMetadata project = new ProjectMetadata();
|
ProjectMetadata project = new ProjectMetadata();
|
||||||
project.setNamespace( artifact.getGroupId() );
|
project.setNamespace( artifact.getNamespace() );
|
||||||
project.setId( artifact.getArtifactId() );
|
project.setId( artifact.getProject() );
|
||||||
|
|
||||||
String projectVersion = VersionUtil.getBaseVersion( artifact.getVersion() );
|
String projectVersion = VersionUtil.getBaseVersion( artifact.getVersion() );
|
||||||
// TODO: maybe not too efficient since it may have already been read and stored for this artifact
|
// TODO: maybe not too efficient since it may have already been read and stored for this artifact
|
||||||
ProjectVersionMetadata versionMetadata = null;
|
ProjectVersionMetadata versionMetadata = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
versionMetadata =
|
versionMetadata = storageResolver.getProjectVersion( repoId, artifact.getNamespace(), artifact.getProject(),
|
||||||
storageResolver.getProjectVersion( repository.getId(), artifact.getGroupId(), artifact.getArtifactId(),
|
|
||||||
projectVersion );
|
projectVersion );
|
||||||
}
|
}
|
||||||
catch ( MetadataResolutionException e )
|
catch ( MetadataResolutionException e )
|
||||||
|
@ -184,25 +163,15 @@ public class ArchivaMetadataCreationConsumer
|
||||||
createVersionMetadata = true;
|
createVersionMetadata = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 );
|
|
||||||
|
|
||||||
// TODO: transaction
|
// TODO: transaction
|
||||||
// read the metadata and update it if it is newer or doesn't exist
|
// read the metadata and update it if it is newer or doesn't exist
|
||||||
metadataRepository.updateArtifact( repository.getId(), project.getNamespace(), project.getId(), projectVersion,
|
artifact.setWhenGathered( whenGathered );
|
||||||
artifactMeta );
|
metadataRepository.updateArtifact( repoId, project.getNamespace(), project.getId(), projectVersion, artifact );
|
||||||
if ( createVersionMetadata )
|
if ( createVersionMetadata )
|
||||||
{
|
{
|
||||||
metadataRepository.updateProjectVersion( repository.getId(), project.getNamespace(), project.getId(),
|
metadataRepository.updateProjectVersion( repoId, project.getNamespace(), project.getId(), versionMetadata );
|
||||||
versionMetadata );
|
|
||||||
}
|
}
|
||||||
metadataRepository.updateProject( repository.getId(), project );
|
metadataRepository.updateProject( repoId, project );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void completeScan()
|
public void completeScan()
|
||||||
|
|
|
@ -19,12 +19,12 @@ package org.apache.archiva.metadata.repository.storage;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
||||||
import org.apache.archiva.metadata.repository.MetadataResolver;
|
import org.apache.archiva.metadata.repository.MetadataResolver;
|
||||||
import org.apache.archiva.metadata.repository.filter.Filter;
|
import org.apache.archiva.metadata.repository.filter.Filter;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public interface StorageMetadataResolver
|
public interface StorageMetadataResolver
|
||||||
extends MetadataResolver
|
extends MetadataResolver
|
||||||
{
|
{
|
||||||
|
@ -38,4 +38,7 @@ public interface StorageMetadataResolver
|
||||||
|
|
||||||
Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId, String projectVersion,
|
Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId, String projectVersion,
|
||||||
Filter<String> filter );
|
Filter<String> filter );
|
||||||
|
|
||||||
|
// TODO: reconsider this API, do we want to expose storage format in the form of a path?
|
||||||
|
ArtifactMetadata getArtifactForPath( String repoId, String path );
|
||||||
}
|
}
|
||||||
|
|
|
@ -497,12 +497,28 @@ public class Maven2RepositoryMetadataResolver
|
||||||
return artifacts;
|
return artifacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArtifactMetadata getArtifactForPath( String repoId, String path )
|
||||||
|
{
|
||||||
|
ArtifactMetadata metadata = pathTranslator.getArtifactForPath( repoId, path );
|
||||||
|
|
||||||
|
populateArtifactMetadataFromFile( metadata, new File( getRepositoryBasedir( repoId ), path ) );
|
||||||
|
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
private ArtifactMetadata getArtifactFromFile( String repoId, String namespace, String projectId,
|
private ArtifactMetadata getArtifactFromFile( String repoId, String namespace, String projectId,
|
||||||
String projectVersion, File file )
|
String projectVersion, File file )
|
||||||
{
|
{
|
||||||
ArtifactMetadata metadata = pathTranslator.getArtifactFromId( repoId, namespace, projectId, projectVersion,
|
ArtifactMetadata metadata = pathTranslator.getArtifactFromId( repoId, namespace, projectId, projectVersion,
|
||||||
file.getName() );
|
file.getName() );
|
||||||
|
|
||||||
|
populateArtifactMetadataFromFile( metadata, file );
|
||||||
|
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void populateArtifactMetadataFromFile( ArtifactMetadata metadata, File file )
|
||||||
|
{
|
||||||
metadata.setWhenGathered( new Date() );
|
metadata.setWhenGathered( new Date() );
|
||||||
metadata.setFileLastModified( file.lastModified() );
|
metadata.setFileLastModified( file.lastModified() );
|
||||||
ChecksummedFile checksummedFile = new ChecksummedFile( file );
|
ChecksummedFile checksummedFile = new ChecksummedFile( file );
|
||||||
|
@ -523,8 +539,6 @@ public class Maven2RepositoryMetadataResolver
|
||||||
log.error( "Unable to checksum file " + file + ": " + e.getMessage() );
|
log.error( "Unable to checksum file " + file + ": " + e.getMessage() );
|
||||||
}
|
}
|
||||||
metadata.setSize( file.length() );
|
metadata.setSize( file.length() );
|
||||||
|
|
||||||
return metadata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isProject( File dir, Filter<String> filter )
|
private boolean isProject( File dir, Filter<String> filter )
|
||||||
|
|
Loading…
Reference in New Issue