From 4c507b7beb1df5e1ca1d62ccaf71a9d6f8f2d7b9 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 26 Sep 2011 19:30:14 +0000 Subject: [PATCH] [MRM-1524] downloading (optionnaly) remote index to display remote artifacts in search results : fix configuration of the network proxy to use for download remote index git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1176008 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/mdo/configuration.mdo | 8 +++++ .../admin/model/beans/RemoteRepository.java | 12 +++++++ .../DefaultNetworkProxyAdmin.java | 10 ++++++ .../remote/DefaultRemoteRepositoryAdmin.java | 4 +++ .../AbstractRepositoryAdminTest.java | 1 + .../networkproxy/NetworkProxyAdminTest.java | 34 +++++++++++++++++++ .../remote/RemoteRepositoryAdminTest.java | 4 ++- .../DefaultDownloadRemoteIndexScheduler.java | 26 ++++---------- .../AbstractRemoteRepositoriesAction.java | 29 ++++++++++++++++ .../AddRemoteRepositoryAction.java | 2 ++ .../EditRemoteRepositoryAction.java | 1 + .../admin/include/remoteRepositoryForm.jspf | 1 + 12 files changed, 111 insertions(+), 21 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo index a56c14920..e312889e2 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo @@ -510,6 +510,14 @@ Remote Index Url : if not starting with http will be relative to the remote repository url. + + remoteDownloadNetworkProxyId + 1.4.0+ + String + + Id of the networkProxy to use when downloading remote index. + + diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RemoteRepository.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RemoteRepository.java index b8a789692..668e07cde 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RemoteRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RemoteRepository.java @@ -50,6 +50,8 @@ public class RemoteRepository */ private String remoteIndexUrl = ".index"; + private String remoteDownloadNetworkProxyId; + public RemoteRepository() { @@ -132,6 +134,15 @@ public class RemoteRepository this.remoteIndexUrl = remoteIndexUrl; } + public String getRemoteDownloadNetworkProxyId() + { + return remoteDownloadNetworkProxyId; + } + + public void setRemoteDownloadNetworkProxyId( String remoteDownloadNetworkProxyId ) + { + this.remoteDownloadNetworkProxyId = remoteDownloadNetworkProxyId; + } @Override public String toString() @@ -145,6 +156,7 @@ public class RemoteRepository sb.append( ", timeout=" ).append( timeout ); sb.append( ", downloadRemoteIndex=" ).append( downloadRemoteIndex ); sb.append( ", remoteIndexUrl='" ).append( remoteIndexUrl ).append( '\'' ); + sb.append( ", remoteDownloadNetworkProxyId='" ).append( remoteDownloadNetworkProxyId ).append( '\'' ); sb.append( '}' ); return sb.toString(); } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java index 6f9805e88..f97c2ee01 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java @@ -25,11 +25,13 @@ import org.apache.archiva.admin.model.beans.NetworkProxy; import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin; import org.apache.archiva.admin.repository.AbstractRepositoryAdmin; import org.apache.archiva.audit.AuditEvent; +import org.apache.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.commons.lang.StringUtils; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.NetworkProxyConfiguration; import org.springframework.stereotype.Service; +import java.rmi.Remote; import java.util.ArrayList; import java.util.List; @@ -124,6 +126,14 @@ public class DefaultNetworkProxyAdmin NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy ); configuration.removeNetworkProxy( networkProxyConfiguration ); + for ( RemoteRepositoryConfiguration rrc : configuration.getRemoteRepositories()) + { + if (StringUtils.equals( rrc.getRemoteDownloadNetworkProxyId(), networkProxyId )) + { + rrc.setRemoteDownloadNetworkProxyId( null ); + } + } + triggerAuditEvent( networkProxy.getId(), null, AuditEvent.DELETE_NETWORK_PROXY, auditInformation ); saveConfiguration( configuration ); diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java index 294e3cb90..0fa646110 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java @@ -61,6 +61,8 @@ public class DefaultRemoteRepositoryAdmin remoteRepository.setRemoteIndexUrl( repositoryConfiguration.getRemoteIndexUrl() ); remoteRepository.setCronExpression( repositoryConfiguration.getRefreshCronExpression() ); remoteRepository.setIndexDirectory( repositoryConfiguration.getIndexDir() ); + remoteRepository.setRemoteDownloadNetworkProxyId( + repositoryConfiguration.getRemoteDownloadNetworkProxyId() ); remoteRepositories.add( remoteRepository ); } return remoteRepositories; @@ -195,6 +197,8 @@ public class DefaultRemoteRepositoryAdmin remoteRepositoryConfiguration.setRemoteIndexUrl( remoteRepository.getRemoteIndexUrl() ); remoteRepositoryConfiguration.setRefreshCronExpression( remoteRepository.getCronExpression() ); remoteRepositoryConfiguration.setIndexDir( remoteRepository.getIndexDirectory() ); + remoteRepositoryConfiguration.setRemoteDownloadNetworkProxyId( + remoteRepository.getRemoteDownloadNetworkProxyId() ); return remoteRepositoryConfiguration; } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java index e62ecad90..d16feade0 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java @@ -135,6 +135,7 @@ public abstract class AbstractRepositoryAdminTest remoteRepository.setUserName( "foo-name" ); remoteRepository.setPassword( "toto" ); remoteRepository.setId( id ); + remoteRepository.setRemoteDownloadNetworkProxyId( "foo" ); return remoteRepository; } } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/networkproxy/NetworkProxyAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/networkproxy/NetworkProxyAdminTest.java index 42550624d..0f6d37634 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/networkproxy/NetworkProxyAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/networkproxy/NetworkProxyAdminTest.java @@ -19,6 +19,7 @@ package org.apache.archiva.admin.repository.networkproxy; */ import org.apache.archiva.admin.model.beans.NetworkProxy; +import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin; import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest; import org.apache.archiva.audit.AuditEvent; @@ -128,6 +129,39 @@ public class NetworkProxyAdminTest mockAuditListener.clearEvents(); } + /** + * ensure we cleanup remote repos linked to a network proxy + */ + @Test + public void addAndDeleteWithRemoteRepoLinked() + throws Exception + { + mockAuditListener.clearEvents(); + int initialSize = networkProxyAdmin.getNetworkProxies().size(); + NetworkProxy networkProxy = getNetworkProxyTest( "foo" ); + + networkProxyAdmin.addNetworkProxy( networkProxy, getFakeAuditInformation() ); + + assertEquals( initialSize + 1, networkProxyAdmin.getNetworkProxies().size() ); + + networkProxy = networkProxyAdmin.getNetworkProxy( "foo" ); + + assertNotNull( networkProxy ); + + RemoteRepository remoteRepository = getRemoteRepository(); + remoteRepository.setRemoteDownloadNetworkProxyId( networkProxy.getId() ); + + remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() ); + + networkProxyAdmin.deleteNetworkProxy( "foo", getFakeAuditInformation() ); + + remoteRepository = remoteRepositoryAdmin.getRemoteRepository( getRemoteRepository().getId() ); + + assertNull( remoteRepository.getRemoteDownloadNetworkProxyId() ); + + remoteRepositoryAdmin.deleteRemoteRepository( getRemoteRepository().getId(), getFakeAuditInformation() ); + } + protected NetworkProxy getNetworkProxyTest( String id ) { diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java index 87f46c294..7f851cb91 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java @@ -114,10 +114,12 @@ public class RemoteRepositoryAdminTest assertEquals( getRemoteRepository().getUserName(), repo.getUserName() ); assertEquals( getRemoteRepository().getName(), repo.getName() ); assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() ); + assertEquals( getRemoteRepository().getRemoteDownloadNetworkProxyId(), repo.getRemoteDownloadNetworkProxyId() ); repo.setUserName( "foo-name-changed" ); repo.setPassword( "titi" ); repo.setUrl( "http://foo.com/maven-really-rocks" ); + repo.setRemoteDownloadNetworkProxyId( "toto" ); remoteRepositoryAdmin.updateRemoteRepository( repo, getFakeAuditInformation() ); @@ -126,6 +128,7 @@ public class RemoteRepositoryAdminTest assertEquals( "foo-name-changed", repo.getUserName() ); assertEquals( "titi", repo.getPassword() ); assertEquals( "http://foo.com/maven-really-rocks", repo.getUrl() ); + assertEquals( "toto", repo.getRemoteDownloadNetworkProxyId() ); remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() ); @@ -150,5 +153,4 @@ public class RemoteRepositoryAdminTest } - } 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 a3445034e..e0bde549b 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 @@ -20,7 +20,6 @@ package org.apache.archiva.scheduler.indexing; import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.NetworkProxy; -import org.apache.archiva.admin.model.beans.ProxyConnector; import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin; import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin; @@ -160,28 +159,15 @@ public class DefaultDownloadRemoteIndexScheduler log.warn( "ignore scheduleDownloadRemote for repo with id {} as not exists", repositoryId ); return; } - String networkProxyId = null; - for ( ProxyConnector proxyConnector : proxyConnectorAdmin.getProxyConnectors() ) - { - if ( StringUtils.equals( proxyConnector.getTargetRepoId(), repositoryId ) ) - { - networkProxyId = proxyConnector.getProxyId(); - break; - } - } - - // FIXME add a field networkProxy at the remoteRepositories level : only use for remote index download - NetworkProxy networkProxy = null; - if ( networkProxyId != null ) + if ( remoteRepository.getRemoteDownloadNetworkProxyId() != null ) { - for ( NetworkProxy np : networkProxyAdmin.getNetworkProxies() ) + networkProxy = networkProxyAdmin.getNetworkProxy( remoteRepository.getRemoteDownloadNetworkProxyId() ); + if ( networkProxy == null ) { - if ( StringUtils.equals( np.getId(), networkProxyId ) ) - { - networkProxy = np; - break; - } + log.warn( + "your remote repository is configured to download remote index trought a proxy we cannot find id:{}", + remoteRepository.getRemoteDownloadNetworkProxyId() ); } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRemoteRepositoriesAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRemoteRepositoriesAction.java index 2bfb322fd..e1a94f67d 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRemoteRepositoriesAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRemoteRepositoriesAction.java @@ -1,8 +1,12 @@ package org.apache.archiva.web.action.admin.repositories; +import org.apache.archiva.admin.model.beans.NetworkProxy; +import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin; import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; import javax.inject.Inject; +import java.util.Collections; +import java.util.List; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -34,6 +38,11 @@ public class AbstractRemoteRepositoriesAction @Inject private RemoteRepositoryAdmin remoteRepositoryAdmin; + @Inject + private NetworkProxyAdmin networkProxyAdmin; + + private List networkProxies; + public RemoteRepositoryAdmin getRemoteRepositoryAdmin() { return remoteRepositoryAdmin; @@ -43,4 +52,24 @@ public class AbstractRemoteRepositoriesAction { this.remoteRepositoryAdmin = remoteRepositoryAdmin; } + + public NetworkProxyAdmin getNetworkProxyAdmin() + { + return networkProxyAdmin; + } + + public void setNetworkProxyAdmin( NetworkProxyAdmin networkProxyAdmin ) + { + this.networkProxyAdmin = networkProxyAdmin; + } + + public List getNetworkProxies() + { + return networkProxies == null ? Collections.emptyList() : networkProxies; + } + + public void setNetworkProxies( List networkProxies ) + { + this.networkProxies = networkProxies; + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java index bc01b2fff..4a2cd85bc 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java @@ -43,8 +43,10 @@ public class AddRemoteRepositoryAction private RemoteRepository repository; public void prepare() + throws RepositoryAdminException { this.repository = new RemoteRepository(); + setNetworkProxies( getNetworkProxyAdmin().getNetworkProxies() ); } public String input() diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java index 802328163..eabba6b79 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java @@ -63,6 +63,7 @@ public class EditRemoteRepositoryAction { this.repository = getRemoteRepositoryAdmin().getRemoteRepository( repoid ); } + setNetworkProxies( getNetworkProxyAdmin().getNetworkProxies() ); } public String input() diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf index be1b074cb..a99449dc7 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf @@ -29,6 +29,7 @@ +