diff options
author | Martin Stockhammer <martin_s@apache.org> | 2020-03-12 15:38:12 +0100 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2020-03-12 15:38:12 +0100 |
commit | fb63a9d09d27c93a4884130cbc436582c0573639 (patch) | |
tree | 049549ef952500e199bb3662f046927781f5e2c8 /archiva-modules/archiva-base | |
parent | 31e3fbd883c549f4bb94c475ed07cafefc1fbd07 (diff) | |
download | archiva-fb63a9d09d27c93a4884130cbc436582c0573639.tar.gz archiva-fb63a9d09d27c93a4884130cbc436582c0573639.zip |
Modifying query interface and implementing new repo content methods
Diffstat (limited to 'archiva-modules/archiva-base')
5 files changed, 99 insertions, 36 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 ce819eb12..318a6a6c0 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 @@ -186,7 +186,7 @@ public interface ManagedRepositoryContent extends RepositoryContent * @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> getArtifactStream( ItemSelector selector) throws ContentAccessException; + Stream<? extends Artifact> newArtifactStream( ItemSelector selector) throws ContentAccessException; /** @@ -247,8 +247,9 @@ public interface ManagedRepositoryContent extends RepositoryContent * @param item the item from where the artifacts should be returned * @return a stream of artifacts. The stream is auto closable. You should always make sure, that the stream * is closed after use. + * @throws ContentAccessException if the access to the underlying storage failed */ - Stream<? extends Artifact> getArtifactStream( ContentItem item ) throws ContentAccessException; + Stream<? extends Artifact> newArtifactStream( ContentItem item ) throws ContentAccessException; /** diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ItemSelector.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ItemSelector.java index 6bff84363..bc048f9c0 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ItemSelector.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ItemSelector.java @@ -30,7 +30,7 @@ public interface ItemSelector { /** - * Selects the namespace to search for. You can use the {@link #searchSubNamespaces()} flag + * Selects the namespace to search for. You can use the {@link #recurse()} flag * to decide, if only the given namespace or the namespace and all sub namespaces (if they exist) should be * queried. If empty, the root namespace is searched. * @return the namespace to search @@ -96,10 +96,10 @@ public interface ItemSelector Map<String, String> getAttributes( ); /** - * Returns <code>true</code>, if not only the given namespace but all sub namespaces - * of the given namespace should be queried too. + * Returns <code>true</code>, if the query should recurse into all sub directories for + * retrieving artifacts. */ - boolean searchSubNamespaces(); + boolean recurse(); /** * <code>true</code>, if all files/assets should be returned that match the given selector, @@ -107,7 +107,7 @@ public interface ItemSelector * Related assets are e.g. hash files or signature files. * @return <code>true</code>, if all assets should be found otherwise <code>false</code> */ - boolean findRelatedArtifacts(); + boolean includeRelatedArtifacts(); default boolean hasNamespace( ) { 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 37374298e..103ce28c9 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 @@ -32,17 +32,17 @@ import java.util.Map; public class ArchivaItemSelector implements ItemSelector { - private String projectId = null; - private String version = null; - private String artifactVersion = null; - private String artifactId = null; + private String projectId = ""; + private String version = ""; + private String artifactVersion = ""; + private String artifactId = ""; private String namespace = ""; - private String type = null; - private String classifier = null; - private String extension = null; + private String type = ""; + private String classifier = ""; + private String extension = ""; private Map<String, String> attributes; - private boolean searchRelatedArtifacts = false; - private boolean searchSubNamespaces = false; + private boolean includeRelatedArtifacts = false; + private boolean recurse = false; private ArchivaItemSelector( ) @@ -61,49 +61,70 @@ public class ArchivaItemSelector implements ItemSelector public Builder withNamespace( String namespace ) { - selector.namespace = namespace; + if (namespace!=null) + { + selector.namespace = namespace; + } return this; } public Builder withProjectId( String projectId ) { - selector.projectId = projectId; + if (projectId!=null) + { + selector.projectId = projectId; + } return this; } public Builder withVersion( String version ) { - selector.version = version; + if (version!=null) + { + selector.version = version; + } return this; } public Builder withArtifactVersion( String artifactVersion ) { - selector.artifactVersion = artifactVersion; + if (artifactVersion!=null) + { + selector.artifactVersion = artifactVersion; + } return this; } public Builder withArtifactId( String artifactId ) { - selector.artifactId = artifactId; + if (artifactId!=null) + { + selector.artifactId = artifactId; + } return this; } public Builder withType( String type ) { - selector.type = type; + if (type!=null) + { + selector.type = type; + } return this; } public Builder withClassifier( String classifier ) { - selector.classifier = classifier; + if (classifier != null ) + { + selector.classifier = classifier; + } return this; } @@ -116,17 +137,20 @@ public class ArchivaItemSelector implements ItemSelector public Builder withExtension( String extension ) { - selector.extension = extension; + if (extension!=null) + { + selector.extension = extension; + } return this; } - public Builder enableSearchRelatedArtifacts() { - selector.searchRelatedArtifacts = true; + public Builder includeRelatedArtifacts() { + selector.includeRelatedArtifacts = true; return this; } - public Builder enableSearchSubNamespaces() { - selector.searchSubNamespaces = true; + public Builder recurse() { + selector.recurse = true; return this; } @@ -221,15 +245,15 @@ public class ArchivaItemSelector implements ItemSelector } @Override - public boolean searchSubNamespaces( ) + public boolean recurse( ) { - return searchSubNamespaces; + return recurse; } @Override - public boolean findRelatedArtifacts( ) + public boolean includeRelatedArtifacts( ) { - return searchRelatedArtifacts; + return includeRelatedArtifacts; } @Override @@ -243,4 +267,42 @@ public class ArchivaItemSelector implements ItemSelector { return StringUtils.isNotEmpty( extension ); } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) return true; + if ( o == null || getClass( ) != o.getClass( ) ) return false; + + ArchivaItemSelector that = (ArchivaItemSelector) o; + + if ( includeRelatedArtifacts != that.includeRelatedArtifacts ) return false; + if ( recurse != that.recurse ) return false; + if ( !projectId.equals( that.projectId ) ) return false; + if ( !version.equals( that.version ) ) return false; + if ( !artifactVersion.equals( that.artifactVersion ) ) return false; + if ( !artifactId.equals( that.artifactId ) ) return false; + if ( !namespace.equals( that.namespace ) ) return false; + if ( !type.equals( that.type ) ) return false; + if ( !classifier.equals( that.classifier ) ) return false; + if ( !extension.equals( that.extension ) ) return false; + return attributes != null ? attributes.equals( that.attributes ) : that.attributes == null; + } + + @Override + public int hashCode( ) + { + int result = projectId.hashCode( ); + result = 31 * result + version.hashCode( ); + result = 31 * result + artifactVersion.hashCode( ); + result = 31 * result + artifactId.hashCode( ); + result = 31 * result + namespace.hashCode( ); + result = 31 * result + type.hashCode( ); + result = 31 * result + classifier.hashCode( ); + result = 31 * result + extension.hashCode( ); + result = 31 * result + ( attributes != null ? attributes.hashCode( ) : 0 ); + result = 31 * result + ( includeRelatedArtifacts ? 1 : 0 ); + result = 31 * result + ( recurse ? 1 : 0 ); + return result; + } } 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 9eb4b819a..21230c869 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 @@ -133,7 +133,7 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent } @Override - public Stream<? extends Artifact> getArtifactStream( ItemSelector selector ) throws ContentAccessException + public Stream<? extends Artifact> newArtifactStream( ItemSelector selector ) throws ContentAccessException { return null; } @@ -169,7 +169,7 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent } @Override - public Stream<? extends Artifact> getArtifactStream( ContentItem item ) throws ContentAccessException + public Stream<? extends Artifact> newArtifactStream( ContentItem item ) 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 6db475b92..b79e47e0a 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 @@ -134,7 +134,7 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent } @Override - public Stream<? extends Artifact> getArtifactStream( ItemSelector selector ) throws ContentAccessException + public Stream<? extends Artifact> newArtifactStream( ItemSelector selector ) throws ContentAccessException { return null; } @@ -170,7 +170,7 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent } @Override - public Stream<? extends Artifact> getArtifactStream( ContentItem item ) throws ContentAccessException + public Stream<? extends Artifact> newArtifactStream( ContentItem item ) throws ContentAccessException { return null; } |