From c7a924305a643f6c495aa950838252acc26d5e49 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 8 Mar 2020 13:20:51 +0100 Subject: [PATCH] Fixing path matching for repository content --- .../repository/ManagedRepositoryContent.java | 12 ++++++++++++ .../mock/ManagedRepositoryContentMock.java | 6 ++++++ .../mock/ManagedRepositoryContentMock.java | 18 ++++++++++++++++++ .../mock/ManagedRepositoryContentMock.java | 6 ++++++ .../AbstractDefaultRepositoryContent.java | 5 +++++ .../ManagedDefaultRepositoryContent.java | 19 +++++++++++++++++-- 6 files changed, 64 insertions(+), 2 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java index a4565c4d4..09e7621e6 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java @@ -58,6 +58,18 @@ public interface ManagedRepositoryContent extends RepositoryContent */ void deleteItem( ContentItem item) throws ItemNotFoundException, ContentAccessException; + + /** + * Returns a item for the given selector. The type of the returned item depends on the + * selector. + * + * @param selector the item selector + * @return the content item that matches the given selector + * @throws ContentAccessException if an error occured while accessing the backend + * @throws IllegalArgumentException if the selector does not select a valid content item + */ + ContentItem getItem(ItemSelector selector) throws ContentAccessException, IllegalArgumentException; + /** * Returns the namespace for the given selected coordinates. The selector must specify a namespace. All other * coordinates are ignored. 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 c719d3871..ac1444543 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 @@ -81,6 +81,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent } + @Override + public ContentItem getItem( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException + { + return null; + } + @Override public Namespace getNamespace( ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException { 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 09794b757..66ab810ad 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 @@ -97,6 +97,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent } + @Override + public ContentItem getItem( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException + { + return null; + } + @Override public Namespace getNamespace( ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException { @@ -181,6 +187,18 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent } + @Override + public ContentItem toItem( String path ) throws LayoutException + { + return null; + } + + @Override + public ContentItem toItem( StorageAsset assetPath ) throws LayoutException + { + return null; + } + @Override public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException { 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 bc1a16f1e..d06ccd205 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 @@ -101,6 +101,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent } + @Override + public ContentItem getItem( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException + { + return null; + } + @Override public Namespace getNamespace( ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException { diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java index e2532e159..d33843f70 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java @@ -58,6 +58,11 @@ public abstract class AbstractDefaultRepositoryContent implements RepositoryCont private PathParser defaultPathParser = new DefaultPathParser(); + PathParser getPathParser() { + return defaultPathParser; + } + + /** * 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 c5d371e5d..dfc0f04d5 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 @@ -199,6 +199,20 @@ public class ManagedDefaultRepositoryContent } } + @Override + public ContentItem getItem( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException + { + if (selector.hasVersion() && selector.hasArtifactId()) { + return getArtifact( selector ); + } else if (selector.hasProjectId() && selector.hasVersion()) { + return getVersion( selector ); + } else if (selector.hasProjectId()) { + return getProject( selector ); + } else { + return getNamespace( selector ); + } + } + @Override public Namespace getNamespace( final ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException { @@ -620,13 +634,14 @@ public class ManagedDefaultRepositoryContent @Override public ContentItem toItem( String path ) throws LayoutException { - return getItemFromPath( getAssetByPath( path ) ); + ItemSelector selector = getPathParser( ).toItemSelector( path ); + return getItem( selector ); } @Override public ContentItem toItem( StorageAsset assetPath ) throws LayoutException { - return getItemFromPath( assetPath ); + return toItem( assetPath.getPath( ) ); } /// ************* End of new generation interface ****************** -- 2.39.5