]> source.dussan.org Git - archiva.git/blob
6ba6fc1748c56ac56f27942dcc85107427ef8b6e
[archiva.git] /
1 package org.apache.archiva.web.xmlrpc.services;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21
22 import org.apache.archiva.audit.AuditEvent;
23 import org.apache.archiva.audit.AuditListener;
24 import org.apache.archiva.metadata.model.ArtifactMetadata;
25 import org.apache.archiva.metadata.repository.MetadataRepository;
26 import org.apache.archiva.metadata.repository.RepositorySession;
27 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
28 import org.apache.archiva.metadata.repository.filter.Filter;
29 import org.apache.archiva.metadata.repository.filter.IncludesFilter;
30 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
31 import org.apache.archiva.repository.events.RepositoryListener;
32 import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
33 import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
34 import org.apache.archiva.scheduler.repository.RepositoryTask;
35 import org.apache.archiva.stagerepository.merge.RepositoryMerger;
36 import org.apache.archiva.web.xmlrpc.api.AdministrationService;
37 import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
38 import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
39 import org.apache.commons.io.FileUtils;
40 import org.apache.commons.lang.StringUtils;
41 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
42 import org.apache.maven.archiva.configuration.Configuration;
43 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
44 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
45 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
46 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
47 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
48 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
49 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
50 import org.apache.maven.archiva.model.VersionedReference;
51 import org.apache.maven.archiva.repository.ContentNotFoundException;
52 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
53 import org.apache.maven.archiva.repository.RepositoryContentFactory;
54 import org.apache.maven.archiva.repository.RepositoryException;
55 import org.apache.maven.archiva.repository.RepositoryNotFoundException;
56 import org.codehaus.plexus.registry.Registry;
57 import org.codehaus.plexus.registry.RegistryException;
58 import org.codehaus.plexus.scheduler.CronExpressionValidator;
59 import org.slf4j.Logger;
60 import org.slf4j.LoggerFactory;
61
62 import java.io.File;
63 import java.io.IOException;
64 import java.util.ArrayList;
65 import java.util.Collection;
66 import java.util.Date;
67 import java.util.List;
68 import java.util.Map;
69
70 /**
71  * AdministrationServiceImpl
72  *
73  * @version $Id: AdministrationServiceImpl.java
74  */
75 public class AdministrationServiceImpl
76     implements AdministrationService
77 {
78     protected Logger log = LoggerFactory.getLogger( getClass() );
79
80     private ArchivaConfiguration archivaConfiguration;
81
82     private RepositoryContentConsumers repoConsumersUtil;
83
84     private RepositoryContentFactory repoFactory;
85
86     private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
87
88     private Collection<RepositoryListener> listeners;
89
90     private RepositoryStatisticsManager repositoryStatisticsManager;
91
92     private RepositoryMerger repositoryMerger;
93
94     private static final String STAGE = "-stage";
95
96     private AuditListener auditListener;
97
98     private RepositorySessionFactory repositorySessionFactory;
99
100     private Registry registry;
101
102     public AdministrationServiceImpl( ArchivaConfiguration archivaConfig, RepositoryContentConsumers repoConsumersUtil,
103                                       RepositoryContentFactory repoFactory,
104                                       RepositorySessionFactory repositorySessionFactory,
105                                       RepositoryArchivaTaskScheduler repositoryTaskScheduler,
106                                       Collection<RepositoryListener> listeners,
107                                       RepositoryStatisticsManager repositoryStatisticsManager,
108                                       RepositoryMerger repositoryMerger, AuditListener auditListener,
109                                       Registry registry )
110     {
111         this.archivaConfiguration = archivaConfig;
112         this.repoConsumersUtil = repoConsumersUtil;
113         this.repoFactory = repoFactory;
114         this.repositoryTaskScheduler = repositoryTaskScheduler;
115         this.listeners = listeners;
116         this.repositorySessionFactory = repositorySessionFactory;
117         this.repositoryStatisticsManager = repositoryStatisticsManager;
118         this.repositoryMerger = repositoryMerger;
119         this.auditListener = auditListener;
120         this.registry = registry;
121     }
122
123     /**
124      * @see AdministrationService#configureRepositoryConsumer(String, String, boolean)
125      */
126     public Boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable )
127         throws Exception
128     {
129         // TODO use repoId once consumers are configured per repository! (MRM-930)
130
131         List<KnownRepositoryContentConsumer> knownConsumers = repoConsumersUtil.getAvailableKnownConsumers();
132         List<InvalidRepositoryContentConsumer> invalidConsumers = repoConsumersUtil.getAvailableInvalidConsumers();
133
134         boolean found = false;
135         boolean isKnownContentConsumer = false;
136         for ( KnownRepositoryContentConsumer consumer : knownConsumers )
137         {
138             if ( consumer.getId().equals( consumerId ) )
139             {
140                 found = true;
141                 isKnownContentConsumer = true;
142                 break;
143             }
144         }
145
146         if ( !found )
147         {
148             for ( InvalidRepositoryContentConsumer consumer : invalidConsumers )
149             {
150                 if ( consumer.getId().equals( consumerId ) )
151                 {
152                     found = true;
153                     break;
154                 }
155             }
156         }
157
158         if ( !found )
159         {
160             throw new Exception( "Invalid repository consumer." );
161         }
162
163         Configuration config = archivaConfiguration.getConfiguration();
164         RepositoryScanningConfiguration repoScanningConfig = config.getRepositoryScanning();
165
166         if ( isKnownContentConsumer )
167         {
168             repoScanningConfig.addKnownContentConsumer( consumerId );
169         }
170         else
171         {
172             repoScanningConfig.addInvalidContentConsumer( consumerId );
173         }
174
175         config.setRepositoryScanning( repoScanningConfig );
176         saveConfiguration( config );
177
178         return true;
179     }
180
181     /**
182      * @see AdministrationService#deleteArtifact(String, String, String, String)
183      */
184     public Boolean deleteArtifact( String repoId, String groupId, String artifactId, String version )
185         throws Exception
186     {
187         // TODO: remove duplication with web
188
189         Configuration config = archivaConfiguration.getConfiguration();
190         ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( repoId );
191
192         if ( repoConfig == null )
193         {
194             throw new Exception( "Repository does not exist." );
195         }
196
197         RepositorySession repositorySession = repositorySessionFactory.createSession();
198         try
199         {
200             ManagedRepositoryContent repoContent = repoFactory.getManagedRepositoryContent( repoId );
201             VersionedReference ref = new VersionedReference();
202             ref.setGroupId( groupId );
203             ref.setArtifactId( artifactId );
204             ref.setVersion( version );
205
206             // delete from file system
207             repoContent.deleteVersion( ref );
208
209             MetadataRepository metadataRepository = repositorySession.getRepository();
210             Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts( repoId, groupId, artifactId,
211                                                                                       version );
212
213             for ( ArtifactMetadata artifact : artifacts )
214             {
215                 // TODO: mismatch between artifact (snapshot) version and project (base) version here
216                 if ( artifact.getVersion().equals( version ) )
217                 {
218                     metadataRepository.removeArtifact( artifact.getRepositoryId(), artifact.getNamespace(),
219                                                        artifact.getProject(), artifact.getVersion(), artifact.getId() );
220
221                     // TODO: move into the metadata repository proper - need to differentiate attachment of
222                     // repository metadata to an artifact
223                     for ( RepositoryListener listener : listeners )
224                     {
225                         listener.deleteArtifact( metadataRepository, repoId, artifact.getNamespace(),
226                                                  artifact.getProject(), artifact.getVersion(), artifact.getId() );
227                     }
228                 }
229             }
230             repositorySession.save();
231         }
232         catch ( ContentNotFoundException e )
233         {
234             throw new Exception( "Artifact does not exist." );
235         }
236         catch ( RepositoryNotFoundException e )
237         {
238             throw new Exception( "Repository does not exist." );
239         }
240         catch ( RepositoryException e )
241         {
242             throw new Exception( "Repository exception occurred." );
243         }
244         finally
245         {
246             repositorySession.close();
247         }
248
249         return true;
250     }
251
252     /**
253      * @see AdministrationService#executeRepositoryScanner(String)
254      */
255     public Boolean executeRepositoryScanner( String repoId )
256         throws Exception
257     {
258         Configuration config = archivaConfiguration.getConfiguration();
259         if ( config.findManagedRepositoryById( repoId ) == null )
260         {
261             throw new Exception( "Repository does not exist." );
262         }
263
264         if ( repositoryTaskScheduler.isProcessingRepositoryTask( repoId ) )
265         {
266             return false;
267         }
268
269         RepositoryTask task = new RepositoryTask();
270         task.setRepositoryId( repoId );
271
272         repositoryTaskScheduler.queueTask( task );
273
274         return true;
275     }
276
277     /**
278      * @see AdministrationService#getAllRepositoryConsumers()
279      */
280     public List<String> getAllRepositoryConsumers()
281     {
282         List<String> consumers = new ArrayList<String>();
283
284         List<KnownRepositoryContentConsumer> knownConsumers = repoConsumersUtil.getAvailableKnownConsumers();
285         List<InvalidRepositoryContentConsumer> invalidConsumers = repoConsumersUtil.getAvailableInvalidConsumers();
286
287         for ( KnownRepositoryContentConsumer consumer : knownConsumers )
288         {
289             consumers.add( consumer.getId() );
290         }
291
292         for ( InvalidRepositoryContentConsumer consumer : invalidConsumers )
293         {
294             consumers.add( consumer.getId() );
295         }
296
297         return consumers;
298     }
299
300     /**
301      * @see AdministrationService#getAllManagedRepositories()
302      */
303     public List<ManagedRepository> getAllManagedRepositories()
304     {
305         List<ManagedRepository> managedRepos = new ArrayList<ManagedRepository>();
306
307         Configuration config = archivaConfiguration.getConfiguration();
308         List<ManagedRepositoryConfiguration> managedRepoConfigs = config.getManagedRepositories();
309
310         for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
311         {
312             // TODO fix resolution of repo url!
313             ManagedRepository repo = new ManagedRepository( repoConfig.getId(), repoConfig.getName(), "URL",
314                                                             repoConfig.getLayout(), repoConfig.isSnapshots(),
315                                                             repoConfig.isReleases() );
316             managedRepos.add( repo );
317         }
318
319         return managedRepos;
320     }
321
322     /**
323      * @see AdministrationService#getAllRemoteRepositories()
324      */
325     public List<RemoteRepository> getAllRemoteRepositories()
326     {
327         List<RemoteRepository> remoteRepos = new ArrayList<RemoteRepository>();
328
329         Configuration config = archivaConfiguration.getConfiguration();
330         List<RemoteRepositoryConfiguration> remoteRepoConfigs = config.getRemoteRepositories();
331
332         for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs )
333         {
334             RemoteRepository repo = new RemoteRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getUrl(),
335                                                           repoConfig.getLayout() );
336             remoteRepos.add( repo );
337         }
338
339         return remoteRepos;
340     }
341
342     private void saveConfiguration( Configuration config )
343         throws Exception
344     {
345         try
346         {
347             archivaConfiguration.save( config );
348         }
349         catch ( RegistryException e )
350         {
351             throw new Exception( "Error occurred in the registry." );
352         }
353         catch ( IndeterminateConfigurationException e )
354         {
355             throw new Exception( "Error occurred while saving the configuration." );
356         }
357     }
358
359     public Boolean addManagedRepository( String repoId, String layout, String name, String location,
360                                          boolean blockRedeployments, boolean releasesIncluded,
361                                          boolean snapshotsIncluded, boolean stageRepoNeeded, String cronExpression )
362         throws Exception
363     {
364
365         Configuration config = archivaConfiguration.getConfiguration();
366
367         CronExpressionValidator validator = new CronExpressionValidator();
368
369         if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
370         {
371             throw new Exception( "Unable to add new repository with id [" + repoId +
372                                      "], that id already exists as a managed repository." );
373         }
374         else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
375         {
376             throw new Exception( "Unable to add new repository with id [" + repoId +
377                                      "], that id already exists as a remote repository." );
378         }
379         else if ( config.getRepositoryGroupsAsMap().containsKey( repoId ) )
380         {
381             throw new Exception( "Unable to add new repository with id [" + repoId +
382                                      "], that id already exists as a repository group." );
383         }
384
385         if ( !validator.validate( cronExpression ) )
386         {
387             throw new Exception( "Invalid cron expression." );
388         }
389
390         ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration();
391
392         repository.setId( repoId );
393         repository.setBlockRedeployments( blockRedeployments );
394         repository.setReleases( releasesIncluded );
395         repository.setSnapshots( snapshotsIncluded );
396         repository.setName( name );
397         repository.setLocation( removeExpressions( location ) );
398         repository.setLayout( layout );
399         repository.setRefreshCronExpression( cronExpression );
400
401         addRepository( repository, config );
402
403         if ( stageRepoNeeded )
404         {
405             ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
406             addRepository( stagingRepository, config );
407         }
408
409         saveConfiguration( config );
410         return Boolean.TRUE;
411     }
412
413     public Boolean deleteManagedRepository( String repoId )
414         throws Exception
415     {
416         Configuration config = archivaConfiguration.getConfiguration();
417
418         ManagedRepositoryConfiguration repository = config.findManagedRepositoryById( repoId );
419
420         if ( repository == null )
421         {
422             throw new Exception( "A repository with that id does not exist" );
423         }
424
425         RepositorySession repositorySession = repositorySessionFactory.createSession();
426         try
427         {
428             MetadataRepository metadataRepository = repositorySession.getRepository();
429             metadataRepository.removeRepository( repository.getId() );
430             repositoryStatisticsManager.deleteStatistics( metadataRepository, repository.getId() );
431             repositorySession.save();
432         }
433         finally
434         {
435             repositorySession.close();
436         }
437         config.removeManagedRepository( repository );
438
439         try
440         {
441             saveConfiguration( config );
442         }
443         catch ( Exception e )
444         {
445             throw new Exception( "Error saving configuration for delete action" + e.getMessage() );
446         }
447
448         File dir = new File( repository.getLocation() );
449         if ( !FileUtils.deleteQuietly( dir ) )
450         {
451             throw new IOException( "Cannot delete repository " + dir );
452         }
453
454         List<ProxyConnectorConfiguration> proxyConnectors = config.getProxyConnectors();
455         for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
456         {
457             if ( StringUtils.equals( proxyConnector.getSourceRepoId(), repository.getId() ) )
458             {
459                 archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector );
460             }
461         }
462
463         Map<String, List<String>> repoToGroupMap = archivaConfiguration.getConfiguration().getRepositoryToGroupMap();
464         if ( repoToGroupMap != null )
465         {
466             if ( repoToGroupMap.containsKey( repository.getId() ) )
467             {
468                 List<String> repoGroups = repoToGroupMap.get( repository.getId() );
469                 for ( String repoGroup : repoGroups )
470                 {
471                     archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository(
472                         repository.getId() );
473                 }
474             }
475         }
476
477         return Boolean.TRUE;
478     }
479
480     public Boolean deleteManagedRepositoryContent( String repoId )
481         throws Exception
482     {
483         Configuration config = archivaConfiguration.getConfiguration();
484
485         ManagedRepositoryConfiguration repository = config.findManagedRepositoryById( repoId );
486
487         if ( repository == null )
488         {
489             throw new Exception( "Repository Id : " + repoId + " not found." );
490         }
491
492         RepositorySession repositorySession = repositorySessionFactory.createSession();
493         try
494         {
495             MetadataRepository metadataRepository = repositorySession.getRepository();
496             metadataRepository.removeRepository( repository.getId() );
497             repositorySession.save();
498         }
499         finally
500         {
501             repositorySession.close();
502         }
503
504         File repoDir = new File( repository.getLocation() );
505         File[] children = repoDir.listFiles();
506
507         if ( children != null )
508         {
509             for ( File child : children )
510             {
511                 FileUtils.deleteQuietly( child );
512             }
513
514             if ( repoDir.listFiles().length > 0 )
515             {
516                 throw new IOException( "Cannot delete repository contents of " + repoDir );
517             }
518         }
519
520         return Boolean.TRUE;
521     }
522
523     public ManagedRepository getManagedRepository( String repoId )
524         throws Exception
525     {
526         Configuration config = archivaConfiguration.getConfiguration();
527         ManagedRepositoryConfiguration managedRepository = config.findManagedRepositoryById( repoId );
528         if ( managedRepository == null )
529         {
530             throw new Exception( "A repository with that id does not exist" );
531         }
532         ManagedRepository repo = new ManagedRepository( managedRepository.getId(), managedRepository.getName(), "URL",
533                                                         managedRepository.getLayout(), managedRepository.isSnapshots(),
534                                                         managedRepository.isReleases() );
535
536         return repo;
537     }
538
539     public boolean merge( String repoId, boolean skipConflicts )
540         throws Exception
541     {
542         String stagingId = repoId + STAGE;
543         ManagedRepositoryConfiguration repoConfig;
544         ManagedRepositoryConfiguration stagingConfig;
545
546         Configuration config = archivaConfiguration.getConfiguration();
547         repoConfig = config.findManagedRepositoryById( repoId );
548
549         log.debug( "Retrieved repository configuration for repo '" + repoId + "'" );
550
551         RepositorySession repositorySession = repositorySessionFactory.createSession();
552         try
553         {
554             MetadataRepository metadataRepository = repositorySession.getRepository();
555             if ( repoConfig != null )
556             {
557                 stagingConfig = config.findManagedRepositoryById( stagingId );
558
559                 if ( stagingConfig != null )
560                 {
561                     List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( stagingId );
562
563                     if ( repoConfig.isReleases() && !repoConfig.isSnapshots() )
564                     {
565                         log.info( "Repository to be merged contains releases only.." );
566                         if ( skipConflicts )
567                         {
568                             List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts(
569                                 metadataRepository, repoId, stagingId );
570
571                             if ( log.isDebugEnabled() )
572                             {
573                                 log.debug( "Artifacts in conflict.." );
574                                 for ( ArtifactMetadata metadata : conflicts )
575                                 {
576                                     log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":" +
577                                                    metadata.getProjectVersion() );
578                                 }
579                             }
580
581                             sourceArtifacts.removeAll( conflicts );
582
583                             log.debug( "Source artifacts size :: " + sourceArtifacts.size() );
584                             mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId, metadataRepository );
585                         }
586                         else
587                         {
588                             log.debug( "Source artifacts size :: " + sourceArtifacts.size() );
589                             mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId, metadataRepository );
590                         }
591                     }
592                     else
593                     {
594                         log.info( "Repository to be merged has snapshot artifacts.." );
595                         if ( skipConflicts )
596                         {
597                             List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts(
598                                 metadataRepository, repoId, stagingId );
599
600                             if ( log.isDebugEnabled() )
601                             {
602                                 log.debug( "Artifacts in conflict.." );
603                                 for ( ArtifactMetadata metadata : conflicts )
604                                 {
605                                     log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":" +
606                                                    metadata.getProjectVersion() );
607                                 }
608                             }
609
610                             sourceArtifacts.removeAll( conflicts );
611
612                             log.debug( "Source artifacts size :: " + sourceArtifacts.size() );
613
614                             Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>(
615                                 sourceArtifacts );
616                             repositoryMerger.merge( metadataRepository, stagingId, repoId, artifactsWithOutConflicts );
617
618                             log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '" +
619                                           repoId + "'." );
620                         }
621                         else
622                         {
623                             repositoryMerger.merge( metadataRepository, stagingId, repoId );
624
625                             log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '" +
626                                           repoId + "'." );
627                         }
628                     }
629                 }
630                 else
631                 {
632                     throw new Exception( "Staging Id : " + stagingId + " not found." );
633                 }
634             }
635             else
636             {
637                 throw new Exception( "Repository Id : " + repoId + " not found." );
638             }
639
640             if ( !repositoryTaskScheduler.isProcessingRepositoryTask( repoId ) )
641             {
642                 RepositoryTask task = new RepositoryTask();
643                 task.setRepositoryId( repoId );
644
645                 repositoryTaskScheduler.queueTask( task );
646             }
647
648             AuditEvent event = createAuditEvent( repoConfig );
649
650             // add event for audit log reports
651             metadataRepository.addMetadataFacet( event.getRepositoryId(), event );
652
653             // log event in archiva audit log
654             auditListener.auditEvent( createAuditEvent( repoConfig ) );
655             repositorySession.save();
656         }
657         finally
658         {
659             repositorySession.close();
660         }
661
662         return true;
663     }
664
665     protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
666         throws IOException
667     {
668         // Normalize the path
669         File file = new File( repository.getLocation() );
670         repository.setLocation( file.getCanonicalPath() );
671         if ( !file.exists() )
672         {
673             file.mkdirs();
674         }
675         if ( !file.exists() || !file.isDirectory() )
676         {
677             throw new IOException(
678                 "Unable to add repository - no write access, can not create the root directory: " + file );
679         }
680
681         configuration.addManagedRepository( repository );
682     }
683
684     // todo: setting userid of audit event
685     private AuditEvent createAuditEvent( ManagedRepositoryConfiguration repoConfig )
686     {
687
688         AuditEvent event = new AuditEvent();
689         event.setAction( AuditEvent.MERGE_REPO_REMOTE );
690         event.setRepositoryId( repoConfig.getId() );
691         event.setResource( repoConfig.getLocation() );
692         event.setTimestamp( new Date() );
693
694         return event;
695     }
696
697     private void mergeWithOutSnapshots( List<ArtifactMetadata> sourceArtifacts, String sourceRepoId, String repoid,
698                                         MetadataRepository metadataRepository )
699         throws Exception
700     {
701         List<ArtifactMetadata> artifactsWithOutSnapshots = new ArrayList<ArtifactMetadata>();
702         for ( ArtifactMetadata metadata : sourceArtifacts )
703         {
704
705             if ( metadata.getProjectVersion().contains( "SNAPSHOT" ) )
706             {
707                 artifactsWithOutSnapshots.add( metadata );
708             }
709
710         }
711         sourceArtifacts.removeAll( artifactsWithOutSnapshots );
712
713         Filter<ArtifactMetadata> artifactListWithOutSnapShots = new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
714
715         repositoryMerger.merge( metadataRepository, sourceRepoId, repoid, artifactListWithOutSnapShots );
716     }
717
718     private ManagedRepositoryConfiguration getStageRepoConfig( ManagedRepositoryConfiguration repository )
719     {
720         ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
721         stagingRepository.setId( repository.getId() + "-stage" );
722         stagingRepository.setLayout( repository.getLayout() );
723         stagingRepository.setName( repository.getName() + "-stage" );
724         stagingRepository.setBlockRedeployments( repository.isBlockRedeployments() );
725         stagingRepository.setDaysOlder( repository.getDaysOlder() );
726         stagingRepository.setDeleteReleasedSnapshots( repository.isDeleteReleasedSnapshots() );
727         stagingRepository.setIndexDir( repository.getIndexDir() );
728         String path = repository.getLocation();
729         int lastIndex = path.lastIndexOf( '/' );
730         stagingRepository.setLocation( path.substring( 0, lastIndex ) + "/" + stagingRepository.getId() );
731         stagingRepository.setRefreshCronExpression( repository.getRefreshCronExpression() );
732         stagingRepository.setReleases( repository.isReleases() );
733         stagingRepository.setRetentionCount( repository.getRetentionCount() );
734         stagingRepository.setScanned( repository.isScanned() );
735         stagingRepository.setSnapshots( repository.isSnapshots() );
736         return stagingRepository;
737     }
738
739     private String removeExpressions( String directory )
740     {
741         String value = StringUtils.replace( directory, "${appserver.base}", registry.getString( "appserver.base",
742                                                                                                 "${appserver.base}" ) );
743         value = StringUtils.replace( value, "${appserver.home}", registry.getString( "appserver.home",
744                                                                                      "${appserver.home}" ) );
745         return value;
746     }
747 }