From 20257a2d59f1bf797df55b616db83af1e9a50209 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sat, 20 Jun 2020 19:54:20 +0200 Subject: [PATCH] Dependency cleanup of metadata-store-cassandra --- .../plugins/metadata-store-cassandra/pom.xml | 75 +++++++++++----- .../CassandraMetadataRepository.java | 85 ++++++++----------- .../CassandraRepositorySessionFactory.java | 6 +- .../CassandraMetadataRepositoryTest.java | 2 +- .../cassandra/RepositoriesNamespaceTest.java | 2 +- status-dep.txt | 1 + 6 files changed, 95 insertions(+), 76 deletions(-) diff --git a/archiva-modules/plugins/metadata-store-cassandra/pom.xml b/archiva-modules/plugins/metadata-store-cassandra/pom.xml index 5b9cc0603..07e066b26 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/pom.xml +++ b/archiva-modules/plugins/metadata-store-cassandra/pom.xml @@ -50,15 +50,50 @@ org.apache.archiva - archiva-test-utils - ${project.version} - test - - - org.slf4j - slf4j-simple - - + archiva-common + + + org.apache.archiva + archiva-configuration + + + org.apache.archiva + archiva-policies + + + org.apache.archiva + archiva-xml-tools + + + org.apache.archiva + archiva-repository-api + + + org.apache.archiva + archiva-checksum + + + org.apache.archiva + metadata-model + + + + + javax.annotation + javax.annotation-api + + + javax.inject + javax.inject + + + + org.springframework + spring-beans + + + org.springframework + spring-context @@ -154,6 +189,18 @@ + + org.apache.archiva + archiva-test-utils + ${project.version} + test + + + org.slf4j + slf4j-simple + + + org.easymock easymock @@ -185,17 +232,7 @@ ${log4j.version} test - - com.lmax - disruptor - test - - - org.apache.archiva.components.cache - archiva-components-spring-cache-ehcache - test - 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 d350c6792..bc8d7da66 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 @@ -19,8 +19,6 @@ package org.apache.archiva.metadata.repository.cassandra; * under the License. */ -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; import me.prettyprint.cassandra.serializers.LongSerializer; import me.prettyprint.cassandra.serializers.StringSerializer; import me.prettyprint.cassandra.service.template.ColumnFamilyResult; @@ -38,7 +36,6 @@ import me.prettyprint.hector.api.mutation.Mutator; import me.prettyprint.hector.api.query.QueryResult; import me.prettyprint.hector.api.query.RangeSlicesQuery; import org.apache.archiva.checksum.ChecksumAlgorithm; -import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.metadata.QueryParameter; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.CiManagement; @@ -73,7 +70,18 @@ import org.slf4j.LoggerFactory; import java.time.Instant; import java.time.ZonedDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Spliterator; +import java.util.UUID; import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -95,8 +103,6 @@ public class CassandraMetadataRepository private static final String ARTIFACT_METADATA_MODEL_KEY = "artifactMetadataModel.key"; private Logger logger = LoggerFactory.getLogger( getClass() ); - private ArchivaConfiguration configuration; - private final CassandraArchivaManager cassandraArchivaManager; private final ColumnFamilyTemplate projectVersionMetadataTemplate; @@ -120,11 +126,9 @@ public class CassandraMetadataRepository private final StringSerializer ss = StringSerializer.get(); public CassandraMetadataRepository( MetadataService metadataService, - ArchivaConfiguration configuration, CassandraArchivaManager cassandraArchivaManager ) { super( metadataService ); - this.configuration = configuration; this.cassandraArchivaManager = cassandraArchivaManager; this.keyspace = cassandraArchivaManager.getKeyspace(); @@ -468,7 +472,7 @@ public class CassandraMetadataRepository .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // .execute(); - Set namespaces = new HashSet( result.get().getCount() ); + Set namespaces = new HashSet<>( result.get( ).getCount( ) ); for ( Row row : result.get() ) { @@ -553,11 +557,7 @@ public class CassandraMetadataRepository .execute(); // project exists ? if yes return nothing to update here - if ( result.get().getCount() > 0 ) - { - return; - } - else + if ( result.get( ).getCount( ) <= 0 ) { Namespace namespace = updateOrAddNamespace( repositoryId, projectMetadata.getNamespace() ); @@ -587,7 +587,7 @@ public class CassandraMetadataRepository .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // .execute(); - final Set projects = new HashSet( result.get().getCount() ); + final Set projects = new HashSet<>( result.get( ).getCount( ) ); for ( Row row : result.get() ) { @@ -660,7 +660,7 @@ public class CassandraMetadataRepository return Collections.emptyList(); } - Set versions = new HashSet( count ); + Set versions = new HashSet<>( count ); for ( Row orderedRows : result.get() ) { @@ -757,7 +757,7 @@ public class CassandraMetadataRepository .addEqualsExpression( PROJECT_VERSION.toString(), versionMetadata.getId() ) // .execute(); - ProjectVersionMetadataModel projectVersionMetadataModel = null; + ProjectVersionMetadataModel projectVersionMetadataModel; boolean creation = true; if ( result.get().getCount() > 0 ) { @@ -853,7 +853,7 @@ public class CassandraMetadataRepository recordDependencies( key, versionMetadata.getDependencies(), repositoryId ); - MutationResult mutationResult = mutator.execute(); + mutator.execute(); } else { @@ -1021,12 +1021,7 @@ public class CassandraMetadataRepository { ColumnSlice columnSlice = row.getColumnSlice(); String facetId = getStringValue( columnSlice, FACET_ID.toString() ); - Map metaValues = metadataFacetsPerFacetIds.get( facetId ); - if ( metaValues == null ) - { - metaValues = new HashMap<>(); - metadataFacetsPerFacetIds.put( facetId, metaValues ); - } + Map metaValues = metadataFacetsPerFacetIds.computeIfAbsent( facetId, k -> new HashMap<>( ) ); metaValues.put( getStringValue( columnSlice, KEY.toString() ), getStringValue( columnSlice, VALUE.toString() ) ); } @@ -1034,7 +1029,7 @@ public class CassandraMetadataRepository { for ( Map.Entry> entry : metadataFacetsPerFacetIds.entrySet() ) { - MetadataFacetFactory metadataFacetFactory = getFacetFactory( entry.getKey() ); + MetadataFacetFactory metadataFacetFactory = getFacetFactory( entry.getKey() ); if ( metadataFacetFactory != null ) { MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet(); @@ -1381,13 +1376,13 @@ public class CassandraMetadataRepository private Map mapChecksums(Map checksums) { return checksums.entrySet().stream().collect(Collectors.toMap( - e -> e.getKey().name(), e -> e.getValue() + e -> e.getKey().name(), Map.Entry::getValue )); } private Map mapChecksumsReverse(Map checksums) { return checksums.entrySet().stream().collect(Collectors.toMap( - e -> ChecksumAlgorithm.valueOf(e.getKey()), e -> e.getValue() + e -> ChecksumAlgorithm.valueOf(e.getKey()), Map.Entry::getValue )); } @@ -1736,10 +1731,6 @@ public class CassandraMetadataRepository return null; } final String facetId = metadataFacetFactory.getFacetId( ); - if ( metadataFacetFactory == null ) - { - return null; - } QueryResult> result = HFactory // .createRangeSlicesQuery( keyspace, ss, ss, ss ) // @@ -2025,7 +2016,7 @@ public class CassandraMetadataRepository } } - return new ArrayList(artifactMetadataMap.values()); + return new ArrayList<>(artifactMetadataMap.values()); } /** @@ -2064,7 +2055,7 @@ public class CassandraMetadataRepository return Collections.emptyList(); } - List artifactMetadatas = new LinkedList(); + List artifactMetadatas = new LinkedList<>( ); // TODO doing multiple queries, there should be a way to get all the artifactMetadatas for any number of // projects @@ -2117,7 +2108,7 @@ public class CassandraMetadataRepository return Collections.emptyList(); } - List artifacts = new LinkedList(); + List artifacts = new LinkedList<>( ); for ( Row row : result.get() ) { @@ -2384,21 +2375,15 @@ public class CassandraMetadataRepository for ( final ArtifactMetadata artifactMetadata : artifactMetadatas ) { - Iterable metadataFacetModelIterable = - Iterables.filter( metadataFacetModels, new Predicate() + Iterator iterator = metadataFacetModels.stream( ).filter( metadataFacetModel -> { + if ( metadataFacetModel != null ) { - @Override - public boolean apply( MetadataFacetModel metadataFacetModel ) - { - if ( metadataFacetModel != null ) - { - return StringUtils.equals( artifactMetadata.getVersion(), - metadataFacetModel.getProjectVersion() ); - } - return false; - } - } ); - Iterator iterator = metadataFacetModelIterable.iterator(); + return StringUtils.equals( artifactMetadata.getVersion( ), + metadataFacetModel.getProjectVersion( ) ); + } + return false; + + } ).iterator( ); Map> metadataFacetValuesPerFacetId = new HashMap<>(); while ( iterator.hasNext() ) { @@ -2415,7 +2400,7 @@ public class CassandraMetadataRepository for ( Map.Entry> entry : metadataFacetValuesPerFacetId.entrySet() ) { - MetadataFacetFactory metadataFacetFactory = getFacetFactory( entry.getKey() ); + MetadataFacetFactory metadataFacetFactory = getFacetFactory( entry.getKey() ); if ( metadataFacetFactory != null ) { List facetModels = entry.getValue(); @@ -2476,7 +2461,7 @@ public class CassandraMetadataRepository throws MetadataRepositoryException { // TODO optimize - List artifacts = new LinkedList(); + List artifacts = new LinkedList<>( ); artifacts.addAll( this.getArtifactsByAttribute( session, key, text, repositoryId ) ); artifacts.addAll( this.getArtifactsByProjectVersionAttribute( session, key, text, repositoryId ) ); return artifacts; diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java index b36dc387f..2f3077b3c 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java @@ -20,21 +20,17 @@ package org.apache.archiva.metadata.repository.cassandra; */ import org.apache.archiva.configuration.ArchivaConfiguration; -import org.apache.archiva.metadata.model.MetadataFacetFactory; import org.apache.archiva.metadata.repository.AbstractRepositorySessionFactory; import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.archiva.metadata.repository.MetadataService; import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySessionFactory; -import org.apache.commons.lang3.StringUtils; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; import javax.inject.Inject; import javax.inject.Named; -import java.util.HashMap; -import java.util.Map; /** * @author Olivier Lamy @@ -75,7 +71,7 @@ public class CassandraRepositorySessionFactory extends AbstractRepositorySession public RepositorySession createSession() throws MetadataRepositoryException { CassandraMetadataRepository metadataRepository = - new CassandraMetadataRepository( metadataService, configuration, cassandraArchivaManager ); + new CassandraMetadataRepository( metadataService, cassandraArchivaManager ); return new RepositorySession( metadataRepository, metadataResolver ); } diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java index b095f0533..ea03801c5 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java @@ -93,7 +93,7 @@ public class CassandraMetadataRepositoryTest MetadataService metadataService = new MetadataService( ); metadataService.setMetadataFacetFactories( factories ); - this.cmr = new CassandraMetadataRepository( metadataService, null, cassandraArchivaManager ); + this.cmr = new CassandraMetadataRepository( metadataService, cassandraArchivaManager ); sessionFactoryControl = EasyMock.createControl( ); sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class ); diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java index 09e7fcd5d..9a631907f 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java @@ -57,7 +57,7 @@ public class RepositoriesNamespaceTest public void setup() throws Exception { - cmr = new CassandraMetadataRepository( null, null, cassandraArchivaManager ); + cmr = new CassandraMetadataRepository( null, cassandraArchivaManager ); if ( !cassandraArchivaManager.started() ) { cassandraArchivaManager.start(); diff --git a/status-dep.txt b/status-dep.txt index a43ca99f6..a806a439c 100644 --- a/status-dep.txt +++ b/status-dep.txt @@ -55,6 +55,7 @@ archiva-modules metadata-store-file audit problem-reports + metadata-store-cassandra -- 2.39.5