import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.configuration.InvalidConfigurationException;
+import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.redback.rbac.Resource;
import org.codehaus.plexus.redback.xwork.interceptor.SecureAction;
import org.codehaus.plexus.xwork.action.PlexusActionSupport;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
/**
* Abstract AdminRepositories Action base.
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() );
+ }
}
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.codehaus.plexus.redback.role.RoleManagerException;
import java.io.IOException;
+import java.util.List;
/**
* DeleteManagedRepositoryAction
// 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()
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
+import java.util.List;
+
/**
* DeleteRemoteRepositoryAction
*
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()
import org.apache.maven.archiva.configuration.Configuration;
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.security.ArchivaRoleConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.redback.role.RoleManager;
{
prepareRoleManagerMock();
- Configuration configuration = prepDeletionTest( createRepository(), "delete-entry" );
+ Configuration configuration = prepDeletionTest( createRepository(), 3 );
String status = action.deleteEntry();
assertEquals( Action.SUCCESS, status );
{
prepareRoleManagerMock();
- Configuration configuration = prepDeletionTest( createRepository(), "delete-contents" );
+ Configuration configuration = prepDeletionTest( createRepository(), 3 );
String status = action.deleteContents();
assertEquals( Action.SUCCESS, status );
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()
throws Exception
{
ManagedRepositoryConfiguration originalRepository = createRepository();
- Configuration configuration = prepDeletionTest( originalRepository, null );
+ Configuration configuration = prepDeletionTest( originalRepository, 3 );
String status = action.execute();
assertEquals( Action.SUCCESS, status );
assertTrue( location.exists() );
}
- private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, String mode )
+ private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, int expectCountGetConfig )
throws RegistryException, IndeterminateConfigurationException
{
location.mkdirs();
Configuration configuration = createConfigurationForEditing( originalRepository );
archivaConfiguration.getConfiguration();
- archivaConfigurationControl.setReturnValue( configuration );
- archivaConfiguration.getConfiguration();
- archivaConfigurationControl.setReturnValue( configuration );
+ archivaConfigurationControl.setReturnValue( configuration, expectCountGetConfig );
archivaConfiguration.save( configuration );
archivaConfigurationControl.replay();
{
ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
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;
}
- private void populateRepository( ManagedRepositoryConfiguration repository )
+ private RemoteRepositoryConfiguration createRemoteRepository(String id, String url)
{
- repository.setId( REPO_ID );
- repository.setName( "repo name" );
- repository.setLocation( location.getAbsolutePath() );
- repository.setLayout( "default" );
- repository.setRefreshCronExpression( "* 0/5 * * * ?" );
- repository.setDaysOlder( 31 );
- repository.setRetentionCount( 20 );
- repository.setReleases( true );
- repository.setSnapshots( true );
- repository.setScanned( false );
- repository.setDeleteReleasedSnapshots( true );
+ RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration();
+ r.setId( id );
+ r.setUrl( url );
+ r.setLayout( "default" );
+
+ return r;
+ }
+
+ private ProxyConnectorConfiguration createProxyConnector( String managedRepoId, String remoteRepoId )
+ {
+ ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
+ connector.setSourceRepoId( managedRepoId );
+ connector.setTargetRepoId( remoteRepoId );
+
+ return connector;
}
private void prepareRoleManagerMock()
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
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.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.registry.RegistryException;
throws RegistryException, IndeterminateConfigurationException
{
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();
- archivaConfigurationControl.setReturnValue( configuration );
- archivaConfiguration.getConfiguration();
- archivaConfigurationControl.setReturnValue( configuration );
+ archivaConfigurationControl.setReturnValue( configuration, 4 );
archivaConfiguration.save( configuration );
archivaConfigurationControl.replay();
assertNotNull( repository );
assertRepositoryEquals( repository, createRepository() );
+ assertEquals( 1, configuration.getProxyConnectors().size() );
+
String status = action.delete();
assertEquals( Action.SUCCESS, status );
assertTrue( configuration.getRemoteRepositories().isEmpty() );
+ assertEquals( 0, configuration.getProxyConnectors().size() );
}
public void testDeleteRemoteRepositoryCancelled()
Configuration configuration = createConfigurationForEditing( originalRepository );
archivaConfiguration.getConfiguration();
- archivaConfigurationControl.setReturnValue( configuration );
- archivaConfiguration.getConfiguration();
- archivaConfigurationControl.setReturnValue( configuration );
+ archivaConfigurationControl.setReturnValue( configuration, 2 );
archivaConfiguration.save( configuration );
archivaConfigurationControl.replay();
assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
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 )
{
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?
}