From d9b6ddeba1c88ee0d88b93a27f7b41ac68e39ff3 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 2 Sep 2011 14:53:15 +0000 Subject: [PATCH] [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 --- .../DefaultManagedRepositoryAdmin.java | 21 ++- .../repository/managed/ManagedRepository.java | 91 ++++++++++- .../managed/ManagedRepositoryAdminTest.java | 22 ++- .../AddManagedRepositoryAction.java | 20 +-- .../EditManagedRepositoryAction.java | 46 +++--- .../AddManagedRepositoryAction-validation.xml | 2 +- ...EditManagedRepositoryAction-validation.xml | 2 +- .../AbstractManagedRepositoryActionTest.java | 60 +++++--- .../AddManagedRepositoryActionTest.java | 41 ++--- .../EditManagedRepositoryActionTest.java | 73 +++++---- .../web/validator/utils/ValidatorUtil.java | 34 +++-- .../web/xmlrpc/api/AdministrationService.java | 3 +- .../services/AdministrationServiceImpl.java | 7 +- .../AdministrationServiceImplTest.java | 141 ++++++++---------- 14 files changed, 344 insertions(+), 219 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java index b32992b24..6adab675e 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java @@ -115,7 +115,9 @@ public class DefaultManagedRepositoryAdmin ManagedRepository repo = new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(), 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 ); } @@ -146,7 +148,9 @@ public class DefaultManagedRepositoryAdmin addManagedRepository( managedRepository.getId(), managedRepository.getLayout(), managedRepository.getName(), managedRepository.getLocation(), managedRepository.isBlockRedeployments(), 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, boolean releasesIncluded, boolean snapshotsIncluded, boolean stageRepoNeeded, String cronExpression, + String indexDir, int daysOlder, int retentionCount, + boolean deteleReleasedSnapshots, AuditInformation auditInformation ) throws RepositoryAdminException { @@ -228,6 +234,10 @@ public class DefaultManagedRepositoryAdmin repository.setLocation( repoLocation ); repository.setLayout( layout ); repository.setRefreshCronExpression( cronExpression ); + repository.setIndexDir( indexDir ); + repository.setDaysOlder( daysOlder ); + repository.setRetentionCount( retentionCount ); + repository.setDeleteReleasedSnapshots( deteleReleasedSnapshots ); try { addRepository( repository, config ); @@ -369,8 +379,7 @@ public class DefaultManagedRepositoryAdmin List repoGroups = repoToGroupMap.get( repository.getId() ); for ( String repoGroup : repoGroups ) { - config.findRepositoryGroupById( repoGroup ).removeRepository( - repository.getId() ); + config.findRepositoryGroupById( repoGroup ).removeRepository( repository.getId() ); } } } @@ -426,7 +435,9 @@ public class DefaultManagedRepositoryAdmin addManagedRepository( managedRepository.getId(), managedRepository.getLayout(), managedRepository.getName(), managedRepository.getLocation(), managedRepository.isBlockRedeployments(), managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo, - managedRepository.getCronExpression(), auditInformation ); + managedRepository.getCronExpression(), managedRepository.getIndexDirectory(), + managedRepository.getDaysOlder(), managedRepository.getRetentionCount(), + managedRepository.isDeleteReleasedSnapshots(), auditInformation ); // Save the repository configuration. RepositorySession repositorySession = getRepositorySessionFactory().createSession(); diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepository.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepository.java index b2a148e8a..0ac076bf9 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepository.java @@ -33,30 +33,49 @@ public class ManagedRepository private String location; - private String layout; + private String layout = "default"; 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 */ 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() { // no op } - public ManagedRepository( String id, String name, String location, String layout, boolean snapshots, boolean releases, - boolean blockRedeployments, String cronExpression ) + public ManagedRepository( String id, String name, String location, String layout, boolean snapshots, + boolean releases, boolean blockRedeployments, String cronExpression, String indexDir, + boolean scanned, int daysOlder, int retentionCount, boolean deleteReleasedSnapshots ) { this.id = id; this.name = name; @@ -66,6 +85,11 @@ public class ManagedRepository this.releases = releases; this.blockRedeployments = blockRedeployments; this.cronExpression = cronExpression; + this.indexDirectory = indexDir; + this.scanned = scanned; + this.daysOlder = daysOlder; + this.retentionCount = retentionCount; + this.deleteReleasedSnapshots = deleteReleasedSnapshots; } public String getId() @@ -163,6 +187,56 @@ public class ManagedRepository 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() { int result = 17; @@ -201,8 +275,9 @@ public class ManagedRepository sb.append( ", releases=" ).append( releases ); sb.append( ", blockRedeployments=" ).append( blockRedeployments ); sb.append( ", cronExpression='" ).append( cronExpression ).append( '\'' ); - sb.append( ", stageRepoNeeded=" ).append( stageRepoNeeded ); sb.append( ", stagingRepository=" ).append( stagingRepository ); + sb.append( ", scanned=" ).append( scanned ); + sb.append( ", indexDirectory='" ).append( indexDirectory ).append( '\'' ); sb.append( '}' ); return sb.toString(); } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java index a5eedb46f..534f17117 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java @@ -100,7 +100,7 @@ public class ManagedRepositoryAdminTest repo.setId( repoId ); repo.setName( "test repo" ); repo.setLocation( repoLocation ); - repo.setCronExpression( "0 0 * * * ?" ); + repo.setCronExpression( "0 0 * * * ?" ); managedRepositoryAdmin.addManagedRepository( repo, false, getFakeAuditInformation() ); repos = managedRepositoryAdmin.getManagedRepositories(); assertNotNull( repos ); @@ -148,7 +148,7 @@ public class ManagedRepositoryAdminTest repo.setId( repoId ); repo.setName( "test repo" ); repo.setLocation( repoLocation ); - repo.setCronExpression( "0 0 * * * ?" ); + repo.setCronExpression( "0 0 * * * ?" ); managedRepositoryAdmin.addManagedRepository( repo, false, getFakeAuditInformation() ); assertTemplateRoleExists( repoId ); @@ -162,7 +162,7 @@ public class ManagedRepositoryAdminTest repo.setName( newName ); repo.setLocation( repoLocation ); - repo.setCronExpression( "0 0 * * * ?" ); + repo.setCronExpression( "0 0 * * * ?" ); managedRepositoryAdmin.updateManagedRepository( repo, false, getFakeAuditInformation(), false ); @@ -207,7 +207,7 @@ public class ManagedRepositoryAdminTest repo.setId( repoId ); repo.setName( "test repo" ); repo.setLocation( repoLocation ); - repo.setCronExpression( "0 0 * * * ?" ); + repo.setCronExpression( "0 0 * * * ?" ); managedRepositoryAdmin.addManagedRepository( repo, true, getFakeAuditInformation() ); repos = managedRepositoryAdmin.getManagedRepositories(); assertNotNull( repos ); @@ -276,6 +276,10 @@ public class ManagedRepositoryAdminTest assertNotNull( repos ); assertEquals( initialSize + 1, repos.size() ); + repo = managedRepositoryAdmin.getManagedRepository( repoId ); + + assertEquals( getTestManagedRepository( repoId, repoLocation ).getIndexDirectory(), repo.getIndexDirectory() ); + String newName = "test repo update"; repo.setName( newName ); @@ -292,6 +296,13 @@ public class ManagedRepositoryAdminTest assertEquals( getTestManagedRepository( repoId, repoLocation ).getCronExpression(), repo.getCronExpression() ); assertEquals( getTestManagedRepository( repoId, repoLocation ).getLayout(), repo.getLayout() ); 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 ); assertTrue( new File( stageRepoLocation + STAGE_REPO_ID_END ).exists() ); @@ -424,7 +435,8 @@ public class ManagedRepositoryAdminTest 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 ); } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java index 49b1c4d04..c8ab9b818 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java @@ -47,7 +47,7 @@ public class AddManagedRepositoryAction * FIXME we must manipulate beans from repo admin api * The model for this action. */ - private ManagedRepositoryConfiguration repository; + private ManagedRepository repository; private boolean stageNeeded; @@ -55,7 +55,7 @@ public class AddManagedRepositoryAction public void prepare() { - this.repository = new ManagedRepositoryConfiguration(); + this.repository = new ManagedRepository(); this.repository.setReleases( false ); this.repository.setScanned( false ); this.repository.setBlockRedeployments( false ); @@ -93,11 +93,7 @@ public class AddManagedRepositoryAction String result = SUCCESS; try { - ManagedRepository managedRepository = - new ManagedRepository( repository.getId(), repository.getName(), repository.getLocation(), - repository.getLayout(), repository.isSnapshots(), repository.isReleases(), - repository.isBlockRedeployments(), repository.getRefreshCronExpression() ); - getManagedRepositoryAdmin().addManagedRepository( managedRepository, stageNeeded, getAuditInformation() ); + getManagedRepositoryAdmin().addManagedRepository( repository, stageNeeded, getAuditInformation() ); } catch ( RepositoryAdminException e ) { @@ -139,7 +135,7 @@ public class AddManagedRepositoryAction + "], repository id cannot contains word stage" ); } - if ( !validator.validate( repository.getRefreshCronExpression() ) ) + if ( !validator.validate( repository.getCronExpression() ) ) { addFieldError( "repository.refreshCronExpression", "Invalid cron expression." ); } @@ -165,18 +161,18 @@ public class AddManagedRepositoryAction 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; } - public void setRepository( ManagedRepositoryConfiguration repository ) + public void setRepository( ManagedRepository repository ) { this.repository = repository; } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java index 4a4fa4ac1..545b1914c 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java @@ -46,9 +46,9 @@ public class EditManagedRepositoryAction * FIXME we must manipulate beans from repo admin api * The model for this action. */ - private ManagedRepositoryConfiguration repository; + private ManagedRepository repository; - private ManagedRepositoryConfiguration stagingRepository; + private ManagedRepository stagingRepository; private String repoid; @@ -57,12 +57,14 @@ public class EditManagedRepositoryAction private boolean stageNeeded; + // FIXME better error message public void prepare() + throws RepositoryAdminException { if ( StringUtils.isNotBlank( repoid ) ) { - repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid ); - stagingRepository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid + "-stage" ); + repository = getManagedRepositoryAdmin().getManagedRepository( repoid ); + stagingRepository = getManagedRepositoryAdmin().getManagedRepository( repoid + "-stage" ); } else if ( repository != null ) { @@ -118,12 +120,7 @@ public class EditManagedRepositoryAction String result = SUCCESS; try { - ManagedRepository managedRepository = - new ManagedRepository( repository.getId(), repository.getName(), repository.getLocation(), - repository.getLayout(), repository.isSnapshots(), repository.isReleases(), - repository.isBlockRedeployments(), repository.getRefreshCronExpression() ); - - getManagedRepositoryAdmin().updateManagedRepository( managedRepository, stageNeeded, getAuditInformation(), + getManagedRepositoryAdmin().updateManagedRepository( repository, stageNeeded, getAuditInformation(), resetStats ); } catch ( RepositoryAdminException e ) @@ -141,7 +138,7 @@ public class EditManagedRepositoryAction { CronExpressionValidator validator = new CronExpressionValidator(); - if ( !validator.validate( repository.getRefreshCronExpression() ) ) + if ( !validator.validate( repository.getCronExpression() ) ) { addFieldError( "repository.refreshCronExpression", "Invalid cron expression." ); } @@ -166,9 +163,9 @@ public class EditManagedRepositoryAction 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; } - public ManagedRepositoryConfiguration getRepository() - { - return repository; - } - - public void setRepository( ManagedRepositoryConfiguration repository ) - { - this.repository = repository; - } public boolean isStageNeeded() { @@ -208,12 +196,22 @@ public class EditManagedRepositoryAction return action; } - public ManagedRepositoryConfiguration getStagingRepository() + public ManagedRepository getRepository() + { + return repository; + } + + public void setRepository( ManagedRepository repository ) + { + this.repository = repository; + } + + public ManagedRepository getStagingRepository() { return stagingRepository; } - public void setStagingRepository( ManagedRepositoryConfiguration stagingRepository ) + public void setStagingRepository( ManagedRepository stagingRepository ) { this.stagingRepository = stagingRepository; } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction-validation.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction-validation.xml index 8e7790759..8c951cbd1 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction-validation.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction-validation.xml @@ -42,7 +42,7 @@ Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-). - + true diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction-validation.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction-validation.xml index b00981f06..abc9e5526 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction-validation.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction-validation.xml @@ -42,7 +42,7 @@ Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-). - + true diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryActionTest.java index a2341179e..623eec185 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryActionTest.java @@ -20,12 +20,12 @@ package org.apache.maven.archiva.web.action.admin.repositories; */ 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.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.struts2.StrutsSpringTestCase; +import java.io.File; + public abstract class AbstractManagedRepositoryActionTest extends StrutsSpringTestCase { @@ -71,58 +71,74 @@ public abstract class AbstractManagedRepositoryActionTest } @Override - protected void setUp() throws Exception + protected void setUp() + throws Exception { super.setUp(); - DefaultActionValidatorManagerFactory defaultActionValidatorManagerFactory = new DefaultActionValidatorManagerFactory(); + DefaultActionValidatorManagerFactory defaultActionValidatorManagerFactory = + new DefaultActionValidatorManagerFactory(); actionValidatorManager = defaultActionValidatorManagerFactory.createDefaultActionValidatorManager(); } - protected void populateRepository( ManagedRepositoryConfiguration repository ) + protected void populateRepository( ManagedRepository repository ) { repository.setId( REPO_ID ); repository.setName( "repo name" ); repository.setLocation( location.getAbsolutePath() ); repository.setLayout( "default" ); - repository.setRefreshCronExpression( "* 0/5 * * * ?" ); + repository.setCronExpression( "* 0/5 * * * ?" ); repository.setDaysOlder( 31 ); repository.setRetentionCount( 20 ); repository.setReleases( true ); - repository.setSnapshots( true ); + repository.setSnapshots( false ); repository.setScanned( false ); 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.setName(name); - managedRepositoryConfiguration.setLocation(location); - managedRepositoryConfiguration.setIndexDir(indexDir); - managedRepositoryConfiguration.setDaysOlder(daysOlder); - managedRepositoryConfiguration.setRetentionCount(retentionCount); + managedRepositoryConfiguration.setId( id ); + managedRepositoryConfiguration.setName( name ); + managedRepositoryConfiguration.setLocation( location ); return managedRepositoryConfiguration; } // over-loaded // 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.setName(name); - managedRepositoryConfiguration.setLocation(location); - managedRepositoryConfiguration.setIndexDir(indexDir); + managedRepositoryConfiguration.setId( id ); + managedRepositoryConfiguration.setName( name ); + managedRepositoryConfiguration.setLocation( location ); + managedRepositoryConfiguration.setIndexDirectory( indexDir ); 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() { return applicationContext.getBean( ManagedRepositoryAdmin.class ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java index a8c9aff71..badce92fd 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java @@ -21,12 +21,12 @@ package org.apache.maven.archiva.web.action.admin.repositories; import com.opensymphony.xwork2.Action; 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.RepositoryTask; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; 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.web.validator.utils.ValidatorUtil; import org.codehaus.plexus.redback.role.RoleManager; @@ -123,7 +123,7 @@ public class AddManagedRepositoryActionTest archivaConfigurationControl.replay(); action.prepare(); - ManagedRepositoryConfiguration configuration = action.getRepository(); + ManagedRepository configuration = action.getRepository(); assertNotNull( configuration ); assertNull( configuration.getId() ); // check all booleans are false @@ -182,19 +182,23 @@ public class AddManagedRepositoryActionTest archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration ); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfiguration.save( configuration ); archivaConfigurationControl.replay(); action.prepare(); - ManagedRepositoryConfiguration repository = action.getRepository(); + ManagedRepository repository = action.getRepository(); populateRepository( repository ); assertFalse( location.exists() ); String status = action.commit(); assertEquals( Action.SUCCESS, status ); assertTrue( location.exists() ); - assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() ); + + assertEquals( Collections.singletonList( repository ), getManagedRepositoryAdmin().getManagedRepositories() ); assertEquals( location.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() ); roleManagerControl.verify(); @@ -219,7 +223,7 @@ public class AddManagedRepositoryActionTest registryControl.replay(); action.prepare(); - ManagedRepositoryConfiguration repository = action.getRepository(); + ManagedRepository repository = action.getRepository(); populateRepository( repository ); assertTrue( location.exists() ); @@ -234,8 +238,7 @@ public class AddManagedRepositoryActionTest { // prep // 0 is the default value for primitive int; null for objects - ManagedRepositoryConfiguration managedRepositoryConfiguration = - createManagedRepositoryConfiguration( null, null, null, null ); + ManagedRepository managedRepositoryConfiguration = createManagedRepository( null, null, null, null ); action.setRepository( managedRepositoryConfiguration ); // test @@ -270,8 +273,8 @@ public class AddManagedRepositoryActionTest { // prep // 0 is the default value for primitive int - ManagedRepositoryConfiguration managedRepositoryConfiguration = - createManagedRepositoryConfiguration( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING ); + ManagedRepository managedRepositoryConfiguration = + createManagedRepository( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING ); action.setRepository( managedRepositoryConfiguration ); // test @@ -305,11 +308,10 @@ public class AddManagedRepositoryActionTest throws Exception { // prep - ManagedRepositoryConfiguration managedRepositoryConfiguration = - createManagedRepositoryConfiguration( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT, - REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT, - REPOSITORY_DAYS_OLDER_INVALID_INPUT, - REPOSITORY_RETENTION_COUNT_INVALID_INPUT ); + ManagedRepository managedRepositoryConfiguration = + createManagedRepository( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT, + REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT, + REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_RETENTION_COUNT_INVALID_INPUT ); action.setRepository( managedRepositoryConfiguration ); // test @@ -342,7 +344,7 @@ public class AddManagedRepositoryActionTest expectedErrorMessages = new ArrayList(); 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(-)." ); - expectedFieldErrors.put( "repository.indexDir", expectedErrorMessages ); + expectedFieldErrors.put( "repository.indexDirectory", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." ); @@ -359,11 +361,10 @@ public class AddManagedRepositoryActionTest throws Exception { // prep - ManagedRepositoryConfiguration managedRepositoryConfiguration = - createManagedRepositoryConfiguration( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT, - REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT, - REPOSITORY_DAYS_OLDER_VALID_INPUT, - REPOSITORY_RETENTION_COUNT_VALID_INPUT ); + ManagedRepository managedRepositoryConfiguration = + createManagedRepository( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT, + REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT, + REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_RETENTION_COUNT_VALID_INPUT ); action.setRepository( managedRepositoryConfiguration ); // test diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java index a0a645ab5..2a513650c 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java @@ -20,7 +20,9 @@ package org.apache.maven.archiva.web.action.admin.repositories; */ 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.ManagedRepository; import org.apache.archiva.audit.AuditListener; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.RepositorySession; @@ -124,7 +126,7 @@ public class EditManagedRepositoryActionTest } public void testSecureActionBundle() - throws SecureActionException + throws SecureActionException, RepositoryAdminException { archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( new Configuration() ); @@ -153,10 +155,10 @@ public class EditManagedRepositoryActionTest action.prepare(); assertEquals( REPO_ID, action.getRepoid() ); - ManagedRepositoryConfiguration repository = action.getRepository(); + ManagedRepository repository = action.getRepository(); assertNotNull( repository ); - ManagedRepositoryConfiguration newRepository = createRepository(); + ManagedRepository newRepository = createRepository(); assertRepositoryEquals( repository, newRepository ); assertEquals( repository.getLocation(), newRepository.getLocation() ); @@ -245,7 +247,7 @@ public class EditManagedRepositoryActionTest action.setRepoid( REPO_ID ); action.prepare(); assertEquals( REPO_ID, action.getRepoid() ); - ManagedRepositoryConfiguration repository = action.getRepository(); + ManagedRepository repository = action.getRepository(); populateRepository( repository ); repository.setName( "new repo name" ); @@ -264,7 +266,7 @@ public class EditManagedRepositoryActionTest String status = action.commit(); assertEquals( Action.SUCCESS, status ); - ManagedRepositoryConfiguration newRepository = createRepository(); + ManagedRepository newRepository = createRepository(); newRepository.setName( "new repo name" ); assertRepositoryEquals( repository, newRepository ); //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() ); @@ -360,7 +362,7 @@ public class EditManagedRepositoryActionTest action.prepare(); assertEquals( REPO_ID, action.getRepoid() ); - ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration(); + ManagedRepository repository = new ManagedRepository(); populateRepository( repository ); File testFile = new File( "target/test/location/new" ); FileUtils.deleteDirectory( testFile ); @@ -382,8 +384,7 @@ public class EditManagedRepositoryActionTest { // prep // 0 is the default value for primitive int; null for objects - ManagedRepositoryConfiguration managedRepositoryConfiguration = - createManagedRepositoryConfiguration( null, null, null, null ); + ManagedRepository managedRepositoryConfiguration = createManagedRepository( null, null, null, null, 1, 1 ); action.setRepository( managedRepositoryConfiguration ); // test @@ -418,8 +419,8 @@ public class EditManagedRepositoryActionTest { // prep // 0 is the default value for primitive int - ManagedRepositoryConfiguration managedRepositoryConfiguration = - createManagedRepositoryConfiguration( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING ); + ManagedRepository managedRepositoryConfiguration = + createManagedRepository( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, 1, 1 ); action.setRepository( managedRepositoryConfiguration ); // test @@ -453,11 +454,10 @@ public class EditManagedRepositoryActionTest throws Exception { // prep - ManagedRepositoryConfiguration managedRepositoryConfiguration = - createManagedRepositoryConfiguration( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT, - REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT, - REPOSITORY_DAYS_OLDER_INVALID_INPUT, - REPOSITORY_RETENTION_COUNT_INVALID_INPUT ); + ManagedRepository managedRepositoryConfiguration = + createManagedRepository( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT, + REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT, + REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_RETENTION_COUNT_INVALID_INPUT ); action.setRepository( managedRepositoryConfiguration ); // test @@ -490,7 +490,7 @@ public class EditManagedRepositoryActionTest expectedErrorMessages = new ArrayList(); 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(-)." ); - expectedFieldErrors.put( "repository.indexDir", expectedErrorMessages ); + expectedFieldErrors.put( "repository.indexDirectory", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." ); @@ -507,11 +507,10 @@ public class EditManagedRepositoryActionTest throws Exception { // prep - ManagedRepositoryConfiguration managedRepositoryConfiguration = - createManagedRepositoryConfiguration( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT, - REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT, - REPOSITORY_DAYS_OLDER_VALID_INPUT, - REPOSITORY_RETENTION_COUNT_VALID_INPUT ); + ManagedRepository managedRepositoryConfiguration = + createManagedRepository( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT, + REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT, + REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_RETENTION_COUNT_VALID_INPUT ); action.setRepository( managedRepositoryConfiguration ); // test @@ -521,15 +520,14 @@ public class EditManagedRepositoryActionTest assertFalse( action.hasFieldErrors() ); } - private void assertRepositoryEquals( ManagedRepositoryConfiguration expectedRepository, - ManagedRepositoryConfiguration actualRepository ) + private void assertRepositoryEquals( ManagedRepository expectedRepository, ManagedRepository actualRepository ) { assertEquals( expectedRepository.getDaysOlder(), actualRepository.getDaysOlder() ); assertEquals( expectedRepository.getId(), actualRepository.getId() ); - assertEquals( expectedRepository.getIndexDir(), actualRepository.getIndexDir() ); + assertEquals( expectedRepository.getIndexDirectory(), actualRepository.getIndexDirectory() ); assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() ); assertEquals( expectedRepository.getName(), actualRepository.getName() ); - assertEquals( expectedRepository.getRefreshCronExpression(), actualRepository.getRefreshCronExpression() ); + assertEquals( expectedRepository.getCronExpression(), actualRepository.getCronExpression() ); assertEquals( expectedRepository.getRetentionCount(), actualRepository.getRetentionCount() ); assertEquals( expectedRepository.isDeleteReleasedSnapshots(), actualRepository.isDeleteReleasedSnapshots() ); assertEquals( expectedRepository.isScanned(), actualRepository.isScanned() ); @@ -537,11 +535,28 @@ public class EditManagedRepositoryActionTest assertEquals( expectedRepository.isSnapshots(), actualRepository.isSnapshots() ); } - private Configuration createConfigurationForEditing( ManagedRepositoryConfiguration repositoryConfiguration ) + private Configuration createConfigurationForEditing( ManagedRepository repositoryConfiguration ) throws Exception { 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; } @@ -564,10 +579,10 @@ public class EditManagedRepositoryActionTest }; } - private ManagedRepositoryConfiguration createRepository() + private ManagedRepository createRepository() throws IOException { - ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration(); + ManagedRepository r = new ManagedRepository(); r.setId( REPO_ID ); populateRepository( r ); return r; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/validator/utils/ValidatorUtil.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/validator/utils/ValidatorUtil.java index a02301eeb..36e4651fd 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/validator/utils/ValidatorUtil.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/validator/utils/ValidatorUtil.java @@ -19,44 +19,52 @@ package org.apache.maven.archiva.web.validator.utils; * under the License. */ +import junit.framework.Assert; +import org.apache.commons.lang.SystemUtils; + import java.util.List; import java.util.Map; -import junit.framework.Assert; public class ValidatorUtil { - public static void assertFieldErrors(Map> expectedFieldErrors, Map> actualFieldErrors) + public static void assertFieldErrors( Map> expectedFieldErrors, + Map> actualFieldErrors ) { - if(expectedFieldErrors != null) + if ( expectedFieldErrors != null ) { - Assert.assertNotNull(actualFieldErrors); + Assert.assertNotNull( actualFieldErrors ); // 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 - for(Map.Entry> expectedEntry : expectedFieldErrors.entrySet()) + for ( Map.Entry> 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 - 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 - 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 { - Assert.assertNull(actualFieldErrors.get(expectedEntry.getKey())); + Assert.assertNull( actualFieldErrors.get( expectedEntry.getKey() ) ); } } } else { - Assert.assertNull(actualFieldErrors); + Assert.assertNull( actualFieldErrors ); } } } diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java index f7640c29e..b0ee685a4 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java @@ -104,7 +104,8 @@ public interface AdministrationService */ Boolean addManagedRepository( String repoId, String layout, String name, String location, boolean blockRedeployments, boolean releasesIncluded, boolean snapshotsIncluded, - boolean stageRepoNeeded, String cronExpression ) + boolean stageRepoNeeded, String cronExpression, int daysOlder, int retentionCount, + boolean deleteReleasedSnapshots ) throws Exception; /** diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java index f7eadc19c..e181f4a97 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java @@ -361,14 +361,17 @@ public class AdministrationServiceImpl public Boolean addManagedRepository( String repoId, String layout, String name, String location, boolean blockRedeployments, boolean releasesIncluded, - boolean snapshotsIncluded, boolean stageRepoNeeded, String cronExpression ) + boolean snapshotsIncluded, boolean stageRepoNeeded, String cronExpression, + int daysOlder, int retentionCount, boolean deleteReleasedSnapshots ) throws Exception { org.apache.archiva.admin.repository.managed.ManagedRepository repository = new org.apache.archiva.admin.repository.managed.ManagedRepository( repoId, name, location, layout, snapshotsIncluded, releasesIncluded, - blockRedeployments, cronExpression ); + blockRedeployments, cronExpression, null, + false, daysOlder, retentionCount, + deleteReleasedSnapshots ); return managedRepositoryAdmin.addManagedRepository( repository, stageRepoNeeded, getAuditInformation() ); } diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java index 041c431f5..886bbfc2b 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java @@ -21,7 +21,6 @@ package org.apache.archiva.web.xmlrpc.services; import junit.framework.TestCase; 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.AuditListener; import org.apache.archiva.metadata.model.ArtifactMetadata; @@ -215,7 +214,6 @@ public class AdministrationServiceImplTest registryControl = MockControl.createControl( Registry.class ); registry = (Registry) registryControl.getMock(); - managedRepositoryAdmin = new DefaultManagedRepositoryAdmin(); managedRepositoryAdmin.setArchivaConfiguration( archivaConfig ); managedRepositoryAdmin.setRegistry( registry ); @@ -388,11 +386,9 @@ public class AdministrationServiceImplTest List artifacts = getArtifacts(); ArtifactMetadata artifact = artifacts.get( 0 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( repoContent.getId(), - artifact.getNamespace(), - artifact.getProject(), - artifact.getVersion() ), - artifacts ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), + artifact.getVersion() ), artifacts ); metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), artifact.getVersion(), artifact.getId() ); @@ -446,11 +442,9 @@ public class AdministrationServiceImplTest List artifacts = getArtifacts(); ArtifactMetadata artifact = artifacts.get( 0 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( repoContent.getId(), - artifact.getNamespace(), - artifact.getProject(), - artifact.getVersion() ), - artifacts ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), + artifact.getVersion() ), artifacts ); metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), artifact.getVersion(), artifact.getId() ); @@ -531,8 +525,8 @@ public class AdministrationServiceImplTest FileUtils.copyDirectory( srcDir, repoDir, FileFilterUtils.makeSVNAware( null ) ); - ManagedRepositoryConfiguration managedRepo = createManagedRepo( "internal", layout, "Internal Repository", true, - false ); + ManagedRepositoryConfiguration managedRepo = + createManagedRepo( "internal", layout, "Internal Repository", true, false ); managedRepo.setLocation( repoDir.getAbsolutePath() ); return managedRepo; } @@ -567,16 +561,13 @@ public class AdministrationServiceImplTest throws Exception { archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); - configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), createManagedRepo( "internal", - "default", - "Internal Repository", - true, - false ) ); + configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), + createManagedRepo( "internal", "default", "Internal Repository", true, false ) ); RepositoryTask task = new RepositoryTask(); - repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( - "internal" ), false ); + repositoryTaskSchedulerControl.expectAndReturn( + repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ), false ); repositoryTaskScheduler.queueTask( task ); repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER ); @@ -606,14 +597,11 @@ public class AdministrationServiceImplTest throws Exception { archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); - configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), createManagedRepo( "internal", - "default", - "Internal Repository", - true, - false ) ); + configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), + createManagedRepo( "internal", "default", "Internal Repository", true, false ) ); - repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( - "internal" ), true ); + repositoryTaskSchedulerControl.expectAndReturn( + repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ), true ); archivaConfigControl.replay(); configControl.replay(); @@ -690,10 +678,10 @@ public class AdministrationServiceImplTest throws Exception { List remoteRepos = new ArrayList(); - remoteRepos.add( createRemoteRepository( "central", "Central Repository", "default", - "http://repo1.maven.org/maven2" ) ); - remoteRepos.add( createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy", - "http://dummy.com/dummy" ) ); + remoteRepos.add( + createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" ) ); + remoteRepos.add( + createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy", "http://dummy.com/dummy" ) ); archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); configControl.expectAndReturn( config.getRemoteRepositories(), remoteRepos ); @@ -745,7 +733,7 @@ public class AdministrationServiceImplTest archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo ); metadataRepository.removeRepository( "internal" ); - + archivaConfigControl.replay(); configControl.replay(); metadataRepositoryControl.replay(); @@ -790,9 +778,8 @@ public class AdministrationServiceImplTest throws Exception { archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); - configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ), createManagedRepo( "repo", "default", - "repo", true, - false ) ); + configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ), + createManagedRepo( "repo", "default", "repo", true, false ) ); configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), null ); archivaConfigControl.replay(); @@ -835,10 +822,8 @@ public class AdministrationServiceImplTest configControl.expectAndReturn( config.findManagedRepositoryById( "merge-stage" ), staging ); metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources ); - repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( metadataRepository, - staging.getId(), - merge.getId() ), - sources ); + repositoryMergerControl.expectAndDefaultReturn( + repositoryMerger.getConflictingArtifacts( metadataRepository, staging.getId(), merge.getId() ), sources ); repositoryMerger.merge( metadataRepository, staging.getId(), merge.getId() ); repositoryMergerControl.setVoidCallable(); repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "merge" ), @@ -906,10 +891,8 @@ public class AdministrationServiceImplTest configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), staging ); metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources ); - repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( metadataRepository, - staging.getId(), - repo.getId() ), - conflicts ); + repositoryMergerControl.expectAndDefaultReturn( + repositoryMerger.getConflictingArtifacts( metadataRepository, staging.getId(), repo.getId() ), conflicts ); repositoryMerger.merge( metadataRepository, staging.getId(), repo.getId(), artifactsWithOutConflicts ); repositoryMergerControl.setMatcher( MockControl.ALWAYS_MATCHER ); repositoryMergerControl.setVoidCallable(); @@ -954,8 +937,8 @@ public class AdministrationServiceImplTest String appserverBase = "target"; ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false ); - RemoteRepositoryConfiguration remoteRepo = createRemoteRepository( "central", "Central Repository", "default", - "http://repo1.maven.org/maven2" ); + RemoteRepositoryConfiguration remoteRepo = + createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" ); List repositories = new ArrayList(); repositories.add( managedRepo.getName() ); RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories ); @@ -1004,11 +987,9 @@ public class AdministrationServiceImplTest archivaConfig.save( config ); archivaConfigControl.setVoidCallable(); - - - //managed repo - repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( repoId ), false ); + repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( repoId ), + false ); RepositoryTask task = new RepositoryTask(); task.setRepositoryId( repoId ); @@ -1019,7 +1000,8 @@ public class AdministrationServiceImplTest repositoryTaskSchedulerControl.setVoidCallable(); //staged repo - repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( repoId + STAGE ), false ); + repositoryTaskSchedulerControl.expectAndReturn( + repositoryTaskScheduler.isProcessingRepositoryTask( repoId + STAGE ), false ); task = new RepositoryTask(); task.setRepositoryId( repoId + STAGE ); archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); @@ -1034,8 +1016,9 @@ public class AdministrationServiceImplTest repositoryTaskSchedulerControl.replay(); assertFalse( new File( releaseLocation ).isDirectory() ); assertFalse( new File( stageLocation ).isDirectory() ); - boolean success = service.addManagedRepository( repoId, layout, name, "${appserver.base}/test-repository/" + projId + ".releases", true, true, false, true, - "0 15 3 * * ? *" ); + boolean success = service.addManagedRepository( repoId, layout, name, + "${appserver.base}/test-repository/" + projId + ".releases", + true, true, false, true, "0 15 3 * * ? *", 1, 1, true ); assertTrue( success ); assertTrue( new File( releaseLocation ).isDirectory() ); assertTrue( new File( stageLocation ).isDirectory() ); @@ -1055,8 +1038,8 @@ public class AdministrationServiceImplTest String name = projId + " Releases"; ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false ); - RemoteRepositoryConfiguration remoteRepo = createRemoteRepository( "central", "Central Repository", "default", - "http://repo1.maven.org/maven2" ); + RemoteRepositoryConfiguration remoteRepo = + createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" ); List repositories = new ArrayList(); repositories.add( managedRepo.getName() ); RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories ); @@ -1079,14 +1062,16 @@ public class AdministrationServiceImplTest try { - service.addManagedRepository( repoId, layout, name, "${appserver.base}/test-repository/" + projId + ".releases", true, true, false, true, - "0 15 3 * * ? *" ); + service.addManagedRepository( repoId, layout, name, + "${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." ); } - catch( Exception e ) + catch ( Exception e ) { - assertEquals( "Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-).", - e.getMessage() ); + assertEquals( + "Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-).", + e.getMessage() ); } } @@ -1100,8 +1085,8 @@ public class AdministrationServiceImplTest String name = projId + " "; ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false ); - RemoteRepositoryConfiguration remoteRepo = createRemoteRepository( "central", "Central Repository", "default", - "http://repo1.maven.org/maven2" ); + RemoteRepositoryConfiguration remoteRepo = + createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" ); List repositories = new ArrayList(); repositories.add( managedRepo.getName() ); RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories ); @@ -1124,15 +1109,17 @@ public class AdministrationServiceImplTest try { - service.addManagedRepository( repoId, layout, name, "${appserver.base}/test-repository/" + projId + ".releases", true, true, false, true, - "0 15 3 * * ? *" ); + service.addManagedRepository( repoId, layout, name, + "${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." ); } - catch( Exception e ) + catch ( Exception e ) { - assertEquals( "Invalid repository name. Repository Name must only contain alphanumeric characters, white-spaces(' '), " + - "forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-).", - e.getMessage() ); + assertEquals( + "Invalid repository name. Repository Name must only contain alphanumeric characters, white-spaces(' '), " + + "forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-).", + e.getMessage() ); } } @@ -1147,8 +1134,8 @@ public class AdministrationServiceImplTest String appserverBase = "target"; ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false ); - RemoteRepositoryConfiguration remoteRepo = createRemoteRepository( "central", "Central Repository", "default", - "http://repo1.maven.org/maven2" ); + RemoteRepositoryConfiguration remoteRepo = + createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" ); List repositories = new ArrayList(); repositories.add( managedRepo.getName() ); RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories ); @@ -1174,15 +1161,17 @@ public class AdministrationServiceImplTest try { - service.addManagedRepository( repoId, layout, name, "${appserver.base}/" + projId + ".releases", true, true, false, true, - "0 15 3 * * ? *" ); + service.addManagedRepository( repoId, layout, name, + "${appserver.base}/" + projId + ".releases", + true, true, false, true, "0 15 3 * * ? *", 1, 1, true ); 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(?), " + - "exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-).", - e.getMessage() ); + assertEquals( + "Invalid repository location. Directory must only contain alphanumeric characters, equals(=), question-marks(?), " + + "exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-).", + e.getMessage() ); } registryControl.verify();