Search in sources :

Example 6 with Registry

use of org.apache.archiva.components.registry.Registry 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)

Example 7 with Registry

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

the class BasicManagedRepositoryValidator method interpolateVars.

public String interpolateVars(String directory) {
    Registry registry = configurationHandler.getArchivaConfiguration().getRegistry();
    String value = StringUtils.replace(directory, "${appserver.base}", registry.getString("appserver.base", "${appserver.base}"));
    value = StringUtils.replace(value, "${appserver.home}", registry.getString("appserver.home", "${appserver.home}"));
    return value;
}
Also used : RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) Registry(org.apache.archiva.components.registry.Registry)

Example 8 with Registry

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

the class BasicRemoteRepositoryValidator method interpolateVars.

public String interpolateVars(String directory) {
    Registry registry = configurationHandler.getArchivaConfiguration().getRegistry();
    String value = StringUtils.replace(directory, "${appserver.base}", registry.getString("appserver.base", "${appserver.base}"));
    value = StringUtils.replace(value, "${appserver.home}", registry.getString("appserver.home", "${appserver.home}"));
    return value;
}
Also used : RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) Registry(org.apache.archiva.components.registry.Registry)

Aggregations

Registry (org.apache.archiva.components.registry.Registry)8 CommonsConfigurationRegistry (org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry)6 ArrayList (java.util.ArrayList)2 RegistryException (org.apache.archiva.components.registry.RegistryException)2 RepositoryRegistry (org.apache.archiva.repository.RepositoryRegistry)2 Path (java.nio.file.Path)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 RegistryListener (org.apache.archiva.components.registry.RegistryListener)1 Configuration (org.apache.archiva.configuration.model.Configuration)1 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)1 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)1 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)1 RepositoryCheckPath (org.apache.archiva.configuration.model.RepositoryCheckPath)1 ConfigurationRegistryReader (org.apache.archiva.configuration.provider.io.registry.ConfigurationRegistryReader)1 ConfigurationRegistryWriter (org.apache.archiva.configuration.provider.io.registry.ConfigurationRegistryWriter)1