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
This commit is contained in:
Olivier Lamy 2011-09-01 08:49:08 +00:00
parent 2d5d7683fd
commit 745243b347
9 changed files with 48 additions and 152 deletions

View File

@ -467,7 +467,7 @@ public class DefaultManagedRepositoryAdmin
} }
private String removeExpressions( String directory ) public String removeExpressions( String directory )
{ {
String value = StringUtils.replace( directory, "${appserver.base}", String value = StringUtils.replace( directory, "${appserver.base}",
registry.getString( "appserver.base", "${appserver.base}" ) ); registry.getString( "appserver.base", "${appserver.base}" ) );
@ -654,4 +654,14 @@ public class DefaultManagedRepositoryAdmin
{ {
this.repositoryTaskScheduler = repositoryTaskScheduler; this.repositoryTaskScheduler = repositoryTaskScheduler;
} }
public Registry getRegistry()
{
return registry;
}
public void setRegistry( Registry registry )
{
this.registry = registry;
}
} }

View File

@ -48,4 +48,11 @@ public interface ManagedRepositoryAdmin
AuditInformation auditInformation, boolean resetStats ) AuditInformation auditInformation, boolean resetStats )
throws RepositoryAdminException; throws RepositoryAdminException;
/**
* replace some interpolations ${appserver.base} with correct values
* @param directory
* @return
*/
String removeExpressions( String directory );
} }

View File

@ -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.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.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; 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.Inject;
import javax.inject.Named; import javax.inject.Named;
import java.io.File;
import java.io.IOException;
/** /**
* Abstract ManagedRepositories Action. * Abstract ManagedRepositories Action.
@ -46,44 +38,14 @@ import javax.inject.Named;
public abstract class AbstractManagedRepositoriesAction public abstract class AbstractManagedRepositoriesAction
extends AbstractRepositoriesAdminAction extends AbstractRepositoriesAdminAction
{ {
/**
* plexus.requirement role-hint="default"
*/
@Inject
protected RoleManager roleManager;
/**
* Plexus registry to read the configuration from.
* <p/>
* 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 @Inject
@Named( value = "archivaTaskScheduler#repository" ) @Named( value = "archivaTaskScheduler#repository" )
private RepositoryArchivaTaskScheduler repositoryTaskScheduler; private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
public static final String CONFIRM = "confirm"; 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 ) public void setRepositoryTaskScheduler( RepositoryArchivaTaskScheduler repositoryTaskScheduler )
{ {
@ -109,83 +71,4 @@ public abstract class AbstractManagedRepositoriesAction
configuration.addManagedRepository( repository ); 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 );
}
}
} }

View File

@ -23,7 +23,6 @@ import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.Validateable; import com.opensymphony.xwork2.Validateable;
import org.apache.archiva.admin.repository.RepositoryAdminException; import org.apache.archiva.admin.repository.RepositoryAdminException;
import org.apache.archiva.admin.repository.managed.ManagedRepository; 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.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;
@ -31,7 +30,6 @@ import org.codehaus.redback.components.scheduler.CronExpressionValidator;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import javax.inject.Inject;
import java.io.File; import java.io.File;
/** /**
@ -79,7 +77,7 @@ public class AddManagedRepositoryAction
public String commit() public String commit()
{ {
repository.setLocation( removeExpressions( repository.getLocation() ) ); repository.setLocation( getManagedRepositoryAdmin().removeExpressions( repository.getLocation() ) );
File location = new File( repository.getLocation() ); File location = new File( repository.getLocation() );
if ( location.exists() ) if ( location.exists() )
@ -110,27 +108,7 @@ public class AddManagedRepositoryAction
return result; return result;
} }
private ManagedRepositoryConfiguration getStageRepoConfig() // FIXME olamy dupe with admin repo componennt
{
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;
}
@Override @Override
public void validate() public void validate()
{ {

View File

@ -49,6 +49,7 @@ public class DeleteManagedRepositoryAction
private String repoid; private String repoid;
// FIXME olamy use ManagedRepositoryAdmin rather tha, directly archivaConfiguration
public void prepare() public void prepare()
{ {
if ( StringUtils.isNotBlank( repoid ) ) if ( StringUtils.isNotBlank( repoid ) )
@ -83,7 +84,6 @@ public class DeleteManagedRepositoryAction
private String deleteRepository( boolean deleteContents ) private String deleteRepository( boolean deleteContents )
{ {
ManagedRepositoryConfiguration existingRepository = repository; ManagedRepositoryConfiguration existingRepository = repository;
ManagedRepositoryConfiguration attachedStagingRepo = stagingRepository;
if ( existingRepository == null ) if ( existingRepository == null )
{ {
addActionError( "A repository with that id does not exist" ); addActionError( "A repository with that id does not exist" );

View File

@ -88,6 +88,7 @@ public class EditManagedRepositoryAction
return save( true ); return save( true );
} }
// FIXME olamy use ManagedRepositoryAdmin rather tha, directly archivaConfiguration
public String commit() public String commit()
{ {
ManagedRepositoryConfiguration existingConfig = ManagedRepositoryConfiguration existingConfig =
@ -95,7 +96,7 @@ public class EditManagedRepositoryAction
boolean resetStats = false; boolean resetStats = false;
// check if the location was changed // 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() ) ) if ( !StringUtils.equalsIgnoreCase( existingConfig.getLocation().trim(), repository.getLocation().trim() ) )
{ {

View File

@ -84,11 +84,10 @@ public class AddManagedRepositoryActionTest
roleManagerControl = MockControl.createControl( RoleManager.class ); roleManagerControl = MockControl.createControl( RoleManager.class );
roleManager = (RoleManager) roleManagerControl.getMock(); roleManager = (RoleManager) roleManagerControl.getMock();
action.setRoleManager( roleManager );
registryControl = MockControl.createControl( Registry.class ); registryControl = MockControl.createControl( Registry.class );
registry = (Registry) registryControl.getMock(); registry = (Registry) registryControl.getMock();
action.setRegistry( registry ); //action.setRegistry( registry );
repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class ); repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class );
repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock(); repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock();
@ -97,6 +96,7 @@ public class AddManagedRepositoryActionTest
location = new File( "target/test/location" ); location = new File( "target/test/location" );
( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setArchivaConfiguration( archivaConfiguration ); ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setArchivaConfiguration( archivaConfiguration );
( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRoleManager( roleManager ); ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRoleManager( roleManager );
( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRegistry( registry );
action.setManagedRepositoryAdmin( getManagedRepositoryAdmin() ); action.setManagedRepositoryAdmin( getManagedRepositoryAdmin() );
} }
@ -162,6 +162,11 @@ public class AddManagedRepositoryActionTest
registry.getString( "appserver.home", "${appserver.home}" ); registry.getString( "appserver.home", "${appserver.home}" );
registryControl.setReturnValue( "target/test" ); 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(); registryControl.replay();
RepositoryTask task = new RepositoryTask(); RepositoryTask task = new RepositoryTask();

View File

@ -103,7 +103,7 @@ public class DeleteManagedRepositoryActionTest
roleManagerControl = MockControl.createControl( RoleManager.class ); roleManagerControl = MockControl.createControl( RoleManager.class );
roleManager = (RoleManager) roleManagerControl.getMock(); roleManager = (RoleManager) roleManagerControl.getMock();
action.setRoleManager( roleManager ); //action.setRoleManager( roleManager );
location = new File( "target/test/location" ); location = new File( "target/test/location" );
repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class ); repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );

View File

@ -93,11 +93,11 @@ public class EditManagedRepositoryActionTest
roleManagerControl = MockControl.createControl( RoleManager.class ); roleManagerControl = MockControl.createControl( RoleManager.class );
roleManager = (RoleManager) roleManagerControl.getMock(); roleManager = (RoleManager) roleManagerControl.getMock();
action.setRoleManager( roleManager ); //action.setRoleManager( roleManager );
registryControl = MockControl.createControl( Registry.class ); registryControl = MockControl.createControl( Registry.class );
registry = (Registry) registryControl.getMock(); registry = (Registry) registryControl.getMock();
action.setRegistry( registry ); //action.setRegistry( registry );
repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class ); repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class );
repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock(); repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock();
@ -118,6 +118,8 @@ public class EditManagedRepositoryActionTest
repositoryTaskScheduler ); repositoryTaskScheduler );
( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositorySessionFactory( factory ); ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositorySessionFactory( factory );
( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRegistry( registry );
( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setAuditListeners( ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setAuditListeners(
new ArrayList<AuditListener>( 0 ) ); new ArrayList<AuditListener>( 0 ) );
@ -200,6 +202,11 @@ public class EditManagedRepositoryActionTest
registry.getString( "appserver.home", "${appserver.home}" ); registry.getString( "appserver.home", "${appserver.home}" );
registryControl.setReturnValue( "target/test" ); 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(); registryControl.replay();
RepositoryTask task = new RepositoryTask(); RepositoryTask task = new RepositoryTask();
@ -303,6 +310,11 @@ public class EditManagedRepositoryActionTest
registry.getString( "appserver.home", "${appserver.home}" ); registry.getString( "appserver.home", "${appserver.home}" );
registryControl.setReturnValue( "target/test" ); 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(); registryControl.replay();
RepositoryTask task = new RepositoryTask(); RepositoryTask task = new RepositoryTask();