Search in sources :

Example 1 with ConfigurationRegistryReader

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

the class DefaultArchivaConfiguration method load.

@SuppressWarnings("unchecked")
private Configuration load() {
    // TODO: should this be the same as section? make sure unnamed sections still work (eg, sys properties)
    Registry subset = registry.getSubset(KEY);
    if (subset.getString("version") == null) {
        if (subset.getSubset("repositoryScanning").isEmpty()) {
            // only for empty
            subset = readDefaultConfiguration();
        } else {
            throw new RuntimeException("No version tag found in configuration. Archiva configuration version 1.x is not longer supported.");
        }
    }
    Configuration config = new ConfigurationRegistryReader().read(subset);
    // Resolving data and repositories directories
    // If the config entries are absolute, the path is used as it is
    // if the config entries are empty, they are resolved:
    // dataDirectory = ${appserver.base}/data
    // repositoryDirectory = ${dataDirectory}/repositories
    // If the entries are relative they are resolved
    // relative to the appserver.base, for dataDirectory
    // relative to dataDirectory for repositoryBase
    String dataDir = config.getArchivaRuntimeConfiguration().getDataDirectory();
    if (StringUtils.isEmpty(dataDir)) {
        dataDirectory = getAppServerBaseDir().resolve("data");
    } else {
        Path tmpDataDir = Paths.get(dataDir);
        if (tmpDataDir.isAbsolute()) {
            dataDirectory = tmpDataDir;
        } else {
            dataDirectory = getAppServerBaseDir().resolve(tmpDataDir);
        }
    }
    config.getArchivaRuntimeConfiguration().setDataDirectory(dataDirectory.normalize().toString());
    String repoBaseDir = config.getArchivaRuntimeConfiguration().getRepositoryBaseDirectory();
    if (StringUtils.isEmpty(repoBaseDir)) {
        repositoryBaseDirectory = dataDirectory.resolve("repositories");
    } else {
        Path tmpRepoBaseDir = Paths.get(repoBaseDir);
        if (tmpRepoBaseDir.isAbsolute()) {
            repositoryBaseDirectory = tmpRepoBaseDir;
        } else {
            dataDirectory.resolve(tmpRepoBaseDir);
        }
    }
    String remoteRepoBaseDir = config.getArchivaRuntimeConfiguration().getRemoteRepositoryBaseDirectory();
    if (StringUtils.isEmpty(remoteRepoBaseDir)) {
        remoteRepositoryBaseDirectory = dataDirectory.resolve("remotes");
    } else {
        Path tmpRemoteRepoDir = Paths.get(remoteRepoBaseDir);
        if (tmpRemoteRepoDir.isAbsolute()) {
            remoteRepositoryBaseDirectory = tmpRemoteRepoDir;
        } else {
            dataDirectory.resolve(tmpRemoteRepoDir);
        }
    }
    String repositoryGroupBaseDir = config.getArchivaRuntimeConfiguration().getRepositoryGroupBaseDirectory();
    if (StringUtils.isEmpty(repositoryGroupBaseDir)) {
        repositoryGroupBaseDirectory = dataDirectory.resolve("groups");
    } else {
        Path tmpGroupDir = Paths.get(repositoryGroupBaseDir);
        if (tmpGroupDir.isAbsolute()) {
            repositoryGroupBaseDirectory = tmpGroupDir;
        } else {
            dataDirectory.resolve(tmpGroupDir);
        }
    }
    config.getRepositoryGroups();
    config.getRepositoryGroupsAsMap();
    if (!CollectionUtils.isEmpty(config.getRemoteRepositories())) {
        List<RemoteRepositoryConfiguration> remoteRepos = config.getRemoteRepositories();
        for (RemoteRepositoryConfiguration repo : remoteRepos) {
            // [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
            if (StringUtils.isBlank(repo.getUsername())) {
                repo.setUsername(null);
            }
            if (StringUtils.isBlank(repo.getPassword())) {
                repo.setPassword(null);
            }
        }
    }
    if (!config.getProxyConnectors().isEmpty()) {
        // Fix Proxy Connector Settings.
        // Create a copy of the list to read from (to prevent concurrent modification exceptions)
        List<ProxyConnectorConfiguration> proxyConnectorList = new ArrayList<>(config.getProxyConnectors());
        // Remove the old connector list.
        config.getProxyConnectors().clear();
        for (ProxyConnectorConfiguration connector : proxyConnectorList) {
            // Fix policies
            boolean connectorValid = true;
            Map<String, String> policies = new HashMap<>();
            // Make copy of policies
            policies.putAll(connector.getPolicies());
            // Clear out policies
            connector.getPolicies().clear();
            // Work thru policies. cleaning them up.
            for (Entry<String, String> entry : policies.entrySet()) {
                String policyId = entry.getKey();
                String setting = entry.getValue();
                // Upgrade old policy settings.
                if ("releases".equals(policyId) || "snapshots".equals(policyId)) {
                    if ("ignored".equals(setting)) {
                        setting = AbstractUpdatePolicy.ALWAYS.getId();
                    } else if ("disabled".equals(setting)) {
                        setting = AbstractUpdatePolicy.NEVER.getId();
                    }
                } else if ("cache-failures".equals(policyId)) {
                    if ("ignored".equals(setting)) {
                        setting = CachedFailuresPolicy.NO.getId();
                    } else if ("cached".equals(setting)) {
                        setting = CachedFailuresPolicy.YES.getId();
                    }
                } else if ("checksum".equals(policyId)) {
                    if ("ignored".equals(setting)) {
                        setting = ChecksumPolicy.IGNORE.getId();
                    }
                }
                // Validate existance of policy key.
                connector.addPolicy(policyId, setting);
            }
            if (connectorValid) {
                config.addProxyConnector(connector);
            }
        }
        // Normalize the order fields in the proxy connectors.
        Map<String, java.util.List<ProxyConnectorConfiguration>> proxyConnectorMap = config.getProxyConnectorAsMap();
        for (List<ProxyConnectorConfiguration> connectors : proxyConnectorMap.values()) {
            // Sort connectors by order field.
            Collections.sort(connectors, ProxyConnectorConfigurationOrderComparator.getInstance());
            // Normalize the order field values.
            int order = 1;
            for (ProxyConnectorConfiguration connector : connectors) {
                connector.setOrder(order++);
            }
        }
    }
    this.defaultLocale = Locale.forLanguageTag(config.getArchivaRuntimeConfiguration().getDefaultLanguage());
    this.languagePriorities = Locale.LanguageRange.parse(config.getArchivaRuntimeConfiguration().getLanguageRange());
    return config;
}
Also used : Path(java.nio.file.Path) RepositoryCheckPath(org.apache.archiva.configuration.model.RepositoryCheckPath) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ConfigurationRegistryReader(org.apache.archiva.configuration.provider.io.registry.ConfigurationRegistryReader) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) CommonsConfigurationRegistry(org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry) Registry(org.apache.archiva.components.registry.Registry) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Registry (org.apache.archiva.components.registry.Registry)1 CommonsConfigurationRegistry (org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry)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