mirror of https://github.com/apache/archiva.git
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:
parent
2d5d7683fd
commit
745243b347
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
* <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
|
||||
@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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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" );
|
||||
|
|
|
@ -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() ) )
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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<AuditListener>( 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();
|
||||
|
|
Loading…
Reference in New Issue