Changing contract for nullable parameters

This commit is contained in:
Martin Stockhammer 2019-08-25 13:50:55 +02:00
parent 232ac43077
commit 811c445f04
5 changed files with 95 additions and 53 deletions

View File

@ -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<String> getMetadataFacets( @Nonnull RepositorySession session, @Nonnull String repositoryId, @Nonnull String facetId )
List<String> getMetadataFacets( RepositorySession session, String repositoryId, String facetId )
throws MetadataRepositoryException;
@ -184,8 +185,8 @@ public interface MetadataRepository
* @throws MetadataRepositoryException
* @since 3.0
*/
<T extends MetadataFacet> Stream<T> getMetadataFacetStream( @Nonnull RepositorySession session,
@Nonnull String repositoryId, @Nonnull Class<T> facetClazz)
<T extends MetadataFacet> Stream<T> getMetadataFacetStream( RepositorySession session,
String repositoryId, Class<T> facetClazz)
throws MetadataRepositoryException;
/**
@ -201,9 +202,9 @@ public interface MetadataRepository
* @throws MetadataRepositoryException
* @since 3.0
*/
<T extends MetadataFacet> Stream<T> getMetadataFacetStream(@Nonnull RepositorySession session,
@Nonnull String repositoryId, @Nonnull Class<T> facetClazz,
@Nonnull QueryParameter queryParameter)
<T extends MetadataFacet> Stream<T> getMetadataFacetStream( RepositorySession session,
String repositoryId, Class<T> 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 extends MetadataFacet> T getMetadataFacet(@Nonnull RepositorySession session, @Nonnull String repositoryId,
@Nonnull Class<T> clazz, @Nonnull String name)
<T extends MetadataFacet> T getMetadataFacet( RepositorySession session, String repositoryId,
Class<T> 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<ArtifactMetadata> getArtifactsByDateRange( @Nonnull RepositorySession session, @Nonnull String repositoryId,
List<ArtifactMetadata> 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<ArtifactMetadata> getArtifactsByDateRange(@Nonnull RepositorySession session, @Nonnull String repositoryId,
List<ArtifactMetadata> 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<ArtifactMetadata> getArtifactByDateRangeStream( @Nonnull RepositorySession session, @Nonnull String repositoryId,
Stream<ArtifactMetadata> 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<ArtifactMetadata> getArtifactByDateRangeStream( @Nonnull RepositorySession session, @Nonnull String repositoryId,
Stream<ArtifactMetadata> 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<ArtifactMetadata> getArtifactsByChecksum(@Nonnull RepositorySession session, @Nonnull String repositoryId, @Nonnull String checksum )
List<ArtifactMetadata> getArtifactsByChecksum( RepositorySession session, String repositoryId, String checksum )
throws MetadataRepositoryException;
/**
@ -378,7 +379,7 @@ public interface MetadataRepository
* @return a list of artifacts
* @throws MetadataRepositoryException
*/
List<ArtifactMetadata> getArtifactsByProjectVersionMetadata( @Nonnull RepositorySession session, @Nonnull String key, @Nonnull String value,
List<ArtifactMetadata> 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<ArtifactMetadata> getArtifactStream( @Nonnull RepositorySession session, @Nonnull String repositoryId, @Nonnull QueryParameter queryParameter )
Stream<ArtifactMetadata> 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<ArtifactMetadata> getArtifactStream( @Nonnull RepositorySession session, @Nonnull String repositoryId)
Stream<ArtifactMetadata> 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<ArtifactMetadata> getArtifactStream( @Nonnull RepositorySession session, @Nonnull String repoId,
@Nonnull String namespace, @Nonnull String projectId,
@Nonnull String projectVersion, @Nonnull QueryParameter queryParameter )
Stream<ArtifactMetadata> 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<ArtifactMetadata> getArtifactStream( @Nonnull RepositorySession session, @Nonnull String repoId,
@Nonnull String namespace, @Nonnull String projectId,
@Nonnull String projectVersion)
Stream<ArtifactMetadata> getArtifactStream( RepositorySession session, String repoId,
String namespace, String projectId,
String projectVersion)
throws MetadataResolutionException;
/**
* basically just checking it exists not complete data returned

View File

@ -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
{

View File

@ -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<ArtifactMetadata> getArtifactStream( @Nonnull final RepositorySession session, @Nonnull final String repositoryId,
@Nonnull QueryParameter queryParameter ) throws MetadataResolutionException
public Stream<ArtifactMetadata> getArtifactStream( final RepositorySession session, final String repositoryId,
QueryParameter queryParameter ) throws MetadataResolutionException
{
return getAllNamespacesStream( session, repositoryId ).filter( Objects::nonNull ).flatMap( ns ->

View File

@ -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
{

View File

@ -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 ) )