[MRM-1505] api to configure ManagedRepository : use it in webapp instead of directly archiva model

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1164558 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-09-02 14:53:15 +00:00
parent d1a0d0eb32
commit d9b6ddeba1
14 changed files with 344 additions and 219 deletions

View File

@ -115,7 +115,9 @@ public class DefaultManagedRepositoryAdmin
ManagedRepository repo = ManagedRepository repo =
new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(), new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(), repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(),
repoConfig.isBlockRedeployments(), repoConfig.getRefreshCronExpression() ); repoConfig.isBlockRedeployments(), repoConfig.getRefreshCronExpression(),
repoConfig.getIndexDir(), repoConfig.isScanned(), repoConfig.getDaysOlder(),
repoConfig.getRetentionCount(), repoConfig.isDeleteReleasedSnapshots() );
managedRepos.add( repo ); managedRepos.add( repo );
} }
@ -146,7 +148,9 @@ public class DefaultManagedRepositoryAdmin
addManagedRepository( managedRepository.getId(), managedRepository.getLayout(), managedRepository.getName(), addManagedRepository( managedRepository.getId(), managedRepository.getLayout(), managedRepository.getName(),
managedRepository.getLocation(), managedRepository.isBlockRedeployments(), managedRepository.getLocation(), managedRepository.isBlockRedeployments(),
managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo, managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo,
managedRepository.getCronExpression(), auditInformation ) != null; managedRepository.getCronExpression(), managedRepository.getIndexDirectory(),
managedRepository.getDaysOlder(), managedRepository.getRetentionCount(),
managedRepository.isDeleteReleasedSnapshots(), auditInformation ) != null;
} }
@ -154,6 +158,8 @@ public class DefaultManagedRepositoryAdmin
String location, boolean blockRedeployments, String location, boolean blockRedeployments,
boolean releasesIncluded, boolean snapshotsIncluded, boolean releasesIncluded, boolean snapshotsIncluded,
boolean stageRepoNeeded, String cronExpression, boolean stageRepoNeeded, String cronExpression,
String indexDir, int daysOlder, int retentionCount,
boolean deteleReleasedSnapshots,
AuditInformation auditInformation ) AuditInformation auditInformation )
throws RepositoryAdminException throws RepositoryAdminException
{ {
@ -228,6 +234,10 @@ public class DefaultManagedRepositoryAdmin
repository.setLocation( repoLocation ); repository.setLocation( repoLocation );
repository.setLayout( layout ); repository.setLayout( layout );
repository.setRefreshCronExpression( cronExpression ); repository.setRefreshCronExpression( cronExpression );
repository.setIndexDir( indexDir );
repository.setDaysOlder( daysOlder );
repository.setRetentionCount( retentionCount );
repository.setDeleteReleasedSnapshots( deteleReleasedSnapshots );
try try
{ {
addRepository( repository, config ); addRepository( repository, config );
@ -369,8 +379,7 @@ public class DefaultManagedRepositoryAdmin
List<String> repoGroups = repoToGroupMap.get( repository.getId() ); List<String> repoGroups = repoToGroupMap.get( repository.getId() );
for ( String repoGroup : repoGroups ) for ( String repoGroup : repoGroups )
{ {
config.findRepositoryGroupById( repoGroup ).removeRepository( config.findRepositoryGroupById( repoGroup ).removeRepository( repository.getId() );
repository.getId() );
} }
} }
} }
@ -426,7 +435,9 @@ public class DefaultManagedRepositoryAdmin
addManagedRepository( managedRepository.getId(), managedRepository.getLayout(), managedRepository.getName(), addManagedRepository( managedRepository.getId(), managedRepository.getLayout(), managedRepository.getName(),
managedRepository.getLocation(), managedRepository.isBlockRedeployments(), managedRepository.getLocation(), managedRepository.isBlockRedeployments(),
managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo, managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo,
managedRepository.getCronExpression(), auditInformation ); managedRepository.getCronExpression(), managedRepository.getIndexDirectory(),
managedRepository.getDaysOlder(), managedRepository.getRetentionCount(),
managedRepository.isDeleteReleasedSnapshots(), auditInformation );
// Save the repository configuration. // Save the repository configuration.
RepositorySession repositorySession = getRepositorySessionFactory().createSession(); RepositorySession repositorySession = getRepositorySessionFactory().createSession();

View File

@ -33,30 +33,49 @@ public class ManagedRepository
private String location; private String location;
private String layout; private String layout = "default";
private boolean snapshots = false; private boolean snapshots = false;
private boolean releases = false; private boolean releases = true;
private boolean blockRedeployments; private boolean blockRedeployments = false;
private String cronExpression; /**
* default model value
*/
private String cronExpression = "0 0 * * * ?";
private boolean stageRepoNeeded;
/** /**
* not need when creating the repo : only available when reading * not need when creating the repo : only available when reading
*/ */
private ManagedRepository stagingRepository; private ManagedRepository stagingRepository;
private boolean scanned = true;
private String indexDirectory;
/**
* default model value
*/
private int daysOlder = 100;
/**
* default model value
*/
private int retentionCount = 2;
private boolean deleteReleasedSnapshots;
public ManagedRepository() public ManagedRepository()
{ {
// no op // no op
} }
public ManagedRepository( String id, String name, String location, String layout, boolean snapshots, boolean releases, public ManagedRepository( String id, String name, String location, String layout, boolean snapshots,
boolean blockRedeployments, String cronExpression ) boolean releases, boolean blockRedeployments, String cronExpression, String indexDir,
boolean scanned, int daysOlder, int retentionCount, boolean deleteReleasedSnapshots )
{ {
this.id = id; this.id = id;
this.name = name; this.name = name;
@ -66,6 +85,11 @@ public class ManagedRepository
this.releases = releases; this.releases = releases;
this.blockRedeployments = blockRedeployments; this.blockRedeployments = blockRedeployments;
this.cronExpression = cronExpression; this.cronExpression = cronExpression;
this.indexDirectory = indexDir;
this.scanned = scanned;
this.daysOlder = daysOlder;
this.retentionCount = retentionCount;
this.deleteReleasedSnapshots = deleteReleasedSnapshots;
} }
public String getId() public String getId()
@ -163,6 +187,56 @@ public class ManagedRepository
this.stagingRepository = stagingRepository; this.stagingRepository = stagingRepository;
} }
public boolean isScanned()
{
return scanned;
}
public void setScanned( boolean scanned )
{
this.scanned = scanned;
}
public String getIndexDirectory()
{
return indexDirectory;
}
public void setIndexDirectory( String indexDirectory )
{
this.indexDirectory = indexDirectory;
}
public int getDaysOlder()
{
return daysOlder;
}
public void setDaysOlder( int daysOlder )
{
this.daysOlder = daysOlder;
}
public int getRetentionCount()
{
return retentionCount;
}
public void setRetentionCount( int retentionCount )
{
this.retentionCount = retentionCount;
}
public boolean isDeleteReleasedSnapshots()
{
return deleteReleasedSnapshots;
}
public void setDeleteReleasedSnapshots( boolean deleteReleasedSnapshots )
{
this.deleteReleasedSnapshots = deleteReleasedSnapshots;
}
public int hashCode() public int hashCode()
{ {
int result = 17; int result = 17;
@ -201,8 +275,9 @@ public class ManagedRepository
sb.append( ", releases=" ).append( releases ); sb.append( ", releases=" ).append( releases );
sb.append( ", blockRedeployments=" ).append( blockRedeployments ); sb.append( ", blockRedeployments=" ).append( blockRedeployments );
sb.append( ", cronExpression='" ).append( cronExpression ).append( '\'' ); sb.append( ", cronExpression='" ).append( cronExpression ).append( '\'' );
sb.append( ", stageRepoNeeded=" ).append( stageRepoNeeded );
sb.append( ", stagingRepository=" ).append( stagingRepository ); sb.append( ", stagingRepository=" ).append( stagingRepository );
sb.append( ", scanned=" ).append( scanned );
sb.append( ", indexDirectory='" ).append( indexDirectory ).append( '\'' );
sb.append( '}' ); sb.append( '}' );
return sb.toString(); return sb.toString();
} }

View File

@ -276,6 +276,10 @@ public class ManagedRepositoryAdminTest
assertNotNull( repos ); assertNotNull( repos );
assertEquals( initialSize + 1, repos.size() ); assertEquals( initialSize + 1, repos.size() );
repo = managedRepositoryAdmin.getManagedRepository( repoId );
assertEquals( getTestManagedRepository( repoId, repoLocation ).getIndexDirectory(), repo.getIndexDirectory() );
String newName = "test repo update"; String newName = "test repo update";
repo.setName( newName ); repo.setName( newName );
@ -292,6 +296,13 @@ public class ManagedRepositoryAdminTest
assertEquals( getTestManagedRepository( repoId, repoLocation ).getCronExpression(), repo.getCronExpression() ); assertEquals( getTestManagedRepository( repoId, repoLocation ).getCronExpression(), repo.getCronExpression() );
assertEquals( getTestManagedRepository( repoId, repoLocation ).getLayout(), repo.getLayout() ); assertEquals( getTestManagedRepository( repoId, repoLocation ).getLayout(), repo.getLayout() );
assertEquals( getTestManagedRepository( repoId, repoLocation ).getId(), repo.getId() ); assertEquals( getTestManagedRepository( repoId, repoLocation ).getId(), repo.getId() );
assertEquals( getTestManagedRepository( repoId, repoLocation ).getIndexDirectory(), repo.getIndexDirectory() );
assertEquals( getTestManagedRepository( repoId, repoLocation ).getDaysOlder(), repo.getDaysOlder() );
assertEquals( getTestManagedRepository( repoId, repoLocation ).getRetentionCount(), repo.getRetentionCount() );
assertEquals( getTestManagedRepository( repoId, repoLocation ).isDeleteReleasedSnapshots(),
repo.isDeleteReleasedSnapshots() );
assertTemplateRoleExists( repoId ); assertTemplateRoleExists( repoId );
assertTrue( new File( stageRepoLocation + STAGE_REPO_ID_END ).exists() ); assertTrue( new File( stageRepoLocation + STAGE_REPO_ID_END ).exists() );
@ -424,7 +435,8 @@ public class ManagedRepositoryAdminTest
ManagedRepository getTestManagedRepository( String repoId, String repoLocation ) ManagedRepository getTestManagedRepository( String repoId, String repoLocation )
{ {
return new ManagedRepository( repoId, "test repo", repoLocation, "default", false, true, true, "0 0 * * * ?" ); return new ManagedRepository( repoId, "test repo", repoLocation, "default", false, true, true, "0 0 * * * ?",
repoLocation + "/.index", false, 1, 2, true );
} }
} }

View File

@ -47,7 +47,7 @@ public class AddManagedRepositoryAction
* FIXME we must manipulate beans from repo admin api * FIXME we must manipulate beans from repo admin api
* The model for this action. * The model for this action.
*/ */
private ManagedRepositoryConfiguration repository; private ManagedRepository repository;
private boolean stageNeeded; private boolean stageNeeded;
@ -55,7 +55,7 @@ public class AddManagedRepositoryAction
public void prepare() public void prepare()
{ {
this.repository = new ManagedRepositoryConfiguration(); this.repository = new ManagedRepository();
this.repository.setReleases( false ); this.repository.setReleases( false );
this.repository.setScanned( false ); this.repository.setScanned( false );
this.repository.setBlockRedeployments( false ); this.repository.setBlockRedeployments( false );
@ -93,11 +93,7 @@ public class AddManagedRepositoryAction
String result = SUCCESS; String result = SUCCESS;
try try
{ {
ManagedRepository managedRepository = getManagedRepositoryAdmin().addManagedRepository( repository, stageNeeded, getAuditInformation() );
new ManagedRepository( repository.getId(), repository.getName(), repository.getLocation(),
repository.getLayout(), repository.isSnapshots(), repository.isReleases(),
repository.isBlockRedeployments(), repository.getRefreshCronExpression() );
getManagedRepositoryAdmin().addManagedRepository( managedRepository, stageNeeded, getAuditInformation() );
} }
catch ( RepositoryAdminException e ) catch ( RepositoryAdminException e )
{ {
@ -139,7 +135,7 @@ public class AddManagedRepositoryAction
+ "], repository id cannot contains word stage" ); + "], repository id cannot contains word stage" );
} }
if ( !validator.validate( repository.getRefreshCronExpression() ) ) if ( !validator.validate( repository.getCronExpression() ) )
{ {
addFieldError( "repository.refreshCronExpression", "Invalid cron expression." ); addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
} }
@ -165,18 +161,18 @@ public class AddManagedRepositoryAction
repository.setLocation( repository.getLocation().trim() ); repository.setLocation( repository.getLocation().trim() );
} }
if ( StringUtils.isNotEmpty( repository.getIndexDir() ) ) if ( StringUtils.isNotEmpty( repository.getIndexDirectory() ) )
{ {
repository.setIndexDir( repository.getIndexDir().trim() ); repository.setIndexDirectory( repository.getIndexDirectory().trim() );
} }
} }
public ManagedRepositoryConfiguration getRepository() public ManagedRepository getRepository()
{ {
return repository; return repository;
} }
public void setRepository( ManagedRepositoryConfiguration repository ) public void setRepository( ManagedRepository repository )
{ {
this.repository = repository; this.repository = repository;
} }

View File

@ -46,9 +46,9 @@ public class EditManagedRepositoryAction
* FIXME we must manipulate beans from repo admin api * FIXME we must manipulate beans from repo admin api
* The model for this action. * The model for this action.
*/ */
private ManagedRepositoryConfiguration repository; private ManagedRepository repository;
private ManagedRepositoryConfiguration stagingRepository; private ManagedRepository stagingRepository;
private String repoid; private String repoid;
@ -57,12 +57,14 @@ public class EditManagedRepositoryAction
private boolean stageNeeded; private boolean stageNeeded;
// FIXME better error message
public void prepare() public void prepare()
throws RepositoryAdminException
{ {
if ( StringUtils.isNotBlank( repoid ) ) if ( StringUtils.isNotBlank( repoid ) )
{ {
repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid ); repository = getManagedRepositoryAdmin().getManagedRepository( repoid );
stagingRepository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid + "-stage" ); stagingRepository = getManagedRepositoryAdmin().getManagedRepository( repoid + "-stage" );
} }
else if ( repository != null ) else if ( repository != null )
{ {
@ -118,12 +120,7 @@ public class EditManagedRepositoryAction
String result = SUCCESS; String result = SUCCESS;
try try
{ {
ManagedRepository managedRepository = getManagedRepositoryAdmin().updateManagedRepository( repository, stageNeeded, getAuditInformation(),
new ManagedRepository( repository.getId(), repository.getName(), repository.getLocation(),
repository.getLayout(), repository.isSnapshots(), repository.isReleases(),
repository.isBlockRedeployments(), repository.getRefreshCronExpression() );
getManagedRepositoryAdmin().updateManagedRepository( managedRepository, stageNeeded, getAuditInformation(),
resetStats ); resetStats );
} }
catch ( RepositoryAdminException e ) catch ( RepositoryAdminException e )
@ -141,7 +138,7 @@ public class EditManagedRepositoryAction
{ {
CronExpressionValidator validator = new CronExpressionValidator(); CronExpressionValidator validator = new CronExpressionValidator();
if ( !validator.validate( repository.getRefreshCronExpression() ) ) if ( !validator.validate( repository.getCronExpression() ) )
{ {
addFieldError( "repository.refreshCronExpression", "Invalid cron expression." ); addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
} }
@ -166,9 +163,9 @@ public class EditManagedRepositoryAction
repository.setLocation( repository.getLocation().trim() ); repository.setLocation( repository.getLocation().trim() );
} }
if ( StringUtils.isNotEmpty( repository.getIndexDir() ) ) if ( StringUtils.isNotEmpty( repository.getIndexDirectory() ) )
{ {
repository.setIndexDir( repository.getIndexDir().trim() ); repository.setIndexDirectory( repository.getIndexDirectory().trim() );
} }
} }
@ -182,15 +179,6 @@ public class EditManagedRepositoryAction
this.repoid = repoid; this.repoid = repoid;
} }
public ManagedRepositoryConfiguration getRepository()
{
return repository;
}
public void setRepository( ManagedRepositoryConfiguration repository )
{
this.repository = repository;
}
public boolean isStageNeeded() public boolean isStageNeeded()
{ {
@ -208,12 +196,22 @@ public class EditManagedRepositoryAction
return action; return action;
} }
public ManagedRepositoryConfiguration getStagingRepository() public ManagedRepository getRepository()
{
return repository;
}
public void setRepository( ManagedRepository repository )
{
this.repository = repository;
}
public ManagedRepository getStagingRepository()
{ {
return stagingRepository; return stagingRepository;
} }
public void setStagingRepository( ManagedRepositoryConfiguration stagingRepository ) public void setStagingRepository( ManagedRepository stagingRepository )
{ {
this.stagingRepository = stagingRepository; this.stagingRepository = stagingRepository;
} }

View File

@ -42,7 +42,7 @@
<message>Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&amp;), forward-slashes(/), back-slashes(\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-).</message> <message>Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&amp;), forward-slashes(/), back-slashes(\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-).</message>
</field-validator> </field-validator>
</field> </field>
<field name="repository.indexDir"> <field name="repository.indexDirectory">
<!-- no requiredstring validation, because there was none before(being consistent). --> <!-- no requiredstring validation, because there was none before(being consistent). -->
<field-validator type="regex"> <field-validator type="regex">
<param name="trim">true</param> <param name="trim">true</param>

View File

@ -42,7 +42,7 @@
<message>Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&amp;), forward-slashes(/), back-slashes(\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-).</message> <message>Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&amp;), forward-slashes(/), back-slashes(\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-).</message>
</field-validator> </field-validator>
</field> </field>
<field name="repository.indexDir"> <field name="repository.indexDirectory">
<!-- no requiredstring validation, because there was none before(being consistent). --> <!-- no requiredstring validation, because there was none before(being consistent). -->
<field-validator type="regex"> <field-validator type="regex">
<param name="trim">true</param> <param name="trim">true</param>

View File

@ -20,12 +20,12 @@ package org.apache.maven.archiva.web.action.admin.repositories;
*/ */
import com.opensymphony.xwork2.validator.ActionValidatorManager; import com.opensymphony.xwork2.validator.ActionValidatorManager;
import java.io.File; import org.apache.archiva.admin.repository.managed.ManagedRepository;
import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin; import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.struts2.StrutsSpringTestCase; import org.apache.struts2.StrutsSpringTestCase;
import java.io.File;
public abstract class AbstractManagedRepositoryActionTest public abstract class AbstractManagedRepositoryActionTest
extends StrutsSpringTestCase extends StrutsSpringTestCase
{ {
@ -71,58 +71,74 @@ public abstract class AbstractManagedRepositoryActionTest
} }
@Override @Override
protected void setUp() throws Exception protected void setUp()
throws Exception
{ {
super.setUp(); super.setUp();
DefaultActionValidatorManagerFactory defaultActionValidatorManagerFactory = new DefaultActionValidatorManagerFactory(); DefaultActionValidatorManagerFactory defaultActionValidatorManagerFactory =
new DefaultActionValidatorManagerFactory();
actionValidatorManager = defaultActionValidatorManagerFactory.createDefaultActionValidatorManager(); actionValidatorManager = defaultActionValidatorManagerFactory.createDefaultActionValidatorManager();
} }
protected void populateRepository( ManagedRepositoryConfiguration repository ) protected void populateRepository( ManagedRepository repository )
{ {
repository.setId( REPO_ID ); repository.setId( REPO_ID );
repository.setName( "repo name" ); repository.setName( "repo name" );
repository.setLocation( location.getAbsolutePath() ); repository.setLocation( location.getAbsolutePath() );
repository.setLayout( "default" ); repository.setLayout( "default" );
repository.setRefreshCronExpression( "* 0/5 * * * ?" ); repository.setCronExpression( "* 0/5 * * * ?" );
repository.setDaysOlder( 31 ); repository.setDaysOlder( 31 );
repository.setRetentionCount( 20 ); repository.setRetentionCount( 20 );
repository.setReleases( true ); repository.setReleases( true );
repository.setSnapshots( true ); repository.setSnapshots( false );
repository.setScanned( false ); repository.setScanned( false );
repository.setDeleteReleasedSnapshots( true ); repository.setDeleteReleasedSnapshots( true );
} }
protected ManagedRepositoryConfiguration createManagedRepositoryConfiguration(String id, String name, String location, String indexDir, int daysOlder, int retentionCount) protected ManagedRepository createManagedRepository( String id, String name, String location )
{ {
ManagedRepositoryConfiguration managedRepositoryConfiguration = new ManagedRepositoryConfiguration(); ManagedRepository managedRepositoryConfiguration = new ManagedRepository();
managedRepositoryConfiguration.setId( id ); managedRepositoryConfiguration.setId( id );
managedRepositoryConfiguration.setName( name ); managedRepositoryConfiguration.setName( name );
managedRepositoryConfiguration.setLocation( location ); managedRepositoryConfiguration.setLocation( location );
managedRepositoryConfiguration.setIndexDir(indexDir);
managedRepositoryConfiguration.setDaysOlder(daysOlder);
managedRepositoryConfiguration.setRetentionCount(retentionCount);
return managedRepositoryConfiguration; return managedRepositoryConfiguration;
} }
// over-loaded // over-loaded
// for simulating empty/null form purposes; excluding primitive data-typed values // for simulating empty/null form purposes; excluding primitive data-typed values
protected ManagedRepositoryConfiguration createManagedRepositoryConfiguration(String id, String name, String location, String indexDir) protected ManagedRepository createManagedRepository( String id, String name, String location,
String indexDir )
{ {
ManagedRepositoryConfiguration managedRepositoryConfiguration = new ManagedRepositoryConfiguration(); ManagedRepository managedRepositoryConfiguration = new ManagedRepository();
managedRepositoryConfiguration.setId( id ); managedRepositoryConfiguration.setId( id );
managedRepositoryConfiguration.setName( name ); managedRepositoryConfiguration.setName( name );
managedRepositoryConfiguration.setLocation( location ); managedRepositoryConfiguration.setLocation( location );
managedRepositoryConfiguration.setIndexDir(indexDir); managedRepositoryConfiguration.setIndexDirectory( indexDir );
return managedRepositoryConfiguration; return managedRepositoryConfiguration;
} }
protected ManagedRepository createManagedRepository( String id, String name, String location, String indexDir,
int daysOlder, int retentionCount )
{
ManagedRepository managedRepositoryConfiguration = new ManagedRepository();
managedRepositoryConfiguration.setId( id );
managedRepositoryConfiguration.setName( name );
managedRepositoryConfiguration.setLocation( location );
managedRepositoryConfiguration.setIndexDirectory( indexDir );
managedRepositoryConfiguration.setDaysOlder( daysOlder );
managedRepositoryConfiguration.setRetentionCount( retentionCount );
return managedRepositoryConfiguration;
}
protected ManagedRepositoryAdmin getManagedRepositoryAdmin() protected ManagedRepositoryAdmin getManagedRepositoryAdmin()
{ {
return applicationContext.getBean( ManagedRepositoryAdmin.class ); return applicationContext.getBean( ManagedRepositoryAdmin.class );

View File

@ -21,12 +21,12 @@ package org.apache.maven.archiva.web.action.admin.repositories;
import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.Action;
import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
import org.apache.archiva.admin.repository.managed.ManagedRepository;
import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler; import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
import org.apache.archiva.scheduler.repository.RepositoryTask; import org.apache.archiva.scheduler.repository.RepositoryTask;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
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.security.ArchivaRoleConstants; import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.apache.maven.archiva.web.validator.utils.ValidatorUtil; import org.apache.maven.archiva.web.validator.utils.ValidatorUtil;
import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.redback.role.RoleManager;
@ -123,7 +123,7 @@ public class AddManagedRepositoryActionTest
archivaConfigurationControl.replay(); archivaConfigurationControl.replay();
action.prepare(); action.prepare();
ManagedRepositoryConfiguration configuration = action.getRepository(); ManagedRepository configuration = action.getRepository();
assertNotNull( configuration ); assertNotNull( configuration );
assertNull( configuration.getId() ); assertNull( configuration.getId() );
// check all booleans are false // check all booleans are false
@ -182,19 +182,23 @@ public class AddManagedRepositoryActionTest
archivaConfiguration.getConfiguration(); archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration ); archivaConfigurationControl.setReturnValue( configuration );
archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( configuration );
archivaConfiguration.save( configuration ); archivaConfiguration.save( configuration );
archivaConfigurationControl.replay(); archivaConfigurationControl.replay();
action.prepare(); action.prepare();
ManagedRepositoryConfiguration repository = action.getRepository(); ManagedRepository repository = action.getRepository();
populateRepository( repository ); populateRepository( repository );
assertFalse( location.exists() ); assertFalse( location.exists() );
String status = action.commit(); String status = action.commit();
assertEquals( Action.SUCCESS, status ); assertEquals( Action.SUCCESS, status );
assertTrue( location.exists() ); assertTrue( location.exists() );
assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
assertEquals( Collections.singletonList( repository ), getManagedRepositoryAdmin().getManagedRepositories() );
assertEquals( location.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() ); assertEquals( location.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() );
roleManagerControl.verify(); roleManagerControl.verify();
@ -219,7 +223,7 @@ public class AddManagedRepositoryActionTest
registryControl.replay(); registryControl.replay();
action.prepare(); action.prepare();
ManagedRepositoryConfiguration repository = action.getRepository(); ManagedRepository repository = action.getRepository();
populateRepository( repository ); populateRepository( repository );
assertTrue( location.exists() ); assertTrue( location.exists() );
@ -234,8 +238,7 @@ public class AddManagedRepositoryActionTest
{ {
// prep // prep
// 0 is the default value for primitive int; null for objects // 0 is the default value for primitive int; null for objects
ManagedRepositoryConfiguration managedRepositoryConfiguration = ManagedRepository managedRepositoryConfiguration = createManagedRepository( null, null, null, null );
createManagedRepositoryConfiguration( null, null, null, null );
action.setRepository( managedRepositoryConfiguration ); action.setRepository( managedRepositoryConfiguration );
// test // test
@ -270,8 +273,8 @@ public class AddManagedRepositoryActionTest
{ {
// prep // prep
// 0 is the default value for primitive int // 0 is the default value for primitive int
ManagedRepositoryConfiguration managedRepositoryConfiguration = ManagedRepository managedRepositoryConfiguration =
createManagedRepositoryConfiguration( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING ); createManagedRepository( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING );
action.setRepository( managedRepositoryConfiguration ); action.setRepository( managedRepositoryConfiguration );
// test // test
@ -305,11 +308,10 @@ public class AddManagedRepositoryActionTest
throws Exception throws Exception
{ {
// prep // prep
ManagedRepositoryConfiguration managedRepositoryConfiguration = ManagedRepository managedRepositoryConfiguration =
createManagedRepositoryConfiguration( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT, createManagedRepository( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT,
REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT, REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT,
REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_RETENTION_COUNT_INVALID_INPUT );
REPOSITORY_RETENTION_COUNT_INVALID_INPUT );
action.setRepository( managedRepositoryConfiguration ); action.setRepository( managedRepositoryConfiguration );
// test // test
@ -342,7 +344,7 @@ public class AddManagedRepositoryActionTest
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add( expectedErrorMessages.add(
"Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." ); "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
expectedFieldErrors.put( "repository.indexDir", expectedErrorMessages ); expectedFieldErrors.put( "repository.indexDirectory", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." ); expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." );
@ -359,11 +361,10 @@ public class AddManagedRepositoryActionTest
throws Exception throws Exception
{ {
// prep // prep
ManagedRepositoryConfiguration managedRepositoryConfiguration = ManagedRepository managedRepositoryConfiguration =
createManagedRepositoryConfiguration( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT, createManagedRepository( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT,
REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT, REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT,
REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_RETENTION_COUNT_VALID_INPUT );
REPOSITORY_RETENTION_COUNT_VALID_INPUT );
action.setRepository( managedRepositoryConfiguration ); action.setRepository( managedRepositoryConfiguration );
// test // test

View File

@ -20,7 +20,9 @@ package org.apache.maven.archiva.web.action.admin.repositories;
*/ */
import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.Action;
import org.apache.archiva.admin.repository.RepositoryAdminException;
import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
import org.apache.archiva.admin.repository.managed.ManagedRepository;
import org.apache.archiva.audit.AuditListener; import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySession;
@ -124,7 +126,7 @@ public class EditManagedRepositoryActionTest
} }
public void testSecureActionBundle() public void testSecureActionBundle()
throws SecureActionException throws SecureActionException, RepositoryAdminException
{ {
archivaConfiguration.getConfiguration(); archivaConfiguration.getConfiguration();
archivaConfigurationControl.setReturnValue( new Configuration() ); archivaConfigurationControl.setReturnValue( new Configuration() );
@ -153,10 +155,10 @@ public class EditManagedRepositoryActionTest
action.prepare(); action.prepare();
assertEquals( REPO_ID, action.getRepoid() ); assertEquals( REPO_ID, action.getRepoid() );
ManagedRepositoryConfiguration repository = action.getRepository(); ManagedRepository repository = action.getRepository();
assertNotNull( repository ); assertNotNull( repository );
ManagedRepositoryConfiguration newRepository = createRepository(); ManagedRepository newRepository = createRepository();
assertRepositoryEquals( repository, newRepository ); assertRepositoryEquals( repository, newRepository );
assertEquals( repository.getLocation(), newRepository.getLocation() ); assertEquals( repository.getLocation(), newRepository.getLocation() );
@ -245,7 +247,7 @@ public class EditManagedRepositoryActionTest
action.setRepoid( REPO_ID ); action.setRepoid( REPO_ID );
action.prepare(); action.prepare();
assertEquals( REPO_ID, action.getRepoid() ); assertEquals( REPO_ID, action.getRepoid() );
ManagedRepositoryConfiguration repository = action.getRepository(); ManagedRepository repository = action.getRepository();
populateRepository( repository ); populateRepository( repository );
repository.setName( "new repo name" ); repository.setName( "new repo name" );
@ -264,7 +266,7 @@ public class EditManagedRepositoryActionTest
String status = action.commit(); String status = action.commit();
assertEquals( Action.SUCCESS, status ); assertEquals( Action.SUCCESS, status );
ManagedRepositoryConfiguration newRepository = createRepository(); ManagedRepository newRepository = createRepository();
newRepository.setName( "new repo name" ); newRepository.setName( "new repo name" );
assertRepositoryEquals( repository, newRepository ); assertRepositoryEquals( repository, newRepository );
//assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() ); //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
@ -360,7 +362,7 @@ public class EditManagedRepositoryActionTest
action.prepare(); action.prepare();
assertEquals( REPO_ID, action.getRepoid() ); assertEquals( REPO_ID, action.getRepoid() );
ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration(); ManagedRepository repository = new ManagedRepository();
populateRepository( repository ); populateRepository( repository );
File testFile = new File( "target/test/location/new" ); File testFile = new File( "target/test/location/new" );
FileUtils.deleteDirectory( testFile ); FileUtils.deleteDirectory( testFile );
@ -382,8 +384,7 @@ public class EditManagedRepositoryActionTest
{ {
// prep // prep
// 0 is the default value for primitive int; null for objects // 0 is the default value for primitive int; null for objects
ManagedRepositoryConfiguration managedRepositoryConfiguration = ManagedRepository managedRepositoryConfiguration = createManagedRepository( null, null, null, null, 1, 1 );
createManagedRepositoryConfiguration( null, null, null, null );
action.setRepository( managedRepositoryConfiguration ); action.setRepository( managedRepositoryConfiguration );
// test // test
@ -418,8 +419,8 @@ public class EditManagedRepositoryActionTest
{ {
// prep // prep
// 0 is the default value for primitive int // 0 is the default value for primitive int
ManagedRepositoryConfiguration managedRepositoryConfiguration = ManagedRepository managedRepositoryConfiguration =
createManagedRepositoryConfiguration( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING ); createManagedRepository( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, 1, 1 );
action.setRepository( managedRepositoryConfiguration ); action.setRepository( managedRepositoryConfiguration );
// test // test
@ -453,11 +454,10 @@ public class EditManagedRepositoryActionTest
throws Exception throws Exception
{ {
// prep // prep
ManagedRepositoryConfiguration managedRepositoryConfiguration = ManagedRepository managedRepositoryConfiguration =
createManagedRepositoryConfiguration( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT, createManagedRepository( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT,
REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT, REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT,
REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_RETENTION_COUNT_INVALID_INPUT );
REPOSITORY_RETENTION_COUNT_INVALID_INPUT );
action.setRepository( managedRepositoryConfiguration ); action.setRepository( managedRepositoryConfiguration );
// test // test
@ -490,7 +490,7 @@ public class EditManagedRepositoryActionTest
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add( expectedErrorMessages.add(
"Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." ); "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
expectedFieldErrors.put( "repository.indexDir", expectedErrorMessages ); expectedFieldErrors.put( "repository.indexDirectory", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." ); expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." );
@ -507,11 +507,10 @@ public class EditManagedRepositoryActionTest
throws Exception throws Exception
{ {
// prep // prep
ManagedRepositoryConfiguration managedRepositoryConfiguration = ManagedRepository managedRepositoryConfiguration =
createManagedRepositoryConfiguration( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT, createManagedRepository( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT,
REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT, REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT,
REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_RETENTION_COUNT_VALID_INPUT );
REPOSITORY_RETENTION_COUNT_VALID_INPUT );
action.setRepository( managedRepositoryConfiguration ); action.setRepository( managedRepositoryConfiguration );
// test // test
@ -521,15 +520,14 @@ public class EditManagedRepositoryActionTest
assertFalse( action.hasFieldErrors() ); assertFalse( action.hasFieldErrors() );
} }
private void assertRepositoryEquals( ManagedRepositoryConfiguration expectedRepository, private void assertRepositoryEquals( ManagedRepository expectedRepository, ManagedRepository actualRepository )
ManagedRepositoryConfiguration actualRepository )
{ {
assertEquals( expectedRepository.getDaysOlder(), actualRepository.getDaysOlder() ); assertEquals( expectedRepository.getDaysOlder(), actualRepository.getDaysOlder() );
assertEquals( expectedRepository.getId(), actualRepository.getId() ); assertEquals( expectedRepository.getId(), actualRepository.getId() );
assertEquals( expectedRepository.getIndexDir(), actualRepository.getIndexDir() ); assertEquals( expectedRepository.getIndexDirectory(), actualRepository.getIndexDirectory() );
assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() ); assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
assertEquals( expectedRepository.getName(), actualRepository.getName() ); assertEquals( expectedRepository.getName(), actualRepository.getName() );
assertEquals( expectedRepository.getRefreshCronExpression(), actualRepository.getRefreshCronExpression() ); assertEquals( expectedRepository.getCronExpression(), actualRepository.getCronExpression() );
assertEquals( expectedRepository.getRetentionCount(), actualRepository.getRetentionCount() ); assertEquals( expectedRepository.getRetentionCount(), actualRepository.getRetentionCount() );
assertEquals( expectedRepository.isDeleteReleasedSnapshots(), actualRepository.isDeleteReleasedSnapshots() ); assertEquals( expectedRepository.isDeleteReleasedSnapshots(), actualRepository.isDeleteReleasedSnapshots() );
assertEquals( expectedRepository.isScanned(), actualRepository.isScanned() ); assertEquals( expectedRepository.isScanned(), actualRepository.isScanned() );
@ -537,11 +535,28 @@ public class EditManagedRepositoryActionTest
assertEquals( expectedRepository.isSnapshots(), actualRepository.isSnapshots() ); assertEquals( expectedRepository.isSnapshots(), actualRepository.isSnapshots() );
} }
private Configuration createConfigurationForEditing( ManagedRepositoryConfiguration repositoryConfiguration ) private Configuration createConfigurationForEditing( ManagedRepository repositoryConfiguration )
throws Exception throws Exception
{ {
Configuration configuration = buildEasyConfiguration(); Configuration configuration = buildEasyConfiguration();
configuration.addManagedRepository( repositoryConfiguration );
ManagedRepositoryConfiguration managedRepositoryConfiguration = new ManagedRepositoryConfiguration();
managedRepositoryConfiguration.setDaysOlder( repositoryConfiguration.getDaysOlder() );
managedRepositoryConfiguration.setIndexDir( repositoryConfiguration.getIndexDirectory() );
managedRepositoryConfiguration.setRetentionCount( repositoryConfiguration.getRetentionCount() );
managedRepositoryConfiguration.setBlockRedeployments( repositoryConfiguration.isBlockRedeployments() );
managedRepositoryConfiguration.setDeleteReleasedSnapshots(
repositoryConfiguration.isDeleteReleasedSnapshots() );
managedRepositoryConfiguration.setLocation( repositoryConfiguration.getLocation() );
managedRepositoryConfiguration.setRefreshCronExpression( repositoryConfiguration.getCronExpression() );
managedRepositoryConfiguration.setReleases( repositoryConfiguration.isReleases() );
managedRepositoryConfiguration.setScanned( repositoryConfiguration.isScanned() );
managedRepositoryConfiguration.setId( repositoryConfiguration.getId() );
managedRepositoryConfiguration.setName( repositoryConfiguration.getName() );
managedRepositoryConfiguration.setLayout( repositoryConfiguration.getLayout() );
configuration.addManagedRepository( managedRepositoryConfiguration );
return configuration; return configuration;
} }
@ -564,10 +579,10 @@ public class EditManagedRepositoryActionTest
}; };
} }
private ManagedRepositoryConfiguration createRepository() private ManagedRepository createRepository()
throws IOException throws IOException
{ {
ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration(); ManagedRepository r = new ManagedRepository();
r.setId( REPO_ID ); r.setId( REPO_ID );
populateRepository( r ); populateRepository( r );
return r; return r;

View File

@ -19,33 +19,41 @@ package org.apache.maven.archiva.web.validator.utils;
* under the License. * under the License.
*/ */
import junit.framework.Assert;
import org.apache.commons.lang.SystemUtils;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import junit.framework.Assert;
public class ValidatorUtil public class ValidatorUtil
{ {
public static void assertFieldErrors(Map<String, List<String>> expectedFieldErrors, Map<String, List<String>> actualFieldErrors) public static void assertFieldErrors( Map<String, List<String>> expectedFieldErrors,
Map<String, List<String>> actualFieldErrors )
{ {
if ( expectedFieldErrors != null ) if ( expectedFieldErrors != null )
{ {
Assert.assertNotNull( actualFieldErrors ); Assert.assertNotNull( actualFieldErrors );
// checks the number of field errors // checks the number of field errors
Assert.assertEquals(expectedFieldErrors.size(), actualFieldErrors.size()); Assert.assertEquals(
"expected " + expectedFieldErrors + SystemUtils.LINE_SEPARATOR + ", found " + actualFieldErrors,
expectedFieldErrors.size(), actualFieldErrors.size() );
// check every content of the field error // check every content of the field error
for ( Map.Entry<String, List<String>> expectedEntry : expectedFieldErrors.entrySet() ) for ( Map.Entry<String, List<String>> expectedEntry : expectedFieldErrors.entrySet() )
{ {
if ( expectedEntry.getValue() != null ) if ( expectedEntry.getValue() != null )
{ {
Assert.assertNotNull(actualFieldErrors.get(expectedEntry.getKey())); Assert.assertNotNull( "actual with key " + expectedEntry.getKey() + " is null",
actualFieldErrors.get( expectedEntry.getKey() ) );
// checks the error message count per error field // checks the error message count per error field
Assert.assertEquals(expectedEntry.getValue().size(), actualFieldErrors.get(expectedEntry.getKey()).size()); Assert.assertEquals( expectedEntry.getValue().size(),
actualFieldErrors.get( expectedEntry.getKey() ).size() );
// check the contents of error messages per field error // check the contents of error messages per field error
for ( int i = 0; i < expectedEntry.getValue().size(); i++ ) for ( int i = 0; i < expectedEntry.getValue().size(); i++ )
{ {
Assert.assertEquals(expectedEntry.getValue().get(i), actualFieldErrors.get(expectedEntry.getKey()).get(i)); Assert.assertEquals( expectedEntry.getValue().get( i ),
actualFieldErrors.get( expectedEntry.getKey() ).get( i ) );
} }
} }
else else

View File

@ -104,7 +104,8 @@ public interface AdministrationService
*/ */
Boolean addManagedRepository( String repoId, String layout, String name, String location, Boolean addManagedRepository( String repoId, String layout, String name, String location,
boolean blockRedeployments, boolean releasesIncluded, boolean snapshotsIncluded, boolean blockRedeployments, boolean releasesIncluded, boolean snapshotsIncluded,
boolean stageRepoNeeded, String cronExpression ) boolean stageRepoNeeded, String cronExpression, int daysOlder, int retentionCount,
boolean deleteReleasedSnapshots )
throws Exception; throws Exception;
/** /**

View File

@ -361,14 +361,17 @@ public class AdministrationServiceImpl
public Boolean addManagedRepository( String repoId, String layout, String name, String location, public Boolean addManagedRepository( String repoId, String layout, String name, String location,
boolean blockRedeployments, boolean releasesIncluded, boolean blockRedeployments, boolean releasesIncluded,
boolean snapshotsIncluded, boolean stageRepoNeeded, String cronExpression ) boolean snapshotsIncluded, boolean stageRepoNeeded, String cronExpression,
int daysOlder, int retentionCount, boolean deleteReleasedSnapshots )
throws Exception throws Exception
{ {
org.apache.archiva.admin.repository.managed.ManagedRepository repository = org.apache.archiva.admin.repository.managed.ManagedRepository repository =
new org.apache.archiva.admin.repository.managed.ManagedRepository( repoId, name, location, layout, new org.apache.archiva.admin.repository.managed.ManagedRepository( repoId, name, location, layout,
snapshotsIncluded, releasesIncluded, snapshotsIncluded, releasesIncluded,
blockRedeployments, cronExpression ); blockRedeployments, cronExpression, null,
false, daysOlder, retentionCount,
deleteReleasedSnapshots );
return managedRepositoryAdmin.addManagedRepository( repository, stageRepoNeeded, getAuditInformation() ); return managedRepositoryAdmin.addManagedRepository( repository, stageRepoNeeded, getAuditInformation() );
} }

View File

@ -21,7 +21,6 @@ package org.apache.archiva.web.xmlrpc.services;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener; import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ArtifactMetadata;
@ -215,7 +214,6 @@ public class AdministrationServiceImplTest
registryControl = MockControl.createControl( Registry.class ); registryControl = MockControl.createControl( Registry.class );
registry = (Registry) registryControl.getMock(); registry = (Registry) registryControl.getMock();
managedRepositoryAdmin = new DefaultManagedRepositoryAdmin(); managedRepositoryAdmin = new DefaultManagedRepositoryAdmin();
managedRepositoryAdmin.setArchivaConfiguration( archivaConfig ); managedRepositoryAdmin.setArchivaConfiguration( archivaConfig );
managedRepositoryAdmin.setRegistry( registry ); managedRepositoryAdmin.setRegistry( registry );
@ -388,11 +386,9 @@ public class AdministrationServiceImplTest
List<ArtifactMetadata> artifacts = getArtifacts(); List<ArtifactMetadata> artifacts = getArtifacts();
ArtifactMetadata artifact = artifacts.get( 0 ); ArtifactMetadata artifact = artifacts.get( 0 );
metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( repoContent.getId(), metadataRepositoryControl.expectAndReturn(
artifact.getNamespace(), metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
artifact.getProject(), artifact.getVersion() ), artifacts );
artifact.getVersion() ),
artifacts );
metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
artifact.getVersion(), artifact.getId() ); artifact.getVersion(), artifact.getId() );
@ -446,11 +442,9 @@ public class AdministrationServiceImplTest
List<ArtifactMetadata> artifacts = getArtifacts(); List<ArtifactMetadata> artifacts = getArtifacts();
ArtifactMetadata artifact = artifacts.get( 0 ); ArtifactMetadata artifact = artifacts.get( 0 );
metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( repoContent.getId(), metadataRepositoryControl.expectAndReturn(
artifact.getNamespace(), metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
artifact.getProject(), artifact.getVersion() ), artifacts );
artifact.getVersion() ),
artifacts );
metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
artifact.getVersion(), artifact.getId() ); artifact.getVersion(), artifact.getId() );
@ -531,8 +525,8 @@ public class AdministrationServiceImplTest
FileUtils.copyDirectory( srcDir, repoDir, FileFilterUtils.makeSVNAware( null ) ); FileUtils.copyDirectory( srcDir, repoDir, FileFilterUtils.makeSVNAware( null ) );
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "internal", layout, "Internal Repository", true, ManagedRepositoryConfiguration managedRepo =
false ); createManagedRepo( "internal", layout, "Internal Repository", true, false );
managedRepo.setLocation( repoDir.getAbsolutePath() ); managedRepo.setLocation( repoDir.getAbsolutePath() );
return managedRepo; return managedRepo;
} }
@ -567,16 +561,13 @@ public class AdministrationServiceImplTest
throws Exception throws Exception
{ {
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), createManagedRepo( "internal", configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
"default", createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
"Internal Repository",
true,
false ) );
RepositoryTask task = new RepositoryTask(); RepositoryTask task = new RepositoryTask();
repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( repositoryTaskSchedulerControl.expectAndReturn(
"internal" ), false ); repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ), false );
repositoryTaskScheduler.queueTask( task ); repositoryTaskScheduler.queueTask( task );
repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER ); repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
@ -606,14 +597,11 @@ public class AdministrationServiceImplTest
throws Exception throws Exception
{ {
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), createManagedRepo( "internal", configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
"default", createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
"Internal Repository",
true,
false ) );
repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( repositoryTaskSchedulerControl.expectAndReturn(
"internal" ), true ); repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ), true );
archivaConfigControl.replay(); archivaConfigControl.replay();
configControl.replay(); configControl.replay();
@ -690,10 +678,10 @@ public class AdministrationServiceImplTest
throws Exception throws Exception
{ {
List<RemoteRepositoryConfiguration> remoteRepos = new ArrayList<RemoteRepositoryConfiguration>(); List<RemoteRepositoryConfiguration> remoteRepos = new ArrayList<RemoteRepositoryConfiguration>();
remoteRepos.add( createRemoteRepository( "central", "Central Repository", "default", remoteRepos.add(
"http://repo1.maven.org/maven2" ) ); createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" ) );
remoteRepos.add( createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy", remoteRepos.add(
"http://dummy.com/dummy" ) ); createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy", "http://dummy.com/dummy" ) );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getRemoteRepositories(), remoteRepos ); configControl.expectAndReturn( config.getRemoteRepositories(), remoteRepos );
@ -790,9 +778,8 @@ public class AdministrationServiceImplTest
throws Exception throws Exception
{ {
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ), createManagedRepo( "repo", "default", configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ),
"repo", true, createManagedRepo( "repo", "default", "repo", true, false ) );
false ) );
configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), null ); configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), null );
archivaConfigControl.replay(); archivaConfigControl.replay();
@ -835,10 +822,8 @@ public class AdministrationServiceImplTest
configControl.expectAndReturn( config.findManagedRepositoryById( "merge-stage" ), staging ); configControl.expectAndReturn( config.findManagedRepositoryById( "merge-stage" ), staging );
metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources ); metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources );
repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( metadataRepository, repositoryMergerControl.expectAndDefaultReturn(
staging.getId(), repositoryMerger.getConflictingArtifacts( metadataRepository, staging.getId(), merge.getId() ), sources );
merge.getId() ),
sources );
repositoryMerger.merge( metadataRepository, staging.getId(), merge.getId() ); repositoryMerger.merge( metadataRepository, staging.getId(), merge.getId() );
repositoryMergerControl.setVoidCallable(); repositoryMergerControl.setVoidCallable();
repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "merge" ), repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "merge" ),
@ -906,10 +891,8 @@ public class AdministrationServiceImplTest
configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), staging ); configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), staging );
metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources ); metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources );
repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( metadataRepository, repositoryMergerControl.expectAndDefaultReturn(
staging.getId(), repositoryMerger.getConflictingArtifacts( metadataRepository, staging.getId(), repo.getId() ), conflicts );
repo.getId() ),
conflicts );
repositoryMerger.merge( metadataRepository, staging.getId(), repo.getId(), artifactsWithOutConflicts ); repositoryMerger.merge( metadataRepository, staging.getId(), repo.getId(), artifactsWithOutConflicts );
repositoryMergerControl.setMatcher( MockControl.ALWAYS_MATCHER ); repositoryMergerControl.setMatcher( MockControl.ALWAYS_MATCHER );
repositoryMergerControl.setVoidCallable(); repositoryMergerControl.setVoidCallable();
@ -954,8 +937,8 @@ public class AdministrationServiceImplTest
String appserverBase = "target"; String appserverBase = "target";
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false ); ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false );
RemoteRepositoryConfiguration remoteRepo = createRemoteRepository( "central", "Central Repository", "default", RemoteRepositoryConfiguration remoteRepo =
"http://repo1.maven.org/maven2" ); createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" );
List<String> repositories = new ArrayList<String>(); List<String> repositories = new ArrayList<String>();
repositories.add( managedRepo.getName() ); repositories.add( managedRepo.getName() );
RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories ); RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories );
@ -1004,11 +987,9 @@ public class AdministrationServiceImplTest
archivaConfig.save( config ); archivaConfig.save( config );
archivaConfigControl.setVoidCallable(); archivaConfigControl.setVoidCallable();
//managed repo //managed repo
repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( repoId ), false ); repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( repoId ),
false );
RepositoryTask task = new RepositoryTask(); RepositoryTask task = new RepositoryTask();
task.setRepositoryId( repoId ); task.setRepositoryId( repoId );
@ -1019,7 +1000,8 @@ public class AdministrationServiceImplTest
repositoryTaskSchedulerControl.setVoidCallable(); repositoryTaskSchedulerControl.setVoidCallable();
//staged repo //staged repo
repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( repoId + STAGE ), false ); repositoryTaskSchedulerControl.expectAndReturn(
repositoryTaskScheduler.isProcessingRepositoryTask( repoId + STAGE ), false );
task = new RepositoryTask(); task = new RepositoryTask();
task.setRepositoryId( repoId + STAGE ); task.setRepositoryId( repoId + STAGE );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
@ -1034,8 +1016,9 @@ public class AdministrationServiceImplTest
repositoryTaskSchedulerControl.replay(); repositoryTaskSchedulerControl.replay();
assertFalse( new File( releaseLocation ).isDirectory() ); assertFalse( new File( releaseLocation ).isDirectory() );
assertFalse( new File( stageLocation ).isDirectory() ); assertFalse( new File( stageLocation ).isDirectory() );
boolean success = service.addManagedRepository( repoId, layout, name, "${appserver.base}/test-repository/" + projId + ".releases", true, true, false, true, boolean success = service.addManagedRepository( repoId, layout, name,
"0 15 3 * * ? *" ); "${appserver.base}/test-repository/" + projId + ".releases",
true, true, false, true, "0 15 3 * * ? *", 1, 1, true );
assertTrue( success ); assertTrue( success );
assertTrue( new File( releaseLocation ).isDirectory() ); assertTrue( new File( releaseLocation ).isDirectory() );
assertTrue( new File( stageLocation ).isDirectory() ); assertTrue( new File( stageLocation ).isDirectory() );
@ -1055,8 +1038,8 @@ public class AdministrationServiceImplTest
String name = projId + " Releases"; String name = projId + " Releases";
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false ); ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false );
RemoteRepositoryConfiguration remoteRepo = createRemoteRepository( "central", "Central Repository", "default", RemoteRepositoryConfiguration remoteRepo =
"http://repo1.maven.org/maven2" ); createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" );
List<String> repositories = new ArrayList<String>(); List<String> repositories = new ArrayList<String>();
repositories.add( managedRepo.getName() ); repositories.add( managedRepo.getName() );
RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories ); RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories );
@ -1079,13 +1062,15 @@ public class AdministrationServiceImplTest
try try
{ {
service.addManagedRepository( repoId, layout, name, "${appserver.base}/test-repository/" + projId + ".releases", true, true, false, true, service.addManagedRepository( repoId, layout, name,
"0 15 3 * * ? *" ); "${appserver.base}/test-repository/" + projId + ".releases", true, true,
false, true, "0 15 3 * * ? *", 1, 1, true );
fail( "An exception should have been thrown! Repository ID is not valid." ); fail( "An exception should have been thrown! Repository ID is not valid." );
} }
catch ( Exception e ) catch ( Exception e )
{ {
assertEquals( "Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-).", assertEquals(
"Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-).",
e.getMessage() ); e.getMessage() );
} }
} }
@ -1100,8 +1085,8 @@ public class AdministrationServiceImplTest
String name = projId + " <script>alert('xss')</script>"; String name = projId + " <script>alert('xss')</script>";
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false ); ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false );
RemoteRepositoryConfiguration remoteRepo = createRemoteRepository( "central", "Central Repository", "default", RemoteRepositoryConfiguration remoteRepo =
"http://repo1.maven.org/maven2" ); createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" );
List<String> repositories = new ArrayList<String>(); List<String> repositories = new ArrayList<String>();
repositories.add( managedRepo.getName() ); repositories.add( managedRepo.getName() );
RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories ); RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories );
@ -1124,14 +1109,16 @@ public class AdministrationServiceImplTest
try try
{ {
service.addManagedRepository( repoId, layout, name, "${appserver.base}/test-repository/" + projId + ".releases", true, true, false, true, service.addManagedRepository( repoId, layout, name,
"0 15 3 * * ? *" ); "${appserver.base}/test-repository/" + projId + ".releases", true, true,
false, true, "0 15 3 * * ? *", 1, 1, true );
fail( "An exception should have been thrown! Repository name is not valid." ); fail( "An exception should have been thrown! Repository name is not valid." );
} }
catch ( Exception e ) catch ( Exception e )
{ {
assertEquals( "Invalid repository name. Repository Name must only contain alphanumeric characters, white-spaces(' '), " + assertEquals(
"forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-).", "Invalid repository name. Repository Name must only contain alphanumeric characters, white-spaces(' '), "
+ "forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-).",
e.getMessage() ); e.getMessage() );
} }
} }
@ -1147,8 +1134,8 @@ public class AdministrationServiceImplTest
String appserverBase = "target"; String appserverBase = "target";
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false ); ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false );
RemoteRepositoryConfiguration remoteRepo = createRemoteRepository( "central", "Central Repository", "default", RemoteRepositoryConfiguration remoteRepo =
"http://repo1.maven.org/maven2" ); createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" );
List<String> repositories = new ArrayList<String>(); List<String> repositories = new ArrayList<String>();
repositories.add( managedRepo.getName() ); repositories.add( managedRepo.getName() );
RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories ); RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories );
@ -1174,14 +1161,16 @@ public class AdministrationServiceImplTest
try try
{ {
service.addManagedRepository( repoId, layout, name, "${appserver.base}/<script>alert('xss')</script>" + projId + ".releases", true, true, false, true, service.addManagedRepository( repoId, layout, name,
"0 15 3 * * ? *" ); "${appserver.base}/<script>alert('xss')</script>" + projId + ".releases",
true, true, false, true, "0 15 3 * * ? *", 1, 1, true );
fail( "An exception should have been thrown! Repository location is not valid." ); fail( "An exception should have been thrown! Repository location is not valid." );
} }
catch ( Exception e ) catch ( Exception e )
{ {
assertEquals( "Invalid repository location. Directory must only contain alphanumeric characters, equals(=), question-marks(?), " + assertEquals(
"exclamation-points(!), ampersands(&amp;), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-).", "Invalid repository location. Directory must only contain alphanumeric characters, equals(=), question-marks(?), "
+ "exclamation-points(!), ampersands(&amp;), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-).",
e.getMessage() ); e.getMessage() );
} }