From: Olivier Lamy Date: Mon, 26 Sep 2011 22:48:28 +0000 (+0000) Subject: [MRM-1524] downloading (optionnaly) remote index to display remote artifacts in searc... X-Git-Tag: archiva-1.4-M1~193 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=276eaf0b5ddabe7c48dfc9bb5df03204e9b215a4;p=archiva.git [MRM-1524] downloading (optionnaly) remote index to display remote artifacts in search results : include remote repos when searching git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1176110 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java index fb5986f56..c5e441d6a 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java @@ -21,7 +21,9 @@ package org.apache.archiva.indexer.search; import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.admin.model.beans.ProxyConnector; import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; +import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin; import org.apache.archiva.common.plexusbridge.MavenIndexerUtils; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; @@ -48,6 +50,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -65,17 +68,19 @@ public class NexusRepositorySearch private ManagedRepositoryAdmin managedRepositoryAdmin; + private ProxyConnectorAdmin proxyConnectorAdmin; + private MavenIndexerUtils mavenIndexerUtils; @Inject public NexusRepositorySearch( PlexusSisuBridge plexusSisuBridge, ManagedRepositoryAdmin managedRepositoryAdmin, - MavenIndexerUtils mavenIndexerUtils ) + MavenIndexerUtils mavenIndexerUtils, ProxyConnectorAdmin proxyConnectorAdmin ) throws PlexusSisuBridgeException { this.indexer = plexusSisuBridge.lookup( NexusIndexer.class ); this.managedRepositoryAdmin = managedRepositoryAdmin; this.mavenIndexerUtils = mavenIndexerUtils; - + this.proxyConnectorAdmin = proxyConnectorAdmin; } /** @@ -308,7 +313,7 @@ public class NexusRepositorySearch */ private List addIndexingContexts( List selectedRepos ) { - List indexingContextIds = new ArrayList(); + Set indexingContextIds = new HashSet(); for ( String repo : selectedRepos ) { try @@ -336,6 +341,7 @@ public class NexusRepositorySearch // set searchable flag context.setSearchable( repoConfig.isScanned() ); indexingContextIds.add( context.getId() ); + indexingContextIds.addAll( getRemoteIndexingContextIds( repo ) ); continue; } @@ -345,6 +351,7 @@ public class NexusRepositorySearch context.setSearchable( repoConfig.isScanned() ); if ( context.isSearchable() ) { + indexingContextIds.addAll( getRemoteIndexingContextIds( repo ) ); indexingContextIds.add( context.getId() ); } else @@ -375,7 +382,34 @@ public class NexusRepositorySearch continue; } } - return indexingContextIds; + + return new ArrayList( indexingContextIds ); + } + + + private Set getRemoteIndexingContextIds( String managedRepoId ) + throws RepositoryAdminException + { + Set ids = new HashSet(); + + List proxyConnectors = proxyConnectorAdmin.getProxyConnectorAsMap().get( managedRepoId ); + + if ( proxyConnectors == null || proxyConnectors.isEmpty() ) + { + return ids; + } + + for ( ProxyConnector proxyConnector : proxyConnectors ) + { + String remoteId = "remote-" + proxyConnector.getTargetRepoId(); + IndexingContext context = indexer.getIndexingContexts().get( remoteId ); + if ( context != null && context.isSearchable() ) + { + ids.add( remoteId ); + } + } + + return ids; } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnector/ProxyConnectorAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnector/ProxyConnectorAdmin.java index 069c2d125..361962ace 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnector/ProxyConnectorAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnector/ProxyConnectorAdmin.java @@ -47,15 +47,19 @@ public interface ProxyConnectorAdmin /** * only for enabled/disable or changing bean values except target/source + * * @param proxyConnector * @param auditInformation * @return * @throws RepositoryAdminException */ Boolean updateProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation ) - throws RepositoryAdminException; - + throws RepositoryAdminException; + /** + * @return key/value : managed repo Id / list to proxy connector ordered + * @throws RepositoryAdminException + */ Map> getProxyConnectorAsMap() throws RepositoryAdminException; diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultDownloadRemoteIndexScheduler.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultDownloadRemoteIndexScheduler.java index e0bde549b..b0be98c0e 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultDownloadRemoteIndexScheduler.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultDownloadRemoteIndexScheduler.java @@ -34,6 +34,7 @@ import org.apache.archiva.configuration.ConfigurationListener; import org.apache.archiva.proxy.common.WagonFactory; import org.apache.commons.lang.StringUtils; import org.apache.maven.index.NexusIndexer; +import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.apache.maven.index.updater.IndexUpdater; import org.slf4j.Logger; @@ -43,6 +44,7 @@ import org.springframework.scheduling.support.CronTrigger; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.inject.Inject; import javax.inject.Named; import java.io.File; @@ -142,6 +144,22 @@ public class DefaultDownloadRemoteIndexScheduler } + @PreDestroy + private void shutdown() + throws RepositoryAdminException, IOException + { + for ( RemoteRepository remoteRepository : remoteRepositoryAdmin.getRemoteRepositories() ) + { + String contextKey = "remote-" + remoteRepository.getId(); + IndexingContext context = nexusIndexer.getIndexingContexts().get( contextKey ); + if ( context == null ) + { + continue; + } + nexusIndexer.removeIndexingContext( context, false ); + } + } + public void configurationEvent( ConfigurationEvent event ) { // TODO remove jobs and add again