From 745243b347400e3db9c94882d676b654f3af4f4c Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 1 Sep 2011 08:49:08 +0000 Subject: [PATCH] remove some logic methods not anymore used as move to repo admin api git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1163946 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultManagedRepositoryAdmin.java | 12 +- .../managed/ManagedRepositoryAdmin.java | 7 + .../AbstractManagedRepositoriesAction.java | 123 +----------------- .../AddManagedRepositoryAction.java | 26 +--- .../DeleteManagedRepositoryAction.java | 2 +- .../EditManagedRepositoryAction.java | 3 +- .../AddManagedRepositoryActionTest.java | 9 +- .../DeleteManagedRepositoryActionTest.java | 2 +- .../EditManagedRepositoryActionTest.java | 16 ++- 9 files changed, 48 insertions(+), 152 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java index 34938fa50..bc5d0cf9e 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java @@ -467,7 +467,7 @@ public class DefaultManagedRepositoryAdmin } - private String removeExpressions( String directory ) + public String removeExpressions( String directory ) { String value = StringUtils.replace( directory, "${appserver.base}", registry.getString( "appserver.base", "${appserver.base}" ) ); @@ -654,4 +654,14 @@ public class DefaultManagedRepositoryAdmin { this.repositoryTaskScheduler = repositoryTaskScheduler; } + + public Registry getRegistry() + { + return registry; + } + + public void setRegistry( Registry registry ) + { + this.registry = registry; + } } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java index 35aac68b7..0696b4218 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java @@ -48,4 +48,11 @@ public interface ManagedRepositoryAdmin AuditInformation auditInformation, boolean resetStats ) throws RepositoryAdminException; + /** + * replace some interpolations ${appserver.base} with correct values + * @param directory + * @return + */ + String removeExpressions( String directory ); + } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java index 63bbb3a76..7133cd399 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java @@ -20,21 +20,13 @@ package org.apache.maven.archiva.web.action.admin.repositories; */ import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler; -import org.apache.archiva.scheduler.repository.RepositoryTask; -import org.apache.commons.io.FileUtils; -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.security.ArchivaRoleConstants; -import org.codehaus.plexus.redback.role.RoleManager; -import org.codehaus.plexus.redback.role.RoleManagerException; -import org.codehaus.plexus.registry.Registry; -import org.codehaus.plexus.taskqueue.TaskQueueException; -import java.io.File; -import java.io.IOException; import javax.inject.Inject; import javax.inject.Named; +import java.io.File; +import java.io.IOException; /** * Abstract ManagedRepositories Action. @@ -46,44 +38,14 @@ import javax.inject.Named; public abstract class AbstractManagedRepositoriesAction extends AbstractRepositoriesAdminAction { - /** - * plexus.requirement role-hint="default" - */ - @Inject - protected RoleManager roleManager; - /** - * Plexus registry to read the configuration from. - *

- * plexus.requirement role-hint="commons-configuration" - */ - @Inject - @Named( value = "commons-configuration" ) - private Registry registry; - - /** - * plexus.requirement role="org.apache.archiva.scheduler.ArchivaTaskScheduler" role-hint="repository" - */ + @Inject @Named( value = "archivaTaskScheduler#repository" ) private RepositoryArchivaTaskScheduler repositoryTaskScheduler; public static final String CONFIRM = "confirm"; - public RoleManager getRoleManager() - { - return roleManager; - } - - public void setRoleManager( RoleManager roleManager ) - { - this.roleManager = roleManager; - } - - public void setRegistry( Registry registry ) - { - this.registry = registry; - } public void setRepositoryTaskScheduler( RepositoryArchivaTaskScheduler repositoryTaskScheduler ) { @@ -109,83 +71,4 @@ public abstract class AbstractManagedRepositoriesAction configuration.addManagedRepository( repository ); } - - protected void addRepositoryRoles( ManagedRepositoryConfiguration newRepository ) - throws RoleManagerException - { - String repoId = newRepository.getId(); - - // TODO: double check these are configured on start up - // TODO: belongs in the business logic - - if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) ) - { - roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ); - } - - if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) ) - { - roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ); - } - } - - protected void removeContents( ManagedRepositoryConfiguration existingRepository ) - throws IOException - { - File dir = new File( existingRepository.getLocation() ); - if ( dir.exists() && !FileUtils.deleteQuietly( dir ) ) - { - throw new IOException( "Cannot delete repository " + dir ); - } - } - - protected void removeRepository( String repoId, Configuration configuration ) - { - ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( repoId ); - if ( toremove != null ) - { - configuration.removeManagedRepository( toremove ); - } - } - - protected void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository ) - throws RoleManagerException - { - String repoId = existingRepository.getId(); - - if ( roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) ) - { - roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ); - } - - if ( roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) ) - { - roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ); - } - - log.debug( "removed user roles associated with repository {}", repoId ); - } - - protected String removeExpressions( String directory ) - { - String value = StringUtils.replace( directory, "${appserver.base}", - registry.getString( "appserver.base", "${appserver.base}" ) ); - value = StringUtils.replace( value, "${appserver.home}", - registry.getString( "appserver.home", "${appserver.home}" ) ); - return value; - } - - //MRM-1342 Repository statistics report doesn't appear to be working correctly - //provide a method to scan repository - protected void executeRepositoryScanner( String repoId ) - throws TaskQueueException - { - RepositoryTask task = new RepositoryTask(); - task.setRepositoryId( repoId ); - - if ( repositoryTaskScheduler.isProcessingRepositoryTask( repoId ) ) - { - repositoryTaskScheduler.queueTask( task ); - } - } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java index f7908ed26..8792d8ce7 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java @@ -23,7 +23,6 @@ import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.Validateable; import org.apache.archiva.admin.repository.RepositoryAdminException; import org.apache.archiva.admin.repository.managed.ManagedRepository; -import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; @@ -31,7 +30,6 @@ import org.codehaus.redback.components.scheduler.CronExpressionValidator; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; -import javax.inject.Inject; import java.io.File; /** @@ -79,7 +77,7 @@ public class AddManagedRepositoryAction public String commit() { - repository.setLocation( removeExpressions( repository.getLocation() ) ); + repository.setLocation( getManagedRepositoryAdmin().removeExpressions( repository.getLocation() ) ); File location = new File( repository.getLocation() ); if ( location.exists() ) @@ -110,27 +108,7 @@ public class AddManagedRepositoryAction return result; } - private ManagedRepositoryConfiguration getStageRepoConfig() - { - ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration(); - stagingRepository.setId( repository.getId() + "-stage" ); - stagingRepository.setLayout( repository.getLayout() ); - stagingRepository.setName( repository.getName() + "-stage" ); - stagingRepository.setBlockRedeployments( repository.isBlockRedeployments() ); - stagingRepository.setDaysOlder( repository.getDaysOlder() ); - stagingRepository.setDeleteReleasedSnapshots( repository.isDeleteReleasedSnapshots() ); - stagingRepository.setIndexDir( repository.getIndexDir() ); - String path = repository.getLocation(); - int lastIndex = path.lastIndexOf( '/' ); - stagingRepository.setLocation( path.substring( 0, lastIndex ) + "/" + stagingRepository.getId() ); - stagingRepository.setRefreshCronExpression( repository.getRefreshCronExpression() ); - stagingRepository.setReleases( repository.isReleases() ); - stagingRepository.setRetentionCount( repository.getRetentionCount() ); - stagingRepository.setScanned( repository.isScanned() ); - stagingRepository.setSnapshots( repository.isSnapshots() ); - return stagingRepository; - } - + // FIXME olamy dupe with admin repo componennt @Override public void validate() { 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 cd446165c..929c57e5e 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 @@ -49,6 +49,7 @@ public class DeleteManagedRepositoryAction private String repoid; + // FIXME olamy use ManagedRepositoryAdmin rather tha, directly archivaConfiguration public void prepare() { if ( StringUtils.isNotBlank( repoid ) ) @@ -83,7 +84,6 @@ public class DeleteManagedRepositoryAction private String deleteRepository( boolean deleteContents ) { ManagedRepositoryConfiguration existingRepository = repository; - ManagedRepositoryConfiguration attachedStagingRepo = stagingRepository; if ( existingRepository == null ) { addActionError( "A repository with that id does not exist" ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java index b01bc90f1..4a4fa4ac1 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java @@ -88,6 +88,7 @@ public class EditManagedRepositoryAction return save( true ); } + // FIXME olamy use ManagedRepositoryAdmin rather tha, directly archivaConfiguration public String commit() { ManagedRepositoryConfiguration existingConfig = @@ -95,7 +96,7 @@ public class EditManagedRepositoryAction boolean resetStats = false; // check if the location was changed - repository.setLocation( removeExpressions( repository.getLocation() ) ); + repository.setLocation( getManagedRepositoryAdmin().removeExpressions( repository.getLocation() ) ); if ( !StringUtils.equalsIgnoreCase( existingConfig.getLocation().trim(), repository.getLocation().trim() ) ) { diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java index 3f4f74a0e..dece63542 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java @@ -84,11 +84,10 @@ public class AddManagedRepositoryActionTest roleManagerControl = MockControl.createControl( RoleManager.class ); roleManager = (RoleManager) roleManagerControl.getMock(); - action.setRoleManager( roleManager ); registryControl = MockControl.createControl( Registry.class ); registry = (Registry) registryControl.getMock(); - action.setRegistry( registry ); + //action.setRegistry( registry ); repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class ); repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock(); @@ -97,6 +96,7 @@ public class AddManagedRepositoryActionTest location = new File( "target/test/location" ); ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setArchivaConfiguration( archivaConfiguration ); ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRoleManager( roleManager ); + ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRegistry( registry ); action.setManagedRepositoryAdmin( getManagedRepositoryAdmin() ); } @@ -162,6 +162,11 @@ public class AddManagedRepositoryActionTest registry.getString( "appserver.home", "${appserver.home}" ); registryControl.setReturnValue( "target/test" ); + registry.getString( "appserver.base", "${appserver.base}" ); + registryControl.setReturnValue( "target/test" ); + registry.getString( "appserver.home", "${appserver.home}" ); + registryControl.setReturnValue( "target/test" ); + registryControl.replay(); RepositoryTask task = new RepositoryTask(); 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 ca8398ec7..e86898d8f 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 @@ -103,7 +103,7 @@ public class DeleteManagedRepositoryActionTest roleManagerControl = MockControl.createControl( RoleManager.class ); roleManager = (RoleManager) roleManagerControl.getMock(); - action.setRoleManager( roleManager ); + //action.setRoleManager( roleManager ); location = new File( "target/test/location" ); repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java index 8ce7307f1..6e12a0910 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java @@ -93,11 +93,11 @@ public class EditManagedRepositoryActionTest roleManagerControl = MockControl.createControl( RoleManager.class ); roleManager = (RoleManager) roleManagerControl.getMock(); - action.setRoleManager( roleManager ); + //action.setRoleManager( roleManager ); registryControl = MockControl.createControl( Registry.class ); registry = (Registry) registryControl.getMock(); - action.setRegistry( registry ); + //action.setRegistry( registry ); repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class ); repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock(); @@ -118,6 +118,8 @@ public class EditManagedRepositoryActionTest repositoryTaskScheduler ); ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositorySessionFactory( factory ); + ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRegistry( registry ); + ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setAuditListeners( new ArrayList( 0 ) ); @@ -200,6 +202,11 @@ public class EditManagedRepositoryActionTest registry.getString( "appserver.home", "${appserver.home}" ); registryControl.setReturnValue( "target/test" ); + registry.getString( "appserver.base", "${appserver.base}" ); + registryControl.setReturnValue( "target/test" ); + registry.getString( "appserver.home", "${appserver.home}" ); + registryControl.setReturnValue( "target/test" ); + registryControl.replay(); RepositoryTask task = new RepositoryTask(); @@ -303,6 +310,11 @@ public class EditManagedRepositoryActionTest registry.getString( "appserver.home", "${appserver.home}" ); registryControl.setReturnValue( "target/test" ); + registry.getString( "appserver.base", "${appserver.base}" ); + registryControl.setReturnValue( "target/test" ); + registry.getString( "appserver.home", "${appserver.home}" ); + registryControl.setReturnValue( "target/test" ); + registryControl.replay(); RepositoryTask task = new RepositoryTask();