git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1176008 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.4-M1
@@ -510,6 +510,14 @@ | |||
Remote Index Url : if not starting with http will be relative to the remote repository url. | |||
</description> | |||
</field> | |||
<field> | |||
<name>remoteDownloadNetworkProxyId</name> | |||
<version>1.4.0+</version> | |||
<type>String</type> | |||
<description> | |||
Id of the networkProxy to use when downloading remote index. | |||
</description> | |||
</field> | |||
</fields> | |||
</class> | |||
<class> |
@@ -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(); | |||
} |
@@ -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 ); |
@@ -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; | |||
} | |||
@@ -135,6 +135,7 @@ public abstract class AbstractRepositoryAdminTest | |||
remoteRepository.setUserName( "foo-name" ); | |||
remoteRepository.setPassword( "toto" ); | |||
remoteRepository.setId( id ); | |||
remoteRepository.setRemoteDownloadNetworkProxyId( "foo" ); | |||
return remoteRepository; | |||
} | |||
} |
@@ -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 ) | |||
{ |
@@ -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 | |||
} | |||
} |
@@ -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() ); | |||
} | |||
} | |||
@@ -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<NetworkProxy> 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<NetworkProxy> getNetworkProxies() | |||
{ | |||
return networkProxies == null ? Collections.<NetworkProxy>emptyList() : networkProxies; | |||
} | |||
public void setNetworkProxies( List<NetworkProxy> networkProxies ) | |||
{ | |||
this.networkProxies = networkProxies; | |||
} | |||
} |
@@ -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() |
@@ -63,6 +63,7 @@ public class EditRemoteRepositoryAction | |||
{ | |||
this.repository = getRemoteRepositoryAdmin().getRemoteRepository( repoid ); | |||
} | |||
setNetworkProxies( getNetworkProxyAdmin().getNetworkProxies() ); | |||
} | |||
public String input() |
@@ -29,6 +29,7 @@ | |||
<s:textfield name="repository.remoteIndexUrl" label="Remote index url, can be relative to url" size="60" required="false"/> | |||
<s:textfield name="repository.cronExpression" label="Cron expression" size="10" required="false"/> | |||
<s:textfield name="repository.indexDirectory" label="Directory index storage" size="60" required="false"/> | |||
<s:select list="networkProxies" name="repository.remoteDownloadNetworkProxyId" emptyOption="true" required="false" listKey="id" listValue="id"/> | |||
<s:select list="#@java.util.LinkedHashMap@{'default' : 'Maven 2.x Repository', 'legacy' : 'Maven 1.x Repository'}" |