diff options
author | Martin Stockhammer <martin_s@apache.org> | 2020-06-06 20:02:53 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2020-06-06 20:02:53 +0200 |
commit | 311fe09dd61c4ac09789ed052006395e5df02785 (patch) | |
tree | d98c1baafbac754caecc201271f7e4af9941069f /archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers | |
parent | e9eb36e6ded14e63ccd981a6b7c0472bc7c40f2c (diff) | |
download | archiva-311fe09dd61c4ac09789ed052006395e5df02785.tar.gz archiva-311fe09dd61c4ac09789ed052006395e5df02785.zip |
Refactoring to new content API
Diffstat (limited to 'archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers')
5 files changed, 46 insertions, 43 deletions
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 9c0aeb79e..cbe3dc5a1 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 @@ -24,7 +24,6 @@ import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.consumers.AbstractMonitoredConsumer; import org.apache.archiva.consumers.ConsumerException; 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; @@ -34,6 +33,7 @@ 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.content.Artifact; import org.apache.archiva.repository.metadata.base.MetadataTools; import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.storage.StorageAsset; @@ -174,7 +174,8 @@ public class MetadataUpdaterConsumer { try { - ArtifactReference artifact = repository.toArtifactReference( path ); + BaseRepositoryContentLayout layout = repository.getLayout( BaseRepositoryContentLayout.class ); + Artifact artifact = layout.getArtifact( path ); updateVersionMetadata( artifact, path ); updateProjectMetadata( artifact, path ); } @@ -192,11 +193,11 @@ public class MetadataUpdaterConsumer processFile( path ); } - private void updateProjectMetadata( ArtifactReference artifact, String path ) + private void updateProjectMetadata( Artifact artifact, String path ) { ProjectReference projectRef = new ProjectReference( ); - projectRef.setGroupId( artifact.getGroupId( ) ); - projectRef.setArtifactId( artifact.getArtifactId( ) ); + projectRef.setGroupId( artifact.getNamespace( ).getId() ); + projectRef.setArtifactId( artifact.getId( ) ); try { @@ -221,12 +222,12 @@ public class MetadataUpdaterConsumer } } - private void updateVersionMetadata( ArtifactReference artifact, String path ) + private void updateVersionMetadata( Artifact artifact, String path ) { VersionedReference versionRef = new VersionedReference( ); - versionRef.setGroupId( artifact.getGroupId( ) ); - versionRef.setArtifactId( artifact.getArtifactId( ) ); - versionRef.setVersion( artifact.getVersion( ) ); + versionRef.setGroupId( artifact.getNamespace( ).getId() ); + versionRef.setArtifactId( artifact.getId( ) ); + versionRef.setVersion( artifact.getVersion( ).getId() ); try { 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 72cf81a8d..e676e0b9a 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 @@ -192,8 +192,8 @@ public abstract class AbstractRepositoryPurge Map<String, Collection<ArtifactMetadata>> metaResolved = new HashMap<>( ); for ( Artifact reference : references ) { - String baseVersion = reference.getVersion( ).getVersion( ); - String namespace = reference.getVersion( ).getProject( ).getNamespace( ).getNamespace( ); + String baseVersion = reference.getVersion( ).getId( ); + String namespace = reference.getVersion( ).getProject( ).getNamespace( ).getId( ); // Needed for tracking in the hashmap String metaBaseId = reference.toKey(); @@ -214,7 +214,7 @@ public abstract class AbstractRepositoryPurge for ( RepositoryListener listener : listeners ) { listener.deleteArtifact( metadataRepository, repository.getId( ), namespace, - reference.getId( ), reference.getVersion( ).getVersion(), + reference.getId( ), reference.getVersion( ).getId(), artifactFile.getName( )); } if (reference.exists()) 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 f9dca9999..efa7e3c4c 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 @@ -34,6 +34,7 @@ import org.apache.archiva.repository.BaseRepositoryContentLayout; import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.metadata.audit.RepositoryListener; +import org.apache.archiva.repository.content.Artifact; import org.apache.archiva.repository.content.ItemNotFoundException; import org.apache.archiva.repository.content.ItemSelector; import org.apache.archiva.repository.content.Project; @@ -101,17 +102,18 @@ public class CleanupReleasedSnapshotsRepositoryPurge return; } - ArtifactReference artifactRef = repository.toArtifactReference( path ); + Artifact artifactRef = layout.getArtifact( path ); + // ArtifactReference artifactRef = repository.toArtifactReference( path ); - if ( !VersionUtil.isSnapshot( artifactRef.getVersion( ) ) ) + if ( !VersionUtil.isSnapshot( artifactRef.getVersion().getId( ) ) ) { // Nothing to do here, not a snapshot, skip it. return; } ItemSelector projectSelector = ArchivaItemSelector.builder( ) - .withNamespace( artifactRef.getGroupId( ) ) - .withProjectId( artifactRef.getArtifactId( ) ) + .withNamespace( artifactRef.getNamespace( ).getId() ) + .withProjectId( artifactRef.getId( ) ) .build(); @@ -128,9 +130,9 @@ public class CleanupReleasedSnapshotsRepositoryPurge Project proj = repoContent.getProject( projectSelector ); for ( Version version : repoContent.getVersions( proj ) ) { - if ( !VersionUtil.isSnapshot( version.getVersion() ) ) + if ( !VersionUtil.isSnapshot( version.getId() ) ) { - releasedVersions.add( version.getVersion() ); + releasedVersions.add( version.getId() ); } } } @@ -142,19 +144,19 @@ public class CleanupReleasedSnapshotsRepositoryPurge boolean needsMetadataUpdate = false; VersionedReference versionRef = new VersionedReference( ); - versionRef.setGroupId( artifactRef.getGroupId( ) ); - versionRef.setArtifactId( artifactRef.getArtifactId( ) ); + versionRef.setGroupId( artifactRef.getNamespace( ).getId() ); + versionRef.setArtifactId( artifactRef.getId( ) ); ArchivaItemSelector.Builder versionSelectorBuilder = ArchivaItemSelector.builder( ) - .withNamespace( artifactRef.getGroupId( ) ) - .withProjectId( artifactRef.getArtifactId( ) ) - .withArtifactId( artifactRef.getArtifactId( ) ); + .withNamespace( artifactRef.getNamespace().getId() ) + .withProjectId( artifactRef.getId( ) ) + .withArtifactId( artifactRef.getId( ) ); MetadataRepository metadataRepository = repositorySession.getRepository( ); - if ( releasedVersions.contains( VersionUtil.getReleaseVersion( artifactRef.getVersion( ) ) ) ) + if ( releasedVersions.contains( VersionUtil.getReleaseVersion( artifactRef.getVersion().getId( ) ) ) ) { - ArchivaItemSelector selector = versionSelectorBuilder.withVersion( artifactRef.getVersion( ) ).build( ); + ArchivaItemSelector selector = versionSelectorBuilder.withVersion( artifactRef.getVersion().getId( ) ).build( ); Version version = layout.getVersion( selector ); if (version.exists()) { @@ -162,12 +164,12 @@ public class CleanupReleasedSnapshotsRepositoryPurge } for ( RepositoryListener listener : listeners ) { - listener.deleteArtifact( metadataRepository, repository.getId( ), artifactRef.getGroupId( ), - artifactRef.getArtifactId( ), artifactRef.getVersion( ), + listener.deleteArtifact( metadataRepository, repository.getId( ), artifactRef.getNamespace().getId(), + artifactRef.getId( ), artifactRef.getVersion().getId( ), artifactFile.getName() ); } metadataRepository.removeProjectVersion( repositorySession, repository.getId( ), - artifactRef.getGroupId( ), artifactRef.getArtifactId( ), artifactRef.getVersion( ) ); + artifactRef.getNamespace().getId(), artifactRef.getId( ), artifactRef.getVersion().getId() ); needsMetadataUpdate = true; } @@ -201,16 +203,16 @@ public class CleanupReleasedSnapshotsRepositoryPurge * -> not sure what needs to be changed here. */ @SuppressWarnings( "deprecation" ) - private void updateMetadata( ArtifactReference artifact ) + private void updateMetadata( Artifact artifact ) { VersionedReference versionRef = new VersionedReference( ); - versionRef.setGroupId( artifact.getGroupId( ) ); - versionRef.setArtifactId( artifact.getArtifactId( ) ); - versionRef.setVersion( artifact.getVersion( ) ); + versionRef.setGroupId( artifact.getNamespace().getId( ) ); + versionRef.setArtifactId( artifact.getId( ) ); + versionRef.setVersion( artifact.getVersion().getId( ) ); ProjectReference projectRef = new ProjectReference( ); - projectRef.setGroupId( artifact.getGroupId( ) ); - projectRef.setArtifactId( artifact.getArtifactId( ) ); + projectRef.setGroupId( artifact.getNamespace().getId( ) ); + projectRef.setArtifactId( artifact.getId( ) ); try { 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 7238fd88d..fb42390bb 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 @@ -89,9 +89,9 @@ public class DaysOldRepositoryPurge olderThanThisDate.add( Calendar.DATE, -retentionPeriod ); ArchivaItemSelector selector = ArchivaItemSelector.builder( ) - .withNamespace( artifactItem.getVersion( ).getProject( ).getNamespace( ).getNamespace( ) ) + .withNamespace( artifactItem.getVersion( ).getProject( ).getNamespace( ).getId( ) ) .withProjectId( artifactItem.getVersion( ).getProject( ).getId( ) ) - .withVersion( artifactItem.getVersion( ).getVersion( ) ) + .withVersion( artifactItem.getVersion( ).getId( ) ) .withClassifier( "*" ) .includeRelatedArtifacts( ) .build( ); @@ -116,9 +116,9 @@ public class DaysOldRepositoryPurge ArchivaItemSelector.Builder artifactSelectorBuilder = ArchivaItemSelector.builder( ) - .withNamespace( artifactItem.getVersion( ).getProject( ).getNamespace( ).getNamespace( ) ) + .withNamespace( artifactItem.getVersion( ).getProject( ).getNamespace( ).getId( ) ) .withProjectId( artifactItem.getVersion( ).getProject( ).getId( ) ) - .withVersion( artifactItem.getVersion( ).getVersion( ) ) + .withVersion( artifactItem.getVersion( ).getId( ) ) .withArtifactId( artifactItem.getId() ) .withClassifier( "*" ) .includeRelatedArtifacts( ); 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 be1038009..ec3a242f4 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 @@ -68,13 +68,13 @@ public class RetentionCountRepositoryPurge return; } - if ( VersionUtil.isSnapshot( artifact.getVersion( ).getVersion() ) ) + if ( VersionUtil.isSnapshot( artifact.getVersion( ).getId() ) ) { ArchivaItemSelector selector = ArchivaItemSelector.builder( ) - .withNamespace( artifact.getVersion( ).getProject( ).getNamespace( ).getNamespace( ) ) + .withNamespace( artifact.getVersion( ).getProject( ).getNamespace( ).getId( ) ) .withProjectId( artifact.getVersion( ).getProject( ).getId( ) ) .withArtifactId( artifact.getId( ) ) - .withVersion( artifact.getVersion( ).getVersion( ) ) + .withVersion( artifact.getVersion( ).getId( ) ) .withClassifier( "*" ) .includeRelatedArtifacts() .build( ); @@ -98,12 +98,12 @@ public class RetentionCountRepositoryPurge } ArchivaItemSelector.Builder selectorBuilder = ArchivaItemSelector.builder( ) - .withNamespace( artifact.getVersion( ).getProject( ).getNamespace( ).getNamespace( ) ) + .withNamespace( artifact.getVersion( ).getProject( ).getNamespace( ).getId( ) ) .withProjectId( artifact.getVersion( ).getProject( ).getId( ) ) .withArtifactId( artifact.getId( ) ) .withClassifier( "*" ) .includeRelatedArtifacts() - .withVersion( artifact.getVersion( ).getVersion( ) ); + .withVersion( artifact.getVersion( ).getId( ) ); int countToPurge = versions.size( ) - retentionCount; Set<Artifact> artifactsToDelete = new HashSet<>( ); for ( String version : versions ) |