From 811c445f04c90293b4ff30fbbc8f36a5e174d2e7 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 25 Aug 2019 13:50:55 +0200 Subject: [PATCH] Changing contract for nullable parameters --- .../repository/MetadataRepository.java | 81 ++++++++++--------- .../CassandraMetadataRepository.java | 2 + .../file/FileMetadataRepository.java | 56 +++++++++++-- .../repository/jcr/JcrMetadataRepository.java | 2 + .../repository/jcr/OakRepositoryFactory.java | 7 +- 5 files changed, 95 insertions(+), 53 deletions(-) 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 c267b3678..bf3d8bab5 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 @@ -26,8 +26,8 @@ import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; -import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; import java.time.ZonedDateTime; import java.util.Collection; import java.util.List; @@ -94,6 +94,7 @@ import java.util.stream.Stream; * But for some backends there is no difference. * */ +@ParametersAreNonnullByDefault public interface MetadataRepository { @@ -107,7 +108,7 @@ public interface MetadataRepository * @param project the project metadata to create or update * @throws MetadataRepositoryException if the update fails */ - void updateProject( @Nonnull RepositorySession session, @Nonnull String repositoryId, @Nonnull ProjectMetadata project ) + void updateProject( RepositorySession session, String repositoryId, ProjectMetadata project ) throws MetadataRepositoryException; /** @@ -121,9 +122,9 @@ public interface MetadataRepository * @param artifactMeta Information about the artifact itself. * @throws MetadataRepositoryException if something goes wrong during update. */ - void updateArtifact( @Nonnull RepositorySession session, @Nonnull String repositoryId, - @Nonnull String namespace, @Nonnull String projectId, @Nonnull String projectVersion, - @Nonnull ArtifactMetadata artifactMeta ) + void updateArtifact( RepositorySession session, String repositoryId, + String namespace, String projectId, String projectVersion, + ArtifactMetadata artifactMeta ) throws MetadataRepositoryException; /** @@ -137,9 +138,9 @@ public interface MetadataRepository * @param versionMetadata The metadata for the version * @throws MetadataRepositoryException if something goes wrong during update */ - void updateProjectVersion( @Nonnull RepositorySession session, @Nonnull String repositoryId, - @Nonnull String namespace, @Nonnull String projectId, - @Nonnull ProjectVersionMetadata versionMetadata ) + void updateProjectVersion( RepositorySession session, String repositoryId, + String namespace, String projectId, + ProjectVersionMetadata versionMetadata ) throws MetadataRepositoryException; /** @@ -151,7 +152,7 @@ public interface MetadataRepository * @param namespace The namespace ('.' separated) * @throws MetadataRepositoryException if something goes wrong during update */ - void updateNamespace( @Nonnull RepositorySession session, @Nonnull String repositoryId, @Nonnull String namespace ) + void updateNamespace( RepositorySession session, String repositoryId, String namespace ) throws MetadataRepositoryException; /** @@ -163,7 +164,7 @@ public interface MetadataRepository * @return The list of facet names, or an empty list, if there are no facets stored on this repository for the given facet id. * @throws MetadataRepositoryException if something goes wrong */ - List getMetadataFacets( @Nonnull RepositorySession session, @Nonnull String repositoryId, @Nonnull String facetId ) + List getMetadataFacets( RepositorySession session, String repositoryId, String facetId ) throws MetadataRepositoryException; @@ -184,8 +185,8 @@ public interface MetadataRepository * @throws MetadataRepositoryException * @since 3.0 */ - Stream getMetadataFacetStream( @Nonnull RepositorySession session, - @Nonnull String repositoryId, @Nonnull Class facetClazz) + Stream getMetadataFacetStream( RepositorySession session, + String repositoryId, Class facetClazz) throws MetadataRepositoryException; /** @@ -201,9 +202,9 @@ public interface MetadataRepository * @throws MetadataRepositoryException * @since 3.0 */ - Stream getMetadataFacetStream(@Nonnull RepositorySession session, - @Nonnull String repositoryId, @Nonnull Class facetClazz, - @Nonnull QueryParameter queryParameter) + Stream getMetadataFacetStream( RepositorySession session, + String repositoryId, Class facetClazz, + QueryParameter queryParameter) throws MetadataRepositoryException; /** @@ -217,7 +218,7 @@ public interface MetadataRepository * @throws MetadataRepositoryException if something goes wrong * @since 1.4-M4 */ - boolean hasMetadataFacet( @Nonnull RepositorySession session, @Nonnull String repositoryId, @Nonnull String facetId ) + boolean hasMetadataFacet( RepositorySession session, String repositoryId, String facetId ) throws MetadataRepositoryException; /** @@ -231,8 +232,8 @@ public interface MetadataRepository * @return The facet values * @throws MetadataRepositoryException if something goes wrong. */ - MetadataFacet getMetadataFacet( @Nonnull RepositorySession session, @Nonnull String repositoryId, @Nonnull String facetId, - @Nonnull String name ) + MetadataFacet getMetadataFacet( RepositorySession session, String repositoryId, String facetId, + String name ) throws MetadataRepositoryException; /** @@ -249,8 +250,8 @@ public interface MetadataRepository * @throws MetadataRepositoryException if the data cannot be retrieved from the backend * @since 3.0 */ - T getMetadataFacet(@Nonnull RepositorySession session, @Nonnull String repositoryId, - @Nonnull Class clazz, @Nonnull String name) + T getMetadataFacet( RepositorySession session, String repositoryId, + Class clazz, String name) throws MetadataRepositoryException; /** @@ -261,8 +262,8 @@ public interface MetadataRepository * @param metadataFacet The facet to add * @throws MetadataRepositoryException if the facet cannot be stored. */ - void addMetadataFacet( @Nonnull RepositorySession session, @Nonnull String repositoryId, - @Nonnull MetadataFacet metadataFacet ) + void addMetadataFacet( RepositorySession session, String repositoryId, + MetadataFacet metadataFacet ) throws MetadataRepositoryException; /** @@ -273,7 +274,7 @@ public interface MetadataRepository * @param facetId The facet id * @throws MetadataRepositoryException if the removal fails */ - void removeMetadataFacets( @Nonnull RepositorySession session, @Nonnull String repositoryId, @Nonnull String facetId ) + void removeMetadataFacets( RepositorySession session, String repositoryId, String facetId ) throws MetadataRepositoryException; /** @@ -284,7 +285,7 @@ public interface MetadataRepository * @param facetId The facet id * @param name The facet name or path */ - void removeMetadataFacet( @Nonnull RepositorySession session, @Nonnull String repositoryId, @Nonnull String facetId, @Nonnull String name ) + void removeMetadataFacet( RepositorySession session, String repositoryId, String facetId, String name ) throws MetadataRepositoryException; @@ -293,7 +294,7 @@ public interface MetadataRepository * uses default query parameters. * */ - List getArtifactsByDateRange( @Nonnull RepositorySession session, @Nonnull String repositoryId, + List getArtifactsByDateRange( RepositorySession session, String repositoryId, @Nullable ZonedDateTime startTime, @Nullable ZonedDateTime endTime ) throws MetadataRepositoryException; @@ -312,9 +313,9 @@ public interface MetadataRepository * @throws MetadataRepositoryException if the query fails. * @since 3.0 */ - List getArtifactsByDateRange(@Nonnull RepositorySession session, @Nonnull String repositoryId, + List getArtifactsByDateRange( RepositorySession session, String repositoryId, @Nullable ZonedDateTime startTime, @Nullable ZonedDateTime endTime, - @Nonnull QueryParameter queryParameter ) + QueryParameter queryParameter ) throws MetadataRepositoryException; @@ -331,7 +332,7 @@ public interface MetadataRepository * @throws MetadataRepositoryException * @since 3.0 */ - Stream getArtifactByDateRangeStream( @Nonnull RepositorySession session, @Nonnull String repositoryId, + Stream getArtifactByDateRangeStream( RepositorySession session, String repositoryId, @Nullable ZonedDateTime startTime, @Nullable ZonedDateTime endTime ) throws MetadataRepositoryException; @@ -349,9 +350,9 @@ public interface MetadataRepository * @throws MetadataRepositoryException * @since 3.0 */ - Stream getArtifactByDateRangeStream( @Nonnull RepositorySession session, @Nonnull String repositoryId, + Stream getArtifactByDateRangeStream( RepositorySession session, String repositoryId, @Nullable ZonedDateTime startTime, @Nullable ZonedDateTime endTime, - @Nonnull QueryParameter queryParameter) + QueryParameter queryParameter) throws MetadataRepositoryException; @@ -364,7 +365,7 @@ public interface MetadataRepository * @return The list of artifacts that match the given checksum. * @throws MetadataRepositoryException */ - List getArtifactsByChecksum(@Nonnull RepositorySession session, @Nonnull String repositoryId, @Nonnull String checksum ) + List getArtifactsByChecksum( RepositorySession session, String repositoryId, String checksum ) throws MetadataRepositoryException; /** @@ -378,7 +379,7 @@ public interface MetadataRepository * @return a list of artifacts * @throws MetadataRepositoryException */ - List getArtifactsByProjectVersionMetadata( @Nonnull RepositorySession session, @Nonnull String key, @Nonnull String value, + List getArtifactsByProjectVersionMetadata( RepositorySession session, String key, String value, @Nullable String repositoryId ) throws MetadataRepositoryException; @@ -481,7 +482,7 @@ public interface MetadataRepository * @return A stream of artifact metadata objects for each artifact found in the repository. * @since 3.0 */ - Stream getArtifactStream( @Nonnull RepositorySession session, @Nonnull String repositoryId, @Nonnull QueryParameter queryParameter ) + Stream getArtifactStream( RepositorySession session, String repositoryId, QueryParameter queryParameter ) throws MetadataResolutionException; /** @@ -497,7 +498,7 @@ public interface MetadataRepository * @since 3.0 * @see #getArtifactStream(RepositorySession, String, QueryParameter) */ - Stream getArtifactStream( @Nonnull RepositorySession session, @Nonnull String repositoryId) + Stream getArtifactStream( RepositorySession session, String repositoryId) throws MetadataResolutionException; /** @@ -512,9 +513,9 @@ public interface MetadataRepository * @since 3.0 * @throws MetadataResolutionException if there are no elements for the given artifact coordinates. */ - Stream getArtifactStream( @Nonnull RepositorySession session, @Nonnull String repoId, - @Nonnull String namespace, @Nonnull String projectId, - @Nonnull String projectVersion, @Nonnull QueryParameter queryParameter ) + Stream getArtifactStream( RepositorySession session, String repoId, + String namespace, String projectId, + String projectVersion, QueryParameter queryParameter ) throws MetadataResolutionException; /** @@ -530,9 +531,9 @@ public interface MetadataRepository * @since 3.0 * @throws MetadataResolutionException if there are no elements for the given artifact coordinates. */ - Stream getArtifactStream( @Nonnull RepositorySession session, @Nonnull String repoId, - @Nonnull String namespace, @Nonnull String projectId, - @Nonnull String projectVersion) + Stream getArtifactStream( RepositorySession session, String repoId, + String namespace, String projectId, + String projectVersion) throws MetadataResolutionException; /** * basically just checking it exists not complete data returned 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 763713572..1b6646a3b 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 @@ -71,6 +71,7 @@ import org.modelmapper.ModelMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.ParametersAreNonnullByDefault; import java.time.Instant; import java.time.ZonedDateTime; import java.util.*; @@ -88,6 +89,7 @@ import static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames * @author Olivier Lamy * @since 2.0.0 */ +@ParametersAreNonnullByDefault public class CassandraMetadataRepository extends AbstractMetadataRepository implements MetadataRepository { 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 4719d92a0..aa4e25ab3 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 @@ -23,26 +23,66 @@ import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.archiva.metadata.QueryParameter; -import org.apache.archiva.metadata.model.*; -import org.apache.archiva.metadata.repository.*; +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.model.CiManagement; +import org.apache.archiva.metadata.model.Dependency; +import org.apache.archiva.metadata.model.IssueManagement; +import org.apache.archiva.metadata.model.License; +import org.apache.archiva.metadata.model.MailingList; +import org.apache.archiva.metadata.model.MetadataFacet; +import org.apache.archiva.metadata.model.MetadataFacetFactory; +import org.apache.archiva.metadata.model.Organization; +import org.apache.archiva.metadata.model.ProjectMetadata; +import org.apache.archiva.metadata.model.ProjectVersionMetadata; +import org.apache.archiva.metadata.model.ProjectVersionReference; +import org.apache.archiva.metadata.model.Scm; +import org.apache.archiva.metadata.repository.AbstractMetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; +import org.apache.archiva.metadata.repository.MetadataResolutionException; +import org.apache.archiva.metadata.repository.MetadataService; +import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.nio.file.*; +import java.nio.file.FileVisitOption; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.Set; +import java.util.StringTokenizer; import java.util.stream.Collectors; import java.util.stream.Stream; +/** + * File implementation of the metadata repository. It uses property files in a separate directory tree. + * The implementation has no fulltext index. So fulltext queries are not supported. + * + * Some retrieval methods may not be very efficient. + */ +@ParametersAreNonnullByDefault public class FileMetadataRepository extends AbstractMetadataRepository implements MetadataRepository { @@ -1213,8 +1253,8 @@ public class FileMetadataRepository } @Override - public Stream getArtifactStream( @Nonnull final RepositorySession session, @Nonnull final String repositoryId, - @Nonnull QueryParameter queryParameter ) throws MetadataResolutionException + public Stream getArtifactStream( final RepositorySession session, final String repositoryId, + QueryParameter queryParameter ) throws MetadataResolutionException { return getAllNamespacesStream( session, repositoryId ).filter( Objects::nonNull ).flatMap( ns -> 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 a9d0a85eb..07ef40c29 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 @@ -41,6 +41,7 @@ import org.apache.jackrabbit.commons.cnd.ParseException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.ParametersAreNonnullByDefault; import javax.jcr.NamespaceRegistry; import javax.jcr.Node; import javax.jcr.NodeIterator; @@ -76,6 +77,7 @@ import static org.apache.archiva.metadata.repository.jcr.JcrConstants.*; * TODO below: revise storage format for project version metadata * TODO revise reference storage */ +@ParametersAreNonnullByDefault public class JcrMetadataRepository extends AbstractMetadataRepository implements MetadataRepository, RepositoryStatisticsProvider { diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/OakRepositoryFactory.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/OakRepositoryFactory.java index d30304860..1db4fd1e7 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/OakRepositoryFactory.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/OakRepositoryFactory.java @@ -75,7 +75,6 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; import javax.jcr.Repository; import java.io.Closeable; import java.io.IOException; @@ -90,14 +89,12 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import static com.google.common.base.Preconditions.checkNotNull; +import static org.apache.archiva.metadata.repository.jcr.JcrConstants.*; import static org.apache.archiva.metadata.repository.jcr.OakRepositoryFactory.StoreType.IN_MEMORY_TYPE; import static org.apache.archiva.metadata.repository.jcr.OakRepositoryFactory.StoreType.SEGMENT_FILE_TYPE; import static org.apache.commons.io.FileUtils.ONE_MB; import static org.apache.jackrabbit.JcrConstants.*; import static org.apache.jackrabbit.oak.api.Type.NAME; -import static org.apache.archiva.metadata.repository.jcr.JcrConstants.*; -import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean; -import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.scheduleWithFixedDelay; /** * Created by martin on 14.06.17. @@ -430,7 +427,7 @@ public class OakRepositoryFactory } @Override - public void initialize( @Nonnull NodeBuilder root ) + public void initialize( NodeBuilder root ) { NodeBuilder namespaces; if ( !root.hasChildNode( NamespaceConstants.REP_NAMESPACES ) ) -- 2.39.5