From bf95aca967b54c7b0fa24b52a038b5c4256947bb Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Thu, 11 Jun 2020 16:50:11 +0200 Subject: [PATCH] Switching pathparser to new API --- .../repository/content/PathParser.java | 10 --- .../maven/content/DefaultPathParser.java | 40 --------- .../storage/Maven2RepositoryStorage.java | 82 ------------------- .../security/mock/MockBeanServices.java | 8 -- .../storage/RepositoryPathTranslator.java | 1 - .../repository/storage/RepositoryStorage.java | 16 +--- .../cassandra/MockRepositoryStorage.java | 8 -- 7 files changed, 1 insertion(+), 164 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/PathParser.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/PathParser.java index f72ca2b72..28f1018c1 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/PathParser.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/PathParser.java @@ -28,16 +28,6 @@ import org.apache.archiva.repository.LayoutException; 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. diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/DefaultPathParser.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/DefaultPathParser.java index f37910744..3418e0cc2 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/DefaultPathParser.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/DefaultPathParser.java @@ -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.DefaultArtifactMappingProvider; 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.content.ItemSelector; import org.apache.archiva.repository.content.PathParser; @@ -51,45 +50,6 @@ public class DefaultPathParser private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator( Collections.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 public ItemSelector toItemSelector( String path ) throws LayoutException { diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java index 8c4023dc5..70c967dd8 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java @@ -30,7 +30,6 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.facets.RepositoryProblemFacet; import org.apache.archiva.metadata.repository.storage.*; import org.apache.archiva.model.ArchivaRepositoryMetadata; -import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.SnapshotVersion; import org.apache.archiva.policies.ProxyDownloadException; import org.apache.archiva.proxy.ProxyRegistry; @@ -564,87 +563,6 @@ public class Maven2RepositoryStorage 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 public ItemSelector applyServerSideRelocation(ManagedRepository managedRepository, ItemSelector artifactSelector) throws ProxyDownloadException { diff --git a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/mock/MockBeanServices.java b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/mock/MockBeanServices.java index edb686bff..b2d445e06 100644 --- a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/mock/MockBeanServices.java +++ b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/mock/MockBeanServices.java @@ -25,7 +25,6 @@ import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.filter.Filter; import org.apache.archiva.metadata.repository.storage.*; -import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.policies.ProxyDownloadException; import org.apache.archiva.components.taskqueue.TaskQueueException; import org.apache.archiva.repository.ManagedRepositoryContent; @@ -102,13 +101,6 @@ public class MockBeanServices return null; } - @Override - public void applyServerSideRelocation( ManagedRepository managedRepository, ArtifactReference artifact ) - throws ProxyDownloadException - { - - } - @Override public ItemSelector applyServerSideRelocation( ManagedRepository managedRepository, ItemSelector selector ) throws ProxyDownloadException { diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java index 6b135fda2..1d84a82dd 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java @@ -42,7 +42,6 @@ public interface RepositoryPathTranslator StorageAsset toFile( StorageAsset basedir, String namespace, String projectId, String projectVersion ); - ArtifactMetadata getArtifactForPath( String repoId, String relativePath ); ArtifactMetadata getArtifactFromId( String repoId, String namespace, String projectId, String projectVersion, diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryStorage.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryStorage.java index e56311506..44a4fa764 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryStorage.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryStorage.java @@ -60,20 +60,6 @@ public interface RepositoryStorage // FIXME: reconsider this API, do we want to expose storage format in the form of a path? ArtifactMetadata readArtifactMetadataFromPath( String repoId, String path ) throws RepositoryStorageRuntimeException; - - /** - * 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. - *

- * 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 - */ - 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 @@ -83,7 +69,7 @@ public interface RepositoryStorage * 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 + * @param selector the artifact reference * @throws org.apache.archiva.policies.ProxyDownloadException */ ItemSelector applyServerSideRelocation( ManagedRepository managedRepository, ItemSelector selector ) diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/MockRepositoryStorage.java b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/MockRepositoryStorage.java index d320ecbb4..5c82f6ee5 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/MockRepositoryStorage.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/MockRepositoryStorage.java @@ -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.RepositoryStorageMetadataNotFoundException; import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException; -import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.policies.ProxyDownloadException; import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.ManagedRepository; @@ -106,13 +105,6 @@ public class MockRepositoryStorage return null; } - @Override - public void applyServerSideRelocation( ManagedRepository managedRepository, ArtifactReference artifact ) - throws ProxyDownloadException - { - - } - @Override public ItemSelector applyServerSideRelocation( ManagedRepository managedRepository, ItemSelector selector ) throws ProxyDownloadException { -- 2.39.5