[MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.

Added ability of delete (managed|remote) repository action to clear out the associated proxy connector.
Added tests.



git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@586635 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-10-19 22:47:43 +00:00
parent e74ebe51b7
commit 8042e19982
5 changed files with 127 additions and 29 deletions

View File

@ -23,6 +23,7 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.configuration.InvalidConfigurationException; import org.apache.maven.archiva.configuration.InvalidConfigurationException;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.redback.rbac.Resource; import org.codehaus.plexus.redback.rbac.Resource;
import org.codehaus.plexus.redback.xwork.interceptor.SecureAction; import org.codehaus.plexus.redback.xwork.interceptor.SecureAction;
@ -32,6 +33,8 @@ import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.xwork.action.PlexusActionSupport; import org.codehaus.plexus.xwork.action.PlexusActionSupport;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/** /**
* Abstract AdminRepositories Action base. * Abstract AdminRepositories Action base.
@ -101,4 +104,14 @@ public abstract class AbstractRepositoriesAdminAction
return SUCCESS; return SUCCESS;
} }
/**
* Get the list of ProxyConnectors that are present in the configuration.
*
* @return a new list of ProxyConnectors present in the configuration.
*/
protected List<ProxyConnectorConfiguration> getProxyConnectors()
{
return new ArrayList<ProxyConnectorConfiguration>( archivaConfiguration.getConfiguration().getProxyConnectors() );
}
} }

View File

@ -24,9 +24,11 @@ import com.opensymphony.xwork.Preparable;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.redback.role.RoleManagerException;
import java.io.IOException; import java.io.IOException;
import java.util.List;
/** /**
* DeleteManagedRepositoryAction * DeleteManagedRepositoryAction
@ -123,7 +125,15 @@ public class DeleteManagedRepositoryAction
// TODO: [MRM-265] After removing a managed repository - Browse/Search still see it // TODO: [MRM-265] After removing a managed repository - Browse/Search still see it
// TODO: [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository. // [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
{
if ( StringUtils.equals( proxyConnector.getSourceRepoId(), cleanupRepository.getId() ) )
{
archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector );
}
}
} }
public ManagedRepositoryConfiguration getRepository() public ManagedRepositoryConfiguration getRepository()

View File

@ -23,8 +23,11 @@ import com.opensymphony.xwork.Preparable;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import java.util.List;
/** /**
* DeleteRemoteRepositoryAction * DeleteRemoteRepositoryAction
* *
@ -81,7 +84,16 @@ public class DeleteRemoteRepositoryAction
private void cleanupRepositoryData( RemoteRepositoryConfiguration existingRepository ) private void cleanupRepositoryData( RemoteRepositoryConfiguration existingRepository )
{ {
// TODO: [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository. // [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
{
if ( StringUtils.equals( proxyConnector.getTargetRepoId(), existingRepository.getId() ) )
{
archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector );
}
}
} }
public RemoteRepositoryConfiguration getRepository() public RemoteRepositoryConfiguration getRepository()

View File

@ -25,6 +25,8 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.redback.role.RoleManager;
@ -120,7 +122,7 @@ public class DeleteManagedRepositoryActionTest
{ {
prepareRoleManagerMock(); prepareRoleManagerMock();
Configuration configuration = prepDeletionTest( createRepository(), "delete-entry" ); Configuration configuration = prepDeletionTest( createRepository(), 3 );
String status = action.deleteEntry(); String status = action.deleteEntry();
assertEquals( Action.SUCCESS, status ); assertEquals( Action.SUCCESS, status );
@ -134,7 +136,7 @@ public class DeleteManagedRepositoryActionTest
{ {
prepareRoleManagerMock(); prepareRoleManagerMock();
Configuration configuration = prepDeletionTest( createRepository(), "delete-contents" ); Configuration configuration = prepDeletionTest( createRepository(), 3 );
String status = action.deleteContents(); String status = action.deleteContents();
assertEquals( Action.SUCCESS, status ); assertEquals( Action.SUCCESS, status );
@ -142,12 +144,33 @@ public class DeleteManagedRepositoryActionTest
assertFalse( location.exists() ); assertFalse( location.exists() );
} }
public void testDeleteRepositoryAndAssociatedProxyConnectors()
throws Exception
{
Configuration configuration = prepDeletionTest( createRepository(), 4 );
configuration.addRemoteRepository( createRemoteRepository( "codehaus", "http://repository.codehaus.org" ) );
configuration.addRemoteRepository( createRemoteRepository( "java.net", "http://dev.java.net/maven2" ) );
configuration.addProxyConnector( createProxyConnector( REPO_ID, "codehaus" ) );
prepareRoleManagerMock();
assertEquals( 1, configuration.getProxyConnectors().size() );
String status = action.deleteContents();
assertEquals( Action.SUCCESS, status );
assertTrue( configuration.getManagedRepositories().isEmpty() );
assertEquals( 0, configuration.getProxyConnectors().size() );
assertFalse( location.exists() );
}
public void testDeleteRepositoryCancelled() public void testDeleteRepositoryCancelled()
throws Exception throws Exception
{ {
ManagedRepositoryConfiguration originalRepository = createRepository(); ManagedRepositoryConfiguration originalRepository = createRepository();
Configuration configuration = prepDeletionTest( originalRepository, null ); Configuration configuration = prepDeletionTest( originalRepository, 3 );
String status = action.execute(); String status = action.execute();
assertEquals( Action.SUCCESS, status ); assertEquals( Action.SUCCESS, status );
@ -158,7 +181,7 @@ public class DeleteManagedRepositoryActionTest
assertTrue( location.exists() ); assertTrue( location.exists() );
} }
private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, String mode ) private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, int expectCountGetConfig )
throws RegistryException, IndeterminateConfigurationException throws RegistryException, IndeterminateConfigurationException
{ {
location.mkdirs(); location.mkdirs();
@ -166,9 +189,7 @@ public class DeleteManagedRepositoryActionTest
Configuration configuration = createConfigurationForEditing( originalRepository ); Configuration configuration = createConfigurationForEditing( originalRepository );
archivaConfiguration.getConfiguration(); archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration ); archivaConfigurationControl.setReturnValue( configuration, expectCountGetConfig );
archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration );
archivaConfiguration.save( configuration ); archivaConfiguration.save( configuration );
archivaConfigurationControl.replay(); archivaConfigurationControl.replay();
@ -213,23 +234,36 @@ public class DeleteManagedRepositoryActionTest
{ {
ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration(); ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
r.setId( REPO_ID ); r.setId( REPO_ID );
populateRepository( r ); r.setName( "repo name" );
r.setLocation( location.getAbsolutePath() );
r.setLayout( "default" );
r.setRefreshCronExpression( "* 0/5 * * * ?" );
r.setDaysOlder( 0 );
r.setRetentionCount( 0 );
r.setReleases( true );
r.setSnapshots( true );
r.setScanned( false );
r.setDeleteReleasedSnapshots( false );
return r; return r;
} }
private void populateRepository( ManagedRepositoryConfiguration repository ) private RemoteRepositoryConfiguration createRemoteRepository(String id, String url)
{ {
repository.setId( REPO_ID ); RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration();
repository.setName( "repo name" ); r.setId( id );
repository.setLocation( location.getAbsolutePath() ); r.setUrl( url );
repository.setLayout( "default" ); r.setLayout( "default" );
repository.setRefreshCronExpression( "* 0/5 * * * ?" );
repository.setDaysOlder( 31 ); return r;
repository.setRetentionCount( 20 ); }
repository.setReleases( true );
repository.setSnapshots( true ); private ProxyConnectorConfiguration createProxyConnector( String managedRepoId, String remoteRepoId )
repository.setScanned( false ); {
repository.setDeleteReleasedSnapshots( true ); ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
connector.setSourceRepoId( managedRepoId );
connector.setTargetRepoId( remoteRepoId );
return connector;
} }
private void prepareRoleManagerMock() private void prepareRoleManagerMock()

View File

@ -24,6 +24,8 @@ import com.opensymphony.xwork.Action;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.registry.RegistryException; import org.codehaus.plexus.registry.RegistryException;
@ -89,11 +91,12 @@ public class DeleteRemoteRepositoryActionTest
throws RegistryException, IndeterminateConfigurationException throws RegistryException, IndeterminateConfigurationException
{ {
Configuration configuration = createConfigurationForEditing( createRepository() ); Configuration configuration = createConfigurationForEditing( createRepository() );
configuration.addManagedRepository( createManagedRepository( "internal", getTestPath( "target/repo/internal" ) ) );
configuration.addManagedRepository( createManagedRepository( "snapshots", getTestPath( "target/repo/snapshots" ) ) );
configuration.addProxyConnector( createProxyConnector( "internal", REPO_ID) );
archivaConfiguration.getConfiguration(); archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration ); archivaConfigurationControl.setReturnValue( configuration, 4 );
archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration );
archivaConfiguration.save( configuration ); archivaConfiguration.save( configuration );
archivaConfigurationControl.replay(); archivaConfigurationControl.replay();
@ -106,10 +109,13 @@ public class DeleteRemoteRepositoryActionTest
assertNotNull( repository ); assertNotNull( repository );
assertRepositoryEquals( repository, createRepository() ); assertRepositoryEquals( repository, createRepository() );
assertEquals( 1, configuration.getProxyConnectors().size() );
String status = action.delete(); String status = action.delete();
assertEquals( Action.SUCCESS, status ); assertEquals( Action.SUCCESS, status );
assertTrue( configuration.getRemoteRepositories().isEmpty() ); assertTrue( configuration.getRemoteRepositories().isEmpty() );
assertEquals( 0, configuration.getProxyConnectors().size() );
} }
public void testDeleteRemoteRepositoryCancelled() public void testDeleteRemoteRepositoryCancelled()
@ -119,9 +125,7 @@ public class DeleteRemoteRepositoryActionTest
Configuration configuration = createConfigurationForEditing( originalRepository ); Configuration configuration = createConfigurationForEditing( originalRepository );
archivaConfiguration.getConfiguration(); archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration ); archivaConfigurationControl.setReturnValue( configuration, 2 );
archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration );
archivaConfiguration.save( configuration ); archivaConfiguration.save( configuration );
archivaConfigurationControl.replay(); archivaConfigurationControl.replay();
@ -165,6 +169,32 @@ public class DeleteRemoteRepositoryActionTest
assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() ); assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
assertEquals( expectedRepository.getName(), actualRepository.getName() ); assertEquals( expectedRepository.getName(), actualRepository.getName() );
} }
private ManagedRepositoryConfiguration createManagedRepository( String string, String testPath )
{
ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
r.setId( REPO_ID );
r.setName( "repo name" );
r.setLocation( testPath );
r.setLayout( "default" );
r.setRefreshCronExpression( "* 0/5 * * * ?" );
r.setDaysOlder( 0 );
r.setRetentionCount( 0 );
r.setReleases( true );
r.setSnapshots( true );
r.setScanned( false );
r.setDeleteReleasedSnapshots( false );
return r;
}
private ProxyConnectorConfiguration createProxyConnector( String managedRepoId, String remoteRepoId )
{
ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
connector.setSourceRepoId( managedRepoId );
connector.setTargetRepoId( remoteRepoId );
return connector;
}
private void populateRepository( RemoteRepositoryConfiguration repository ) private void populateRepository( RemoteRepositoryConfiguration repository )
{ {
@ -174,6 +204,5 @@ public class DeleteRemoteRepositoryActionTest
repository.setLayout( "default" ); repository.setLayout( "default" );
} }
// TODO: what if there are proxy connectors attached to a deleted repository?
// TODO: what about removing proxied content if a proxy is removed? // TODO: what about removing proxied content if a proxy is removed?
} }