]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1524] downloading (optionnaly) remote index to display remote artifacts in searc...
authorOlivier Lamy <olamy@apache.org>
Mon, 26 Sep 2011 22:48:28 +0000 (22:48 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 26 Sep 2011 22:48:28 +0000 (22:48 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1176110 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnector/ProxyConnectorAdmin.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultDownloadRemoteIndexScheduler.java

index fb5986f56f8fc517d8e4f60ae74e7ea2c9d9f82f..c5e441d6a55ffd30efccbaf78afeed3f23e4a14a 100644 (file)
@@ -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<String> addIndexingContexts( List<String> selectedRepos )
     {
-        List<String> indexingContextIds = new ArrayList<String>();
+        Set<String> indexingContextIds = new HashSet<String>();
         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<String>( indexingContextIds );
+    }
+
+
+    private Set<String> getRemoteIndexingContextIds( String managedRepoId )
+        throws RepositoryAdminException
+    {
+        Set<String> ids = new HashSet<String>();
+
+        List<ProxyConnector> 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;
     }
 
 
index 069c2d12565d2a7129e749fa319bca99c3154be0..361962ace12bf141fb8139affec7f0d53e9de579 100644 (file)
@@ -47,15 +47,19 @@ public interface ProxyConnectorAdmin
 
     /**
      * <b>only for enabled/disable or changing bean values except target/source</b>
+     *
      * @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<String, List<ProxyConnector>> getProxyConnectorAsMap()
         throws RepositoryAdminException;
 
index e0bde549b4e82e0408e06a0a929c5ede86919ecc..b0be98c0ec8342a7c384614607faf2b69e8073d5 100644 (file)
@@ -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