From 0b904bd4d8f45faba81716074efccc954ad93c83 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 11 Sep 2012 21:30:31 +0000 Subject: [PATCH] [MRM-648] Add description field to the different types of repositories and proxies configuration and rest service implemented. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1383621 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/mdo/configuration.mdo | 8 ++++ .../admin/model/beans/AbstractRepository.java | 16 +++++++ .../admin/model/beans/ManagedRepository.java | 16 ++++++- .../DefaultManagedRepositoryAdmin.java | 23 +++++----- .../managed/ManagedRepositoryAdminTest.java | 19 ++++++-- .../services/AbstractArchivaRestTest.java | 44 +++++++++---------- .../ManagedRepositoriesServiceTest.java | 5 ++- 7 files changed, 93 insertions(+), 38 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo index 3dc20787e..1c02c812b 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo @@ -421,6 +421,14 @@ The directory for the indexes of this repository. + + description + 1.0.0+ + String + + The description of this repository. + + diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/AbstractRepository.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/AbstractRepository.java index 772841d3a..bb90fcabf 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/AbstractRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/AbstractRepository.java @@ -36,6 +36,11 @@ public class AbstractRepository private String indexDirectory; + /** + * @since 1.4-M3 + */ + private String description; + public AbstractRepository() { // no op @@ -90,6 +95,16 @@ public class AbstractRepository this.indexDirectory = indexDirectory; } + public String getDescription() + { + return description; + } + + public void setDescription( String description ) + { + this.description = description; + } + public int hashCode() { int result = 17; @@ -124,6 +139,7 @@ public class AbstractRepository sb.append( ", name='" ).append( name ).append( '\'' ); sb.append( ", layout='" ).append( layout ).append( '\'' ); sb.append( ", indexDirectory='" ).append( indexDirectory ).append( '\'' ); + sb.append( ", description='" ).append( description ).append( '\'' ); sb.append( '}' ); return sb.toString(); } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ManagedRepository.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ManagedRepository.java index 394631990..a1bbbc1ab 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ManagedRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ManagedRepository.java @@ -26,7 +26,7 @@ import java.io.Serializable; * @author Olivier Lamy * @since 1.4-M1 */ -@XmlRootElement( name = "managedRepository" ) +@XmlRootElement (name = "managedRepository") public class ManagedRepository extends AbstractRepository implements Serializable @@ -95,6 +95,20 @@ public class ManagedRepository this.stageRepoNeeded = stageRepoNeeded; } + /** + * + * @since 1.4-M3 + */ + 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, + boolean stageRepoNeeded, String description ) + { + this( id, name, location, layout, snapshots, releases, blockRedeployments, cronExpression, indexDir, scanned, + daysOlder, retentionCount, deleteReleasedSnapshots, stageRepoNeeded ); + setDescription( description ); + } + public String getCronExpression() { return cronExpression; diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java index d181654a9..30d74f704 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java @@ -36,7 +36,9 @@ import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; +import org.apache.archiva.redback.components.taskqueue.TaskQueueException; import org.apache.archiva.redback.role.RoleManager; +import org.apache.archiva.redback.role.RoleManagerException; import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler; import org.apache.archiva.scheduler.repository.RepositoryTask; import org.apache.archiva.security.common.ArchivaRoleConstants; @@ -46,8 +48,6 @@ import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.context.IndexCreator; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; -import org.apache.archiva.redback.role.RoleManagerException; -import org.apache.archiva.redback.components.taskqueue.TaskQueueException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -72,7 +72,7 @@ import java.util.Map; * * @author Olivier Lamy */ -@Service( "managedRepositoryAdmin#default" ) +@Service ( "managedRepositoryAdmin#default" ) public class DefaultManagedRepositoryAdmin extends AbstractRepositoryAdmin implements ManagedRepositoryAdmin @@ -83,7 +83,7 @@ public class DefaultManagedRepositoryAdmin public static final String STAGE_REPO_ID_END = "-stage"; @Inject - @Named( value = "archivaTaskScheduler#repository" ) + @Named ( value = "archivaTaskScheduler#repository" ) private RepositoryArchivaTaskScheduler repositoryTaskScheduler; @Inject @@ -170,7 +170,7 @@ public class DefaultManagedRepositoryAdmin repoConfig.isBlockRedeployments(), repoConfig.getRefreshCronExpression(), repoConfig.getIndexDir(), repoConfig.isScanned(), repoConfig.getDaysOlder(), repoConfig.getRetentionCount(), repoConfig.isDeleteReleasedSnapshots(), false ); - + repo.setDescription( repoConfig.getDescription() ); managedRepos.add( repo ); } @@ -218,8 +218,8 @@ public class DefaultManagedRepositoryAdmin managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo, managedRepository.getCronExpression(), managedRepository.getIndexDirectory(), managedRepository.getDaysOlder(), managedRepository.getRetentionCount(), - managedRepository.isDeleteReleasedSnapshots(), auditInformation, - getArchivaConfiguration().getConfiguration() ) != null; + managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(), + auditInformation, getArchivaConfiguration().getConfiguration() ) != null; createIndexContext( managedRepository ); return res; @@ -231,7 +231,7 @@ public class DefaultManagedRepositoryAdmin boolean releasesIncluded, boolean snapshotsIncluded, boolean stageRepoNeeded, String cronExpression, String indexDir, int daysOlder, int retentionCount, - boolean deteleReleasedSnapshots, + boolean deteleReleasedSnapshots, String description, AuditInformation auditInformation, Configuration config ) throws RepositoryAdminException @@ -252,6 +252,7 @@ public class DefaultManagedRepositoryAdmin repository.setRetentionCount( retentionCount ); repository.setDeleteReleasedSnapshots( deteleReleasedSnapshots ); repository.setIndexDir( indexDir ); + repository.setDescription( description ); try { @@ -480,8 +481,8 @@ public class DefaultManagedRepositoryAdmin managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo, managedRepository.getCronExpression(), managedRepository.getIndexDirectory(), managedRepository.getDaysOlder(), managedRepository.getRetentionCount(), - managedRepository.isDeleteReleasedSnapshots(), auditInformation, - getArchivaConfiguration().getConfiguration() ); + managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(), + auditInformation, getArchivaConfiguration().getConfiguration() ); // Save the repository configuration. RepositorySession repositorySession = getRepositorySessionFactory().createSession(); @@ -634,6 +635,8 @@ public class DefaultManagedRepositoryAdmin stagingRepository.setRetentionCount( repository.getRetentionCount() ); stagingRepository.setScanned( repository.isScanned() ); stagingRepository.setSnapshots( repository.isSnapshots() ); + // do not duplicate description + //stagingRepository.getDescription("") return stagingRepository; } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java index 343cebb7c..b1fa302ef 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java @@ -37,6 +37,7 @@ public class ManagedRepositoryAdminTest String repoId = "test-new-one"; + String repoLocation = APPSERVER_BASE_PATH + File.separator + repoId; @Test @@ -85,12 +86,19 @@ public class ManagedRepositoryAdminTest repo.setName( "test repo" ); repo.setLocation( repoLocation ); repo.setCronExpression( "0 0 * * * ?" ); + repo.setDescription( "cool repo" ); managedRepositoryAdmin.addManagedRepository( repo, false, getFakeAuditInformation() ); repos = managedRepositoryAdmin.getManagedRepositories(); assertNotNull( repos ); assertEquals( initialSize + 1, repos.size() ); - assertNotNull( managedRepositoryAdmin.getManagedRepository( repoId ) ); + ManagedRepository managedRepository = managedRepositoryAdmin.getManagedRepository( repoId ); + + assertNotNull( managedRepository ); + + assertEquals( "test repo", managedRepository.getName() ); + + assertEquals( "cool repo", managedRepository.getDescription() ); assertTemplateRoleExists( repoId ); @@ -142,6 +150,10 @@ public class ManagedRepositoryAdminTest repo.setName( newName ); + String description = "so great repository"; + + repo.setDescription( description ); + repo.setLocation( repoLocation ); repo.setCronExpression( "0 0 * * * ?" ); @@ -152,6 +164,7 @@ public class ManagedRepositoryAdminTest assertEquals( newName, repo.getName() ); assertEquals( new File( repoLocation ).getCanonicalPath(), new File( repo.getLocation() ).getCanonicalPath() ); assertTrue( new File( repoLocation ).exists() ); + assertEquals( description, repo.getDescription() ); assertTemplateRoleExists( repoId ); @@ -300,12 +313,11 @@ public class ManagedRepositoryAdminTest assertAuditListenerCallAndUpdateAddAndDelete( true ); mockAuditListener.clearEvents(); - + new File( repoLocation + STAGE_REPO_ID_END ).delete(); assertFalse( new File( repoLocation + STAGE_REPO_ID_END ).exists() ); } - //---------------------------------- // utility methods //---------------------------------- @@ -368,5 +380,4 @@ public class ManagedRepositoryAdminTest } - } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java index 3d1a91f86..38102a439 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java @@ -34,27 +34,27 @@ import org.apache.archiva.rest.api.services.RepositoriesService; import org.apache.archiva.rest.api.services.RepositoryGroupService; import org.apache.archiva.rest.api.services.SearchService; import org.apache.archiva.security.common.ArchivaRoleConstants; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.cxf.jaxrs.client.JAXRSClientFactory; import org.apache.cxf.jaxrs.client.WebClient; import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider; +import org.junit.Assume; import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.slf4j.LoggerFactory; import javax.ws.rs.core.MediaType; import java.io.File; import java.util.Collections; import java.util.Date; -import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.slf4j.LoggerFactory; /** * @author Olivier Lamy */ -@RunWith( ArchivaBlockJUnit4ClassRunner.class ) +@RunWith (ArchivaBlockJUnit4ClassRunner.class) public abstract class AbstractArchivaRestTest extends AbstractRestServicesTest { @@ -70,41 +70,41 @@ public abstract class AbstractArchivaRestTest // END SNIPPET: authz-header - @BeforeClass - public static void chekRepo() { - Assume.assumeTrue( !System.getProperty( "appserver.base" ).contains(" ") ); + @BeforeClass + public static void chekRepo() + { + Assume.assumeTrue( !System.getProperty( "appserver.base" ).contains( " " ) ); LoggerFactory.getLogger( AbstractArchivaRestTest.class.getName() ). - error( "Rest services unit test must be run in a folder with no space" ); + error( "Rest services unit test must be run in a folder with no space" ); // skygo: was not possible to fix path in this particular module // Skip test if not in proper folder , otherwise test are not fair coz repository // cannot have space in their name. } - + @Override @Before public void startServer() throws Exception - { + { File appServerBase = new File( System.getProperty( "appserver.base" ) ); removeAppsubFolder( appServerBase, "jcr" ); removeAppsubFolder( appServerBase, "conf" ); removeAppsubFolder( appServerBase, "data" ); - - - super.startServer(); + + super.startServer(); } - + private void removeAppsubFolder( File appServerBase, String folder ) - throws Exception + throws Exception { - File directory = new File( appServerBase, folder ); + File directory = new File( appServerBase, folder ); if ( directory.exists() ) { FileUtils.deleteDirectory( directory ); } } - + @Override protected String getSpringConfigLocation() { @@ -295,7 +295,7 @@ public abstract class AbstractArchivaRestTest { String location = new File( FileUtil.getBasedir(), "target/test-repo" ).getAbsolutePath(); return new ManagedRepository( "TEST", "test", location, "default", true, true, false, "2 * * * * ?", null, - false, 2, 3, true, false ); + false, 2, 3, true, false, "my nice repo" ); } @@ -394,7 +394,7 @@ public abstract class AbstractArchivaRestTest } } - + protected void createAndIndexRepo( String testRepoId, String repoPath, boolean scan ) throws Exception { @@ -412,7 +412,7 @@ public abstract class AbstractArchivaRestTest { FileUtils.deleteDirectory( badContent ); } - + managedRepository.setLocation( new File( repoPath ).getPath() ); managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/target/.index-" + Long.toString( new Date().getTime() ) ); diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java index 168cc6e7a..d173b8bf2 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java @@ -48,7 +48,10 @@ public class ManagedRepositoriesServiceTest assertNull( service.getManagedRepository( repo.getId() ) ); } service.addManagedRepository( repo ); - assertNotNull( service.getManagedRepository( repo.getId() ) ); + repo = service.getManagedRepository( repo.getId() ); + assertNotNull( repo ); + + assertEquals( getTestManagedRepository().getDescription(), repo.getDescription() ); RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader ); -- 2.39.5