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 | |
parent | e9eb36e6ded14e63ccd981a6b7c0472bc7c40f2c (diff) | |
download | archiva-311fe09dd61c4ac09789ed052006395e5df02785.tar.gz archiva-311fe09dd61c4ac09789ed052006395e5df02785.zip |
Refactoring to new content API
Diffstat (limited to 'archiva-modules/archiva-base')
22 files changed, 171 insertions, 73 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 f1a219b14..83879415f 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 @@ -36,6 +36,8 @@ import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.BaseRepositoryContentLayout; import org.apache.archiva.repository.RepositoryContentFactory; +import org.apache.archiva.repository.content.Artifact; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Scope; @@ -126,10 +128,9 @@ public class SimpleArtifactConsumer { ManagedRepositoryContent repositoryContent = repository.getContent(); BaseRepositoryContentLayout layout = repositoryContent.getLayout( BaseRepositoryContentLayout.class ); - ArtifactReference artifact = repositoryContent.toArtifactReference( path ); - - repositorySession.getRepository().getArtifacts( repositorySession, repository.getId(), artifact.getGroupId(), - artifact.getArtifactId(), artifact.getVersion() ); + Artifact artifact = layout.getArtifact( path ); + repositorySession.getRepository().getArtifacts( repositorySession, repository.getId(), artifact.getNamespace().getId(), + artifact.getId(), artifact.getVersion().getId() ); } catch ( LayoutException | MetadataResolutionException e ) { 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 ) 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 71562b127..2aeb6454b 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 @@ -138,8 +138,16 @@ public interface BaseRepositoryContentLayout extends ManagedRepositoryContentLay * @throws IllegalArgumentException if the selector coordinates do not specify a artifact * @throws ContentAccessException if the access to the underlying storage failed */ - Artifact getArtifact(ItemSelector selector) throws ContentAccessException; + Artifact getArtifact(ItemSelector selector) throws ContentAccessException, IllegalArgumentException; + /** + * Returns the artifact at the given path + * @param path the path to the artifact + * @return the artifact instance + * @throws LayoutException if the path does not point to a artifact + * @throws ContentAccessException if the access to the underlying storage failed + */ + Artifact getArtifact( String path ) throws LayoutException, ContentAccessException; /** * Returns the artifacts that match the given selector. It is up to the repository implementation @@ -162,10 +170,11 @@ public interface BaseRepositoryContentLayout extends ManagedRepositoryContentLay * * @param selector the selector for the artifacts * @return a stream with artifact elements. + * @throws IllegalArgumentException if the selector is not valid for the layout * @throws ItemNotFoundException if the specified coordinates cannot be found in the repository * @throws ContentAccessException if the access to the underlying storage failed */ - Stream<? extends Artifact> newArtifactStream( ItemSelector selector) throws ContentAccessException; + Stream<? extends Artifact> newArtifactStream( ItemSelector selector) throws ContentAccessException, IllegalArgumentException; /** diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/LayoutRuntimeException.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/LayoutRuntimeException.java new file mode 100644 index 000000000..9abc5e0ed --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/LayoutRuntimeException.java @@ -0,0 +1,40 @@ +package org.apache.archiva.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.common.ArchivaException; + +/** + * LayoutException + * + * + */ +public class LayoutRuntimeException extends RuntimeException +{ + public LayoutRuntimeException( String message, Throwable cause ) + { + super( message, cause ); + } + + public LayoutRuntimeException( String message ) + { + super( message ); + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java index 5de655d9f..fd92be1a2 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java @@ -20,8 +20,6 @@ package org.apache.archiva.repository; */ import org.apache.archiva.model.ArtifactReference; -import org.apache.archiva.model.VersionedReference; -import org.apache.archiva.repository.content.ContentItem; import org.apache.archiva.repository.content.ItemSelector; @@ -33,7 +31,7 @@ public interface RepositoryContent /** - * Given a repository relative path to a filename, return the {@link VersionedReference} object suitable for the path. + * Given a repository relative path to a filename, return the {@link ArtifactReference} object suitable for the path. * * @param path the path relative to the repository base dir for the artifact. * @return the {@link ArtifactReference} representing the path. (or null if path cannot be converted to diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Artifact.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Artifact.java index 0bb7e84cd..693b696ee 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Artifact.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Artifact.java @@ -61,6 +61,18 @@ public interface Artifact extends DataItem String getArtifactVersion( ); /** + * Returns the project this artifact is attached to + * @return the project + */ + Project getProject(); + + /** + * Returns the namespace this artifact is attached to + * @return the namespace object + */ + Namespace getNamespace(); + + /** * Returns the attached version this artifact is part of. * * @return the version object diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Namespace.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Namespace.java index d31aeed0a..fe21c9898 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Namespace.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Namespace.java @@ -53,7 +53,7 @@ public interface Namespace extends ContentItem * * @return the unique name of the namespace */ - String getNamespace( ); + String getId( ); /** * Returns the elements that represent the path to the namespace. diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Version.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Version.java index 071ef5b03..d5441ae17 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Version.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Version.java @@ -30,12 +30,13 @@ import java.util.List; */ public interface Version extends ContentItem { + /** * Returns the version string. * * @return the version string */ - String getVersion( ); + String getId( ); /** * Returns the version segments. E.g. for 1.3.4 it will return ["1","3"."4"] @@ -45,6 +46,12 @@ public interface Version extends ContentItem List<String> getVersionSegments( ); /** + * Returns the namespace this version is attached to + * @return the namespace instance + */ + Namespace getNamespace(); + + /** * Returns the project this version is attached to. * * @return the project instance. Will never return <code>null</code> diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaArtifact.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaArtifact.java index b65fa7400..cf0ead9d0 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaArtifact.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaArtifact.java @@ -22,6 +22,8 @@ package org.apache.archiva.repository.content.base; import org.apache.archiva.repository.content.Artifact; import org.apache.archiva.repository.content.ArtifactType; import org.apache.archiva.repository.content.BaseArtifactTypes; +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.builder.ArtifactOptBuilder; import org.apache.archiva.repository.content.base.builder.ArtifactVersionBuilder; @@ -114,6 +116,17 @@ public class ArchivaArtifact extends BaseContentItem implements Artifact return artifactType; } + @Override + public Namespace getNamespace( ) + { + return version.getProject( ).getNamespace( ); + } + + @Override + public Project getProject( ) + { + return version.getProject( ); + } /** * Returns the builder for creating a new artifact instance. You have to fill the @@ -186,9 +199,9 @@ public class ArchivaArtifact extends BaseContentItem implements Artifact { StringBuilder key = new StringBuilder(); - key.append( defaultString( getVersion().getProject().getNamespace().getNamespace() )).append( ":" ); + key.append( defaultString( getVersion().getProject().getNamespace().getId() )).append( ":" ); key.append( defaultString( getId() ) ).append( ":" ); - key.append( defaultString( getVersion().getVersion() ) ).append( ":" ); + key.append( defaultString( getVersion().getId() ) ).append( ":" ); key.append( defaultString( getArtifactVersion( ) ) ).append( ":" ); key.append( defaultString( getClassifier() ) ).append( ":" ); key.append( defaultString( getRemainder() ) ); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaItemSelector.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaItemSelector.java index 73b730ce9..cb5063087 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaItemSelector.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaItemSelector.java @@ -67,21 +67,21 @@ public class ArchivaItemSelector implements ItemSelector public Builder withItem( ContentItem item ) { if (item instanceof Namespace ) { Namespace ns = (Namespace) item; - selector.namespace = ns.getNamespace(); + selector.namespace = ns.getId(); } else if (item instanceof Project ) { Project proj = (Project)item; - selector.namespace = proj.getNamespace( ).getNamespace( ); + selector.namespace = proj.getNamespace( ).getId( ); selector.projectId = proj.getId( ); } else if (item instanceof Version) { Version version = (Version)item; - selector.namespace = version.getProject( ).getNamespace( ).getNamespace( ); + selector.namespace = version.getProject( ).getNamespace( ).getId( ); selector.projectId = version.getProject( ).getId( ); - selector.version = version.getVersion( ); + selector.version = version.getId( ); } else if (item instanceof Artifact ) { Artifact artifact = (Artifact)item; - selector.namespace = artifact.getVersion( ).getProject( ).getNamespace( ).getNamespace( ); + selector.namespace = artifact.getVersion( ).getProject( ).getNamespace( ).getId( ); selector.projectId = artifact.getVersion( ).getProject( ).getId( ); - selector.version = artifact.getVersion( ).getVersion( ); + selector.version = artifact.getVersion( ).getId( ); selector.artifactId = artifact.getId( ); selector.artifactVersion = artifact.getArtifactVersion( ); selector.extension = artifact.getExtension( ); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaNamespace.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaNamespace.java index 9982ea0de..1cd744a6a 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaNamespace.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaNamespace.java @@ -50,7 +50,7 @@ public class ArchivaNamespace extends BaseContentItem implements Namespace } @Override - public String getNamespace( ) + public String getId( ) { return namespace; } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaVersion.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaVersion.java index e462116e9..a146dd171 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaVersion.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaVersion.java @@ -20,6 +20,7 @@ package org.apache.archiva.repository.content.base; */ import org.apache.archiva.repository.ManagedRepositoryContent; +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.builder.VersionOptBuilder; @@ -80,7 +81,7 @@ public class ArchivaVersion extends BaseContentItem implements Version } @Override - public String getVersion( ) + public String getId( ) { return version; } @@ -91,6 +92,11 @@ public class ArchivaVersion extends BaseContentItem implements Version return project; } + @Override + public Namespace getNamespace( ) + { + return project.getNamespace( ); + } @Override public boolean equals( Object o ) diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/BaseContentItem.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/BaseContentItem.java index 69c75457b..2be593753 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/BaseContentItem.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/BaseContentItem.java @@ -40,7 +40,6 @@ public abstract class BaseContentItem implements ContentItem protected StorageAsset asset; private Map<String, String> attributes; private Map<Class<?>, ContentItem> characteristics = new HashMap<>( ); - private Set<Class<?>> failedConversions = new HashSet<>( ); @Override public <T extends ContentItem> T adapt( Class<T> clazz ) throws ItemConversionException diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java index 3a02bbe30..ce82fa145 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java @@ -21,7 +21,6 @@ package org.apache.archiva.repository.metadata.base; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; -import org.apache.archiva.common.utils.PathUtil; import org.apache.archiva.common.utils.VersionComparator; import org.apache.archiva.common.utils.VersionUtil; import org.apache.archiva.configuration.ArchivaConfiguration; @@ -66,7 +65,6 @@ import javax.inject.Named; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; @@ -552,7 +550,7 @@ public class MetadataTools { Project project = layout.getProject( selector ); allVersions = layout.getVersions( project ).stream() - .map( v -> v.getVersion() ).collect( Collectors.toSet()); + .map( v -> v.getId() ).collect( Collectors.toSet()); } catch ( org.apache.archiva.repository.ContentAccessException e ) { diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/content/base/ArchivaNamespaceTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/content/base/ArchivaNamespaceTest.java index 93774bd70..cddffacec 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/content/base/ArchivaNamespaceTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/content/base/ArchivaNamespaceTest.java @@ -53,7 +53,7 @@ class ArchivaNamespaceTest extends ContentItemTest assertNotNull( result ); assertEquals( this.repository, result.getRepository( ) ); assertEquals( this.asset, result.getAsset( ) ); - assertEquals( "test.1d.d", result.getNamespace( ) ); + assertEquals( "test.1d.d", result.getId( ) ); assertNotNull( result.getAttributes( ) ); assertEquals( 0, result.getAttributes( ).size( ) ); assertArrayEquals( new String[]{ "test", "1d", "d" }, result.getNamespacePath().toArray() ); @@ -69,7 +69,7 @@ class ArchivaNamespaceTest extends ContentItemTest assertNotNull( result ); assertEquals( this.repository, result.getRepository( ) ); assertEquals( this.asset, result.getAsset( ) ); - assertEquals( "test.1d..d.", result.getNamespace( ) ); + assertEquals( "test.1d..d.", result.getId( ) ); assertNotNull( result.getAttributes( ) ); assertEquals( 0, result.getAttributes( ).size( ) ); assertArrayEquals( new String[]{ "test", "1d", "","d" }, result.getNamespacePath().toArray() ); @@ -87,7 +87,7 @@ class ArchivaNamespaceTest extends ContentItemTest assertNotNull( result ); assertEquals( this.repository, result.getRepository( ) ); assertEquals( this.asset, result.getAsset( ) ); - assertEquals( "test.1d.d/abc/def", result.getNamespace( ) ); + assertEquals( "test.1d.d/abc/def", result.getId( ) ); assertNotNull( result.getAttributes( ) ); assertEquals( 0, result.getAttributes( ).size( ) ); assertArrayEquals( new String[]{ "test.1d.d", "abc", "def" }, result.getNamespacePath().toArray() ); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/content/base/ArchivaVersionTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/content/base/ArchivaVersionTest.java index 151bb2349..799e477e2 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/content/base/ArchivaVersionTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/content/base/ArchivaVersionTest.java @@ -55,8 +55,8 @@ class ArchivaVersionTest extends ContentItemTest assertEquals( asset, item.getAsset( ) ); assertNotNull( item.getProject( ) ); assertEquals( project, item.getProject( ) ); - assertNotNull( item.getVersion( ) ); - assertEquals( "3.4.5", item.getVersion( ) ); + assertNotNull( item.getId( ) ); + assertEquals( "3.4.5", item.getId( ) ); assertNotNull( item.getVersionSegments( ) ); assertArrayEquals( new String[]{"3", "4", "5"}, item.getVersionSegments( ).toArray( ) ); } 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 83bddf8e7..bab83734d 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 @@ -148,6 +148,12 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout } @Override + public Artifact getArtifact( String path ) throws LayoutException, ContentAccessException + { + return null; + } + + @Override public List<? extends Artifact> getArtifacts( ItemSelector selector ) throws ContentAccessException { return null; 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 1a9670727..5deb975e7 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 @@ -159,6 +159,12 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout } @Override + public Artifact getArtifact( String path ) throws LayoutException, ContentAccessException + { + return null; + } + + @Override public List<? extends Artifact> getArtifacts( ItemSelector selector ) throws ContentAccessException { return null; |