aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-repository-api/src
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2020-05-24 18:18:37 +0200
committerMartin Stockhammer <martin_s@apache.org>2020-05-30 20:00:22 +0200
commitac25c7a86fe77f5b0f005f03d9d28dc1f6f8580e (patch)
treed6f1650edea83a7ed04c1ae40cf8e03d70ff8ed0 /archiva-modules/archiva-base/archiva-repository-api/src
parent56de9e590b8d040add03b99df2e221eeedde860e (diff)
downloadarchiva-ac25c7a86fe77f5b0f005f03d9d28dc1f6f8580e.tar.gz
archiva-ac25c7a86fe77f5b0f005f03d9d28dc1f6f8580e.zip
Changing content item API
Diffstat (limited to 'archiva-modules/archiva-base/archiva-repository-api/src')
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/GenericManagedRepositoryContent.java141
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ItemConversionException.java49
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java96
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ContentItem.java7
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/DataItem.java6
5 files changed, 206 insertions, 93 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/GenericManagedRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/GenericManagedRepositoryContent.java
new file mode 100644
index 000000000..7242f5da9
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/GenericManagedRepositoryContent.java
@@ -0,0 +1,141 @@
+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.repository.content.ContentItem;
+import org.apache.archiva.repository.content.ItemNotFoundException;
+import org.apache.archiva.repository.content.ItemSelector;
+import org.apache.archiva.repository.storage.StorageAsset;
+
+import java.util.List;
+import java.util.function.Consumer;
+import java.util.stream.Stream;
+
+/**
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+public interface GenericManagedRepositoryContent
+{
+ /**
+ * Delete all items that match the given selector. The type and number of deleted items
+ * depend on the specific selector:
+ * <ul>
+ * <li>namespace: the complete namespace is deleted (recursively if the recurse flag is set)</li>
+ * <li>project: the complete project and all contained versions are deleted</li>
+ * <li>version: the version inside the project is deleted (project is required)</li>
+ * <li>artifactId: all artifacts that match the id (project and version are required)</li>
+ * <li>artifactVersion: all artifacts that match the version (project and version are required)</li>
+ * <li></li>
+ * </ul>
+ *
+ * @param selector the item selector that selects the artifacts to delete
+ * @param consumer a consumer of the items that will be called after deletion
+ * @returns the list of items that are deleted
+ * @throws ContentAccessException if the deletion was not possible or only partly successful, because the access
+ * to the artifacts failed
+ * @throws IllegalArgumentException if the selector does not specify valid artifacts to delete
+ */
+ void deleteAllItems( ItemSelector selector, Consumer<ItemDeleteStatus> consumer ) throws ContentAccessException, IllegalArgumentException;
+
+ /**
+ * Removes the specified content item and if the item is a container or directory,
+ * all content stored under the given item.
+ *
+ * @param item the item.
+ * @throws ItemNotFoundException if the item cannot be found
+ * @throws ContentAccessException if the deletion was not possible or only partly successful, because the access
+ * to the artifacts failed
+ */
+ 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 a stream of items that match the given selector. It may return a stream of mixed types,
+ * like namespaces, projects, versions and artifacts. It will not select a specific type.
+ * The selector can specify the '*' pattern for all fields.
+ * The returned elements will be provided by depth first.
+ *
+ * @param selector the item selector that specifies the items
+ * @return the stream of content items
+ * @throws ContentAccessException if the access to the underlying storage failed
+ * @throws IllegalArgumentException if a illegal coordinate combination was provided
+ */
+ Stream<? extends ContentItem> newItemStream( ItemSelector selector, boolean parallel ) throws ContentAccessException, IllegalArgumentException;
+
+ /**
+ * Returns the item that matches the given path. The item at the path must not exist.
+ *
+ * @param path the path string that points to the item
+ * @return the content item if the path is a valid item path
+ * @throws LayoutException if the path is not valid for the repository layout
+ */
+ ContentItem toItem( String path ) throws LayoutException;
+
+ /**
+ * Returns the item that matches the given asset path. The asset must not exist.
+ *
+ * @param assetPath the path to the artifact or directory
+ * @return the item, if it is a valid path for the repository layout
+ * @throws LayoutException if the path is not valid for the repository
+ */
+ ContentItem toItem( StorageAsset assetPath ) throws LayoutException;
+
+ /**
+ * Returns true, if the selector coordinates point to a existing item in the repository.
+ *
+ * @param selector the item selector
+ * @return <code>true</code>, if there exists such a item, otherwise <code>false</code>
+ */
+ boolean hasContent( ItemSelector selector );
+
+ /**
+ * Returns the parent of the item.
+ * @param item the current item
+ * @return the parent item, or <code>null</code> if no such item exists
+ */
+ ContentItem getParent(ContentItem item);
+
+ /**
+ * Returns the list of children items.
+ * @param item the current item
+ * @return the list of children, or a empty list, if no children exist
+ */
+ List<? extends ContentItem> getChildren( ContentItem item);
+
+ /**
+ * Tries to apply the given characteristic to the content item. If the layout does not allow this,
+ * it will throw a <code>LayoutException</code>.
+ *
+ * @param clazz the characteristic class to apply
+ * @param item the content item
+ * @param <T> The characteristic
+ * @return the applied characteristic
+ */
+ <T extends ContentItem> T applyCharacteristic(Class<T> clazz, ContentItem item) throws LayoutException;
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ItemConversionException.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ItemConversionException.java
new file mode 100644
index 000000000..2290111f2
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ItemConversionException.java
@@ -0,0 +1,49 @@
+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.
+ */
+
+/**
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+public class ItemConversionException extends RuntimeException
+{
+ public ItemConversionException( )
+ {
+ }
+
+ public ItemConversionException( String message )
+ {
+ super( message );
+ }
+
+ public ItemConversionException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public ItemConversionException( Throwable cause )
+ {
+ super( cause );
+ }
+
+ public ItemConversionException( String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace )
+ {
+ super( message, cause, enableSuppression, writableStackTrace );
+ }
+}
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 a093c8a6d..9b2b318b9 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
@@ -45,54 +45,11 @@ import java.util.stream.Stream;
*
* This interface
*/
-public interface ManagedRepositoryContent extends RepositoryContent
+public interface ManagedRepositoryContent extends RepositoryContent, GenericManagedRepositoryContent
{
/// ***************** New generation interface **********************
- /**
- * Delete all items that match the given selector. The type and number of deleted items
- * depend on the specific selector:
- * <ul>
- * <li>namespace: the complete namespace is deleted (recursively if the recurse flag is set)</li>
- * <li>project: the complete project and all contained versions are deleted</li>
- * <li>version: the version inside the project is deleted (project is required)</li>
- * <li>artifactId: all artifacts that match the id (project and version are required)</li>
- * <li>artifactVersion: all artifacts that match the version (project and version are required)</li>
- * <li></li>
- * </ul>
- *
- * @param selector the item selector that selects the artifacts to delete
- * @param consumer a consumer of the items that will be called after deletion
- * @returns the list of items that are deleted
- * @throws ContentAccessException if the deletion was not possible or only partly successful, because the access
- * to the artifacts failed
- * @throws IllegalArgumentException if the selector does not specify valid artifacts to delete
- */
- void deleteAllItems( ItemSelector selector, Consumer<ItemDeleteStatus> consumer) throws ContentAccessException, IllegalArgumentException;
-
- /**
- * Removes the specified content item and if the item is a container or directory,
- * all content stored under the given item.
- *
- * @param item the item.
- * @throws ItemNotFoundException if the item cannot be found
- * @throws ContentAccessException if the deletion was not possible or only partly successful, because the access
- * to the artifacts failed
- */
- 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
@@ -211,19 +168,6 @@ public interface ManagedRepositoryContent extends RepositoryContent
*/
Stream<? extends Artifact> newArtifactStream( ItemSelector selector) throws ContentAccessException;
- /**
- * Returns a stream of items that match the given selector. It may return a stream of mixed types,
- * like namespaces, projects, versions and artifacts. It will not select a specific type.
- * The selector can specify the '*' pattern for all fields.
- * The returned elements will be provided by depth first.
- *
- * @param selector the item selector that specifies the items
- * @return the stream of content items
- * @throws ContentAccessException if the access to the underlying storage failed
- * @throws IllegalArgumentException if a illegal coordinate combination was provided
- */
- Stream<? extends ContentItem> newItemStream(ItemSelector selector, boolean parallel) throws ContentAccessException, IllegalArgumentException;
-
/**
* Return the projects that are part of the given namespace.
@@ -264,6 +208,16 @@ public interface ManagedRepositoryContent extends RepositoryContent
*/
List<? extends Version> getVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException;
+ /**
+ * Returns all found artifact versions that can be found for the given selector. The selector must specify at least
+ * a project.
+ *
+ * @param selector the item selector that must specify at least a project
+ * @return the list of artifact versions
+ * @throws ContentAccessException if the access to the underlying storage failed
+ * @throws IllegalArgumentException if the selector does not have project information
+ */
+ List<String> getArtifactVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException;
/**
* Return all the artifacts of a given content item (namespace, project, version)
@@ -289,14 +243,6 @@ public interface ManagedRepositoryContent extends RepositoryContent
/**
- * Returns true, if the selector coordinates point to a existing item in the repository.
- *
- * @param selector the item selector
- * @return <code>true</code>, if there exists such a item, otherwise <code>false</code>
- */
- boolean hasContent( ItemSelector selector );
-
- /**
* Copies the artifact to the given destination coordinates
*
* @param sourceFile the path to the source file
@@ -306,26 +252,6 @@ public interface ManagedRepositoryContent extends RepositoryContent
void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException, ContentAccessException;
- /**
- * Returns the item that matches the given path. The item at the path must not exist.
- *
- * @param path the path string that points to the item
- * @return the content item if the path is a valid item path
- * @throws LayoutException if the path is not valid for the repository layout
- */
- ContentItem toItem(String path) throws LayoutException;
-
-
- /**
- * Returns the item that matches the given asset path. The asset must not exist.
- *
- * @param assetPath the path to the artifact or directory
- * @return the item, if it is a valid path for the repository layout
- * @throws LayoutException if the path is not valid for the repository
- */
- ContentItem toItem(StorageAsset assetPath) throws LayoutException;
-
-
/// ***************** End of new generation interface **********************
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ContentItem.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ContentItem.java
index 8efdd8461..68aca2d8b 100644
--- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ContentItem.java
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ContentItem.java
@@ -19,6 +19,7 @@ package org.apache.archiva.repository.content;
* under the License.
*/
+import org.apache.archiva.repository.ItemConversionException;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.UnsupportedConversionException;
import org.apache.archiva.repository.storage.StorageAsset;
@@ -34,7 +35,7 @@ public interface ContentItem
* @param <T> the class or interface
* @return the specific project implementation
*/
- <T extends Project> T adapt( Class<T> clazz ) throws UnsupportedConversionException;
+ <T extends ContentItem> T adapt( Class<T> clazz ) throws ItemConversionException;
/**
* Returns <code>true</code>, if this project supports the given adaptor class.
@@ -43,7 +44,9 @@ public interface ContentItem
* @param <T> the type
* @return <code>true/code>, if the implementation is supported, otherwise false
*/
- <T extends Project> boolean supports( Class<T> clazz );
+ <T extends ContentItem> boolean hasCharacteristic( Class<T> clazz );
+
+ <T extends ContentItem> void setCharacteristic( Class<T> clazz, T item );
/**
* Additional attributes
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/DataItem.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/DataItem.java
index 32dc00ee5..5d315b54a 100644
--- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/DataItem.java
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/DataItem.java
@@ -29,12 +29,6 @@ public interface DataItem extends ContentItem
{
/**
- * Returns the parent of the data item
- * @return the parent item, which is either a Version, Project or Namespace
- */
- ContentItem getParent( );
-
- /**
* Returns the identifier of the data item.
* @return the identifier string
*/