archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/ArchivaRepositoryRegistry.java
/**
     * Adds a new repository to the current list, or replaces the repository definition with
     * the same id, if it exists already.
     * The change is saved to the configuration immediately.
     *
     * @param managedRepository the new repository.
     * @throws RepositoryException if the new repository could not be saved to the configuration.
     */
Adds a new repository to the current list, or replaces the repository definition with
the same id, if it exists already.
The change is saved to the configuration immediately.

@param managedRepository the new repository.
@throws RepositoryException if the new repository could not be saved to the configuration.
Adds a new repository to the current list or replaces the repository definition with the same id if it exists already . The change is saved to the configuration immediately . @param managedRepository the new repository . @throws RepositoryException if the new repository could not be saved to the configuration .
@Override
    public ManagedRepository putRepository( ManagedRepository managedRepository ) throws RepositoryException {
        rwLock.writeLock().lock();
        try {
            final String id = managedRepository.getId();
            if (remoteRepositories.containsKey(id)) {
                throw new RepositoryException("There exists a remote repository with id " + id + ". Could not update with managed repository.");
            }
            ManagedRepository originRepo = managedRepositories.put(id, managedRepository);
            try {
                if (originRepo != null && originRepo != managedRepository) {
                    originRepo.close();
                }
                RepositoryProvider provider = getProvider(managedRepository.getType());
                ManagedRepositoryConfiguration newCfg = provider.getManagedConfiguration(managedRepository);
                Configuration configuration = getArchivaConfiguration().getConfiguration();
                updateRepositoryReferences(provider, managedRepository, newCfg, configuration);
                ManagedRepositoryConfiguration oldCfg = configuration.findManagedRepositoryById(id);
                if (oldCfg != null) {
                    configuration.removeManagedRepository(oldCfg);
                }
                configuration.addManagedRepository(newCfg);
                saveConfiguration(configuration);
                if (originRepo != managedRepository) {
                    pushEvent(new LifecycleEvent(LifecycleEvent.REGISTERED, this, managedRepository));
                } else {
                    pushEvent(new LifecycleEvent(LifecycleEvent.UPDATED, this, managedRepository));
                }
                return managedRepository;
            } catch (Exception e) {
                if (originRepo != null) {
                    managedRepositories.put(id, originRepo);
                } else {
                    managedRepositories.remove(id);
                }
                log.error("Exception during configuration update {}", e.getMessage(), e);
                throw new RepositoryException("Could not save the configuration" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
            }
        } finally {
            rwLock.writeLock().unlock();
        }
    }
@ Override public ManagedRepository putRepository ( ManagedRepository managedRepository ) throws RepositoryException { rwLock . writeLock ( ) . lock ( ) ; try { final String id = managedRepository . getId ( ) ; if ( remoteRepositories . containsKey ( id ) ) { throw new RepositoryException ( "There exists a remote repository with id " + id + ". Could not update with managed repository." ) ; } ManagedRepository originRepo = managedRepositories . put ( id , managedRepository ) ; try { if ( originRepo != null && originRepo != managedRepository ) { originRepo . close ( ) ; } RepositoryProvider provider = getProvider ( managedRepository . getType ( ) ) ; ManagedRepositoryConfiguration newCfg = provider . getManagedConfiguration ( managedRepository ) ; Configuration configuration = getArchivaConfiguration ( ) . getConfiguration ( ) ; updateRepositoryReferences ( provider , managedRepository , newCfg , configuration ) ; ManagedRepositoryConfiguration oldCfg = configuration . findManagedRepositoryById ( id ) ; if ( oldCfg != null ) { configuration . removeManagedRepository ( oldCfg ) ; } configuration . addManagedRepository ( newCfg ) ; saveConfiguration ( configuration ) ; if ( originRepo != managedRepository ) { pushEvent ( new LifecycleEvent ( LifecycleEvent . REGISTERED , this , managedRepository ) ) ; } else { pushEvent ( new LifecycleEvent ( LifecycleEvent . UPDATED , this , managedRepository ) ) ; } return managedRepository ; } catch ( Exception e ) { if ( originRepo != null ) { managedRepositories . put ( id , originRepo ) ; } else { managedRepositories . remove ( id ) ; } log . error ( "Exception during configuration update {}" , e . getMessage ( ) , e ) ; throw new RepositoryException ( "Could not save the configuration" + ( e . getMessage ( ) == null ? "" : ": " + e . getMessage ( ) ) ) ; } } finally { rwLock . writeLock ( ) . unlock ( ) ; } }
Adds a new repository to the current list, or replaces the repository definition with
 the same id, if it exists already.
Adds a new repository to the current list or replaces the repository definition with the same id if it exists already .
// Rollback only partly, because repository is closed already