1 package org.apache.archiva.repository;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.archiva.configuration.ArchivaConfiguration;
23 import org.apache.archiva.configuration.Configuration;
24 import org.apache.archiva.configuration.ConfigurationEvent;
25 import org.apache.archiva.configuration.ConfigurationListener;
26 import org.apache.archiva.configuration.IndeterminateConfigurationException;
27 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
28 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
29 import org.apache.archiva.redback.components.registry.RegistryException;
30 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
31 import org.apache.archiva.repository.features.StagingRepositoryFeature;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.stereotype.Service;
36 import javax.annotation.PostConstruct;
37 import javax.inject.Inject;
38 import javax.inject.Named;
39 import java.util.Collection;
40 import java.util.Collections;
41 import java.util.HashMap;
42 import java.util.LinkedHashMap;
43 import java.util.List;
45 import java.util.concurrent.locks.ReentrantReadWriteLock;
46 import java.util.stream.Collectors;
47 import java.util.stream.Stream;
50 * Registry for repositories. This is the central entry point for repositories. It provides methods for
51 * retrieving, adding and removing repositories.
53 * The modification methods addXX and removeXX persist the changes immediately to the configuration. If the
54 * configuration save fails the changes are rolled back.
56 * TODO: Audit events should be sent, but we don't want dependency to the repsitory-metadata-api
58 @Service( "repositoryRegistry" )
59 public class RepositoryRegistry implements ConfigurationListener {
61 private static final Logger log = LoggerFactory.getLogger( RepositoryRegistry.class );
64 * We inject all repository providers
67 List<RepositoryProvider> repositoryProviders;
70 ArchivaConfiguration archivaConfiguration;
73 @Named("repositoryContentFactory#default")
74 RepositoryContentFactory repositoryContentFactory;
78 private Map<String, ManagedRepository> managedRepositories = new HashMap<>( );
79 private Map<String, ManagedRepository> uManagedRepository = Collections.unmodifiableMap( managedRepositories );
81 private Map<String, RemoteRepository> remoteRepositories = new HashMap<>( );
82 private Map<String, RemoteRepository> uRemoteRepositories = Collections.unmodifiableMap( remoteRepositories );
84 private ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock( );
86 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration) {
87 this.archivaConfiguration = archivaConfiguration;
91 private void initialize( )
93 rwLock.writeLock( ).lock( );
96 managedRepositories.clear( );
97 managedRepositories.putAll( getManagedRepositoriesFromConfig( ) );
98 remoteRepositories.clear( );
99 remoteRepositories.putAll( getRemoteRepositoriesFromConfig( ) );
100 // archivaConfiguration.addChangeListener(this);
101 archivaConfiguration.addListener(this);
105 rwLock.writeLock( ).unlock( );
109 private Map<RepositoryType, RepositoryProvider> createProviderMap( )
111 Map<RepositoryType, RepositoryProvider> map = new HashMap<>( );
112 if ( repositoryProviders != null )
114 for ( RepositoryProvider provider : repositoryProviders )
116 for ( RepositoryType type : provider.provides( ) )
118 map.put( type, provider );
125 private RepositoryProvider getProvider( RepositoryType type ) throws RepositoryException
127 return repositoryProviders.stream( ).filter( repositoryProvider -> repositoryProvider.provides( ).contains( type ) ).findFirst( ).orElseThrow( ( ) -> new RepositoryException( "Repository type cannot be handled: " + type ) );
130 private Map<String, ManagedRepository> getManagedRepositoriesFromConfig( )
134 List<ManagedRepositoryConfiguration> managedRepoConfigs =
135 getArchivaConfiguration( ).getConfiguration( ).getManagedRepositories( );
137 if ( managedRepoConfigs == null )
139 return Collections.EMPTY_MAP;
142 Map<String, ManagedRepository> managedRepos = new LinkedHashMap<>( managedRepoConfigs.size( ) );
144 Map<RepositoryType, RepositoryProvider> providerMap = createProviderMap( );
145 for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
147 RepositoryType repositoryType = RepositoryType.valueOf( repoConfig.getType( ) );
148 if ( providerMap.containsKey( repositoryType ) )
152 ManagedRepository repo = createNewManagedRepository( providerMap.get( repositoryType ), repoConfig );
153 managedRepos.put( repo.getId( ), repo );
155 catch ( Exception e )
157 log.error( "Could not create managed repository {}: {}", repoConfig.getId( ), e.getMessage( ), e );
162 } catch (Throwable e) {
163 log.error("Could not initialize repositories from config: {}",e.getMessage(), e );
164 //noinspection unchecked
165 return Collections.EMPTY_MAP;
169 private ManagedRepository createNewManagedRepository( RepositoryProvider provider, ManagedRepositoryConfiguration cfg ) throws RepositoryException
171 ManagedRepository repo = provider.createManagedInstance( cfg );
172 updateRepositoryReferences( provider, repo, cfg , null);
177 private void updateRepositoryReferences(RepositoryProvider provider, ManagedRepository repo, ManagedRepositoryConfiguration cfg, Configuration configuration) throws RepositoryException
179 if ( repo.supportsFeature( StagingRepositoryFeature.class ) )
181 StagingRepositoryFeature feature = repo.getFeature( StagingRepositoryFeature.class ).get( );
182 if ( feature.isStageRepoNeeded( ) && feature.getStagingRepository() == null)
184 ManagedRepository stageRepo = getStagingRepository( provider, cfg, configuration);
185 managedRepositories.put(stageRepo.getId(), stageRepo);
186 feature.setStagingRepository( stageRepo );
187 if (configuration!=null) {
188 replaceOrAddRepositoryConfig( provider.getManagedConfiguration( stageRepo ), configuration );
192 if ( repo instanceof EditableManagedRepository && repo.getContent() == null)
194 ( (EditableManagedRepository) repo ).setContent( repositoryContentFactory.getManagedRepositoryContent( cfg, repo ) );
198 private ManagedRepository getStagingRepository(RepositoryProvider provider, ManagedRepositoryConfiguration baseRepoCfg, Configuration configuration) throws RepositoryException
200 ManagedRepository stageRepo = getManagedRepository( baseRepoCfg.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX );
201 if ( stageRepo == null )
203 stageRepo = provider.createStagingInstance( baseRepoCfg );
204 ManagedRepositoryConfiguration stageCfg = provider.getManagedConfiguration( stageRepo );
205 updateRepositoryReferences( provider, stageRepo, stageCfg, configuration);
213 private Map<String, RemoteRepository> getRemoteRepositoriesFromConfig( )
217 List<RemoteRepositoryConfiguration> remoteRepoConfigs =
218 getArchivaConfiguration( ).getConfiguration( ).getRemoteRepositories( );
220 if ( remoteRepoConfigs == null )
222 //noinspection unchecked
223 return Collections.EMPTY_MAP;
226 Map<String, RemoteRepository> remoteRepos = new LinkedHashMap<>( remoteRepoConfigs.size( ) );
228 Map<RepositoryType, RepositoryProvider> providerMap = createProviderMap( );
229 for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs )
231 RepositoryType repositoryType = RepositoryType.valueOf( repoConfig.getType( ) );
232 if ( providerMap.containsKey( repositoryType ) )
234 RepositoryProvider provider = getProvider( repositoryType );
238 RemoteRepository remoteRepository = createNewRemoteRepository( provider, repoConfig );
239 remoteRepos.put( repoConfig.getId( ), remoteRepository);
241 catch ( Exception e )
243 log.error( "Could not create repository {} from config: {}", repoConfig.getId( ), e.getMessage( ), e );
249 } catch (Throwable e) {
250 log.error("Could not initialize remote repositories from config: {}", e.getMessage(), e);
251 //noinspection unchecked
252 return Collections.EMPTY_MAP;
256 private RemoteRepository createNewRemoteRepository( RepositoryProvider provider, RemoteRepositoryConfiguration cfg ) throws RepositoryException
258 RemoteRepository repo = provider.createRemoteInstance( cfg );
259 updateRepositoryReferences( provider, repo, cfg , null);
264 private void updateRepositoryReferences( RepositoryProvider provider, RemoteRepository repo, RemoteRepositoryConfiguration cfg, Configuration configuration) throws RepositoryException
266 if ( repo instanceof EditableRemoteRepository && repo.getContent() == null)
268 ( (EditableRemoteRepository) repo ).setContent( repositoryContentFactory.getRemoteRepositoryContent( cfg, repo ) );
272 private ArchivaConfiguration getArchivaConfiguration( )
274 return this.archivaConfiguration;
278 * Returns all repositories that are registered. There is no defined order of the returned repositories.
280 * @return a list of managed and remote repositories
282 public Collection<Repository> getRepositories( )
284 rwLock.readLock( ).lock( );
287 return Stream.concat( managedRepositories.values( ).stream( ), remoteRepositories.values( ).stream( ) ).collect( Collectors.toList( ) );
291 rwLock.readLock( ).unlock( );
296 * Returns only the managed repositories. There is no defined order of the returned repositories.
298 * @return a list of managed repositories
300 public Collection<ManagedRepository> getManagedRepositories( )
302 rwLock.readLock().lock();
305 return uManagedRepository.values( );
308 rwLock.readLock().unlock();
313 * Returns only the remote repositories. There is no defined order of the returned repositories.
315 * @return a list of remote repositories
317 public Collection<RemoteRepository> getRemoteRepositories( )
319 rwLock.readLock().lock();
322 return uRemoteRepositories.values( );
325 rwLock.readLock().unlock();
330 * Returns the repository with the given id. The returned repository may be a managed or remote repository.
331 * It returns null, if no repository is registered with the given id.
333 * @param repoId the repository id
334 * @return the repository if found, otherwise null
336 public Repository getRepository( String repoId )
338 rwLock.readLock( ).lock( );
341 if ( managedRepositories.containsKey( repoId ) )
343 return managedRepositories.get( repoId );
347 return remoteRepositories.get( repoId );
352 rwLock.readLock( ).unlock( );
357 * Convenience method, that returns the managed repository with the given id.
358 * It returns null, if no managed repository is registered with this id.
360 * @param repoId the repository id
361 * @return the managed repository if found, otherwise null
363 public ManagedRepository getManagedRepository( String repoId )
365 rwLock.readLock( ).lock( );
368 return managedRepositories.get( repoId );
372 rwLock.readLock( ).unlock( );
377 * Convenience method, that returns the remote repository with the given id.
378 * It returns null, if no remote repository is registered with this id.
380 * @param repoId the repository id
381 * @return the remote repository if found, otherwise null
383 public RemoteRepository getRemoteRepository( String repoId )
385 rwLock.readLock( ).lock( );
388 return remoteRepositories.get( repoId );
392 rwLock.readLock( ).unlock( );
397 * Adds a new repository to the current list, or replaces the repository definition with
398 * the same id, if it exists already.
399 * The change is saved to the configuration immediately.
401 * @param managedRepository the new repository.
402 * @throws RepositoryException if the new repository could not be saved to the configuration.
404 public ManagedRepository putRepository( ManagedRepository managedRepository ) throws RepositoryException
406 rwLock.writeLock( ).lock( );
409 final String id = managedRepository.getId();
410 if (remoteRepositories.containsKey( id )) {
411 throw new RepositoryException( "There exists a remote repository with id "+id+". Could not update with managed repository." );
414 ManagedRepository originRepo = managedRepositories.put( id, managedRepository );
417 RepositoryProvider provider = getProvider( managedRepository.getType() );
418 ManagedRepositoryConfiguration newCfg = provider.getManagedConfiguration( managedRepository );
419 Configuration configuration = getArchivaConfiguration( ).getConfiguration( );
420 updateRepositoryReferences( provider, managedRepository, newCfg, configuration );
421 ManagedRepositoryConfiguration oldCfg = configuration.findManagedRepositoryById( id );
423 configuration.removeManagedRepository( oldCfg );
425 configuration.addManagedRepository( newCfg );
426 getArchivaConfiguration( ).save( configuration );
427 return managedRepository;
429 catch ( Exception e )
432 if ( originRepo != null )
434 managedRepositories.put( id, originRepo );
436 managedRepositories.remove(id);
438 log.error("Exception during configuration update {}", e.getMessage(), e);
439 throw new RepositoryException( "Could not save the configuration" + (e.getMessage( )==null?"":": "+e.getMessage()) );
444 rwLock.writeLock( ).unlock( );
449 * Adds a new repository or updates the repository with the same id, if it exists already.
450 * The configuration is saved immediately.
452 * @param managedRepositoryConfiguration the repository configuration
453 * @return the updated or created repository
454 * @throws RepositoryException if an error occurs, or the configuration is not valid.
456 public ManagedRepository putRepository( ManagedRepositoryConfiguration managedRepositoryConfiguration) throws RepositoryException
458 rwLock.writeLock( ).lock( );
461 final String id = managedRepositoryConfiguration.getId();
462 final RepositoryType repositoryType = RepositoryType.valueOf( managedRepositoryConfiguration.getType() );
463 Configuration configuration = getArchivaConfiguration().getConfiguration();
464 ManagedRepository repo = managedRepositories.get(id);
465 ManagedRepositoryConfiguration oldCfg = repo!=null ? getProvider( repositoryType ).getManagedConfiguration( repo ) : null;
466 repo = putRepository( managedRepositoryConfiguration, configuration );
469 getArchivaConfiguration().save(configuration);
471 catch ( IndeterminateConfigurationException | RegistryException e )
474 getProvider( repositoryType ).updateManagedInstance( (EditableManagedRepository)repo, oldCfg );
476 log.error("Could not save the configuration for repository {}: {}", id, e.getMessage(),e );
477 throw new RepositoryException( "Could not save the configuration for repository "+id+": "+e.getMessage() );
483 rwLock.writeLock( ).unlock( );
489 * Adds a new repository or updates the repository with the same id. The given configuration object is updated, but
490 * the configuration is not saved.
492 * @param managedRepositoryConfiguration the new or changed repository configuration
493 * @param configuration the configuration object
494 * @return the new or updated repository
495 * @throws RepositoryException if the configuration cannot be saved or updated
497 public ManagedRepository putRepository( ManagedRepositoryConfiguration managedRepositoryConfiguration, Configuration configuration) throws RepositoryException
499 rwLock.writeLock( ).lock( );
502 final String id = managedRepositoryConfiguration.getId();
503 final RepositoryType repoType = RepositoryType.valueOf( managedRepositoryConfiguration.getType() );
504 ManagedRepository repo;
505 if (managedRepositories.containsKey( id )) {
506 repo = managedRepositories.get(id);
507 if (repo instanceof EditableManagedRepository)
509 getProvider( repoType ).updateManagedInstance( (EditableManagedRepository) repo, managedRepositoryConfiguration );
511 throw new RepositoryException( "The repository is not editable "+id );
515 repo = getProvider( repoType ).createManagedInstance( managedRepositoryConfiguration );
516 managedRepositories.put(id, repo);
518 updateRepositoryReferences( getProvider( repoType ), repo, managedRepositoryConfiguration, configuration );
519 replaceOrAddRepositoryConfig( managedRepositoryConfiguration, configuration );
524 rwLock.writeLock( ).unlock( );
528 private void replaceOrAddRepositoryConfig(ManagedRepositoryConfiguration managedRepositoryConfiguration, Configuration configuration) {
529 ManagedRepositoryConfiguration oldCfg = configuration.findManagedRepositoryById( managedRepositoryConfiguration.getId() );
530 if ( oldCfg !=null) {
531 configuration.removeManagedRepository( oldCfg );
533 configuration.addManagedRepository( managedRepositoryConfiguration );
536 private void replaceOrAddRepositoryConfig(RemoteRepositoryConfiguration remoteRepositoryConfiguration, Configuration configuration) {
537 RemoteRepositoryConfiguration oldCfg = configuration.findRemoteRepositoryById( remoteRepositoryConfiguration.getId() );
538 if ( oldCfg !=null) {
539 configuration.removeRemoteRepository( oldCfg );
541 configuration.addRemoteRepository( remoteRepositoryConfiguration );
544 public RemoteRepository putRepository( RemoteRepository remoteRepository, Configuration configuration) throws RepositoryException
546 rwLock.writeLock( ).lock( );
549 final String id = remoteRepository.getId();
550 if (managedRepositories.containsKey( id )) {
551 throw new RepositoryException( "There exists a managed repository with id "+id+". Could not update with remote repository." );
553 RemoteRepository originRepo = remoteRepositories.put( id, remoteRepository );
554 RemoteRepositoryConfiguration oldCfg=null;
555 RemoteRepositoryConfiguration newCfg=null;
558 final RepositoryProvider provider = getProvider( remoteRepository.getType() );
559 newCfg = provider.getRemoteConfiguration( remoteRepository );
560 updateRepositoryReferences( provider, remoteRepository, newCfg, configuration );
561 oldCfg = configuration.findRemoteRepositoryById( id );
563 configuration.removeRemoteRepository( oldCfg );
565 configuration.addRemoteRepository( newCfg );
566 return remoteRepository;
568 catch ( Exception e )
571 if ( originRepo != null )
573 remoteRepositories.put( id, originRepo );
575 remoteRepositories.remove( id);
578 RemoteRepositoryConfiguration cfg = configuration.findRemoteRepositoryById( id );
580 configuration.removeRemoteRepository( cfg );
581 configuration.addRemoteRepository( oldCfg );
584 log.error("Error while adding remote repository {}", e.getMessage(), e);
585 throw new RepositoryException( "Could not save the configuration" + (e.getMessage( )==null?"":": "+e.getMessage()) );
590 rwLock.writeLock( ).unlock( );
595 * Adds a remote repository, or overwrites the repository definition with the same id, if it exists already.
596 * The modification is saved to the configuration immediately.
598 * @param remoteRepository the remote repository to add
599 * @throws RepositoryException if an error occurs during configuration save
601 public RemoteRepository putRepository( RemoteRepository remoteRepository ) throws RepositoryException
603 rwLock.writeLock( ).lock( );
606 Configuration configuration = getArchivaConfiguration().getConfiguration();
609 RemoteRepository repo = putRepository( remoteRepository, configuration );
610 getArchivaConfiguration().save(configuration);
613 catch ( RegistryException | IndeterminateConfigurationException e )
615 log.error("Error while saving remote repository {}", e.getMessage(), e);
616 throw new RepositoryException( "Could not save the configuration" + (e.getMessage( )==null?"":": "+e.getMessage()) );
621 rwLock.writeLock( ).unlock( );
626 * Adds a new repository or updates the repository with the same id, if it exists already.
627 * The configuration is saved immediately.
629 * @param remoteRepositoryConfiguration the repository configuration
630 * @return the updated or created repository
631 * @throws RepositoryException if an error occurs, or the configuration is not valid.
633 public RemoteRepository putRepository( RemoteRepositoryConfiguration remoteRepositoryConfiguration) throws RepositoryException
635 rwLock.writeLock( ).lock( );
638 final String id = remoteRepositoryConfiguration.getId();
639 final RepositoryType repositoryType = RepositoryType.valueOf( remoteRepositoryConfiguration.getType() );
640 Configuration configuration = getArchivaConfiguration().getConfiguration();
641 RemoteRepository repo = remoteRepositories.get(id);
642 RemoteRepositoryConfiguration oldCfg = repo!=null ? getProvider( repositoryType ).getRemoteConfiguration( repo ) : null;
643 repo = putRepository( remoteRepositoryConfiguration, configuration );
646 getArchivaConfiguration().save(configuration);
648 catch ( IndeterminateConfigurationException | RegistryException e )
651 getProvider( repositoryType ).updateRemoteInstance( (EditableRemoteRepository)repo, oldCfg );
653 log.error("Could not save the configuration for repository {}: {}", id, e.getMessage(),e );
654 throw new RepositoryException( "Could not save the configuration for repository "+id+": "+e.getMessage() );
660 rwLock.writeLock( ).unlock( );
666 * Adds a new repository or updates the repository with the same id. The given configuration object is updated, but
667 * the configuration is not saved.
669 * @param remoteRepositoryConfiguration the new or changed repository configuration
670 * @param configuration the configuration object
671 * @return the new or updated repository
672 * @throws RepositoryException if the configuration cannot be saved or updated
674 public RemoteRepository putRepository( RemoteRepositoryConfiguration remoteRepositoryConfiguration, Configuration configuration) throws RepositoryException
676 rwLock.writeLock( ).lock( );
679 final String id = remoteRepositoryConfiguration.getId();
680 final RepositoryType repoType = RepositoryType.valueOf( remoteRepositoryConfiguration.getType() );
681 RemoteRepository repo;
682 if (remoteRepositories.containsKey( id )) {
683 repo = remoteRepositories.get(id);
684 if (repo instanceof EditableRemoteRepository)
686 getProvider( repoType ).updateRemoteInstance( (EditableRemoteRepository) repo, remoteRepositoryConfiguration );
688 throw new RepositoryException( "The repository is not editable "+id );
692 repo = getProvider( repoType ).createRemoteInstance( remoteRepositoryConfiguration );
693 remoteRepositories.put(id, repo);
695 updateRepositoryReferences( getProvider( repoType ), repo, remoteRepositoryConfiguration, configuration );
696 replaceOrAddRepositoryConfig( remoteRepositoryConfiguration, configuration );
701 rwLock.writeLock( ).unlock( );
707 public void removeRepository(Repository repo) throws RepositoryException
709 if (repo instanceof RemoteRepository ) {
710 removeRepository( (RemoteRepository)repo );
711 } else if (repo instanceof ManagedRepository) {
712 removeRepository( (ManagedRepository)repo);
714 throw new RepositoryException( "Repository type not known: "+repo.getClass() );
719 * Removes a managed repository from the registry and configuration, if it exists.
720 * The change is saved to the configuration immediately.
722 * @param managedRepository the managed repository to remove
723 * @throws RepositoryException if a error occurs during configuration save
725 public void removeRepository( ManagedRepository managedRepository ) throws RepositoryException
727 final String id = managedRepository.getId();
728 ManagedRepository repo = getManagedRepository( id );
730 rwLock.writeLock().lock();
732 repo = managedRepositories.remove( id );
734 Configuration configuration = getArchivaConfiguration().getConfiguration();
735 ManagedRepositoryConfiguration cfg = configuration.findManagedRepositoryById( id );
737 configuration.removeManagedRepository( cfg );
739 getArchivaConfiguration().save( configuration );
743 catch ( RegistryException | IndeterminateConfigurationException e )
746 log.error("Could not save config after repository removal: {}", e.getMessage(), e);
747 managedRepositories.put(repo.getId(), repo);
748 throw new RepositoryException( "Could not save configuration after repository removal: "+e.getMessage() );
752 rwLock.writeLock().unlock();
757 public void removeRepository(ManagedRepository managedRepository, Configuration configuration) throws RepositoryException
759 final String id = managedRepository.getId();
760 ManagedRepository repo = getManagedRepository( id );
762 rwLock.writeLock().lock();
764 repo = managedRepositories.remove( id );
766 ManagedRepositoryConfiguration cfg = configuration.findManagedRepositoryById( id );
768 configuration.removeManagedRepository( cfg );
774 rwLock.writeLock().unlock();
781 * Removes the remote repository from the registry and configuration.
782 * The change is saved to the configuration immediately.
784 * @param remoteRepository the remote repository to remove
785 * @throws RepositoryException if a error occurs during configuration save
787 public void removeRepository( RemoteRepository remoteRepository ) throws RepositoryException
789 final String id = remoteRepository.getId();
790 RemoteRepository repo = getRemoteRepository( id );
792 rwLock.writeLock().lock();
794 repo = remoteRepositories.remove( id );
796 Configuration configuration = getArchivaConfiguration().getConfiguration();
797 RemoteRepositoryConfiguration cfg = configuration.findRemoteRepositoryById( id );
799 configuration.removeRemoteRepository( cfg );
801 getArchivaConfiguration().save( configuration );
805 catch ( RegistryException | IndeterminateConfigurationException e )
808 log.error("Could not save config after repository removal: {}", e.getMessage(), e);
809 remoteRepositories.put(repo.getId(), repo);
810 throw new RepositoryException( "Could not save configuration after repository removal: "+e.getMessage() );
814 rwLock.writeLock().unlock();
819 public void removeRepository( RemoteRepository remoteRepository, Configuration configuration) throws RepositoryException
821 final String id = remoteRepository.getId();
822 RemoteRepository repo = getRemoteRepository( id );
824 rwLock.writeLock().lock();
826 repo = remoteRepositories.remove( id );
828 RemoteRepositoryConfiguration cfg = configuration.findRemoteRepositoryById( id );
830 configuration.removeRemoteRepository( cfg );
836 rwLock.writeLock().unlock();
843 * Reloads the registry from the configuration.
845 public void reload() {
851 * Creates a new repository instance with the same settings as this one. The cloned repository is not
852 * registered or saved to the configuration.
854 * @param repo The origin repository
855 * @return The cloned repository.
857 public ManagedRepository clone(ManagedRepository repo, String newId) throws RepositoryException
859 if (managedRepositories.containsKey(newId) || remoteRepositories.containsKey(newId)) {
860 throw new RepositoryException("The given id exists already "+newId);
862 RepositoryProvider provider = getProvider(repo.getType());
863 ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration(repo);
865 ManagedRepository cloned = provider.createManagedInstance(cfg);
869 public <T extends Repository> Repository clone(T repo, String newId) throws RepositoryException {
870 if (repo instanceof RemoteRepository ) {
871 return this.clone((RemoteRepository)repo, newId);
872 } else if (repo instanceof ManagedRepository) {
873 return this.clone((ManagedRepository)repo, newId);
875 throw new RepositoryException("This repository class is not supported "+ repo.getClass().getName());
880 * Creates a new repository instance with the same settings as this one. The cloned repository is not
881 * registered or saved to the configuration.
883 * @param repo The origin repository
884 * @return The cloned repository.
886 public RemoteRepository clone( RemoteRepository repo, String newId) throws RepositoryException
888 if (managedRepositories.containsKey(newId) || remoteRepositories.containsKey(newId)) {
889 throw new RepositoryException("The given id exists already "+newId);
891 RepositoryProvider provider = getProvider(repo.getType());
892 RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration(repo);
894 RemoteRepository cloned = provider.createRemoteInstance(cfg);
900 public void configurationEvent(ConfigurationEvent event) {