Search in sources :

Example 1 with RegistryException

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

the class DefaultArchivaConfiguration method handleUpgradeConfiguration.

/**
 * Handle upgrade to newer version
 */
private void handleUpgradeConfiguration() throws RegistryException, IndeterminateConfigurationException {
    List<String> dbConsumers = Arrays.asList("update-db-artifact", "update-db-repository-metadata");
    // remove database consumers if here
    List<String> intersec = ListUtils.intersection(dbConsumers, configuration.getRepositoryScanning().getKnownContentConsumers());
    if (!intersec.isEmpty()) {
        List<String> knowContentConsumers = new ArrayList<>(configuration.getRepositoryScanning().getKnownContentConsumers().size());
        for (String knowContentConsumer : configuration.getRepositoryScanning().getKnownContentConsumers()) {
            if (!dbConsumers.contains(knowContentConsumer)) {
                knowContentConsumers.add(knowContentConsumer);
            }
        }
        configuration.getRepositoryScanning().setKnownContentConsumers(knowContentConsumers);
    }
    // ensure create-archiva-metadata is here
    if (!configuration.getRepositoryScanning().getKnownContentConsumers().contains("create-archiva-metadata")) {
        List<String> knowContentConsumers = new ArrayList<>(configuration.getRepositoryScanning().getKnownContentConsumers());
        knowContentConsumers.add("create-archiva-metadata");
        configuration.getRepositoryScanning().setKnownContentConsumers(knowContentConsumers);
    }
    // ensure duplicate-artifacts is here
    if (!configuration.getRepositoryScanning().getKnownContentConsumers().contains("duplicate-artifacts")) {
        List<String> knowContentConsumers = new ArrayList<>(configuration.getRepositoryScanning().getKnownContentConsumers());
        knowContentConsumers.add("duplicate-artifacts");
        configuration.getRepositoryScanning().setKnownContentConsumers(knowContentConsumers);
    }
    Registry defaultOnlyConfiguration = readDefaultOnlyConfiguration();
    // Currently we check only for configuration version change, not certain version numbers.
    if (hasConfigVersionChanged(configuration, defaultOnlyConfiguration)) {
        updateCheckPathDefaults(configuration, defaultOnlyConfiguration);
        String newVersion = defaultOnlyConfiguration.getString("version");
        if (newVersion == null) {
            throw new IndeterminateConfigurationException("The default configuration has no version information!");
        }
        configuration.setVersion(newVersion);
        try {
            save(configuration);
        } catch (IndeterminateConfigurationException e) {
            log.error("Error occured during configuration update to new version: {}", e.getMessage());
        } catch (RegistryException e) {
            log.error("Error occured during configuration update to new version: {}", e.getMessage());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Registry(org.apache.archiva.redback.components.registry.Registry) CommonsConfigurationRegistry(org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 2 with RegistryException

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

the class DefaultArchivaConfiguration method createDefaultConfigurationFile.

private Registry createDefaultConfigurationFile() 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)) {
            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).setProperties(contents);
    registry.initialize();
    for (RegistryListener regListener : registryListeners) {
        addRegistryChangeListener(regListener);
    }
    triggerEvent(ConfigurationEvent.SAVED);
    Registry section = registry.getSection(KEY + ".user");
    return section == null ? new CommonsConfigurationRegistry(new BaseConfiguration()) : section;
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) CommonsConfigurationRegistry(org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry) RegistryListener(org.apache.archiva.redback.components.registry.RegistryListener) Registry(org.apache.archiva.redback.components.registry.Registry) CommonsConfigurationRegistry(org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 3 with RegistryException

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

the class DefaultArchivaConfiguration method initialize.

@PostConstruct
public void initialize() {
    this.postPolicies = componentContainer.buildMapWithRole(PostDownloadPolicy.class);
    this.prePolicies = componentContainer.buildMapWithRole(PreDownloadPolicy.class);
    this.downloadErrorPolicies = componentContainer.buildMapWithRole(DownloadErrorPolicy.class);
    // Resolve expressions in the userConfigFilename and altConfigFilename
    try {
        ExpressionEvaluator expressionEvaluator = new DefaultExpressionEvaluator();
        expressionEvaluator.addExpressionSource(new SystemPropertyExpressionSource());
        String userConfigFileNameSysProps = System.getProperty("archiva.user.configFileName");
        if (StringUtils.isNotBlank(userConfigFileNameSysProps)) {
            userConfigFilename = userConfigFileNameSysProps;
        } 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 : PostDownloadPolicy(org.apache.archiva.policies.PostDownloadPolicy) PreDownloadPolicy(org.apache.archiva.policies.PreDownloadPolicy) EvaluatorException(org.apache.archiva.redback.components.evaluator.EvaluatorException) DownloadErrorPolicy(org.apache.archiva.policies.DownloadErrorPolicy) ExpressionEvaluator(org.apache.archiva.redback.components.evaluator.ExpressionEvaluator) DefaultExpressionEvaluator(org.apache.archiva.redback.components.evaluator.DefaultExpressionEvaluator) RegistryException(org.apache.archiva.redback.components.registry.RegistryException) DefaultExpressionEvaluator(org.apache.archiva.redback.components.evaluator.DefaultExpressionEvaluator) SystemPropertyExpressionSource(org.apache.archiva.redback.components.evaluator.sources.SystemPropertyExpressionSource) PostConstruct(javax.annotation.PostConstruct)

Example 4 with RegistryException

use of org.apache.archiva.redback.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.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.ArchivaConfiguration) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration) LdapConfiguration(org.apache.archiva.admin.model.beans.LdapConfiguration) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) Configuration(org.apache.archiva.configuration.Configuration) UserConfiguration(org.apache.archiva.redback.configuration.UserConfiguration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 5 with RegistryException

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

the class RepositoryRegistry method putRepository.

/**
 * Adds a new repository or updates the repository with the same id, if it exists already.
 * The configuration is saved immediately.
 *
 * @param managedRepositoryConfiguration the repository configuration
 * @return the updated or created repository
 * @throws RepositoryException if an error occurs, or the configuration is not valid.
 */
public ManagedRepository putRepository(ManagedRepositoryConfiguration managedRepositoryConfiguration) throws RepositoryException {
    rwLock.writeLock().lock();
    try {
        final String id = managedRepositoryConfiguration.getId();
        final RepositoryType repositoryType = RepositoryType.valueOf(managedRepositoryConfiguration.getType());
        Configuration configuration = getArchivaConfiguration().getConfiguration();
        ManagedRepository repo = managedRepositories.get(id);
        ManagedRepositoryConfiguration oldCfg = repo != null ? getProvider(repositoryType).getManagedConfiguration(repo) : null;
        repo = putRepository(managedRepositoryConfiguration, configuration);
        try {
            getArchivaConfiguration().save(configuration);
        } catch (IndeterminateConfigurationException | RegistryException e) {
            if (oldCfg != null) {
                getProvider(repositoryType).updateManagedInstance((EditableManagedRepository) repo, oldCfg);
            }
            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());
        }
        return repo;
    } finally {
        rwLock.writeLock().unlock();
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Aggregations

RegistryException (org.apache.archiva.redback.components.registry.RegistryException)13 Configuration (org.apache.archiva.configuration.Configuration)8 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)8 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)7 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)6 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)6 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)5 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)3 CommonsConfigurationRegistry (org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry)3 PostConstruct (javax.annotation.PostConstruct)2 CacheConfiguration (org.apache.archiva.admin.model.beans.CacheConfiguration)2 Registry (org.apache.archiva.redback.components.registry.Registry)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 ArchivaRuntimeConfiguration (org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration)1 FileLockConfiguration (org.apache.archiva.admin.model.beans.FileLockConfiguration)1 LdapConfiguration (org.apache.archiva.admin.model.beans.LdapConfiguration)1 RedbackRuntimeConfiguration (org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration)1 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)1 ConfigurationRegistryReader (org.apache.archiva.configuration.io.registry.ConfigurationRegistryReader)1