From 2ab8942ccff2a85c356b878875632410a3999ce8 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 5 Nov 2017 19:36:42 +0100 Subject: [PATCH] Extracting indexing api as single module [MRM-1964] Step to move all indexing features behind archiva API --- .../archiva-base/archiva-indexer-api/pom.xml | 99 +++++++++++++++++++ .../indexer/search/ArtifactInfoFilter.java | 5 +- .../indexer/search/RepositorySearch.java | 4 +- .../search/RepositorySearchException.java | 0 .../archiva/indexer/search/SearchFields.java | 0 .../indexer/search/SearchResultHit.java | 0 .../indexer/search/SearchResultLimits.java | 0 .../archiva/indexer/search/SearchResults.java | 0 .../archiva/indexer/util/SearchUtil.java | 36 +++++++ .../resources/META-INF/spring-context.xml | 39 ++++++++ .../archiva-base/archiva-indexer/pom.xml | 4 + .../indexer/search/MavenRepositorySearch.java | 31 +++++- .../NoClassifierArtifactInfoFilter.java | 4 +- archiva-modules/archiva-base/pom.xml | 1 + .../webdav/ArchivaDavResourceFactory.java | 6 +- pom.xml | 5 + 16 files changed, 221 insertions(+), 13 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-indexer-api/pom.xml rename archiva-modules/archiva-base/{archiva-indexer => archiva-indexer-api}/src/main/java/org/apache/archiva/indexer/search/ArtifactInfoFilter.java (81%) rename archiva-modules/archiva-base/{archiva-indexer => archiva-indexer-api}/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java (94%) rename archiva-modules/archiva-base/{archiva-indexer => archiva-indexer-api}/src/main/java/org/apache/archiva/indexer/search/RepositorySearchException.java (100%) rename archiva-modules/archiva-base/{archiva-indexer => archiva-indexer-api}/src/main/java/org/apache/archiva/indexer/search/SearchFields.java (100%) rename archiva-modules/archiva-base/{archiva-indexer => archiva-indexer-api}/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java (100%) rename archiva-modules/archiva-base/{archiva-indexer => archiva-indexer-api}/src/main/java/org/apache/archiva/indexer/search/SearchResultLimits.java (100%) rename archiva-modules/archiva-base/{archiva-indexer => archiva-indexer-api}/src/main/java/org/apache/archiva/indexer/search/SearchResults.java (100%) create mode 100644 archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/util/SearchUtil.java create mode 100644 archiva-modules/archiva-base/archiva-indexer-api/src/main/resources/META-INF/spring-context.xml diff --git a/archiva-modules/archiva-base/archiva-indexer-api/pom.xml b/archiva-modules/archiva-base/archiva-indexer-api/pom.xml new file mode 100644 index 000000000..5aec104c3 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-indexer-api/pom.xml @@ -0,0 +1,99 @@ + + + + + + org.apache.archiva + archiva-base + 3.0.0-SNAPSHOT + + 4.0.0 + archiva-indexer-api + bundle + Archiva Base :: Indexer API + + + + org.apache.archiva + archiva-common + + + + commons-lang + commons-lang + + + org.apache.archiva + archiva-model + + + + + + + org.apache.rat + apache-rat-plugin + + + src/test/maven-search-test-repo*/** + src/test/repo-release*/** + + + + + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.archiva.indexer.api + ${project.version} + + org.apache.archiva.indexer.*;version=${project.version};-split-package:=merge-first + + + javax.annotation, + javax.inject, + org.apache.commons.lang*;version="[2.4,3)", + org.slf4j;resolution:=optional + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${project.build.directory}/appserver-base + ${project.build.directory}/appserver-base + ${project.build.directory}/appserver-base + ${redbackTestJdbcUrl} + ${redbackTestJdbcDriver} + mock + ${openjpa.Log} + + + + + + diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/ArtifactInfoFilter.java b/archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/ArtifactInfoFilter.java similarity index 81% rename from archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/ArtifactInfoFilter.java rename to archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/ArtifactInfoFilter.java index cecb8c8bf..39c32daf6 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/ArtifactInfoFilter.java +++ b/archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/ArtifactInfoFilter.java @@ -18,7 +18,8 @@ package org.apache.archiva.indexer.search; * under the License. */ -import org.apache.maven.index.ArtifactInfo; +import org.apache.archiva.model.ArchivaArtifactModel; +import org.apache.archiva.model.ArtifactReference; import java.util.Map; @@ -28,5 +29,5 @@ import java.util.Map; */ public interface ArtifactInfoFilter { - boolean addArtifactInResult( ArtifactInfo artifact, Map currentResult ); + boolean addArtifactInResult( ArchivaArtifactModel artifact, Map currentResult ); } diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java similarity index 94% rename from archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java rename to archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java index 4879ee353..272561b32 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java @@ -19,8 +19,6 @@ package org.apache.archiva.indexer.search; * under the License. */ -import org.apache.archiva.admin.model.RepositoryAdminException; - import java.util.Collection; import java.util.List; import java.util.Set; @@ -57,5 +55,5 @@ public interface RepositorySearch throws RepositorySearchException; Set getRemoteIndexingContextIds( String managedRepoId ) - throws RepositoryAdminException; + throws RepositorySearchException; } diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearchException.java b/archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/RepositorySearchException.java similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearchException.java rename to archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/RepositorySearchException.java diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchFields.java b/archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/SearchFields.java similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchFields.java rename to archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/SearchFields.java diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java b/archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java rename to archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultLimits.java b/archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/SearchResultLimits.java similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultLimits.java rename to archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/SearchResultLimits.java diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResults.java b/archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/SearchResults.java similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResults.java rename to archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/search/SearchResults.java diff --git a/archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/util/SearchUtil.java b/archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/util/SearchUtil.java new file mode 100644 index 000000000..0a0c922ee --- /dev/null +++ b/archiva-modules/archiva-base/archiva-indexer-api/src/main/java/org/apache/archiva/indexer/util/SearchUtil.java @@ -0,0 +1,36 @@ +package org.apache.archiva.indexer.util; + +/* + * 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.commons.lang.StringUtils; + +/** + * SearchUtil - utility class for search. + */ +public class SearchUtil +{ + public static String getHitId( String groupId, String artifactId, String classifier, String packaging ) + { + return ( StringUtils.isBlank( groupId ) ? "" : StringUtils.trim( groupId ) ) + ":" // + + ( StringUtils.isBlank( artifactId ) ? "" : StringUtils.trim( artifactId ) ) + ":" // + + ( StringUtils.isBlank( classifier ) ? "" : StringUtils.trim( classifier ) ) + ":" // + + ( StringUtils.isBlank( packaging ) ? "" : StringUtils.trim( packaging ) ); + } +} diff --git a/archiva-modules/archiva-base/archiva-indexer-api/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-indexer-api/src/main/resources/META-INF/spring-context.xml new file mode 100644 index 000000000..ce334de40 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-indexer-api/src/main/resources/META-INF/spring-context.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-indexer/pom.xml b/archiva-modules/archiva-base/archiva-indexer/pom.xml index 992fcf7ef..ab0d89792 100644 --- a/archiva-modules/archiva-base/archiva-indexer/pom.xml +++ b/archiva-modules/archiva-base/archiva-indexer/pom.xml @@ -42,6 +42,10 @@ org.apache.archiva archiva-repository-layer + + org.apache.archiva + archiva-indexer-api + diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java index 892d7b71a..b6f49840e 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java @@ -26,6 +26,8 @@ import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin; import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; import org.apache.archiva.indexer.util.SearchUtil; +import org.apache.archiva.model.ArchivaArtifactModel; +import org.apache.archiva.model.ArtifactReference; import org.apache.commons.lang.StringUtils; import org.apache.maven.index.ArtifactInfo; import org.apache.maven.index.FlatSearchRequest; @@ -407,6 +409,12 @@ public class MavenRepositorySearch e.getMessage() ); continue; } + catch ( RepositorySearchException e ) + { + log.warn( "RepositorySearchException occured while accessing index of repository '{}' : {}", repo, + e.getMessage() ); + continue; + } } return new ArrayList<>( indexingContextIds ); @@ -415,11 +423,19 @@ public class MavenRepositorySearch @Override public Set getRemoteIndexingContextIds( String managedRepoId ) - throws RepositoryAdminException + throws RepositorySearchException { Set ids = new HashSet<>(); - List proxyConnectors = proxyConnectorAdmin.getProxyConnectorAsMap().get( managedRepoId ); + List proxyConnectors = null; + try + { + proxyConnectors = proxyConnectorAdmin.getProxyConnectorAsMap().get( managedRepoId ); + } + catch ( RepositoryAdminException e ) + { + throw new RepositorySearchException( e.getMessage(), e ); + } if ( proxyConnectors == null || proxyConnectors.isEmpty() ) { @@ -486,6 +502,7 @@ public class MavenRepositorySearch artifactInfo.getPackaging() ); Map hitsMap = results.getHitsMap(); + if ( !applyArtifactInfoFilters( artifactInfo, artifactInfoFilters, hitsMap ) ) { continue; @@ -650,9 +667,17 @@ public class MavenRepositorySearch return true; } + ArchivaArtifactModel artifact = new ArchivaArtifactModel(); + artifact.setArtifactId( artifactInfo.getArtifactId() ); + artifact.setClassifier( artifactInfo.getClassifier() ); + artifact.setGroupId( artifactInfo.getGroupId() ); + artifact.setRepositoryId( artifactInfo.getRepository() ); + artifact.setVersion( artifactInfo.getVersion() ); + artifact.setChecksumMD5( artifactInfo.getMd5() ); + artifact.setChecksumSHA1( artifactInfo.getSha1() ); for ( ArtifactInfoFilter filter : artifactInfoFilters ) { - if ( !filter.addArtifactInResult( artifactInfo, currentResult ) ) + if ( !filter.addArtifactInResult( artifact, currentResult ) ) { return false; } diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NoClassifierArtifactInfoFilter.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NoClassifierArtifactInfoFilter.java index 49feb2d81..f37c87407 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NoClassifierArtifactInfoFilter.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NoClassifierArtifactInfoFilter.java @@ -18,8 +18,8 @@ package org.apache.archiva.indexer.search; * under the License. */ +import org.apache.archiva.model.ArchivaArtifactModel; import org.apache.commons.lang.StringUtils; -import org.apache.maven.index.ArtifactInfo; import java.util.Arrays; import java.util.List; @@ -36,7 +36,7 @@ public class NoClassifierArtifactInfoFilter public static final List LIST = Arrays.asList( INSTANCE ); @Override - public boolean addArtifactInResult( ArtifactInfo artifact, Map currentResult ) + public boolean addArtifactInResult( ArchivaArtifactModel artifact, Map currentResult ) { return StringUtils.isBlank( artifact.getClassifier() ); } diff --git a/archiva-modules/archiva-base/pom.xml b/archiva-modules/archiva-base/pom.xml index e78f79b76..d77129d62 100644 --- a/archiva-modules/archiva-base/pom.xml +++ b/archiva-modules/archiva-base/pom.xml @@ -39,6 +39,7 @@ archiva-checksum archiva-plexus-bridge archiva-policies + archiva-indexer-api archiva-indexer archiva-consumers archiva-repository-layer diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java index 6774e8558..6598b0771 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java @@ -38,6 +38,7 @@ import org.apache.archiva.indexer.merger.MergedRemoteIndexesTask; import org.apache.archiva.indexer.merger.MergedRemoteIndexesTaskRequest; import org.apache.archiva.indexer.merger.TemporaryGroupIndex; import org.apache.archiva.indexer.search.RepositorySearch; +import org.apache.archiva.indexer.search.RepositorySearchException; import org.apache.archiva.maven2.metadata.MavenMetadataReader; import org.apache.archiva.metadata.model.facets.AuditEvent; import org.apache.archiva.metadata.repository.storage.RelocationException; @@ -60,8 +61,6 @@ import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryContentFactory; -import org.apache.archiva.repository.RepositoryException; -import org.apache.archiva.repository.RepositoryNotFoundException; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.content.maven2.RepositoryRequest; import org.apache.archiva.repository.events.AuditListener; @@ -1348,6 +1347,7 @@ public class ArchivaDavResourceFactory log.debug( "Skipping repository '{}' for user '{}': {}", repository, activePrincipal, e.getMessage() ); } + } log.info( "generate temporary merged index for repository group '{}' for repositories '{}'", repositoryGroupConfiguration.getId(), authzRepos ); @@ -1378,7 +1378,7 @@ public class ArchivaDavResourceFactory temporaryGroupIndexMap ); return mergedRepoDir; } - catch ( RepositoryAdminException e ) + catch ( RepositorySearchException e ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e ); } diff --git a/pom.xml b/pom.xml index c4da9a2f0..8b981b620 100644 --- a/pom.xml +++ b/pom.xml @@ -287,6 +287,11 @@ test-repository ${project.version} + + org.apache.archiva + archiva-indexer-api + ${project.version} + org.apache.archiva archiva-indexer -- 2.39.5