From: Maria Odea B. Ching Date: Fri, 1 Oct 2010 03:50:04 +0000 (+0000) Subject: [MRM-1409] web services for repository merge X-Git-Tag: archiva-1.4-M1~904 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d35e740ca9af5352e77788e3929db365c2d1a051;p=archiva.git [MRM-1409] web services for repository merge submitted by Gwen Harold Autencio git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1003378 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/MergeAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/MergeAction.java index ff252a151..9dc984d0d 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/MergeAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/MergeAction.java @@ -167,14 +167,14 @@ public class } } - public String mergeWithOutConlficts() + public String mergeWithOutConlficts() { sourceRepoId = repoid + "-stage"; try { - conflictSourceArtifacts = repositoryMerger.getConflictsartifacts( sourceRepoId, repoid ); + conflictSourceArtifacts = repositoryMerger.getConflictingArtifacts( sourceRepoId, repoid ); } catch ( Exception e ) { @@ -201,7 +201,7 @@ public class throws Exception { sourceRepoId = repoid + "-stage"; - conflictSourceArtifacts = repositoryMerger.getConflictsartifacts( sourceRepoId, repoid ); + conflictSourceArtifacts = repositoryMerger.getConflictingArtifacts( sourceRepoId, repoid ); this.scheduler.setRepoid( repoid ); Configuration config = archivaConfiguration.getConfiguration(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml index 144eccb40..1a8c45ce1 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml @@ -57,7 +57,10 @@ - + + + + diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/pom.xml b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/pom.xml index b307f9b1b..f2ad04de0 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/pom.xml +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/pom.xml @@ -13,6 +13,10 @@ org.apache.archiva archiva-indexer + + org.apache.archiva + stage-repository-merge + com.atlassian.xmlrpc atlassian-xmlrpc-binder-annotations 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 84e23433b..ecff3da4e 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 @@ -24,7 +24,6 @@ import java.util.List; import com.atlassian.xmlrpc.ServiceObject; import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository; import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository; -import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; @ServiceObject( "AdministrationService" ) public interface AdministrationService @@ -125,4 +124,14 @@ public interface AdministrationService // consider the following as additional services: // - getAllConfiguredRepositoryConsumers( String repoId ) - list all enabled consumers for the repo // - getAllConfiguredDatabaseConsumers() - list all enabled db consumers + + /** + * Merge staging repository with the managed repository and skips if there are conflicts + * @param repoId + * @param skipConflicts + * @return + * @throws Exception + */ + public boolean merge( String repoId, boolean skipConflicts ) throws Exception; + } diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/main/java/org/apache/archiva/web/xmlrpc/security/ServiceMethodsPermissionsMapping.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/main/java/org/apache/archiva/web/xmlrpc/security/ServiceMethodsPermissionsMapping.java index d194a910d..457ab8b7b 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/main/java/org/apache/archiva/web/xmlrpc/security/ServiceMethodsPermissionsMapping.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/main/java/org/apache/archiva/web/xmlrpc/security/ServiceMethodsPermissionsMapping.java @@ -42,7 +42,8 @@ public class ServiceMethodsPermissionsMapping "AdministrationService.getAllRepositoryConsumers", "AdministrationService.deleteArtifact", "AdministrationService.addManagedRepository", - "AdministrationService.deleteManagedRepository", "AdministrationService.getManagedRepository" ); + "AdministrationService.deleteManagedRepository", "AdministrationService.getManagedRepository", + "AdministrationService.merge"); public static final List SERVICE_METHODS_FOR_OPERATION_RUN_INDEXER = Arrays.asList( "AdministrationService.executeRepositoryScanner" ); diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml index c62817b77..06377c24d 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml @@ -46,6 +46,10 @@ org.apache.archiva archiva-xmlrpc-api + + org.apache.archiva + audit + org.apache.archiva archiva-repository-scanner @@ -79,6 +83,6 @@ org.slf4j slf4j-simple test - + 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 33bea017b..08db94ec7 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 @@ -19,13 +19,26 @@ package org.apache.archiva.web.xmlrpc.services; * under the License. */ +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import org.apache.archiva.audit.AuditEvent; +import org.apache.archiva.audit.AuditListener; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.filter.Filter; +import org.apache.archiva.metadata.repository.filter.IncludesFilter; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.archiva.repository.scanner.RepositoryContentConsumers; import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler; import org.apache.archiva.scheduler.repository.RepositoryTask; +import org.apache.archiva.stagerepository.merge.RepositoryMerger; import org.apache.archiva.web.xmlrpc.api.AdministrationService; import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository; import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository; @@ -46,20 +59,11 @@ import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.RepositoryNotFoundException; -import org.apache.maven.archiva.security.ArchivaRoleConstants; -import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.registry.RegistryException; import org.codehaus.plexus.scheduler.CronExpressionValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - /** * AdministrationServiceImpl * @@ -83,12 +87,19 @@ public class AdministrationServiceImpl private MetadataRepository metadataRepository; private RepositoryStatisticsManager repositoryStatisticsManager; + + private RepositoryMerger repositoryMerger; + + private static final String STAGE = "-stage"; + + private AuditListener auditListener; public AdministrationServiceImpl( ArchivaConfiguration archivaConfig, RepositoryContentConsumers repoConsumersUtil, RepositoryContentFactory repoFactory, MetadataRepository metadataRepository, RepositoryArchivaTaskScheduler repositoryTaskScheduler, Collection listeners, - RepositoryStatisticsManager repositoryStatisticsManager ) + RepositoryStatisticsManager repositoryStatisticsManager, RepositoryMerger repositoryMerger, + AuditListener auditListener ) { this.archivaConfiguration = archivaConfig; this.repoConsumersUtil = repoConsumersUtil; @@ -97,6 +108,8 @@ public class AdministrationServiceImpl this.listeners = listeners; this.metadataRepository = metadataRepository; this.repositoryStatisticsManager = repositoryStatisticsManager; + this.repositoryMerger = repositoryMerger; + this.auditListener = auditListener; } /** @@ -459,4 +472,111 @@ public class AdministrationServiceImpl return repo; } + public boolean merge( String repoId, boolean skipConflicts ) + throws Exception + { + String stagingId = repoId + STAGE; + ManagedRepositoryConfiguration repoConfig; + ManagedRepositoryConfiguration stagingConfig; + + Configuration config = archivaConfiguration.getConfiguration(); + repoConfig = config.findManagedRepositoryById( repoId ); + + if( repoConfig != null ) + { + stagingConfig = config.findManagedRepositoryById( stagingId ); + + if( stagingConfig != null ) + { + List sourceArtifacts = metadataRepository.getArtifacts( stagingId ); + + if( repoConfig.isReleases() && !repoConfig.isSnapshots() ) + { + if( skipConflicts ) + { + List conflicts = repositoryMerger.getConflictingArtifacts( stagingId, stagingId ); + sourceArtifacts.removeAll( conflicts ); + mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId ); + } + else + { + mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId ); + } + } + else + { + if( skipConflicts ) + { + List conflicts = repositoryMerger.getConflictingArtifacts( stagingId, stagingId ); + sourceArtifacts.removeAll( conflicts ); + Filter artifactsWithOutConflicts = new IncludesFilter( sourceArtifacts ); + repositoryMerger.merge( stagingId, repoId, artifactsWithOutConflicts ); + } + else + { + repositoryMerger.merge( stagingId, repoId ); + } + } + } + else + { + throw new Exception( "Staging Id : " + stagingId + " not found." ); + } + } + else + { + throw new Exception( "Repository Id : " + repoId + " not found." ); + } + + if ( !repositoryTaskScheduler.isProcessingRepositoryTask( repoId ) ) + { + RepositoryTask task = new RepositoryTask(); + task.setRepositoryId( repoId ); + + repositoryTaskScheduler.queueTask( task ); + } + + AuditEvent event = createAuditEvent( repoConfig ); + + // add event for audit log reports + metadataRepository.addMetadataFacet( event.getRepositoryId(), event ); + + // log event in archiva audit log + auditListener.auditEvent( createAuditEvent( repoConfig ) ); + + return true; + } + + // todo: setting userid of audit event + private AuditEvent createAuditEvent( ManagedRepositoryConfiguration repoConfig ) + { + + AuditEvent event = new AuditEvent(); + event.setAction( AuditEvent.MERGE_REPO_REMOTE ); + event.setRepositoryId( repoConfig.getId() ); + event.setResource( repoConfig.getLocation() ); + event.setTimestamp( new Date( ) ); + + return event; + } + + private void mergeWithOutSnapshots( List sourceArtifacts, String sourceRepoId, String repoid ) + throws Exception + { + List artifactsWithOutSnapshots = new ArrayList(); + for ( ArtifactMetadata metadata : sourceArtifacts ) + { + + if ( metadata.getProjectVersion().contains( "SNAPSHOT" ) ) + { + artifactsWithOutSnapshots.add( metadata ); + } + + } + sourceArtifacts.removeAll( artifactsWithOutSnapshots ); + + Filter artifactListWithOutSnapShots = new IncludesFilter( sourceArtifacts ); + + repositoryMerger.merge( sourceRepoId, repoid, artifactListWithOutSnapShots ); + } } 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 5b0a2bdd5..50ba22f63 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 @@ -19,13 +19,18 @@ package org.apache.archiva.web.xmlrpc.services; * under the License. */ +import org.apache.archiva.audit.AuditEvent; +import org.apache.archiva.audit.AuditListener; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.filter.Filter; +import org.apache.archiva.metadata.repository.filter.IncludesFilter; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.archiva.repository.scanner.RepositoryContentConsumers; import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler; import org.apache.archiva.scheduler.repository.RepositoryTask; +import org.apache.archiva.stagerepository.merge.RepositoryMerger; import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository; import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository; import org.apache.commons.io.FileUtils; @@ -52,6 +57,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; /** @@ -109,7 +115,17 @@ public class AdministrationServiceImplTest private MockControl repositoryStatisticsManagerControl; private RepositoryStatisticsManager repositoryStatisticsManager; + + private MockControl repositoryMergerControl; + + private RepositoryMerger repositoryMerger; + + private MockControl auditListenerControl; + + private AuditListener auditListener; + private static final String STAGE = "-stage"; + protected void setUp() throws Exception { @@ -148,12 +164,17 @@ public class AdministrationServiceImplTest repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class ); repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock(); - + repositoryMergerControl = MockControl.createControl( RepositoryMerger.class ); + repositoryMerger = (RepositoryMerger) repositoryMergerControl.getMock(); + + auditListenerControl = MockControl.createControl( AuditListener.class ); + auditListener = ( AuditListener ) auditListenerControl.getMock(); + service = new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, repositoryFactory, metadataRepository, repositoryTaskScheduler, - Collections.singletonList( listener ), repositoryStatisticsManager ); + Collections.singletonList( listener ), repositoryStatisticsManager, repositoryMerger, auditListener ); } /* Tests for repository consumers */ @@ -617,6 +638,174 @@ public class AdministrationServiceImplTest assertRemoteRepo( repos.get( 1 ), remoteRepos.get( 1 ) ); } +/* Merge method */ + + public void testMergeRepositoryWithInvalidRepository() + throws Exception + { + archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); + configControl.expectAndReturn( config.findManagedRepositoryById( "invalid" ), null ); + + archivaConfigControl.replay(); + configControl.replay(); + + try + { + service.merge( "invalid", true ); + } + catch( Exception e ) + { + assertEquals( "Repository Id : invalid not found.", e.getMessage() ); + } + + archivaConfigControl.verify(); + configControl.verify(); + } + + public void testMergeWithNoStagingRepository() + throws Exception + { + archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); + configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ), createManagedRepo( "repo", "default", "repo", true, false ) ); + configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), null ); + + archivaConfigControl.replay(); + configControl.replay(); + + try + { + service.merge( "repo", true ); + } + catch( Exception e ) + { + assertEquals( "Staging Id : repo-stage not found.", e.getMessage() ); + } + + archivaConfigControl.verify(); + configControl.verify(); + } + + public void testMergeRepositoriesAndScan( ) + throws Exception + { + List sources = new ArrayList(); + + ArtifactMetadata artifact = new ArtifactMetadata(); + artifact.setId( "artifact" ); + artifact.setFileLastModified( System.currentTimeMillis() ); + + sources.add( artifact ); + + ManagedRepositoryConfiguration merge = createManagedRepo( "merge", "default", "merge", true, true ); + merge.setLocation( "target/test-repository/merge" ); + ManagedRepositoryConfiguration staging = createStagingRepo( merge ); + + RepositoryTask task = new RepositoryTask(); + task.setScanAll( true ); + + archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); + configControl.expectAndReturn( config.findManagedRepositoryById( "merge" ), merge ); + configControl.expectAndReturn( config.findManagedRepositoryById( "merge-stage" ), staging ); + + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources ); + repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( staging.getId(), merge.getId() ), sources ); + repositoryMerger.merge( staging.getId(), merge.getId() ); + repositoryMergerControl.setMatcher( MockControl.ALWAYS_MATCHER ); + repositoryMergerControl.setVoidCallable(); + repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "merge" ), false); + + // scanning after merge + repositoryTaskScheduler.queueTask( task ); + repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER ); + repositoryTaskSchedulerControl.setVoidCallable(); + + // audit logs + metadataRepository.addMetadataFacet( merge.getId() ,createAuditEvent( merge) ); + metadataRepositoryControl.setMatcher( MockControl.ALWAYS_MATCHER ); + metadataRepositoryControl.setVoidCallable(); + + archivaConfigControl.replay(); + metadataRepositoryControl.replay(); + configControl.replay(); + repositoryMergerControl.replay(); + repositoryTaskSchedulerControl.replay(); + + boolean a = service.merge( "merge", false ); + assertTrue( a ); + + archivaConfigControl.verify(); + configControl.verify(); + configControl.verify(); + metadataRepositoryControl.verify(); + repositoryMergerControl.verify(); + repositoryTaskSchedulerControl.verify(); + } + + public void testMergeRepositoriesWithConflictsAndScan( ) + throws Exception + { + List sources = new ArrayList(); + ArtifactMetadata one = new ArtifactMetadata(); + one.setId( "one" ); + one.setVersion( "1.0" ); + + ArtifactMetadata two = new ArtifactMetadata(); + two.setId( "two" ); + two.setVersion( "1.0-SNAPSHOT" ); + + sources.add( one ); + sources.add( two ); + + List conflicts = new ArrayList(); + conflicts.add( one ); + + sources.removeAll( conflicts ); + + Filter artifactsWithOutConflicts = new IncludesFilter( sources ); + + RepositoryTask task = new RepositoryTask(); + task.setScanAll( true ); + + ManagedRepositoryConfiguration repo = createManagedRepo( "repo", "default", "repo", true, true ); + repo.setLocation( "target/test-repository/one" ); + ManagedRepositoryConfiguration staging = createStagingRepo( repo ); + + archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); + configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ), repo ); + configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), staging ); + + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources ); + repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( staging.getId(), repo.getId() ), conflicts ); + repositoryMerger.merge( staging.getId(), repo.getId(), artifactsWithOutConflicts ); + repositoryMergerControl.setMatcher( MockControl.ALWAYS_MATCHER ); + repositoryMergerControl.setVoidCallable(); + repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "repo" ), false); + repositoryTaskScheduler.queueTask( task ); + repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER ); + repositoryTaskSchedulerControl.setVoidCallable(); + + // audit logs + metadataRepository.addMetadataFacet( repo.getId() ,createAuditEvent( repo ) ); + metadataRepositoryControl.setMatcher( MockControl.ALWAYS_MATCHER ); + metadataRepositoryControl.setVoidCallable(); + + archivaConfigControl.replay(); + metadataRepositoryControl.replay(); + configControl.replay(); + repositoryMergerControl.replay(); + repositoryTaskSchedulerControl.replay(); + + boolean a = service.merge( "repo", true ); + assertTrue( a ); + + archivaConfigControl.verify(); + configControl.verify(); + configControl.verify(); + metadataRepositoryControl.verify(); + repositoryMergerControl.verify(); + repositoryTaskSchedulerControl.verify(); + } + /* private methods */ private void assertRemoteRepo( RemoteRepository remoteRepo, RemoteRepositoryConfiguration expectedRepoConfig ) @@ -663,6 +852,31 @@ public class AdministrationServiceImplTest return repoConfig; } + private ManagedRepositoryConfiguration createStagingRepo( ManagedRepositoryConfiguration repoConfig ) + { + ManagedRepositoryConfiguration stagingRepo = new ManagedRepositoryConfiguration(); + stagingRepo.setId( repoConfig.getId() + STAGE ); + stagingRepo.setLayout( repoConfig.getLayout() ); + stagingRepo.setName( repoConfig + STAGE ); + stagingRepo.setReleases( repoConfig.isReleases() ); + stagingRepo.setSnapshots( repoConfig.isSnapshots() ); + stagingRepo.setLocation( repoConfig.getLocation() ); + + return stagingRepo; + } + + private AuditEvent createAuditEvent( ManagedRepositoryConfiguration repoConfig ) + { + AuditEvent auditEvent = new AuditEvent(); + + auditEvent.setAction( AuditEvent.MERGE_REPO_REMOTE ); + auditEvent.setRepositoryId( repoConfig.getId() ); + auditEvent.setResource( repoConfig.getLocation() ); + auditEvent.setTimestamp( new Date( ) ); + + return auditEvent; + } + private void recordRepoConsumers() { List availableKnownConsumers = new ArrayList(); diff --git a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditEvent.java b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditEvent.java index bf84c90ab..77d7ad8de 100644 --- a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditEvent.java +++ b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditEvent.java @@ -101,6 +101,8 @@ public class AuditEvent public static final String REMOVE_PATTERN = "Removed File Type Pattern"; + public static final String MERGE_REPO_REMOTE = "Merged Staging Repository Triggered Remotely"; + private String repositoryId; private String userId; diff --git a/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java b/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java index 943b667d6..7b45b067d 100644 --- a/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java +++ b/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java @@ -325,7 +325,7 @@ public class Maven2RepositoryMerger return metadata; } - public List getConflictsartifacts( String sourceRepo, String targetRepo ) + public List getConflictingArtifacts( String sourceRepo, String targetRepo ) throws Exception { List targetArtifacts = metadataRepository.getArtifacts( targetRepo ); diff --git a/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/RepositoryMerger.java b/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/RepositoryMerger.java index 44fb3a172..85bb52cb5 100644 --- a/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/RepositoryMerger.java +++ b/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/RepositoryMerger.java @@ -19,6 +19,8 @@ package org.apache.archiva.stagerepository.merge; * under the License. */ +import java.util.List; + import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.filter.Filter; @@ -28,4 +30,7 @@ public interface RepositoryMerger throws Exception; void merge( String sourceRepoId, String targetRepoId, Filter filter ) throws Exception; -} + + public List getConflictingArtifacts( String sourceRepo, String targetRepo ) + throws Exception; +} \ No newline at end of file diff --git a/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMergerTest.java b/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMergerTest.java index 5773d1bba..2346850fc 100644 --- a/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMergerTest.java +++ b/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMergerTest.java @@ -154,7 +154,7 @@ public class Maven2RepositoryMergerTest when( metadataRepository.getArtifacts( sourceRepoId ) ).thenReturn( sourceRepoArtifactsList ); when( metadataRepository.getArtifacts( TEST_REPO_ID ) ).thenReturn( targetRepoArtifactsList ); - assertEquals( 1, repositoryMerger.getConflictsartifacts( sourceRepoId, TEST_REPO_ID ).size() ); + assertEquals( 1, repositoryMerger.getConflictingArtifacts( sourceRepoId, TEST_REPO_ID ).size() ); verify( metadataRepository ).getArtifacts( TEST_REPO_ID ); } diff --git a/pom.xml b/pom.xml index 352104cd7..95af5ffeb 100644 --- a/pom.xml +++ b/pom.xml @@ -508,6 +508,11 @@ archiva-xmlrpc-security 1.4-SNAPSHOT + + org.apache.archiva + stage-repository-merge + 1.4-SNAPSHOT + org.codehaus.plexus plexus-spring