From: Martin Stockhammer Date: Tue, 2 Jun 2020 20:53:18 +0000 (+0200) Subject: Switching to new repository layout X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=873753536bbc1cd1639016ae845625f631f3cff1;p=archiva.git Switching to new repository layout --- diff --git a/archiva-modules/archiva-base/archiva-model/src/main/java/org/apache/archiva/model/ArtifactReference.java b/archiva-modules/archiva-base/archiva-model/src/main/java/org/apache/archiva/model/ArtifactReference.java index 93173773f..ebed7c494 100644 --- a/archiva-modules/archiva-base/archiva-model/src/main/java/org/apache/archiva/model/ArtifactReference.java +++ b/archiva-modules/archiva-base/archiva-model/src/main/java/org/apache/archiva/model/ArtifactReference.java @@ -69,6 +69,19 @@ public class ArtifactReference private String type; + public String getProjectVersion( ) + { + return projectVersion; + } + + public void setProjectVersion( String projectVersion ) + { + this.projectVersion = projectVersion; + } + + private String projectVersion; + + //-----------/ //- Methods -/ //-----------/ diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java index e5c0b4b0d..d01058116 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java @@ -49,6 +49,9 @@ import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.RemoteRepository; import org.apache.archiva.repository.RemoteRepositoryContent; import org.apache.archiva.repository.RepositoryType; +import org.apache.archiva.repository.content.Artifact; +import org.apache.archiva.repository.content.ItemSelector; +import org.apache.archiva.repository.content.base.ArchivaItemSelector; import org.apache.archiva.repository.metadata.base.MetadataTools; import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.storage.fs.FilesystemStorage; @@ -418,7 +421,15 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa private StorageAsset toLocalFile(ManagedRepository repository, ArtifactReference artifact ) throws LayoutException { - return repository.getContent().getLayout( BaseRepositoryContentLayout.class ).toFile( artifact ); + ItemSelector selector = ArchivaItemSelector.builder( ) + .withNamespace( artifact.getGroupId( ) ) + .withProjectId( artifact.getArtifactId( ) ) + .withArtifactId( artifact.getArtifactId( ) ) + .withArtifactVersion( artifact.getVersion() ) + .withVersion( artifact.getProjectVersion( ) ) + .withType( artifact.getType( ) ).build(); + Artifact repoArtifact = repository.getContent( ).getLayout( BaseRepositoryContentLayout.class ).getArtifact( selector ); + return repoArtifact.getAsset( ); } /** diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java index e15bbfb1d..291e0a914 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java @@ -34,8 +34,7 @@ import java.nio.file.Paths; import java.nio.file.attribute.FileTime; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * SnapshotTransferTest @@ -314,6 +313,7 @@ public class SnapshotTransferTest StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path); + assertNotNull( downloadedFile ); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile ); assertNoTempFiles( expectedFile ); } @@ -333,6 +333,7 @@ public class SnapshotTransferTest BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); + artifact.setProjectVersion( "1.0-SNAPSHOT" ); assertTrue( Files.exists(expectedFile) ); @@ -344,6 +345,7 @@ public class SnapshotTransferTest StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path); + assertNotNull( downloadedFile ); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile ); assertNoTempFiles( expectedFile ); } diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java index e49c913c7..970645139 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java @@ -36,6 +36,7 @@ import org.apache.archiva.repository.content.ItemSelector; import org.apache.archiva.repository.content.Namespace; import org.apache.archiva.repository.content.Project; import org.apache.archiva.repository.content.Version; +import org.apache.archiva.repository.content.base.ArchivaArtifact; import org.apache.archiva.repository.content.base.ArchivaContentItem; import org.apache.archiva.repository.content.base.ArchivaDataItem; import org.apache.archiva.repository.content.base.ArchivaNamespace; @@ -173,7 +174,15 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout @Override public Artifact getArtifact( ItemSelector selector ) throws ContentAccessException { - return null; + StringBuilder path = new StringBuilder(selector.getNamespace( ).replace( ".", "/" )); + path.append( "/" ).append( selector.getProjectId( ) ).append( "/" ).append( selector.getVersion( ) ); + path.append( "/" ).append( selector.getArtifactId( ) ).append( "-" ).append( selector.getArtifactVersion( ) ).append( "." ).append( selector.getType( ) ); + StorageAsset asset = fsStorage.getAsset( path.toString( ) ); + ArchivaNamespace ns = ArchivaNamespace.withRepository( repository.getContent( ) ).withAsset( asset.getParent( ).getParent( ).getParent( ) ).withNamespace( selector.getNamespace( ) ).build( ); + ArchivaProject project = ArchivaProject.withRepository( repository.getContent( ) ).withAsset( asset.getParent( ).getParent( ) ).withNamespace( ns ).withId( selector.getProjectId( ) ).build( ); + ArchivaVersion version = ArchivaVersion.withRepository( repository.getContent( ) ).withAsset( asset.getParent( ) ).withProject( project ).withVersion( selector.getVersion( ) ).build( ); + ArchivaArtifact artifact = ArchivaArtifact.withAsset( asset ).withVersion( version ).withId( selector.getArtifactId( ) ).withArtifactVersion( selector.getArtifactVersion( ) ).withType( selector.getType( ) ).build( ); + return artifact; } @Override @@ -424,6 +433,7 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout 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 ) { 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 4754f1360..f37910744 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 @@ -79,6 +79,7 @@ public class DefaultPathParser 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 ) { 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 552e766a9..bcda250eb 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 @@ -39,7 +39,10 @@ import org.apache.archiva.proxy.model.NetworkProxy; import org.apache.archiva.proxy.model.ProxyConnector; import org.apache.archiva.proxy.model.RepositoryProxyHandler; import org.apache.archiva.repository.*; +import org.apache.archiva.repository.content.Artifact; +import org.apache.archiva.repository.content.ItemSelector; import org.apache.archiva.repository.content.PathParser; +import org.apache.archiva.repository.content.base.ArchivaItemSelector; import org.apache.archiva.repository.maven.MavenSystemManager; import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.storage.StorageAsset; @@ -572,28 +575,39 @@ public class Maven2RepositoryStorage 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 - StorageAsset pom = null; - try - { - pom = managedRepository.getContent().getLayout( BaseRepositoryContentLayout.class ).toFile(pomReference); - } - catch ( LayoutException e ) - { - throw new ProxyDownloadException( "Cannot convert layout ", new HashMap<>( ) ); - } if (!pom.exists()) { return; @@ -603,7 +617,7 @@ public class Maven2RepositoryStorage // MavenXpp3Reader leaves the file open, so we need to close it ourselves. Model model; - try (Reader reader = Channels.newReader(pom.getReadChannel(), Charset.defaultCharset().name())) { + try (Reader reader = Channels.newReader(pom.getAsset().getReadChannel(), Charset.defaultCharset().name())) { model = MAVEN_XPP_3_READER.read(reader); } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactBuilder.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactBuilder.java index b6fee0864..6b48247ba 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactBuilder.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactBuilder.java @@ -25,8 +25,11 @@ import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.repository.BaseRepositoryContentLayout; import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.LayoutException; +import org.apache.archiva.repository.content.ItemSelector; +import org.apache.archiva.repository.content.base.ArchivaItemSelector; import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.repository.storage.util.StorageUtil; +import org.apache.commons.lang3.StringUtils; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; @@ -65,11 +68,6 @@ public class ArtifactBuilder public Artifact build() { - ArtifactReference ref = new ArtifactReference(); - ref.setArtifactId( artifactMetadata.getProject() ); - ref.setGroupId( artifactMetadata.getNamespace() ); - ref.setVersion( artifactMetadata.getVersion() ); - String type = null, classifier = null; MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID ); @@ -79,8 +77,20 @@ public class ArtifactBuilder classifier = facet.getClassifier(); } - ref.setClassifier( classifier ); - ref.setType( type ); + ArchivaItemSelector.Builder selectorBuilder = ArchivaItemSelector.builder( ) + .withNamespace( artifactMetadata.getNamespace( ) ) + .withProjectId( artifactMetadata.getProject( ) ) + .withVersion( artifactMetadata.getProjectVersion( ) ) + .withArtifactId( artifactMetadata.getProject( ) ) + .withArtifactVersion( artifactMetadata.getVersion( ) ); + if (StringUtils.isNotEmpty( type ) ) { + selectorBuilder.withType( type ); + } + if (StringUtils.isNotEmpty( classifier )) { + selectorBuilder.withClassifier( classifier ); + } + + BaseRepositoryContentLayout layout; try { @@ -90,17 +100,17 @@ public class ArtifactBuilder { throw new RuntimeException( "Could not convert to layout " + e.getMessage( ) ); } - StorageAsset file = layout.toFile( ref ); + org.apache.archiva.repository.content.Artifact repoArtifact = layout.getArtifact( selectorBuilder.build( ) ); + + String extension = repoArtifact.getExtension(); - String extension = getExtensionFromFile(file); - - Artifact artifact = new Artifact( ref.getGroupId(), ref.getArtifactId(), ref.getVersion() ); + Artifact artifact = new Artifact( repoArtifact.getVersion( ).getProject( ).getNamespace( ).getNamespace( ), repoArtifact.getId( ), repoArtifact.getArtifactVersion( ) ); artifact.setRepositoryId( artifactMetadata.getRepositoryId() ); artifact.setClassifier( classifier ); artifact.setPackaging( type ); artifact.setType( type ); artifact.setFileExtension( extension ); - artifact.setPath( managedRepositoryContent.toPath( ref ) ); + artifact.setPath( managedRepositoryContent.toPath( repoArtifact ) ); // TODO: find a reusable formatter for this double s = this.artifactMetadata.getSize(); String symbol = "b"; @@ -125,7 +135,7 @@ public class ArtifactBuilder DecimalFormat df = new DecimalFormat( "#,###.##", new DecimalFormatSymbols( Locale.US ) ); artifact.setSize( df.format( s ) + " " + symbol ); - artifact.setId( ref.getArtifactId() + "-" + ref.getVersion() + "." + ref.getType() ); + artifact.setId( repoArtifact.getId() + "-" + repoArtifact.getArtifactVersion() + "." + repoArtifact.getType() ); return artifact; diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java index c4d9c1b46..993935519 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java @@ -35,6 +35,7 @@ import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.configuration.RepositoryGroupConfiguration; import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.maven.content.MavenContentHelper; import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider; import org.apache.archiva.proxy.ProxyRegistry; import org.apache.archiva.repository.EditableManagedRepository; @@ -68,6 +69,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; +import javax.inject.Named; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -141,6 +143,9 @@ public class ArchivaDavResourceFactoryTest @Inject ProxyRegistry proxyRegistry; + @Inject + @Named( "MavenContentHelper" ) + MavenContentHelper mavenContentHelper; @Inject DefaultRepositoryGroupAdmin defaultRepositoryGroupAdmin; @@ -255,11 +260,12 @@ public class ArchivaDavResourceFactoryTest throws RepositoryAdminException { org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( repoId ); - ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent(repo, artifactMappingProviders, fileTypes, fileLockManager); + ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent(repo, artifactMappingProviders, fileTypes, fileLockManager); if (repo!=null && repo instanceof EditableManagedRepository) { ( (EditableManagedRepository) repo ).setContent( repoContent ); } + repoContent.setMavenContentHelper( mavenContentHelper ); return repoContent; }