From 22a8cbfd22c8cfb33a8d4e3e82cf22a7c03df68b Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Tue, 2 Jun 2020 16:33:20 +0200 Subject: Switching to layout interface --- .../repository/BaseRepositoryContentLayout.java | 25 ---------------- .../mock/ManagedRepositoryContentMock.java | 19 ------------ .../scanner/mock/ManagedRepositoryContentMock.java | 19 ------------ .../mock/ManagedRepositoryContentMock.java | 19 ------------ .../content/ManagedDefaultRepositoryContent.java | 34 ---------------------- .../archiva/webdav/ArchivaDavResourceFactory.java | 13 +++++---- 6 files changed, 8 insertions(+), 121 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java index 20a9577ff..bd1e2933c 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java @@ -386,23 +386,6 @@ public interface BaseRepositoryContentLayout extends ManagedRepositoryContentLay */ String getRepoRoot(); - /** - * Determines if the artifact referenced exists in the repository. - * - * @param reference the artifact reference to check for. - * @return true if the artifact referenced exists. - */ - boolean hasContent( ArtifactReference reference ) throws ContentAccessException; - - /** - * Determines if the version reference exists in the repository. - * - * @param reference the version reference to check for. - * @return true if the version referenced exists. - */ - boolean hasContent( VersionedReference reference ) throws ContentAccessException; - - /** * Given an {@link ArtifactReference}, return the file reference to the artifact. @@ -420,13 +403,5 @@ public interface BaseRepositoryContentLayout extends ManagedRepositoryContentLay */ StorageAsset toFile( ArtifactReference reference ); - /** - * Given an {@link ArchivaArtifact}, return the file reference to the artifact. - * - * @param reference the archiva artifact to use. - * @return the relative path to the artifact. - */ - StorageAsset toFile( ArchivaArtifact reference ); - } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java index 16c83a7af..ae32b0ee9 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java @@ -19,7 +19,6 @@ package org.apache.archiva.repository.mock; * under the License. */ -import org.apache.archiva.model.ArchivaArtifact; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.ProjectReference; import org.apache.archiva.model.VersionedReference; @@ -375,18 +374,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout return repository; } - @Override - public boolean hasContent( ArtifactReference reference ) throws ContentAccessException - { - return false; - } - - @Override - public boolean hasContent( VersionedReference reference ) throws ContentAccessException - { - return false; - } - @Override public void setRepository( ManagedRepository repo ) { @@ -411,12 +398,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout return null; } - @Override - public StorageAsset toFile( ArchivaArtifact reference ) - { - return null; - } - @Override public String toPath( ArtifactReference reference ) { diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java index ab42866bb..604c70b21 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java @@ -23,7 +23,6 @@ import org.apache.archiva.common.filelock.DefaultFileLockManager; import org.apache.archiva.common.utils.VersionUtil; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.maven.model.MavenArtifactFacet; -import org.apache.archiva.model.ArchivaArtifact; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.ProjectReference; import org.apache.archiva.model.VersionedReference; @@ -385,18 +384,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout return repository; } - @Override - public boolean hasContent( ArtifactReference reference ) throws ContentAccessException - { - return false; - } - - @Override - public boolean hasContent( VersionedReference reference ) throws ContentAccessException - { - return false; - } - @Override public void setRepository( ManagedRepository repo ) { @@ -604,12 +591,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout return getRepoRootAsset().resolve(refs.get(reference)); } - @Override - public StorageAsset toFile( ArchivaArtifact reference ) - { - return null; - } - private String formatAsDirectory( String directory ) { return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR ); 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 623bf8c67..e49c913c7 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 @@ -23,7 +23,6 @@ import org.apache.archiva.common.filelock.DefaultFileLockManager; import org.apache.archiva.common.utils.VersionUtil; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.maven.model.MavenArtifactFacet; -import org.apache.archiva.model.ArchivaArtifact; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.ProjectReference; import org.apache.archiva.model.VersionedReference; @@ -397,18 +396,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout return repository; } - @Override - public boolean hasContent( ArtifactReference reference ) throws ContentAccessException - { - return false; - } - - @Override - public boolean hasContent( VersionedReference reference ) throws ContentAccessException - { - return false; - } - @Override public void setRepository( ManagedRepository repo ) { @@ -616,12 +603,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout return getRepoRootAsset().resolve( refs.get(reference)); } - @Override - public StorageAsset toFile( ArchivaArtifact reference ) - { - return null; - } - private String formatAsDirectory( String directory ) { return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR ); diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java index 91657ce09..032c531d7 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java @@ -20,11 +20,9 @@ package org.apache.archiva.repository.maven.content; import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.common.utils.FileUtils; -import org.apache.archiva.common.utils.VersionUtil; import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.metadata.maven.MavenMetadataReader; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; -import org.apache.archiva.model.ArchivaArtifact; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.ProjectReference; import org.apache.archiva.model.VersionedReference; @@ -1624,32 +1622,6 @@ public class ManagedDefaultRepositoryContent return repository; } - @Override - public boolean hasContent( ArtifactReference reference ) throws ContentAccessException - { - StorageAsset artifactFile = toFile( reference ); - return artifactFile.exists( ) && !artifactFile.isContainer( ); - } - - @Override - public boolean hasContent( VersionedReference reference ) throws ContentAccessException - { - try - { - return ( getFirstArtifact( reference ) != null ); - } - catch ( LayoutException | ContentNotFoundException e ) - { - return false; - } - catch ( IOException e ) - { - String path = toPath( reference ); - log.error( "Could not read directory from repository {} - {}: ", getId( ), path, e.getMessage( ), e ); - throw new ContentAccessException( "Could not read path from repository " + getId( ) + ": " + path, e ); - } - } - @Override public void setRepository( final ManagedRepository repo ) { @@ -1723,12 +1695,6 @@ public class ManagedDefaultRepositoryContent return repository.getAsset( toPath( reference ) ); } - @Override - public StorageAsset toFile( ArchivaArtifact reference ) - { - return repository.getAsset( toPath( reference ) ); - } - @Override public StorageAsset toFile( VersionedReference reference ) { diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java index f10286339..fcc9c844b 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java @@ -66,6 +66,8 @@ import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryGroup; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.RepositoryRequestInfo; +import org.apache.archiva.repository.content.Artifact; +import org.apache.archiva.repository.content.ContentItem; import org.apache.archiva.repository.storage.fs.FilesystemStorage; import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.metadata.audit.AuditListener; @@ -647,16 +649,17 @@ public class ArchivaDavResourceFactory if ( managedRepositoryContent.getRepository().getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE ) && !repositoryRequestInfo.isMetadata( resourcePath ) && !repositoryRequestInfo.isSupportFile( resourcePath ) ) { - ArtifactReference artifact = null; + // ArtifactReference artifact = null; + Artifact artifact = null; try { BaseRepositoryContentLayout layout = managedRepositoryContent.getLayout( BaseRepositoryContentLayout.class ); - artifact = managedRepositoryContent.toArtifactReference( resourcePath ); - - if ( !VersionUtil.isSnapshot( artifact.getVersion() ) ) + ContentItem artifactItem = managedRepositoryContent.toItem( resourcePath ); + artifact = layout.adaptItem( Artifact.class, artifactItem ); + if ( !VersionUtil.isSnapshot( artifact.getVersion().getVersion() ) ) { // check if artifact already exists and if artifact re-deployment to the repository is allowed - if ( layout.hasContent( artifact ) + if ( artifactItem.exists() && managedRepositoryContent.getRepository().blocksRedeployments()) { log.warn( "Overwriting released artifacts in repository '{}' is not allowed.", -- cgit v1.2.3