Search in sources :

Example 1 with ConfigurationRegistryWriter

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

the class DefaultArchivaConfiguration method save.

/**
 * Saves the configuration and adds the given tag to the event.
 * @param configuration the configuration to save
 * @param eventTag the tag to add to the configuration saved event
 * @throws IndeterminateConfigurationException if the
 * @throws RegistryException
 */
@Override
public synchronized void save(Configuration configuration, String eventTag) 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(eventTag);
        }
    } 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, eventTag);
}
Also used : ConfigurationRegistryWriter(org.apache.archiva.configuration.provider.io.registry.ConfigurationRegistryWriter) Iterator(java.util.Iterator) Collection(java.util.Collection) CommonsConfigurationRegistry(org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry) Registry(org.apache.archiva.components.registry.Registry)

Aggregations

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