Search in sources :

Example 1 with ConfigurationRegistryWriter

use of org.apache.archiva.configuration.io.registry.ConfigurationRegistryWriter in project archiva by apache.

the class DefaultArchivaConfiguration method save.

@SuppressWarnings("unchecked")
@Override
public synchronized void save(Configuration configuration) throws IndeterminateConfigurationException, RegistryException {
    Registry section = registry.getSection(KEY + ".user");
    Registry baseSection = registry.getSection(KEY + ".base");
    if (section == null) {
        section = baseSection;
        if (section == null) {
            section = createDefaultConfigurationFile();
        }
    } else if (baseSection != null) {
        Collection<String> keys = baseSection.getKeys();
        boolean foundList = false;
        for (Iterator<String> i = keys.iterator(); i.hasNext() && !foundList; ) {
            String key = i.next();
            // that configuration
            if (// 
            key.startsWith("repositories") || // 
            key.startsWith("proxyConnectors") || // 
            key.startsWith("networkProxies") || // 
            key.startsWith("repositoryScanning") || // 
            key.startsWith("remoteRepositories") || // 
            key.startsWith("managedRepositories") || // 
            key.startsWith("repositoryGroups")) {
                foundList = true;
            }
        }
        if (foundList) {
            this.configuration = null;
            throw new IndeterminateConfigurationException("Configuration can not be saved when it is loaded from two sources");
        }
    }
    // escape all cron expressions to handle ','
    escapeCronExpressions(configuration);
    // [MRM-661] Due to a bug in the modello registry writer, we need to take these out by hand. They'll be put back by the writer.
    if (section != null) {
        if (configuration.getManagedRepositories().isEmpty()) {
            section.removeSubset("managedRepositories");
        }
        if (configuration.getRemoteRepositories().isEmpty()) {
            section.removeSubset("remoteRepositories");
        }
        if (configuration.getProxyConnectors().isEmpty()) {
            section.removeSubset("proxyConnectors");
        }
        if (configuration.getNetworkProxies().isEmpty()) {
            section.removeSubset("networkProxies");
        }
        if (configuration.getLegacyArtifactPaths().isEmpty()) {
            section.removeSubset("legacyArtifactPaths");
        }
        if (configuration.getRepositoryGroups().isEmpty()) {
            section.removeSubset("repositoryGroups");
        }
        if (configuration.getRepositoryScanning() != null) {
            if (configuration.getRepositoryScanning().getKnownContentConsumers().isEmpty()) {
                section.removeSubset("repositoryScanning.knownContentConsumers");
            }
            if (configuration.getRepositoryScanning().getInvalidContentConsumers().isEmpty()) {
                section.removeSubset("repositoryScanning.invalidContentConsumers");
            }
        }
        if (configuration.getArchivaRuntimeConfiguration() != null) {
            section.removeSubset("archivaRuntimeConfiguration.defaultCheckPaths");
        }
        new ConfigurationRegistryWriter().write(configuration, section);
        section.save();
    }
    this.configuration = unescapeExpressions(configuration);
    isConfigurationDefaulted = false;
    triggerEvent(ConfigurationEvent.SAVED);
}
Also used : ConfigurationRegistryWriter(org.apache.archiva.configuration.io.registry.ConfigurationRegistryWriter) Iterator(java.util.Iterator) Collection(java.util.Collection) Registry(org.apache.archiva.redback.components.registry.Registry) CommonsConfigurationRegistry(org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry)

Aggregations

Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 ConfigurationRegistryWriter (org.apache.archiva.configuration.io.registry.ConfigurationRegistryWriter)1 Registry (org.apache.archiva.redback.components.registry.Registry)1 CommonsConfigurationRegistry (org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry)1