From: Maria Odea B. Ching Date: Mon, 2 Jun 2008 06:51:21 +0000 (+0000) Subject: [MRM-823] X-Git-Tag: archiva-r676265~84 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=eb6967d2e6e06e7be06096e9a25076adbfeefdab;p=archiva.git [MRM-823] -remove repo in group when repo is removed git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@662342 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java index 8a6ab5688..438031320 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java @@ -41,6 +41,7 @@ import org.codehaus.plexus.redback.role.RoleManagerException; import java.io.IOException; import java.util.List; +import java.util.Map; /** * DeleteManagedRepositoryAction @@ -140,14 +141,9 @@ public class DeleteManagedRepositoryAction throws RoleManagerException, ArchivaDatabaseException { removeRepositoryRoles( cleanupRepository ); - - // TODO: [MRM-382] Remove index from artifacts of deleted managed repositories. - - // [MRM-265] After removing a managed repository - Browse/Search still see it cleanupDatabase( cleanupRepository.getId() ); cleanupScanStats( cleanupRepository.getId() ); - - // [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository. + List proxyConnectors = getProxyConnectors(); for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors ) { @@ -156,6 +152,19 @@ public class DeleteManagedRepositoryAction archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector ); } } + + Map> repoToGroupMap = archivaConfiguration.getConfiguration().getRepositoryToGroupMap(); + if( repoToGroupMap != null ) + { + if( repoToGroupMap.containsKey( cleanupRepository.getId() ) ) + { + List repoGroups = repoToGroupMap.get( cleanupRepository.getId() ); + for( String repoGroup : repoGroups ) + { + archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository( cleanupRepository.getId() ); + } + } + } } private void cleanupDatabase( String repoId ) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java index f9e205f4c..41536c1c7 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java @@ -26,6 +26,7 @@ import org.apache.maven.archiva.configuration.IndeterminateConfigurationExceptio 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.RepositoryGroupConfiguration; import org.apache.maven.archiva.model.ArchivaProjectModel; import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.codehaus.plexus.redback.role.RoleManager; @@ -37,7 +38,9 @@ import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; import java.io.File; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; /** * DeleteManagedRepositoryActionTest @@ -128,7 +131,7 @@ public class DeleteManagedRepositoryActionTest { prepareRoleManagerMock(); - Configuration configuration = prepDeletionTest( createRepository(), 3 ); + Configuration configuration = prepDeletionTest( createRepository(), 4 ); String status = action.deleteEntry(); @@ -144,7 +147,7 @@ public class DeleteManagedRepositoryActionTest { prepareRoleManagerMock(); - Configuration configuration = prepDeletionTest( createRepository(), 3 ); + Configuration configuration = prepDeletionTest( createRepository(), 4 ); String status = action.deleteContents(); @@ -158,7 +161,7 @@ public class DeleteManagedRepositoryActionTest public void testDeleteRepositoryAndAssociatedProxyConnectors() throws Exception { - Configuration configuration = prepDeletionTest( createRepository(), 4 ); + Configuration configuration = prepDeletionTest( createRepository(), 5 ); configuration.addRemoteRepository( createRemoteRepository( "codehaus", "http://repository.codehaus.org" ) ); configuration.addRemoteRepository( createRemoteRepository( "java.net", "http://dev.java.net/maven2" ) ); configuration.addProxyConnector( createProxyConnector( REPO_ID, "codehaus" ) ); @@ -190,6 +193,27 @@ public class DeleteManagedRepositoryActionTest assertTrue( location.exists() ); } + + public void testDeleteRepositoryAndReposUnderRepoGroup() + throws Exception + { + Configuration configuration = prepDeletionTest( createRepository(), 5 ); + List repoIds = new ArrayList(); + repoIds.add( REPO_ID ); + configuration.addRepositoryGroup( createRepoGroup( repoIds, "repo.group" ) ); + + prepareRoleManagerMock(); + + assertEquals( 1, configuration.getRepositoryGroups().size() ); + + String status = action.deleteContents(); + assertEquals( Action.SUCCESS, status ); + + assertTrue( configuration.getManagedRepositories().isEmpty() ); + assertEquals( 0, ( ( RepositoryGroupConfiguration ) configuration.getRepositoryGroups().get( 0 ) ).getRepositories().size() ); + + assertFalse( location.exists() ); + } private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, int expectCountGetConfig ) throws RegistryException, IndeterminateConfigurationException @@ -276,6 +300,15 @@ public class DeleteManagedRepositoryActionTest return connector; } + private RepositoryGroupConfiguration createRepoGroup( List repoIds, String repoGroupId ) + { + RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration(); + repoGroup.setId( repoGroupId ); + repoGroup.setRepositories( repoIds ); + + return repoGroup; + } + private void prepareRoleManagerMock() throws RoleManagerException {