From 81be3487966f89c7e5860094f41e8bfa0202b1ea Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 25 Aug 2019 22:29:00 +0200 Subject: [PATCH] Switching to list as return values. --- .../memory/TestMetadataRepository.java | 7 ++--- .../AbstractMetadataRepository.java | 20 ++++++------- .../repository/MetadataRepository.java | 21 +++++++------ .../CassandraMetadataRepository.java | 30 +++++++++---------- .../file/FileMetadataRepository.java | 24 +++++++-------- .../repository/jcr/JcrMetadataRepository.java | 24 +++++++-------- 6 files changed, 62 insertions(+), 64 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java index 1275200c2..662d2c267 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java @@ -26,7 +26,6 @@ import org.apache.archiva.metadata.repository.RepositorySession; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; @@ -74,7 +73,7 @@ public class TestMetadataRepository } @Override - public Collection getProjectVersions( RepositorySession session, String repoId, String namespace, String projectId ) + public List getProjectVersions( RepositorySession session, String repoId, String namespace, String projectId ) { return versions; } @@ -99,8 +98,8 @@ public class TestMetadataRepository @Override - public Collection getArtifacts( RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion ) + public List getArtifacts( RepositorySession session, String repoId, String namespace, String projectId, + String projectVersion ) { return artifacts; } diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/AbstractMetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/AbstractMetadataRepository.java index db2fc8339..5f54ef973 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/AbstractMetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/AbstractMetadataRepository.java @@ -204,44 +204,44 @@ public abstract class AbstractMetadataRepository } @Override - public Collection getArtifactVersions( RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion ) + public List getArtifactVersions( RepositorySession session, String repoId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException { throw new UnsupportedOperationException(); } @Override - public Collection getProjectReferences( RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion ) + public List getProjectReferences( RepositorySession session, String repoId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException { throw new UnsupportedOperationException(); } @Override - public Collection getRootNamespaces( RepositorySession session, String repoId ) + public List getRootNamespaces( RepositorySession session, String repoId ) throws MetadataResolutionException { throw new UnsupportedOperationException(); } @Override - public Collection getChildNamespaces( RepositorySession session, String repoId, String namespace ) + public List getChildNamespaces( RepositorySession session, String repoId, String namespace ) throws MetadataResolutionException { throw new UnsupportedOperationException(); } @Override - public Collection getProjects( RepositorySession session, String repoId, String namespace ) + public List getProjects( RepositorySession session, String repoId, String namespace ) throws MetadataResolutionException { throw new UnsupportedOperationException(); } @Override - public Collection getProjectVersions( RepositorySession session, String repoId, String namespace, String projectId ) + public List getProjectVersions( RepositorySession session, String repoId, String namespace, String projectId ) throws MetadataResolutionException { throw new UnsupportedOperationException(); @@ -294,8 +294,8 @@ public abstract class AbstractMetadataRepository } @Override - public Collection getArtifacts( RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion ) + public List getArtifacts( RepositorySession session, String repoId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException { throw new UnsupportedOperationException(); diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index 321ed2ef8..c63420ac5 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -29,7 +29,6 @@ import org.apache.archiva.metadata.model.ProjectVersionReference; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; import java.time.ZonedDateTime; -import java.util.Collection; import java.util.List; import java.util.stream.Stream; @@ -589,7 +588,7 @@ public interface MetadataRepository * @return A list of version strings, or a empty list if no versions are found, or this is not a snapshot version. * @throws MetadataResolutionException if the retrieval of the metadata failed. */ - Collection getArtifactVersions( RepositorySession session, String repoId, String namespace, String projectId, String projectVersion ) + List getArtifactVersions( RepositorySession session, String repoId, String namespace, String projectId, String projectVersion ) throws MetadataResolutionException; /** @@ -605,8 +604,8 @@ public interface MetadataRepository * @return a list of project references * @throws MetadataResolutionException if the version could not be found. */ - Collection getProjectReferences( RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion ) + List getProjectReferences( RepositorySession session, String repoId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException; /** @@ -617,7 +616,7 @@ public interface MetadataRepository * @return A list of namespace names, or empty list, if no namespace is stored for this repository. * @throws MetadataResolutionException If the retrieval failed. */ - Collection getRootNamespaces( RepositorySession session, String repoId ) + List getRootNamespaces( RepositorySession session, String repoId ) throws MetadataResolutionException; /** @@ -626,10 +625,10 @@ public interface MetadataRepository * @param session The repository session. * @param repoId The repository id. * @param namespace The parent namespace '.'-separated. - * @return {@link Collection} of child namespace names, or a empty list, if there are no children for the given parent namespace. + * @return {@link List} of child namespace names, or a empty list, if there are no children for the given parent namespace. * @throws MetadataResolutionException if the retrieval failed. */ - Collection getChildNamespaces( RepositorySession session, String repoId, String namespace ) + List getChildNamespaces( RepositorySession session, String repoId, String namespace ) throws MetadataResolutionException; /** @@ -641,7 +640,7 @@ public interface MetadataRepository * @return The list of project names or empty list if no project exists at the given namespace. * @throws MetadataResolutionException if the retrieval failed. */ - Collection getProjects( RepositorySession session, String repoId, String namespace ) + List getProjects( RepositorySession session, String repoId, String namespace ) throws MetadataResolutionException; /** @@ -654,7 +653,7 @@ public interface MetadataRepository * @return The list of versions or a empty list, if not version was found. * @throws MetadataResolutionException if the retrieval failed. */ - Collection getProjectVersions( RepositorySession session, String repoId, String namespace, String projectId ) + List getProjectVersions( RepositorySession session, String repoId, String namespace, String projectId ) throws MetadataResolutionException; /** @@ -682,8 +681,8 @@ public interface MetadataRepository * @return The list of artifact metadata objects, or a empty list, if no artifact exists for this version. * @throws MetadataResolutionException if the retrieval failed. */ - Collection getArtifacts( RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion ) + List getArtifacts( RepositorySession session, String repoId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException; /** diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java index f3a0fee9e..7a020efa8 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java @@ -459,7 +459,7 @@ public class CassandraMetadataRepository // FIXME this one need peformance improvement maybe a cache? @Override - public Collection getRootNamespaces( RepositorySession session, final String repoId ) + public List getRootNamespaces( RepositorySession session, final String repoId ) throws MetadataResolutionException { @@ -477,12 +477,12 @@ public class CassandraMetadataRepository namespaces.add( StringUtils.substringBefore( getStringValue( row.getColumnSlice(), NAME.toString() ), "." ) ); } - return namespaces; + return new ArrayList<>( namespaces ); } // FIXME this one need peformance improvement maybe a cache? @Override - public Collection getChildNamespaces( RepositorySession session, final String repoId, final String namespaceId ) + public List getChildNamespaces( RepositorySession session, final String repoId, final String namespaceId ) throws MetadataResolutionException { @@ -577,7 +577,7 @@ public class CassandraMetadataRepository } @Override - public Collection getProjects( RepositorySession session, final String repoId, final String namespace ) + public List getProjects( RepositorySession session, final String repoId, final String namespace ) throws MetadataResolutionException { @@ -596,7 +596,7 @@ public class CassandraMetadataRepository projects.add( getStringValue( row.getColumnSlice(), PROJECT_ID.toString() ) ); } - return projects; + return new ArrayList<>( projects ); } @Override @@ -642,7 +642,7 @@ public class CassandraMetadataRepository } @Override - public Collection getProjectVersions( RepositorySession session, final String repoId, final String namespace, final String projectId ) + public List getProjectVersions( RepositorySession session, final String repoId, final String namespace, final String projectId ) throws MetadataResolutionException { @@ -669,7 +669,7 @@ public class CassandraMetadataRepository versions.add( getStringValue( orderedRows.getColumnSlice(), PROJECT_VERSION.toString() ) ); } - return versions; + return new ArrayList<>( versions ); } @@ -1500,8 +1500,8 @@ public class CassandraMetadataRepository } @Override - public Collection getArtifactVersions( RepositorySession session, final String repoId, final String namespace, final String projectId, - final String projectVersion ) + public List getArtifactVersions( RepositorySession session, final String repoId, final String namespace, final String projectId, + final String projectVersion ) throws MetadataResolutionException { @@ -1522,11 +1522,11 @@ public class CassandraMetadataRepository versions.add( getStringValue( row.getColumnSlice(), VERSION.toString() ) ); } - return versions; + return new ArrayList<>( versions ); } - /** + /* * iterate over available facets to remove/add from the artifactMetadata * * @param facetedMetadata @@ -2237,8 +2237,8 @@ public class CassandraMetadataRepository @Override - public Collection getProjectReferences( RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion ) + public List getProjectReferences( RepositorySession session, String repoId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException { QueryResult> result = HFactory // @@ -2317,8 +2317,8 @@ public class CassandraMetadataRepository } @Override - public Collection getArtifacts( RepositorySession session, final String repoId, final String namespace, - final String projectId, final String projectVersion ) + public List getArtifacts( RepositorySession session, final String repoId, final String namespace, + final String projectId, final String projectVersion ) throws MetadataResolutionException { diff --git a/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java index e694ec915..a5e63a279 100644 --- a/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -498,8 +498,8 @@ public class FileMetadataRepository @Override - public Collection getArtifacts(RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion) + public List getArtifacts( RepositorySession session, String repoId, String namespace, String projectId, + String projectVersion) throws MetadataResolutionException { try { Map artifacts = new HashMap<>(); @@ -567,7 +567,7 @@ public class FileMetadataRepository } } } - return artifacts.values(); + return new ArrayList<>(artifacts.values()); } catch (IOException e) { throw new MetadataResolutionException(e.getMessage(), e); } @@ -996,8 +996,8 @@ public class FileMetadataRepository } @Override - public Collection getArtifactVersions(RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion) + public List getArtifactVersions( RepositorySession session, String repoId, String namespace, String projectId, + String projectVersion) throws MetadataResolutionException { try { Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion); @@ -1011,15 +1011,15 @@ public class FileMetadataRepository versions.add((String) entry.getValue()); } } - return versions; + return new ArrayList<>( versions ); } catch (IOException e) { throw new MetadataResolutionException(e.getMessage(), e); } } @Override - public Collection getProjectReferences(RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion) + public List getProjectReferences( RepositorySession session, String repoId, String namespace, String projectId, + String projectVersion) throws MetadataResolutionException { try { Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion); @@ -1044,7 +1044,7 @@ public class FileMetadataRepository } @Override - public Collection getRootNamespaces(RepositorySession session, String repoId) + public List getRootNamespaces( RepositorySession session, String repoId) throws MetadataResolutionException { return this.getChildNamespaces(session, repoId, null); } @@ -1076,7 +1076,7 @@ public class FileMetadataRepository } @Override - public Collection getChildNamespaces( RepositorySession session, String repoId, String baseNamespace) + public List getChildNamespaces( RepositorySession session, String repoId, String baseNamespace) throws MetadataResolutionException { try { List allNamespaces; @@ -1110,7 +1110,7 @@ public class FileMetadataRepository } @Override - public Collection getProjects(RepositorySession session, String repoId, String namespace) + public List getProjects( RepositorySession session, String repoId, String namespace) throws MetadataResolutionException { try { List projects; @@ -1132,7 +1132,7 @@ public class FileMetadataRepository } @Override - public Collection getProjectVersions(RepositorySession session, String repoId, String namespace, String projectId) + public List getProjectVersions( RepositorySession session, String repoId, String namespace, String projectId) throws MetadataResolutionException { try { List projectVersions; diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java index 2efdf9681..b11d5603f 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java @@ -1267,8 +1267,8 @@ public class JcrMetadataRepository } @Override - public Collection getArtifactVersions( RepositorySession session, String repositoryId, String namespace, String projectId, - String projectVersion ) + public List getArtifactVersions( RepositorySession session, String repositoryId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException { final Session jcrSession; @@ -1302,12 +1302,12 @@ public class JcrMetadataRepository throw new MetadataResolutionException( e.getMessage(), e ); } - return versions; + return new ArrayList<>( versions ); } @Override - public Collection getProjectReferences( RepositorySession session, String repositoryId, String namespace, - String projectId, String projectVersion ) + public List getProjectReferences( RepositorySession session, String repositoryId, String namespace, + String projectId, String projectVersion ) throws MetadataResolutionException { final Session jcrSession; @@ -1364,14 +1364,14 @@ public class JcrMetadataRepository } @Override - public Collection getRootNamespaces( RepositorySession session, String repositoryId ) + public List getRootNamespaces( RepositorySession session, String repositoryId ) throws MetadataResolutionException { return this.getChildNamespaces(session , repositoryId, null ); } @Override - public Collection getChildNamespaces( RepositorySession session, String repositoryId, String baseNamespace ) + public List getChildNamespaces( RepositorySession session, String repositoryId, String baseNamespace ) throws MetadataResolutionException { String path = baseNamespace != null @@ -1389,7 +1389,7 @@ public class JcrMetadataRepository } @Override - public Collection getProjects( RepositorySession session, String repositoryId, String namespace ) + public List getProjects( RepositorySession session, String repositoryId, String namespace ) throws MetadataResolutionException { try @@ -1403,7 +1403,7 @@ public class JcrMetadataRepository } @Override - public Collection getProjectVersions( RepositorySession session, String repositoryId, String namespace, String projectId ) + public List getProjectVersions( RepositorySession session, String repositoryId, String namespace, String projectId ) throws MetadataResolutionException { try @@ -1561,8 +1561,8 @@ public class JcrMetadataRepository } @Override - public Collection getArtifacts( RepositorySession session, String repositoryId, String namespace, String projectId, - String projectVersion ) + public List getArtifacts( RepositorySession session, String repositoryId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException { final Session jcrSession; @@ -1720,7 +1720,7 @@ public class JcrMetadataRepository return node.hasProperty( name ) ? node.getProperty( name ).getString() : null; } - private Collection getNodeNames( Session jcrSession, String path, String nodeType ) + private List getNodeNames( Session jcrSession, String path, String nodeType ) throws MetadataResolutionException { -- 2.39.5