]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1409] web services for repository merge
authorMaria Odea B. Ching <oching@apache.org>
Fri, 1 Oct 2010 03:50:04 +0000 (03:50 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Fri, 1 Oct 2010 03:50:04 +0000 (03:50 +0000)
submitted by Gwen Harold Autencio

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1003378 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/MergeAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/pom.xml
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/main/java/org/apache/archiva/web/xmlrpc/security/ServiceMethodsPermissionsMapping.java
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditEvent.java
archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java
archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/RepositoryMerger.java
archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMergerTest.java
pom.xml

index ff252a151958a2c70fc3198278c1c62955ab8a8b..9dc984d0de532c4065d172c2c6d1095e35c057e9 100644 (file)
@@ -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();
index 144eccb40feebcc452ed005a0553e913b946e7ea..1a8c45ce1f001e357b9ba0d4735d3f17ca5b60aa 100644 (file)
     <constructor-arg>
       <bean class="org.apache.archiva.web.spring.RepositoryListenerFactoryBean" />
     </constructor-arg>       
-    <constructor-arg ref="repositoryStatisticsManager"/>    
+    <constructor-arg ref="repositoryStatisticsManager"/>
+    <constructor-arg ref="repositoryMerger#maven2"/>
+    <constructor-arg ref="auditListener#logging"/>
+       
   </bean> 
 
   <bean name="xmlrpcServicesList" lazy-init="true" scope="singleton" class="java.util.ArrayList">
index b307f9b1be5666ed6f64285f0b5894e446b7d0c4..f2ad04de08525abb85aec87edc5979bd4aba2e36 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-indexer</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>stage-repository-merge</artifactId>
+    </dependency>
     <dependency>
       <groupId>com.atlassian.xmlrpc</groupId>
       <artifactId>atlassian-xmlrpc-binder-annotations</artifactId>
index 84e23433b53a541943f05c029aafed57212b36b9..ecff3da4ef42573faf1084dd479758d7bb826206 100644 (file)
@@ -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;
+   
 }
index d194a910d19e556277df7ece781b6d6892fe9ee6..457ab8b7bb8fd10edec66a4871488f4e07755dc5 100644 (file)
@@ -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<String> SERVICE_METHODS_FOR_OPERATION_RUN_INDEXER =
         Arrays.asList( "AdministrationService.executeRepositoryScanner" );
index c62817b77ca27db0d593b4daaa7160f0c94df9c9..06377c24d21b8c097582eebad07441dbd8b09354 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-xmlrpc-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>audit</artifactId>
+    </dependency>    
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-repository-scanner</artifactId>
@@ -79,6 +83,6 @@
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
       <scope>test</scope>
-    </dependency>
+    </dependency>    
   </dependencies>
 </project>
index 33bea017b9bd5984953b82424357671b4dac836b..08db94ec72a9e5b6086b8406195911e3f8b20ea5 100644 (file)
@@ -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<RepositoryListener> 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<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( stagingId );
+                
+                if( repoConfig.isReleases() && !repoConfig.isSnapshots() )
+                {
+                    if( skipConflicts )
+                    {        
+                        List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts( stagingId, stagingId );
+                        sourceArtifacts.removeAll( conflicts );
+                        mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId );
+                    }
+                    else
+                    {
+                        mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId );    
+                    }       
+                }
+                else
+                {
+                    if( skipConflicts )
+                    {
+                        List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts( stagingId, stagingId );
+                        sourceArtifacts.removeAll( conflicts );
+                        Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>( 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<ArtifactMetadata> sourceArtifacts, String sourceRepoId, String repoid )
+        throws Exception
+    {
+        List<ArtifactMetadata> artifactsWithOutSnapshots = new ArrayList<ArtifactMetadata>();
+        for ( ArtifactMetadata metadata : sourceArtifacts )
+        {
+    
+            if ( metadata.getProjectVersion().contains( "SNAPSHOT" ) )
+            {
+                artifactsWithOutSnapshots.add( metadata );
+            }
+    
+        }
+        sourceArtifacts.removeAll( artifactsWithOutSnapshots );
+    
+        Filter<ArtifactMetadata> artifactListWithOutSnapShots = new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
+        
+        repositoryMerger.merge( sourceRepoId, repoid, artifactListWithOutSnapShots );
+    }
 }
index 5b0a2bdd5d2b28a8a4fa37ad2c4ebc5cbe5030e6..50ba22f6303611d3fa36e32aa1603f513e04f829 100644 (file)
@@ -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<ArtifactMetadata> sources = new ArrayList<ArtifactMetadata>();
+        
+        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<ArtifactMetadata> sources = new ArrayList<ArtifactMetadata>();
+        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<ArtifactMetadata> conflicts = new ArrayList<ArtifactMetadata>();
+        conflicts.add( one );
+        
+        sources.removeAll( conflicts );
+        
+        Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>( 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<KnownRepositoryContentConsumer> availableKnownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
index bf84c90abcc66ac6018cd43dd550ccbad28e5b18..77d7ad8dea256cd6b33386129f605e37640914d1 100644 (file)
@@ -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;
index 943b667d62ed99d6ef0a5057eb2f5c7fb7bb4b67..7b45b067dc1697b2865ffb641f8afa55a1bd348f 100644 (file)
@@ -325,7 +325,7 @@ public class Maven2RepositoryMerger
         return metadata;
     }
 
-    public List<ArtifactMetadata> getConflictsartifacts( String sourceRepo, String targetRepo )
+    public List<ArtifactMetadata> getConflictingArtifacts( String sourceRepo, String targetRepo )
         throws Exception
     {
         List<ArtifactMetadata> targetArtifacts = metadataRepository.getArtifacts( targetRepo );
index 44fb3a1729165adbafc4742308597075bed542ae..85bb52cb53c756049f71d230f3ed497f79e7ef44 100644 (file)
@@ -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<ArtifactMetadata> filter ) throws Exception;
-}
+    
+    public List<ArtifactMetadata> getConflictingArtifacts( String sourceRepo, String targetRepo )
+        throws Exception;
+}
\ No newline at end of file
index 5773d1bbaa4f40e8328d555f682c07c3a0cb0a77..2346850fc8137f2496f092748678b5689b43b39e 100644 (file)
@@ -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 352104cd7b709b27083d29d4832fcd7658d24f76..95af5ffeb24b04f9b3f35653e920215b983bec7d 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <artifactId>archiva-xmlrpc-security</artifactId>
         <version>1.4-SNAPSHOT</version>
       </dependency>
+      <dependency>
+        <groupId>org.apache.archiva</groupId>
+        <artifactId>stage-repository-merge</artifactId>
+        <version>1.4-SNAPSHOT</version>
+      </dependency>
       <dependency>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-spring</artifactId>