mirror of https://github.com/apache/archiva.git
Switching pathparser to new API
This commit is contained in:
parent
e38eebeadd
commit
bf95aca967
|
@ -28,16 +28,6 @@ import org.apache.archiva.repository.LayoutException;
|
||||||
public interface PathParser
|
public interface PathParser
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Take a path and get the ArtifactReference associated with it.
|
|
||||||
*
|
|
||||||
* @param path the relative path to parse.
|
|
||||||
* @return the ArtifactReference for the provided path. (never null)
|
|
||||||
* @throws LayoutException if there was a problem parsing the path.
|
|
||||||
*/
|
|
||||||
ArtifactReference toArtifactReference( String path )
|
|
||||||
throws LayoutException;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a item selector for the given path.
|
* Return a item selector for the given path.
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
|
||||||
import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
|
import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
|
||||||
import org.apache.archiva.repository.maven.metadata.storage.DefaultArtifactMappingProvider;
|
import org.apache.archiva.repository.maven.metadata.storage.DefaultArtifactMappingProvider;
|
||||||
import org.apache.archiva.repository.maven.metadata.storage.Maven2RepositoryPathTranslator;
|
import org.apache.archiva.repository.maven.metadata.storage.Maven2RepositoryPathTranslator;
|
||||||
import org.apache.archiva.model.ArtifactReference;
|
|
||||||
import org.apache.archiva.repository.LayoutException;
|
import org.apache.archiva.repository.LayoutException;
|
||||||
import org.apache.archiva.repository.content.ItemSelector;
|
import org.apache.archiva.repository.content.ItemSelector;
|
||||||
import org.apache.archiva.repository.content.PathParser;
|
import org.apache.archiva.repository.content.PathParser;
|
||||||
|
@ -51,45 +50,6 @@ public class DefaultPathParser
|
||||||
private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator(
|
private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator(
|
||||||
Collections.<ArtifactMappingProvider>singletonList( new DefaultArtifactMappingProvider() ) );
|
Collections.<ArtifactMappingProvider>singletonList( new DefaultArtifactMappingProvider() ) );
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* @see org.apache.archiva.repository.content.PathParser#toArtifactReference(String)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ArtifactReference toArtifactReference( String path )
|
|
||||||
throws LayoutException
|
|
||||||
{
|
|
||||||
if ( StringUtils.isBlank( path ) )
|
|
||||||
{
|
|
||||||
throw new LayoutException( "Unable to convert blank path." );
|
|
||||||
}
|
|
||||||
|
|
||||||
ArtifactMetadata metadata;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
metadata = pathTranslator.getArtifactForPath( null, path );
|
|
||||||
}
|
|
||||||
catch ( IllegalArgumentException e )
|
|
||||||
{
|
|
||||||
throw new LayoutException( e.getMessage(), e );
|
|
||||||
}
|
|
||||||
|
|
||||||
ArtifactReference artifact = new ArtifactReference();
|
|
||||||
artifact.setGroupId( metadata.getNamespace() );
|
|
||||||
artifact.setArtifactId( metadata.getProject() );
|
|
||||||
artifact.setVersion( metadata.getVersion() );
|
|
||||||
artifact.setProjectVersion( metadata.getProjectVersion( ) );
|
|
||||||
MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID );
|
|
||||||
if ( facet != null )
|
|
||||||
{
|
|
||||||
artifact.setClassifier( facet.getClassifier() );
|
|
||||||
artifact.setType( facet.getType() );
|
|
||||||
}
|
|
||||||
|
|
||||||
return artifact;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemSelector toItemSelector( String path ) throws LayoutException
|
public ItemSelector toItemSelector( String path ) throws LayoutException
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata;
|
||||||
import org.apache.archiva.metadata.model.facets.RepositoryProblemFacet;
|
import org.apache.archiva.metadata.model.facets.RepositoryProblemFacet;
|
||||||
import org.apache.archiva.metadata.repository.storage.*;
|
import org.apache.archiva.metadata.repository.storage.*;
|
||||||
import org.apache.archiva.model.ArchivaRepositoryMetadata;
|
import org.apache.archiva.model.ArchivaRepositoryMetadata;
|
||||||
import org.apache.archiva.model.ArtifactReference;
|
|
||||||
import org.apache.archiva.model.SnapshotVersion;
|
import org.apache.archiva.model.SnapshotVersion;
|
||||||
import org.apache.archiva.policies.ProxyDownloadException;
|
import org.apache.archiva.policies.ProxyDownloadException;
|
||||||
import org.apache.archiva.proxy.ProxyRegistry;
|
import org.apache.archiva.proxy.ProxyRegistry;
|
||||||
|
@ -564,87 +563,6 @@ public class Maven2RepositoryStorage
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyServerSideRelocation(ManagedRepository managedRepository, ArtifactReference artifact)
|
|
||||||
throws ProxyDownloadException {
|
|
||||||
if ("pom".equals(artifact.getType())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the artifact POM reference
|
|
||||||
ArtifactReference pomReference = new ArtifactReference();
|
|
||||||
pomReference.setGroupId(artifact.getGroupId());
|
|
||||||
pomReference.setArtifactId(artifact.getArtifactId());
|
|
||||||
pomReference.setVersion(artifact.getVersion());
|
|
||||||
pomReference.setProjectVersion( artifact.getProjectVersion() );
|
|
||||||
pomReference.setType("pom");
|
|
||||||
BaseRepositoryContentLayout layout;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
layout = managedRepository.getContent( ).getLayout( BaseRepositoryContentLayout.class );
|
|
||||||
}
|
|
||||||
catch ( LayoutException e )
|
|
||||||
{
|
|
||||||
throw new ProxyDownloadException( "Could not set layout " + e.getMessage( ), new HashMap<>( ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
RepositoryType repositoryType = managedRepository.getType();
|
|
||||||
if (!proxyRegistry.hasHandler(repositoryType)) {
|
|
||||||
throw new ProxyDownloadException("No proxy handler found for repository type " + repositoryType, new HashMap<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemSelector selector = ArchivaItemSelector.builder( )
|
|
||||||
.withNamespace( artifact.getGroupId( ) )
|
|
||||||
.withProjectId( artifact.getArtifactId( ) )
|
|
||||||
.withArtifactId( artifact.getArtifactId( ) )
|
|
||||||
.withVersion( artifact.getVersion( ) )
|
|
||||||
.withArtifactVersion( artifact.getVersion( ) )
|
|
||||||
.withType( "pom" ).build( );
|
|
||||||
|
|
||||||
Artifact pom = layout.getArtifact( selector );
|
|
||||||
|
|
||||||
RepositoryProxyHandler proxyHandler = proxyRegistry.getHandler(repositoryType).get(0);
|
|
||||||
|
|
||||||
// Get the artifact POM from proxied repositories if needed
|
|
||||||
proxyHandler.fetchFromProxies(managedRepository, pomReference);
|
|
||||||
|
|
||||||
// Open and read the POM from the managed repo
|
|
||||||
|
|
||||||
if (!pom.exists()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// MavenXpp3Reader leaves the file open, so we need to close it ourselves.
|
|
||||||
|
|
||||||
Model model;
|
|
||||||
try (Reader reader = Channels.newReader(pom.getAsset().getReadChannel(), Charset.defaultCharset().name())) {
|
|
||||||
model = MAVEN_XPP_3_READER.read(reader);
|
|
||||||
}
|
|
||||||
|
|
||||||
DistributionManagement dist = model.getDistributionManagement();
|
|
||||||
if (dist != null) {
|
|
||||||
Relocation relocation = dist.getRelocation();
|
|
||||||
if (relocation != null) {
|
|
||||||
// artifact is relocated : update the repositoryPath
|
|
||||||
if (relocation.getGroupId() != null) {
|
|
||||||
artifact.setGroupId(relocation.getGroupId());
|
|
||||||
}
|
|
||||||
if (relocation.getArtifactId() != null) {
|
|
||||||
artifact.setArtifactId(relocation.getArtifactId());
|
|
||||||
}
|
|
||||||
if (relocation.getVersion() != null) {
|
|
||||||
artifact.setVersion(relocation.getVersion());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Unable to read POM : ignore.
|
|
||||||
} catch (XmlPullParserException e) {
|
|
||||||
// Invalid POM : ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemSelector applyServerSideRelocation(ManagedRepository managedRepository, ItemSelector artifactSelector)
|
public ItemSelector applyServerSideRelocation(ManagedRepository managedRepository, ItemSelector artifactSelector)
|
||||||
throws ProxyDownloadException {
|
throws ProxyDownloadException {
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.apache.archiva.metadata.repository.MetadataRepository;
|
||||||
import org.apache.archiva.metadata.repository.RepositorySession;
|
import org.apache.archiva.metadata.repository.RepositorySession;
|
||||||
import org.apache.archiva.filter.Filter;
|
import org.apache.archiva.filter.Filter;
|
||||||
import org.apache.archiva.metadata.repository.storage.*;
|
import org.apache.archiva.metadata.repository.storage.*;
|
||||||
import org.apache.archiva.model.ArtifactReference;
|
|
||||||
import org.apache.archiva.policies.ProxyDownloadException;
|
import org.apache.archiva.policies.ProxyDownloadException;
|
||||||
import org.apache.archiva.components.taskqueue.TaskQueueException;
|
import org.apache.archiva.components.taskqueue.TaskQueueException;
|
||||||
import org.apache.archiva.repository.ManagedRepositoryContent;
|
import org.apache.archiva.repository.ManagedRepositoryContent;
|
||||||
|
@ -102,13 +101,6 @@ public class MockBeanServices
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyServerSideRelocation( ManagedRepository managedRepository, ArtifactReference artifact )
|
|
||||||
throws ProxyDownloadException
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemSelector applyServerSideRelocation( ManagedRepository managedRepository, ItemSelector selector ) throws ProxyDownloadException
|
public ItemSelector applyServerSideRelocation( ManagedRepository managedRepository, ItemSelector selector ) throws ProxyDownloadException
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,6 @@ public interface RepositoryPathTranslator
|
||||||
|
|
||||||
StorageAsset toFile( StorageAsset basedir, String namespace, String projectId, String projectVersion );
|
StorageAsset toFile( StorageAsset basedir, String namespace, String projectId, String projectVersion );
|
||||||
|
|
||||||
|
|
||||||
ArtifactMetadata getArtifactForPath( String repoId, String relativePath );
|
ArtifactMetadata getArtifactForPath( String repoId, String relativePath );
|
||||||
|
|
||||||
ArtifactMetadata getArtifactFromId( String repoId, String namespace, String projectId, String projectVersion,
|
ArtifactMetadata getArtifactFromId( String repoId, String namespace, String projectId, String projectVersion,
|
||||||
|
|
|
@ -69,21 +69,7 @@ public interface RepositoryStorage
|
||||||
* For such clients, archiva does server-side relocation by reading itself the <relocation> element in
|
* For such clients, archiva does server-side relocation by reading itself the <relocation> element in
|
||||||
* metadatas and serving the expected artifact.
|
* metadatas and serving the expected artifact.
|
||||||
* @param managedRepository the used managed repository
|
* @param managedRepository the used managed repository
|
||||||
* @param artifact the artifact reference
|
* @param selector the artifact reference
|
||||||
* @throws org.apache.archiva.policies.ProxyDownloadException
|
|
||||||
*/
|
|
||||||
void applyServerSideRelocation( ManagedRepository managedRepository, ArtifactReference artifact )
|
|
||||||
throws ProxyDownloadException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A relocation capable client will request the POM prior to the artifact, and will then read meta-data and do
|
|
||||||
* client side relocation. A simplier client (like maven 1) will only request the artifact and not use the
|
|
||||||
* metadatas.
|
|
||||||
* <p>
|
|
||||||
* For such clients, archiva does server-side relocation by reading itself the <relocation> element in
|
|
||||||
* metadatas and serving the expected artifact.
|
|
||||||
* @param managedRepository the used managed repository
|
|
||||||
* @param artifact the artifact reference
|
|
||||||
* @throws org.apache.archiva.policies.ProxyDownloadException
|
* @throws org.apache.archiva.policies.ProxyDownloadException
|
||||||
*/
|
*/
|
||||||
ItemSelector applyServerSideRelocation( ManagedRepository managedRepository, ItemSelector selector )
|
ItemSelector applyServerSideRelocation( ManagedRepository managedRepository, ItemSelector selector )
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataE
|
||||||
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
|
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
|
||||||
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
|
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
|
||||||
import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
|
import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
|
||||||
import org.apache.archiva.model.ArtifactReference;
|
|
||||||
import org.apache.archiva.policies.ProxyDownloadException;
|
import org.apache.archiva.policies.ProxyDownloadException;
|
||||||
import org.apache.archiva.repository.ManagedRepositoryContent;
|
import org.apache.archiva.repository.ManagedRepositoryContent;
|
||||||
import org.apache.archiva.repository.ManagedRepository;
|
import org.apache.archiva.repository.ManagedRepository;
|
||||||
|
@ -106,13 +105,6 @@ public class MockRepositoryStorage
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyServerSideRelocation( ManagedRepository managedRepository, ArtifactReference artifact )
|
|
||||||
throws ProxyDownloadException
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemSelector applyServerSideRelocation( ManagedRepository managedRepository, ItemSelector selector ) throws ProxyDownloadException
|
public ItemSelector applyServerSideRelocation( ManagedRepository managedRepository, ItemSelector selector ) throws ProxyDownloadException
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue