Search in sources :

Example 1 with RegistryException

use of org.apache.archiva.components.registry.RegistryException in project archiva by apache.

the class DefaultRedbackRuntimeConfigurationAdmin method updateRedbackRuntimeConfiguration.

@Override
public void updateRedbackRuntimeConfiguration(RedbackRuntimeConfiguration redbackRuntimeConfiguration) throws RepositoryAdminException {
    org.apache.archiva.configuration.model.RedbackRuntimeConfiguration runtimeConfiguration = build(redbackRuntimeConfiguration);
    Configuration configuration = archivaConfiguration.getConfiguration();
    configuration.setRedbackRuntimeConfiguration(runtimeConfiguration);
    try {
        archivaConfiguration.save(configuration);
    } catch (RegistryException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    } catch (IndeterminateConfigurationException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) LdapConfiguration(org.apache.archiva.admin.model.beans.LdapConfiguration) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) UserConfiguration(org.apache.archiva.redback.configuration.UserConfiguration) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RegistryException(org.apache.archiva.components.registry.RegistryException)

Example 2 with RegistryException

use of org.apache.archiva.components.registry.RegistryException in project archiva by apache.

the class ManagedRepositoryHandler method put.

@Override
public ManagedRepository put(ManagedRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
    final String id = repositoryConfiguration.getId();
    final RepositoryType repositoryType = RepositoryType.valueOf(repositoryConfiguration.getType());
    final RepositoryProvider provider = getProvider(repositoryType);
    ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
    configLock.lock();
    ManagedRepository repo = null;
    ManagedRepository oldRepository = null;
    Configuration configuration = null;
    try {
        boolean updated = false;
        configuration = getConfigurationHandler().getBaseConfiguration();
        repo = getRepositories().get(id);
        oldRepository = repo == null ? null : clone(repo, id);
        if (repo == null) {
            repo = put(repositoryConfiguration, configuration);
        } else {
            setRepositoryDefaults(repositoryConfiguration);
            provider.updateManagedInstance((EditableManagedRepository) repo, repositoryConfiguration);
            updated = true;
            pushEvent(LifecycleEvent.UPDATED, repo);
        }
        registerNewRepository(repositoryConfiguration, repo, configuration, updated);
    } catch (IndeterminateConfigurationException | RegistryException e) {
        if (oldRepository != null) {
            ManagedRepositoryConfiguration oldCfg = provider.getManagedConfiguration(oldRepository);
            provider.updateManagedInstance((EditableManagedRepository) repo, oldCfg);
            rollback(configuration, oldRepository, e, oldCfg);
        } else {
            getRepositories().remove(id);
        }
        log.error("Could not save the configuration for repository {}: {}", id, e.getMessage(), e);
        throw new RepositoryException("Could not save the configuration for repository " + id + ": " + e.getMessage());
    } finally {
        configLock.unlock();
    }
    return repo;
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryType(org.apache.archiva.repository.RepositoryType) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RepositoryException(org.apache.archiva.repository.RepositoryException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) RegistryException(org.apache.archiva.components.registry.RegistryException) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Example 3 with RegistryException

use of org.apache.archiva.components.registry.RegistryException in project archiva by apache.

the class ArchivaConfigurationTest method testLoadConfigurationFromInvalidBothLocationsOnDisk.

@Test
public void testLoadConfigurationFromInvalidBothLocationsOnDisk() throws Exception {
    String propFile = System.getProperty(ArchivaConfiguration.USER_CONFIG_PROPERTY);
    System.setProperty(ArchivaConfiguration.USER_CONFIG_PROPERTY, "/../../..//*intentionally:invalid*/.m2/archiva-user.xml");
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-not-allowed-to-write-to-both");
    Configuration config = archivaConfiguration.getConfiguration();
    try {
        archivaConfiguration.save(config);
        fail("Should have thrown a RegistryException because the configuration can't be saved.");
    } catch (RegistryException e) {
    /* expected exception */
    }
    if (propFile != null) {
        System.setProperty(ArchivaConfiguration.USER_CONFIG_PROPERTY, propFile);
    }
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RegistryException(org.apache.archiva.components.registry.RegistryException) Test(org.junit.Test)

Example 4 with RegistryException

use of org.apache.archiva.components.registry.RegistryException in project archiva by apache.

the class DefaultArchivaConfiguration method createDefaultConfigurationFile.

private Registry createDefaultConfigurationFile(String eventTag) throws RegistryException {
    // TODO: may not be needed under commons-configuration 1.4 - check
    String contents = "<configuration />";
    String fileLocation = userConfigFilename;
    if (!writeFile("user configuration", userConfigFilename, contents)) {
        fileLocation = altConfigFilename;
        if (!writeFile("alternative configuration", altConfigFilename, contents, true)) {
            throw new RegistryException("Unable to create configuration file in either user [" + userConfigFilename + "] or alternative [" + altConfigFilename + "] locations on disk, usually happens when not allowed to write to those locations.");
        }
    }
    // olamy hackish I know :-)
    contents = "<configuration><xml fileName=\"" + fileLocation + "\" config-forceCreate=\"true\" config-name=\"org.apache.archiva.user\"/>" + "</configuration>";
    ((CommonsConfigurationRegistry) registry).setInitialConfiguration(contents);
    registry.initialize();
    for (RegistryListener regListener : registryListeners) {
        addRegistryChangeListener(regListener);
    }
    triggerEvent(ConfigurationEvent.SAVED, eventTag == null ? "default-file" : eventTag);
    Registry section = registry.getSection(KEY + ".user");
    if (section == null) {
        return new CommonsConfigurationRegistry();
    } else {
        return section;
    }
}
Also used : CommonsConfigurationRegistry(org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry) RegistryListener(org.apache.archiva.components.registry.RegistryListener) CommonsConfigurationRegistry(org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry) Registry(org.apache.archiva.components.registry.Registry) RegistryException(org.apache.archiva.components.registry.RegistryException)

Example 5 with RegistryException

use of org.apache.archiva.components.registry.RegistryException in project archiva by apache.

the class DefaultArchivaConfiguration method initialize.

@PostConstruct
public void initialize() {
    // Resolve expressions in the userConfigFilename and altConfigFilename
    try {
        ExpressionEvaluator expressionEvaluator = new DefaultExpressionEvaluator();
        expressionEvaluator.addExpressionSource(new SystemPropertyExpressionSource());
        String userConfigFileNameSysProps = System.getProperty(USER_CONFIG_PROPERTY);
        if (StringUtils.isNotBlank(userConfigFileNameSysProps)) {
            userConfigFilename = userConfigFileNameSysProps;
        } else {
            String userConfigFileNameEnv = System.getenv(USER_CONFIG_ENVVAR);
            if (StringUtils.isNotBlank(userConfigFileNameEnv)) {
                userConfigFilename = userConfigFileNameEnv;
            } else {
                userConfigFilename = expressionEvaluator.expand(userConfigFilename);
            }
        }
        altConfigFilename = expressionEvaluator.expand(altConfigFilename);
        loadConfiguration();
        handleUpgradeConfiguration();
    } catch (IndeterminateConfigurationException | RegistryException e) {
        throw new RuntimeException("failed during upgrade from previous version" + e.getMessage(), e);
    } catch (EvaluatorException e) {
        throw new RuntimeException("Unable to evaluate expressions found in " + "userConfigFilename or altConfigFilename.", e);
    }
    registry.addChangeListener(this);
}
Also used : EvaluatorException(org.apache.archiva.components.evaluator.EvaluatorException) DefaultExpressionEvaluator(org.apache.archiva.components.evaluator.DefaultExpressionEvaluator) ExpressionEvaluator(org.apache.archiva.components.evaluator.ExpressionEvaluator) RegistryException(org.apache.archiva.components.registry.RegistryException) DefaultExpressionEvaluator(org.apache.archiva.components.evaluator.DefaultExpressionEvaluator) SystemPropertyExpressionSource(org.apache.archiva.components.evaluator.sources.SystemPropertyExpressionSource) PostConstruct(javax.annotation.PostConstruct)

Aggregations

RegistryException (org.apache.archiva.components.registry.RegistryException)10 Configuration (org.apache.archiva.configuration.model.Configuration)7 IndeterminateConfigurationException (org.apache.archiva.configuration.provider.IndeterminateConfigurationException)6 RepositoryException (org.apache.archiva.repository.RepositoryException)4 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)3 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)3 RepositoryProvider (org.apache.archiva.repository.RepositoryProvider)3 RepositoryType (org.apache.archiva.repository.RepositoryType)3 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)2 CacheConfiguration (org.apache.archiva.admin.model.beans.CacheConfiguration)2 Registry (org.apache.archiva.components.registry.Registry)2 CommonsConfigurationRegistry (org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry)2 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)2 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)2 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)2 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)2 ArrayList (java.util.ArrayList)1 PostConstruct (javax.annotation.PostConstruct)1 ArchivaRuntimeConfiguration (org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration)1 FileLockConfiguration (org.apache.archiva.admin.model.beans.FileLockConfiguration)1