diff options
author | Martin Stockhammer <martin_s@apache.org> | 2020-05-30 19:58:46 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2020-05-30 20:00:22 +0200 |
commit | 6d7a510dea283ff8c4b1e6ae54a395dbe386e4a5 (patch) | |
tree | 706add65520704a887961e65c5d2b7d31ac34e46 /archiva-modules/archiva-base/archiva-consumers | |
parent | ac25c7a86fe77f5b0f005f03d9d28dc1f6f8580e (diff) | |
download | archiva-6d7a510dea283ff8c4b1e6ae54a395dbe386e4a5.tar.gz archiva-6d7a510dea283ff8c4b1e6ae54a395dbe386e4a5.zip |
Refactoring of content interfaces. Adding layout for repository content.
Diffstat (limited to 'archiva-modules/archiva-base/archiva-consumers')
8 files changed, 36 insertions, 61 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/main/java/SimpleArtifactConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/main/java/SimpleArtifactConsumer.java index 381e6a2aa..bf2faa947 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/main/java/SimpleArtifactConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/main/java/SimpleArtifactConsumer.java @@ -31,9 +31,10 @@ import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.components.registry.Registry; import org.apache.archiva.components.registry.RegistryListener; +import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.ManagedRepository; -import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.BaseRepositoryContentLayout; import org.apache.archiva.repository.RepositoryContentFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -124,7 +125,8 @@ public class SimpleArtifactConsumer try { ManagedRepositoryContent repositoryContent = repository.getContent(); - ArtifactReference artifact = repositoryContent.toArtifactReference( path ); + BaseRepositoryContentLayout layout = repositoryContent.getLayout( BaseRepositoryContentLayout.class ); + ArtifactReference artifact = layout.toArtifactReference( path ); repositorySession.getRepository().getArtifacts( repositorySession, repository.getId(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java index 66bfc4a30..f7f9ef730 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java @@ -27,14 +27,16 @@ import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.ProjectReference; import org.apache.archiva.model.VersionedReference; +import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.ManagedRepository; -import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.BaseRepositoryContentLayout; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryNotFoundException; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.metadata.base.MetadataTools; import org.apache.archiva.repository.metadata.RepositoryMetadataException; +import org.apache.archiva.repository.storage.StorageAsset; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Scope; @@ -42,10 +44,6 @@ import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import javax.inject.Inject; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -90,7 +88,7 @@ public class MetadataUpdaterConsumer private ManagedRepositoryContent repository; - private Path repositoryDir; + private StorageAsset repositoryDir; private List<String> includes = new ArrayList<>( 0 ); @@ -127,7 +125,7 @@ public class MetadataUpdaterConsumer if (this.repository==null) { throw new RepositoryNotFoundException( "Repository content not found: "+repoConfig.getId() ); } - this.repositoryDir = Paths.get( repository.getRepoRoot( ) ); + this.repositoryDir = repository.getRepository().getAsset( "" ); this.scanStartTimestamp = System.currentTimeMillis( ); } catch ( RepositoryException e ) @@ -176,7 +174,7 @@ public class MetadataUpdaterConsumer { try { - ArtifactReference artifact = repository.toArtifactReference( path ); + ArtifactReference artifact = repository.getLayout( BaseRepositoryContentLayout.class ).toArtifactReference( path ); updateVersionMetadata( artifact, path ); updateProjectMetadata( artifact, path ); } @@ -204,9 +202,9 @@ public class MetadataUpdaterConsumer { String metadataPath = this.metadataTools.toPath( projectRef ); - Path projectMetadata = this.repositoryDir.resolve( metadataPath ); + StorageAsset projectMetadata = this.repositoryDir.resolve( metadataPath ); - if ( Files.exists(projectMetadata) && ( Files.getLastModifiedTime( projectMetadata).toMillis() >= this.scanStartTimestamp ) ) + if ( projectMetadata.exists() && ( projectMetadata.getModificationTime().toEpochMilli() >= this.scanStartTimestamp ) ) { // This metadata is up to date. skip it. log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( projectRef ) ); @@ -221,12 +219,6 @@ public class MetadataUpdaterConsumer triggerConsumerError( TYPE_METADATA_WRITE_FAILURE, "Unable to write project metadata for artifact [" + path + "]: " + e.getMessage( ) ); } - catch ( IOException e ) - { - log.warn( "Project metadata not written due to IO warning: ", e ); - triggerConsumerWarning( TYPE_METADATA_IO, - "Project metadata not written due to IO warning: " + e.getMessage( ) ); - } } private void updateVersionMetadata( ArtifactReference artifact, String path ) @@ -240,9 +232,9 @@ public class MetadataUpdaterConsumer { String metadataPath = this.metadataTools.toPath( versionRef ); - Path projectMetadata = this.repositoryDir.resolve( metadataPath ); + StorageAsset projectMetadata = this.repositoryDir.resolve( metadataPath ); - if ( Files.exists(projectMetadata) && ( Files.getLastModifiedTime( projectMetadata ).toMillis() >= this.scanStartTimestamp ) ) + if ( projectMetadata.exists() && ( projectMetadata.getModificationTime().toEpochMilli() >= this.scanStartTimestamp ) ) { // This metadata is up to date. skip it. log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( versionRef ) ); @@ -258,12 +250,6 @@ public class MetadataUpdaterConsumer triggerConsumerError( TYPE_METADATA_WRITE_FAILURE, "Unable to write version metadata for artifact [" + path + "]: " + e.getMessage( ) ); } - catch ( IOException e ) - { - log.warn( "Version metadata not written due to IO warning: ", e ); - triggerConsumerWarning( TYPE_METADATA_IO, - "Version metadata not written due to IO warning: " + e.getMessage( ) ); - } } /* diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java index f2384ace5..72cf81a8d 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java @@ -24,10 +24,8 @@ import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.facets.AuditEvent; import org.apache.archiva.metadata.maven.model.MavenArtifactFacet; import org.apache.archiva.metadata.repository.*; -import org.apache.archiva.model.ArtifactReference; -import org.apache.archiva.repository.ContentNotFoundException; -import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.metadata.audit.RepositoryListener; +import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.content.Artifact; import org.apache.archiva.repository.content.ItemNotFoundException; import org.apache.archiva.repository.storage.StorageAsset; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java index b7f590e35..5142ed94c 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java @@ -28,10 +28,10 @@ import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.ProjectReference; import org.apache.archiva.model.VersionedReference; import org.apache.archiva.repository.ContentNotFoundException; -import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.LayoutException; +import org.apache.archiva.repository.BaseRepositoryContentLayout; import org.apache.archiva.repository.ReleaseScheme; -import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.metadata.audit.RepositoryListener; import org.apache.archiva.repository.content.ItemSelector; @@ -40,11 +40,9 @@ import org.apache.archiva.repository.content.Version; 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.StorageAsset; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -93,15 +91,16 @@ public class CleanupReleasedSnapshotsRepositoryPurge { try { - Path artifactFile = Paths.get( repository.getRepoRoot( ), path ); + StorageAsset artifactFile = repository.getRepository( ).getAsset( "" ).resolve( path ); + BaseRepositoryContentLayout layout = repository.getLayout( BaseRepositoryContentLayout.class ); - if ( !Files.exists(artifactFile) ) + if ( !artifactFile.exists() ) { // Nothing to do here, file doesn't exist, skip it. return; } - ArtifactReference artifactRef = repository.toArtifactReference( path ); + ArtifactReference artifactRef = repository.getLayout( BaseRepositoryContentLayout.class ).toArtifactReference( path ); if ( !VersionUtil.isSnapshot( artifactRef.getVersion( ) ) ) { @@ -124,7 +123,7 @@ public class CleanupReleasedSnapshotsRepositoryPurge if ( repo.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE )) { - ManagedRepositoryContent repoContent = repo.getContent(); + BaseRepositoryContentLayout repoContent = repo.getContent().getLayout( BaseRepositoryContentLayout.class ); Project proj = repoContent.getProject( selector ); for ( Version version : repoContent.getVersions( proj ) ) { @@ -150,13 +149,13 @@ public class CleanupReleasedSnapshotsRepositoryPurge if ( releasedVersions.contains( VersionUtil.getReleaseVersion( artifactRef.getVersion( ) ) ) ) { versionRef.setVersion( artifactRef.getVersion( ) ); - repository.deleteVersion( versionRef ); + layout.deleteVersion( versionRef ); for ( RepositoryListener listener : listeners ) { listener.deleteArtifact( metadataRepository, repository.getId( ), artifactRef.getGroupId( ), artifactRef.getArtifactId( ), artifactRef.getVersion( ), - artifactFile.getFileName().toString() ); + artifactFile.getName() ); } metadataRepository.removeProjectVersion( repositorySession, repository.getId( ), artifactRef.getGroupId( ), artifactRef.getArtifactId( ), artifactRef.getVersion( ) ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java index 7e6159307..7238fd88d 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java @@ -23,15 +23,12 @@ import org.apache.archiva.common.utils.VersionComparator; import org.apache.archiva.common.utils.VersionUtil; import org.apache.archiva.metadata.audit.RepositoryListener; import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.model.ArtifactReference; -import org.apache.archiva.repository.ContentNotFoundException; -import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.LayoutException; +import org.apache.archiva.repository.BaseRepositoryContentLayout; import org.apache.archiva.repository.content.Artifact; import org.apache.archiva.repository.content.ContentItem; -import org.apache.archiva.repository.content.ItemNotFoundException; import org.apache.archiva.repository.content.base.ArchivaItemSelector; -import org.apache.archiva.repository.storage.StorageAsset; import org.apache.commons.lang3.StringUtils; import java.text.ParseException; @@ -100,7 +97,7 @@ public class DaysOldRepositoryPurge .build( ); List<String> artifactVersions; - try( Stream<? extends Artifact> stream = repository.newArtifactStream( selector )){ + try( Stream<? extends Artifact> stream = repository.getLayout( BaseRepositoryContentLayout.class ).newArtifactStream( selector )){ artifactVersions = stream.map( a -> a.getArtifactVersion( ) ) .filter( StringUtils::isNotEmpty ) .distinct() @@ -142,7 +139,7 @@ public class DaysOldRepositoryPurge // Is this a generic snapshot "1.0-SNAPSHOT" ? if ( VersionUtil.isGenericSnapshot( version ) ) { - List<? extends Artifact> artifactList = repository.getArtifacts( artifactSelector ); + List<? extends Artifact> artifactList = repository.getLayout( BaseRepositoryContentLayout.class ).getArtifacts( artifactSelector ); if ( artifactList.size()>0 && artifactList.get(0).getAsset().getModificationTime( ).toEpochMilli( ) < olderThanThisDate.getTimeInMillis( ) ) { artifactsToDelete.addAll( artifactList ); @@ -155,7 +152,7 @@ public class DaysOldRepositoryPurge if ( timestampCal.getTimeInMillis( ) < olderThanThisDate.getTimeInMillis( ) ) { - artifactsToDelete.addAll( repository.getArtifacts( artifactSelector ) ); + artifactsToDelete.addAll( repository.getLayout( BaseRepositoryContentLayout.class ).getArtifacts( artifactSelector ) ); } } } catch ( IllegalArgumentException e ) { diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java index 248e96d4b..24779a77e 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java @@ -29,8 +29,8 @@ import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.components.registry.Registry; import org.apache.archiva.components.registry.RegistryListener; -import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.RepositoryContentFactory; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.metadata.audit.RepositoryListener; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java index 3a4ae7ce9..be1038009 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java @@ -23,22 +23,15 @@ import org.apache.archiva.common.utils.VersionComparator; import org.apache.archiva.common.utils.VersionUtil; import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.model.ArtifactReference; -import org.apache.archiva.model.VersionedReference; -import org.apache.archiva.repository.ContentNotFoundException; -import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.LayoutException; +import org.apache.archiva.repository.BaseRepositoryContentLayout; import org.apache.archiva.metadata.audit.RepositoryListener; import org.apache.archiva.repository.content.Artifact; import org.apache.archiva.repository.content.ContentItem; -import org.apache.archiva.repository.content.ItemSelector; -import org.apache.archiva.repository.content.Version; import org.apache.archiva.repository.content.base.ArchivaItemSelector; import org.apache.commons.lang3.StringUtils; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -88,7 +81,7 @@ public class RetentionCountRepositoryPurge List<String> versions; - try( Stream<? extends Artifact> stream = repository.newArtifactStream( selector) ){ + try( Stream<? extends Artifact> stream = repository.getLayout( BaseRepositoryContentLayout.class ).newArtifactStream( selector) ){ versions = stream.map( a -> a.getArtifactVersion( ) ) .filter( StringUtils::isNotEmpty ) .distinct() @@ -119,7 +112,7 @@ public class RetentionCountRepositoryPurge { break; } - List<? extends Artifact> delArtifacts = repository.getArtifacts( selectorBuilder.withArtifactVersion( version ).build( ) ); + List<? extends Artifact> delArtifacts = repository.getLayout( BaseRepositoryContentLayout.class ).getArtifacts( selectorBuilder.withArtifactVersion( version ).build( ) ); if (delArtifacts!=null && delArtifacts.size()>0) { artifactsToDelete.addAll( delArtifacts ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java index d860f7c2b..cfcd19efe 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java @@ -23,9 +23,9 @@ import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySessionFactory; +import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.maven.metadata.storage.Maven2RepositoryPathTranslator; import org.apache.archiva.repository.base.BasicManagedRepository; -import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryContentProvider; import org.apache.archiva.metadata.audit.RepositoryListener; |