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;
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;
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;
}
/**
*/
private List<String> addIndexingContexts( List<String> selectedRepos )
{
- List<String> indexingContextIds = new ArrayList<String>();
+ Set<String> indexingContextIds = new HashSet<String>();
for ( String repo : selectedRepos )
{
try
// set searchable flag
context.setSearchable( repoConfig.isScanned() );
indexingContextIds.add( context.getId() );
+ indexingContextIds.addAll( getRemoteIndexingContextIds( repo ) );
continue;
}
context.setSearchable( repoConfig.isScanned() );
if ( context.isSearchable() )
{
+ indexingContextIds.addAll( getRemoteIndexingContextIds( repo ) );
indexingContextIds.add( context.getId() );
}
else
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;
}
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;
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;
}
+ @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