diff options
Diffstat (limited to 'archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src')
36 files changed, 8071 insertions, 0 deletions
diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/ArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/ArchivaConfiguration.java new file mode 100644 index 000000000..b71d26bb9 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/ArchivaConfiguration.java @@ -0,0 +1,149 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.components.registry.Registry; +import org.apache.archiva.components.registry.RegistryException; +import org.apache.archiva.components.registry.RegistryListener; +import org.apache.archiva.configuration.model.Configuration; + +import java.nio.file.Path; +import java.util.List; +import java.util.Locale; + +/** + * Configuration holder for the model read from the registry. + */ +public interface ArchivaConfiguration +{ + + + String USER_CONFIG_PROPERTY = "archiva.user.configFileName"; + String USER_CONFIG_ENVVAR = "ARCHIVA_USER_CONFIG_FILE"; + + /** + * Get the configuration. + * + * @return the configuration + */ + Configuration getConfiguration(); + + /** + * Save any updated configuration. + * + * @param configuration the configuration to save + * @throws org.apache.archiva.components.registry.RegistryException + * if there is a problem saving the registry data + * @throws IndeterminateConfigurationException + * if the configuration cannot be saved because it was read from two sources + */ + void save( Configuration configuration ) + throws RegistryException, IndeterminateConfigurationException; + + /** + * Save any updated configuration. This method allows to add a tag to the thrown event. + * This allows to verify the origin if the caller is the same as the listener. + * + * @param configuration the configuration to save + * @param eventTag the tag to add to the thrown event + * @throws org.apache.archiva.components.registry.RegistryException + * if there is a problem saving the registry data + * @throws IndeterminateConfigurationException + * if the configuration cannot be saved because it was read from two sources + */ + void save( Configuration configuration, String eventTag ) + throws RegistryException, IndeterminateConfigurationException; + + /** + * Determines if the configuration in use was as a result of a defaulted configuration. + * + * @return true if the configuration was created from the default-archiva.xml as opposed + * to being loaded from the usual locations of ${user.home}/.m2/archiva.xml or + * ${appserver.base}/conf/archiva.xml + */ + boolean isDefaulted(); + + /** + * Add a configuration listener to notify of changes to the configuration. + * + * @param listener the listener + */ + void addListener( ConfigurationListener listener ); + + /** + * Remove a configuration listener to stop notifications of changes to the configuration. + * + * @param listener the listener + */ + void removeListener( ConfigurationListener listener ); + + /** + * Add a registry listener to notify of events in spring-registry. + * + * @param listener the listener + * TODO: Remove in future. + */ + void addChangeListener( RegistryListener listener ); + + void removeChangeListener( RegistryListener listener ); + + /** + * reload configuration from file included registry + * + * @since 1.4-M1 + */ + void reload(); + + public Locale getDefaultLocale(); + + public List<Locale.LanguageRange> getLanguagePriorities(); + + public Path getAppServerBaseDir(); + + /** + * Returns the base directory for repositories that have a relative location path set. + * @return + */ + public Path getRepositoryBaseDir(); + + /** + * Returns the base directory for remote repositories + * @return + */ + public Path getRemoteRepositoryBaseDir(); + + /** + * Returns the base directory for repository group files. + * @return + */ + public Path getRepositoryGroupBaseDir(); + + /** + * Returns the data directory where repositories and metadata reside + * @return + */ + public Path getDataDirectory(); + + /** + * Return the used configuration registry + * @return + */ + Registry getRegistry( ); +} + diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/ConfigurationEvent.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/ConfigurationEvent.java new file mode 100644 index 000000000..5ad758c8b --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/ConfigurationEvent.java @@ -0,0 +1,81 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * ConfigurationEvent + * + * + */ +public class ConfigurationEvent +{ + public static final int SAVED = 1; + + public static final int CHANGED = 2; + + private int type; + + private String tag; + + public ConfigurationEvent( int type ) + { + this.type = type; + tag = ""; + } + + public ConfigurationEvent(int type, String tag) { + this.type = type; + this.tag = tag; + } + + public int getType() + { + return type; + } + + public String getTag( ) + { + return tag; + } + + public void setTag( String tag ) + { + this.tag = tag; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) return true; + if ( o == null || getClass( ) != o.getClass( ) ) return false; + + ConfigurationEvent that = (ConfigurationEvent) o; + + if ( type != that.type ) return false; + return tag.equals( that.tag ); + } + + @Override + public int hashCode( ) + { + int result = type; + result = 31 * result + tag.hashCode( ); + return result; + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/ConfigurationListener.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/ConfigurationListener.java new file mode 100644 index 000000000..370c61cec --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/ConfigurationListener.java @@ -0,0 +1,32 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * ConfigurationListener + * + * + */ +public interface ConfigurationListener +{ + /** + * Generic event point to notify components that something has happend in the configuration. + */ + void configurationEvent( ConfigurationEvent event ); +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/ConfigurationRuntimeException.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/ConfigurationRuntimeException.java new file mode 100644 index 000000000..abf2b7038 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/ConfigurationRuntimeException.java @@ -0,0 +1,31 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Unrecoverable exception in the configuration mechanism that is the result of a programming error. + */ +public class ConfigurationRuntimeException + extends RuntimeException +{ + public ConfigurationRuntimeException( String msg, Throwable cause ) + { + super( msg, cause ); + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/DefaultArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/DefaultArchivaConfiguration.java new file mode 100644 index 000000000..88efcf90a --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/DefaultArchivaConfiguration.java @@ -0,0 +1,908 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.components.evaluator.DefaultExpressionEvaluator; +import org.apache.archiva.components.evaluator.EvaluatorException; +import org.apache.archiva.components.evaluator.ExpressionEvaluator; +import org.apache.archiva.components.evaluator.sources.SystemPropertyExpressionSource; +import org.apache.archiva.components.registry.Registry; +import org.apache.archiva.components.registry.RegistryException; +import org.apache.archiva.components.registry.RegistryListener; +import org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry; +import org.apache.archiva.configuration.model.Configuration; +import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.model.ProxyConnectorConfiguration; +import org.apache.archiva.configuration.model.RemoteRepositoryConfiguration; +import org.apache.archiva.configuration.model.RepositoryCheckPath; +import org.apache.archiva.configuration.model.functors.ProxyConnectorConfigurationOrderComparator; +import org.apache.archiva.configuration.provider.io.registry.ConfigurationRegistryReader; +import org.apache.archiva.configuration.provider.io.registry.ConfigurationRegistryWriter; +import org.apache.archiva.policies.AbstractUpdatePolicy; +import org.apache.archiva.policies.CachedFailuresPolicy; +import org.apache.archiva.policies.ChecksumPolicy; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.ListUtils; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +/** + * <p> + * Implementation of configuration holder that retrieves it from the registry. + * </p> + * <p> + * The registry layers and merges the 2 configuration files: user, and application server. + * </p> + * <p> + * Instead of relying on the model defaults, if the registry is empty a default configuration file is loaded and + * applied from a resource. The defaults are not loaded into the registry as the lists (eg repositories) could no longer + * be removed if that was the case. + * </p> + * <p> + * When saving the configuration, it is saved to the location it was read from. If it was read from the defaults, it + * will be saved to the user location. + * However, if the configuration contains information from both sources, an exception is raised as this is currently + * unsupported. The reason for this is that it is not possible to identify where to re-save elements, and can result + * in list configurations (eg repositories) becoming inconsistent. + * </p> + * <p> + * If the configuration is outdated, it will be upgraded when it is loaded. This is done by checking the version flag + * before reading it from the registry. + * <p> + * FIXME: The synchronization must be improved, the current impl may lead to inconsistent data or multiple getConfiguration() calls (martin_s@apache.org) + * </p> + */ +@Service("archivaConfiguration#default") +public class DefaultArchivaConfiguration + implements ArchivaConfiguration, RegistryListener { + private final Logger log = LoggerFactory.getLogger(DefaultArchivaConfiguration.class); + + private static String FILE_ENCODING = "UTF-8"; + + /** + * Plexus registry to read the configuration from. + */ + @Inject + @Named(value = "commons-configuration") + private Registry registry; + + /** + * The configuration that has been converted. + */ + private Configuration configuration; + + /** + * see #initialize + * default-value="${user.home}/.m2/archiva.xml" + */ + private String userConfigFilename = "${user.home}/.m2/archiva.xml"; + + /** + * see #initialize + * default-value="${appserver.base}/conf/archiva.xml" + */ + private String altConfigFilename = "${appserver.base}/conf/archiva.xml"; + + /** + * Configuration Listeners we've registered. + */ + private Set<ConfigurationListener> listeners = new HashSet<>(); + + /** + * Registry Listeners we've registered. + */ + private Set<RegistryListener> registryListeners = new HashSet<>(); + + /** + * Boolean to help determine if the configuration exists as a result of pulling in + * the default-archiva.xml + */ + private boolean isConfigurationDefaulted = false; + + private static final String KEY = "org.apache.archiva"; + + // Section used for default only configuration + private static final String KEY_DEFAULT_ONLY = "org.apache.archiva_default"; + + private Locale defaultLocale = Locale.getDefault(); + + private List<Locale.LanguageRange> languagePriorities = new ArrayList<>(); + + private volatile Path dataDirectory; + private volatile Path repositoryBaseDirectory; + private volatile Path remoteRepositoryBaseDirectory; + private volatile Path repositoryGroupBaseDirectory; + + @PostConstruct + private void init() { + languagePriorities = Locale.LanguageRange.parse("en,fr,de"); + } + + + @Override + public Configuration getConfiguration() { + return loadConfiguration(); + } + + private synchronized Configuration loadConfiguration() { + if (configuration == null) { + configuration = load(); + configuration = unescapeExpressions(configuration); + if (isConfigurationDefaulted) { + configuration = checkRepositoryLocations(configuration); + } + } + + return configuration; + } + + private boolean hasConfigVersionChanged(Configuration current, Registry defaultOnlyConfiguration) { + return current == null || current.getVersion() == null || + !current.getVersion().trim().equals(defaultOnlyConfiguration.getString("version", "").trim()); + } + + @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; + } + + /* + * Updates the checkpath list for repositories. + * + * We are replacing existing ones and adding new ones. This allows to update the list with new releases. + * + * We are also updating existing remote repositories, if they exist already. + * + * This update method should only be called, if the config version changes to avoid overwriting + * user repository settings all the time. + */ + private void updateCheckPathDefaults(Configuration config, Registry defaultConfiguration) { + List<RepositoryCheckPath> existingCheckPathList = config.getArchivaDefaultConfiguration().getDefaultCheckPaths(); + HashMap<String, RepositoryCheckPath> existingCheckPaths = new HashMap<>(); + HashMap<String, RepositoryCheckPath> newCheckPaths = new HashMap<>(); + for (RepositoryCheckPath path : config.getArchivaDefaultConfiguration().getDefaultCheckPaths()) { + existingCheckPaths.put(path.getUrl(), path); + } + List defaultCheckPathsSubsets = defaultConfiguration.getSubsetList("archivaDefaultConfiguration.defaultCheckPaths.defaultCheckPath"); + for (Iterator i = defaultCheckPathsSubsets.iterator(); i.hasNext(); ) { + RepositoryCheckPath v = readRepositoryCheckPath((Registry) i.next()); + if (existingCheckPaths.containsKey(v.getUrl())) { + existingCheckPathList.remove(existingCheckPaths.get(v.getUrl())); + } + existingCheckPathList.add(v); + newCheckPaths.put(v.getUrl(), v); + } + // Remote repositories update + for (RemoteRepositoryConfiguration remoteRepositoryConfiguration : config.getRemoteRepositories()) { + String url = remoteRepositoryConfiguration.getUrl().toLowerCase(); + if (newCheckPaths.containsKey(url)) { + String currentPath = remoteRepositoryConfiguration.getCheckPath(); + String newPath = newCheckPaths.get(url).getPath(); + log.info("Updating connection check path for repository {}, from '{}' to '{}'.", remoteRepositoryConfiguration.getId(), + currentPath, newPath); + remoteRepositoryConfiguration.setCheckPath(newPath); + } + } + } + + private RepositoryCheckPath readRepositoryCheckPath(Registry registry) { + RepositoryCheckPath value = new RepositoryCheckPath(); + + String url = registry.getString("url", value.getUrl()); + + value.setUrl(url); + String path = registry.getString("path", value.getPath()); + value.setPath(path); + return value; + } + + + private Registry readDefaultConfiguration() { + // if it contains some old configuration, remove it (Archiva 0.9) + registry.removeSubset(KEY); + + try { + registry.addConfigurationFromResource("org/apache/archiva/configuration/default-archiva.xml", KEY); + this.isConfigurationDefaulted = true; + } catch (RegistryException e) { + throw new ConfigurationRuntimeException( + "Fatal error: Unable to find the built-in default configuration and load it into the registry", e); + } + return registry.getSubset(KEY); + } + + /* + * Reads the default only configuration into a special prefix. This allows to check for changes + * of the default configuration. + */ + private Registry readDefaultOnlyConfiguration() { + registry.removeSubset(KEY_DEFAULT_ONLY); + try { + registry.addConfigurationFromResource("org/apache/archiva/configuration/default-archiva.xml", KEY_DEFAULT_ONLY); + } catch (RegistryException e) { + throw new ConfigurationRuntimeException( + "Fatal error: Unable to find the built-in default configuration and load it into the registry", e); + } + return registry.getSubset(KEY_DEFAULT_ONLY); + } + + @SuppressWarnings("unchecked") + @Override + public synchronized void save(Configuration configuration) throws IndeterminateConfigurationException, RegistryException + { + save( configuration, "" ); + } + + /** + * 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(); + + // a little aggressive with the repositoryScanning and databaseScanning - should be no need to split + // 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); + } + + private void escapeCronExpressions(Configuration configuration) { + for ( ManagedRepositoryConfiguration c : configuration.getManagedRepositories()) { + c.setRefreshCronExpression(escapeCronExpression(c.getRefreshCronExpression())); + } + } + + private Registry createDefaultConfigurationFile(String eventTag) + 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, true)) { + 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).setInitialConfiguration(contents); + + registry.initialize(); + + for (RegistryListener regListener : registryListeners) { + addRegistryChangeListener(regListener); + } + + triggerEvent(ConfigurationEvent.SAVED, eventTag==null?"default-file":eventTag); + + Registry section = registry.getSection(KEY + ".user"); + if (section == null) { + return new CommonsConfigurationRegistry( ); + } else { + return section; + } + } + + private boolean writeFile(String filetype, String path, String contents) { + return writeFile( filetype, path, contents, false ); + } + + /** + * Attempts to write the contents to a file, if an IOException occurs, return false. + * <p/> + * The file will be created if the directory to the file exists, otherwise this will return false. + * + * @param filetype the filetype (freeform text) to use in logging messages when failure to write. + * @param path the path to write to. + * @param contents the contents to write. + * @return true if write successful. + */ + private boolean writeFile(String filetype, String path, String contents, boolean createDirs) { + try { + Path file = Paths.get(path); + // Check parent directory (if it is declared) + final Path parent = file.getParent(); + if (parent != null) { + // Check that directory exists + if (!Files.exists( parent ) && createDirs) { + Files.createDirectories( parent ); + } + if (!Files.isDirectory(parent)) { + // Directory to file must exist for file to be created + return false; + } + } + FileUtils.writeStringToFile(file.toFile(), contents, FILE_ENCODING); + return true; + } catch (IOException e) { + log.error("Unable to create {} file: {}", filetype, e.getMessage(), e); + return false; + } catch (InvalidPathException ipe) { + log.error("Unable to read {} file: {}", path, ipe.getMessage(), ipe); + return false; + } + } + + private void triggerEvent(int type, String eventTag) { + ConfigurationEvent evt = new ConfigurationEvent(type, eventTag); + for (ConfigurationListener listener : listeners) { + listener.configurationEvent(evt); + } + } + + @Override + public void addListener(ConfigurationListener listener) { + if (listener == null) { + return; + } + + listeners.add(listener); + } + + @Override + public void removeListener(ConfigurationListener listener) { + if (listener == null) { + return; + } + + listeners.remove(listener); + } + + + @Override + public void addChangeListener(RegistryListener listener) { + addRegistryChangeListener(listener); + + // keep track for later + registryListeners.add(listener); + } + + private void addRegistryChangeListener(RegistryListener listener) { + Registry section = registry.getSection(KEY + ".user"); + if (section != null) { + section.addChangeListener(listener); + } + section = registry.getSection(KEY + ".base"); + if (section != null) { + section.addChangeListener(listener); + } + } + + @Override + public void removeChangeListener(RegistryListener listener) { + boolean removed = registryListeners.remove(listener); + log.debug("RegistryListener: '{}' removed {}", listener, removed); + + Registry section = registry.getSection(KEY + ".user"); + if (section != null) { + section.removeChangeListener(listener); + } + section = registry.getSection(KEY + ".base"); + if (section != null) { + section.removeChangeListener(listener); + } + + } + + @PostConstruct + public void initialize() { + + // Resolve expressions in the userConfigFilename and altConfigFilename + try { + ExpressionEvaluator expressionEvaluator = new DefaultExpressionEvaluator(); + expressionEvaluator.addExpressionSource(new SystemPropertyExpressionSource()); + String userConfigFileNameSysProps = System.getProperty(USER_CONFIG_PROPERTY); + if (StringUtils.isNotBlank(userConfigFileNameSysProps)) { + userConfigFilename = userConfigFileNameSysProps; + } else { + String userConfigFileNameEnv = System.getenv(USER_CONFIG_ENVVAR); + if (StringUtils.isNotBlank(userConfigFileNameEnv)) { + userConfigFilename = userConfigFileNameEnv; + } 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); + } + + /** + * 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()); + } + } + } + + @Override + public void reload() { + this.configuration = null; + try { + this.registry.initialize(); + } catch (RegistryException e) { + throw new ConfigurationRuntimeException(e.getMessage(), e); + } + this.initialize(); + } + + @Override + public Locale getDefaultLocale() { + return defaultLocale; + } + + @Override + public List<Locale.LanguageRange> getLanguagePriorities() { + return languagePriorities; + } + + @Override + public Path getAppServerBaseDir() { + String basePath = registry.getString("appserver.base"); + if (!StringUtils.isEmpty(basePath)) { + return Paths.get(basePath); + } else { + return Paths.get(""); + } + } + + @Override + public Path getRepositoryBaseDir() { + if (repositoryBaseDirectory == null) { + getConfiguration(); + } + return repositoryBaseDirectory; + + } + + @Override + public Path getRemoteRepositoryBaseDir() { + if (remoteRepositoryBaseDirectory == null) { + getConfiguration(); + } + return remoteRepositoryBaseDirectory; + } + + @Override + public Path getRepositoryGroupBaseDir() { + if (repositoryGroupBaseDirectory == null) { + getConfiguration(); + } + return repositoryGroupBaseDirectory; + } + + @Override + public Path getDataDirectory() { + if (dataDirectory == null) { + getConfiguration(); + } + return dataDirectory; + } + + @Override + public void beforeConfigurationChange(Registry registry, String propertyName, Object propertyValue) { + // nothing to do here + } + + @Override + public synchronized void afterConfigurationChange(Registry registry, String propertyName, Object propertyValue) { + // configuration = null; + // this.dataDirectory = null; + // this.repositoryBaseDirectory = null; + } + + private String removeExpressions(String directory) { + 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; + } + + private String unescapeCronExpression(String cronExpression) { + return StringUtils.replace(cronExpression, "\\,", ","); + } + + private String escapeCronExpression(String cronExpression) { + return StringUtils.replace(cronExpression, ",", "\\,"); + } + + private Configuration unescapeExpressions(Configuration config) { + // TODO: for commons-configuration 1.3 only + for (ManagedRepositoryConfiguration c : config.getManagedRepositories()) { + c.setLocation(removeExpressions(c.getLocation())); + c.setRefreshCronExpression(unescapeCronExpression(c.getRefreshCronExpression())); + } + + return config; + } + + private Configuration checkRepositoryLocations(Configuration config) { + // additional check for [MRM-789], ensure that the location of the default repositories + // are not installed in the server installation + for (ManagedRepositoryConfiguration repo : (List<ManagedRepositoryConfiguration>) config.getManagedRepositories()) { + String repoPath = repo.getLocation(); + Path repoLocation = Paths.get(repoPath); + + if (Files.exists(repoLocation) && Files.isDirectory(repoLocation) && !repoPath.endsWith( + "/repositories/" + repo.getId())) { + repo.setLocation(repoPath + "/data/repositories/" + repo.getId()); + } + } + + return config; + } + + public String getUserConfigFilename() { + return userConfigFilename; + } + + public String getAltConfigFilename() { + return altConfigFilename; + } + + @Override + public boolean isDefaulted() { + return this.isConfigurationDefaulted; + } + + public Registry getRegistry() { + return registry; + } + + public void setRegistry(Registry registry) { + this.registry = registry; + } + + + public void setUserConfigFilename(String userConfigFilename) { + this.userConfigFilename = userConfigFilename; + } + + public void setAltConfigFilename(String altConfigFilename) { + this.altConfigFilename = altConfigFilename; + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/FileTypes.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/FileTypes.java new file mode 100644 index 000000000..a08e4bf14 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/FileTypes.java @@ -0,0 +1,210 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.common.FileTypeUtils; +import org.apache.archiva.components.registry.Registry; +import org.apache.archiva.components.registry.RegistryListener; +import org.apache.archiva.configuration.model.Configuration; +import org.apache.archiva.configuration.model.FileType; +import org.apache.archiva.configuration.model.RepositoryScanningConfiguration; +import org.apache.archiva.configuration.model.functors.FiletypeSelectionPredicate; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.IterableUtils; +import org.apache.commons.collections4.Predicate; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; +import java.nio.file.FileSystems; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * FileTypes + */ +@Service("fileTypes") +public class FileTypes + implements RegistryListener +{ + public static final String ARTIFACTS = "artifacts"; + + public static final String AUTO_REMOVE = "auto-remove"; + + public static final String INDEXABLE_CONTENT = "indexable-content"; + + public static final String IGNORED = "ignored"; + + @Inject + @Named(value = "archivaConfiguration#default") + private ArchivaConfiguration archivaConfiguration; + + + public FileTypes() { + + } + + /** + * Map of default values for the file types. + */ + private Map<String, List<String>> defaultTypeMap = new HashMap<>(); + + private List<String> artifactPatterns; + + /** + * Default exclusions from artifact consumers that are using the file types. Note that this is simplistic in the + * case of the support files (based on extension) as it is elsewhere - it may be better to match these to actual + * artifacts and exclude later during scanning. + * + * @deprecated + */ + public static final List<String> DEFAULT_EXCLUSIONS = FileTypeUtils.DEFAULT_EXCLUSIONS; + + public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) + { + this.archivaConfiguration = archivaConfiguration; + } + + /** + * Get the list of patterns for a specified filetype. + * You will always get a list. In this order. + * <ul> + * <li>The Configured List</li> + * <li>The Default List</li> + * <li>A single item list of <code>"**/*"</code></li> + * </ul> + * + * @param id the id to lookup. + * @return the list of patterns. + */ + public List<String> getFileTypePatterns( String id ) + { + Configuration config = archivaConfiguration.getConfiguration(); + Predicate selectedFiletype = new FiletypeSelectionPredicate( id ); + RepositoryScanningConfiguration repositoryScanningConfiguration = config.getRepositoryScanning(); + if ( repositoryScanningConfiguration != null ) + { + FileType filetype = + IterableUtils.find( config.getRepositoryScanning().getFileTypes(), selectedFiletype ); + + if ( ( filetype != null ) && CollectionUtils.isNotEmpty( filetype.getPatterns() ) ) + { + return filetype.getPatterns(); + } + } + List<String> defaultPatterns = defaultTypeMap.get( id ); + + if ( CollectionUtils.isEmpty( defaultPatterns ) ) + { + return Collections.singletonList( "**/*" ); + } + + return defaultPatterns; + } + + public synchronized boolean matchesArtifactPattern( String relativePath ) + { + // Correct the slash pattern. + relativePath = relativePath.replace( '\\', '/' ); + + if ( artifactPatterns == null ) + { + artifactPatterns = getFileTypePatterns( ARTIFACTS ); + } + + for ( String pattern : artifactPatterns ) + { + if ( FileSystems.getDefault().getPathMatcher( "glob:" + pattern).matches( Paths.get( relativePath ) ) ) + { + // Found match + return true; + } + } + + // No match. + return false; + } + + public boolean matchesDefaultExclusions( String relativePath ) + { + // Correct the slash pattern. + relativePath = relativePath.replace( '\\', '/' ); + + for ( String pattern : DEFAULT_EXCLUSIONS ) + { + if ( FileSystems.getDefault().getPathMatcher( "glob:" + pattern).matches( Paths.get( relativePath ) ) ) + { + // Found match + return true; + } + } + + // No match. + return false; + } + + @PostConstruct + public void initialize() + { + initialiseTypeMap( this.archivaConfiguration.getConfiguration() ); + + this.archivaConfiguration.addChangeListener( this ); + } + + private void initialiseTypeMap( Configuration configuration ) + { + defaultTypeMap.clear(); + + // Store the default file type declaration. + List<FileType> filetypes = configuration.getRepositoryScanning().getFileTypes(); + for ( FileType filetype : filetypes ) + { + List<String> patterns = defaultTypeMap.get( filetype.getId() ); + if ( patterns == null ) + { + patterns = new ArrayList<>( filetype.getPatterns().size() ); + } + patterns.addAll( filetype.getPatterns() ); + + defaultTypeMap.put( filetype.getId(), patterns ); + } + } + + @Override + public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + if ( propertyName.contains( "fileType" ) ) + { + artifactPatterns = null; + + initialiseTypeMap( archivaConfiguration.getConfiguration() ); + } + } + + @Override + public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + /* nothing to do */ + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/IndeterminateConfigurationException.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/IndeterminateConfigurationException.java new file mode 100644 index 000000000..39054ced6 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/IndeterminateConfigurationException.java @@ -0,0 +1,31 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Occurs when the configuration is stored in two locations and the save location can not be determined. + */ +public class IndeterminateConfigurationException + extends Exception +{ + public IndeterminateConfigurationException( String message ) + { + super( message ); + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/InvalidConfigurationException.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/InvalidConfigurationException.java new file mode 100644 index 000000000..f65aa7d1b --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/InvalidConfigurationException.java @@ -0,0 +1,46 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * An error in the configuration. + */ +public class InvalidConfigurationException + extends Exception +{ + private final String name; + + public InvalidConfigurationException( String name, String message ) + { + super( message ); + this.name = name; + } + + public InvalidConfigurationException( String name, String message, Throwable cause ) + { + super( message, cause ); + + this.name = name; + } + + public String getName() + { + return name; + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/MavenProxyPropertyLoader.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/MavenProxyPropertyLoader.java new file mode 100644 index 000000000..7f657f92f --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/MavenProxyPropertyLoader.java @@ -0,0 +1,156 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.configuration.model.Configuration; +import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.model.NetworkProxyConfiguration; +import org.apache.archiva.configuration.model.ProxyConnectorConfiguration; +import org.apache.archiva.configuration.model.RemoteRepositoryConfiguration; +import org.apache.archiva.policies.ReleasesPolicy; +import org.apache.archiva.policies.SnapshotsPolicy; +import org.apache.commons.lang3.StringUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Properties; +import java.util.StringTokenizer; + +/** + */ +public class MavenProxyPropertyLoader +{ + private static final String REPO_LOCAL_STORE = "repo.local.store"; + + private static final String PROXY_LIST = "proxy.list"; + + private static final String REPO_LIST = "repo.list"; + + public void load( Properties props, Configuration configuration ) + throws InvalidConfigurationException + { + // set up the managed repository + String localCachePath = getMandatoryProperty( props, REPO_LOCAL_STORE ); + + ManagedRepositoryConfiguration config = new ManagedRepositoryConfiguration(); + config.setLocation( localCachePath ); + config.setName( "Imported Maven-Proxy Cache" ); + config.setId( "maven-proxy" ); + config.setScanned( false ); + config.setReleases( true ); + config.setSnapshots( false ); + configuration.addManagedRepository( config ); + + // Add the network proxies. + String propertyList = props.getProperty( PROXY_LIST ); + if ( propertyList != null ) + { + StringTokenizer tok = new StringTokenizer( propertyList, "," ); + while ( tok.hasMoreTokens() ) + { + String key = tok.nextToken(); + if ( StringUtils.isNotEmpty( key ) ) + { + NetworkProxyConfiguration proxy = new NetworkProxyConfiguration(); + proxy.setHost( getMandatoryProperty( props, "proxy." + key + ".host" ) ); + proxy.setPort( Integer.parseInt( getMandatoryProperty( props, "proxy." + key + ".port" ) ) ); + + // the username and password isn't required + proxy.setUsername( props.getProperty( "proxy." + key + ".username" ) ); + proxy.setPassword( props.getProperty( "proxy." + key + ".password" ) ); + + configuration.addNetworkProxy( proxy ); + } + } + } + + // Add the remote repository list + String repoList = getMandatoryProperty( props, REPO_LIST ); + + StringTokenizer tok = new StringTokenizer( repoList, "," ); + while ( tok.hasMoreTokens() ) + { + String key = tok.nextToken(); + + Properties repoProps = getSubset( props, "repo." + key + "." ); + String url = getMandatoryProperty( props, "repo." + key + ".url" ); + String proxyKey = repoProps.getProperty( "proxy" ); + +// int cachePeriod = Integer.parseInt( repoProps.getProperty( "cache.period", "60" ) ); + + RemoteRepositoryConfiguration repository = new RemoteRepositoryConfiguration(); + repository.setId( key ); + repository.setName( "Imported Maven-Proxy Remote Proxy" ); + repository.setUrl( url ); + repository.setLayout( "legacy" ); + + configuration.addRemoteRepository( repository ); + + ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration(); + proxyConnector.setSourceRepoId( "maven-proxy" ); + proxyConnector.setTargetRepoId( key ); + proxyConnector.setProxyId( proxyKey ); + // TODO: convert cachePeriod to closest "daily" or "hourly" + proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, SnapshotsPolicy.DAILY.getId() ); + proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.ALWAYS.getId() ); + + configuration.addProxyConnector( proxyConnector ); + } + } + + @SuppressWarnings( "unchecked" ) + private Properties getSubset( Properties props, String prefix ) + { + Enumeration keys = props.keys(); + Properties result = new Properties(); + while ( keys.hasMoreElements() ) + { + String key = (String) keys.nextElement(); + String value = props.getProperty( key ); + if ( key.startsWith( prefix ) ) + { + String newKey = key.substring( prefix.length() ); + result.setProperty( newKey, value ); + } + } + return result; + } + + public void load( InputStream is, Configuration configuration ) + throws IOException, InvalidConfigurationException + { + Properties props = new Properties(); + props.load( is ); + load( props, configuration ); + } + + private String getMandatoryProperty( Properties props, String key ) + throws InvalidConfigurationException + { + String value = props.getProperty( key ); + + if ( value == null ) + { + throw new InvalidConfigurationException( key, "Missing required field: " + key ); + } + + return value; + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/io/registry/ConfigurationRegistryReader.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/io/registry/ConfigurationRegistryReader.java new file mode 100644 index 000000000..6a89e1cf7 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/io/registry/ConfigurationRegistryReader.java @@ -0,0 +1,1704 @@ + +package org.apache.archiva.configuration.provider.io.registry; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.components.registry.Registry; +import org.apache.archiva.configuration.model.AbstractRepositoryConfiguration; +import org.apache.archiva.configuration.model.AbstractRepositoryConnectorConfiguration; +import org.apache.archiva.configuration.model.ArchivaDefaultConfiguration; +import org.apache.archiva.configuration.model.ArchivaRuntimeConfiguration; +import org.apache.archiva.configuration.model.CacheConfiguration; +import org.apache.archiva.configuration.model.Configuration; +import org.apache.archiva.configuration.model.FileLockConfiguration; +import org.apache.archiva.configuration.model.FileType; +import org.apache.archiva.configuration.model.LdapConfiguration; +import org.apache.archiva.configuration.model.LdapGroupMapping; +import org.apache.archiva.configuration.model.LegacyArtifactPath; +import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.model.NetworkConfiguration; +import org.apache.archiva.configuration.model.NetworkProxyConfiguration; +import org.apache.archiva.configuration.model.OrganisationInformation; +import org.apache.archiva.configuration.model.ProxyConnectorConfiguration; +import org.apache.archiva.configuration.model.ProxyConnectorRuleConfiguration; +import org.apache.archiva.configuration.model.RedbackRuntimeConfiguration; +import org.apache.archiva.configuration.model.RemoteRepositoryConfiguration; +import org.apache.archiva.configuration.model.RepositoryCheckPath; +import org.apache.archiva.configuration.model.RepositoryGroupConfiguration; +import org.apache.archiva.configuration.model.RepositoryScanningConfiguration; +import org.apache.archiva.configuration.model.SyncConnectorConfiguration; +import org.apache.archiva.configuration.model.UserInterfaceOptions; +import org.apache.archiva.configuration.model.WebappConfiguration; + +import java.util.Iterator; +import java.util.List; + +// Util imports +// Model class imports + + +/** + * Generate Redback Registry input mechanism for model 'Configuration'. + */ +public class ConfigurationRegistryReader { + public Configuration read( Registry registry) { + return readConfiguration("", registry); + } + + private Configuration readConfiguration(String prefix, Registry registry) { + Configuration value = new Configuration(); + + //String version = registry.getString( prefix + "version", value.getVersion() ); + + List<String> versionList = registry.getList(prefix + "version"); + String version = value.getVersion(); + if (versionList != null && !versionList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = versionList.size(); i < size; i++) { + sb.append(versionList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + version = sb.toString(); + } + + value.setVersion(version); + //String metadataStore = registry.getString( prefix + "metadataStore", value.getMetadataStore() ); + + List<String> metadataStoreList = registry.getList(prefix + "metadataStore"); + String metadataStore = value.getMetadataStore(); + if (metadataStoreList != null && !metadataStoreList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = metadataStoreList.size(); i < size; i++) { + sb.append(metadataStoreList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + metadataStore = sb.toString(); + } + + value.setMetadataStore(metadataStore); + java.util.List repositoryGroups = new java.util.ArrayList/*<RepositoryGroupConfiguration>*/(); + List repositoryGroupsSubsets = registry.getSubsetList(prefix + "repositoryGroups.repositoryGroup"); + for (Iterator i = repositoryGroupsSubsets.iterator(); i.hasNext(); ) { + RepositoryGroupConfiguration v = readRepositoryGroupConfiguration("", (Registry) i.next()); + repositoryGroups.add(v); + } + value.setRepositoryGroups(repositoryGroups); + java.util.List managedRepositories = new java.util.ArrayList/*<ManagedRepositoryConfiguration>*/(); + List managedRepositoriesSubsets = registry.getSubsetList(prefix + "managedRepositories.managedRepository"); + for (Iterator i = managedRepositoriesSubsets.iterator(); i.hasNext(); ) { + ManagedRepositoryConfiguration v = readManagedRepositoryConfiguration("", (Registry) i.next()); + managedRepositories.add(v); + } + value.setManagedRepositories(managedRepositories); + java.util.List remoteRepositories = new java.util.ArrayList/*<RemoteRepositoryConfiguration>*/(); + List remoteRepositoriesSubsets = registry.getSubsetList(prefix + "remoteRepositories.remoteRepository"); + for (Iterator i = remoteRepositoriesSubsets.iterator(); i.hasNext(); ) { + RemoteRepositoryConfiguration v = readRemoteRepositoryConfiguration("", (Registry) i.next()); + remoteRepositories.add(v); + } + value.setRemoteRepositories(remoteRepositories); + java.util.List proxyConnectors = new java.util.ArrayList/*<ProxyConnectorConfiguration>*/(); + List proxyConnectorsSubsets = registry.getSubsetList(prefix + "proxyConnectors.proxyConnector"); + for (Iterator i = proxyConnectorsSubsets.iterator(); i.hasNext(); ) { + ProxyConnectorConfiguration v = readProxyConnectorConfiguration("", (Registry) i.next()); + proxyConnectors.add(v); + } + value.setProxyConnectors(proxyConnectors); + java.util.List networkProxies = new java.util.ArrayList/*<NetworkProxyConfiguration>*/(); + List networkProxiesSubsets = registry.getSubsetList(prefix + "networkProxies.networkProxy"); + for (Iterator i = networkProxiesSubsets.iterator(); i.hasNext(); ) { + NetworkProxyConfiguration v = readNetworkProxyConfiguration("", (Registry) i.next()); + networkProxies.add(v); + } + value.setNetworkProxies(networkProxies); + java.util.List legacyArtifactPaths = new java.util.ArrayList/*<LegacyArtifactPath>*/(); + List legacyArtifactPathsSubsets = registry.getSubsetList(prefix + "legacyArtifactPaths.legacyArtifactPath"); + for (Iterator i = legacyArtifactPathsSubsets.iterator(); i.hasNext(); ) { + LegacyArtifactPath v = readLegacyArtifactPath("", (Registry) i.next()); + legacyArtifactPaths.add(v); + } + value.setLegacyArtifactPaths(legacyArtifactPaths); + RepositoryScanningConfiguration repositoryScanning = readRepositoryScanningConfiguration(prefix + "repositoryScanning.", registry); + value.setRepositoryScanning(repositoryScanning); + WebappConfiguration webapp = readWebappConfiguration(prefix + "webapp.", registry); + value.setWebapp(webapp); + OrganisationInformation organisationInfo = readOrganisationInformation(prefix + "organisationInfo.", registry); + value.setOrganisationInfo(organisationInfo); + NetworkConfiguration networkConfiguration = readNetworkConfiguration(prefix + "networkConfiguration.", registry); + value.setNetworkConfiguration(networkConfiguration); + RedbackRuntimeConfiguration redbackRuntimeConfiguration = readRedbackRuntimeConfiguration(prefix + "redbackRuntimeConfiguration.", registry); + value.setRedbackRuntimeConfiguration(redbackRuntimeConfiguration); + ArchivaRuntimeConfiguration archivaRuntimeConfiguration = readArchivaRuntimeConfiguration(prefix + "archivaRuntimeConfiguration.", registry); + value.setArchivaRuntimeConfiguration(archivaRuntimeConfiguration); + java.util.List proxyConnectorRuleConfigurations = new java.util.ArrayList/*<ProxyConnectorRuleConfiguration>*/(); + List proxyConnectorRuleConfigurationsSubsets = registry.getSubsetList(prefix + "proxyConnectorRuleConfigurations.proxyConnectorRuleConfiguration"); + for (Iterator i = proxyConnectorRuleConfigurationsSubsets.iterator(); i.hasNext(); ) { + ProxyConnectorRuleConfiguration v = readProxyConnectorRuleConfiguration("", (Registry) i.next()); + proxyConnectorRuleConfigurations.add(v); + } + value.setProxyConnectorRuleConfigurations(proxyConnectorRuleConfigurations); + ArchivaDefaultConfiguration archivaDefaultConfiguration = readArchivaDefaultConfiguration(prefix + "archivaDefaultConfiguration.", registry); + value.setArchivaDefaultConfiguration(archivaDefaultConfiguration); + + return value; + } + + private AbstractRepositoryConfiguration readAbstractRepositoryConfiguration( String prefix, Registry registry) { + AbstractRepositoryConfiguration value = new AbstractRepositoryConfiguration(); + + //String id = registry.getString( prefix + "id", value.getId() ); + + List<String> idList = registry.getList(prefix + "id"); + String id = value.getId(); + if (idList != null && !idList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = idList.size(); i < size; i++) { + sb.append(idList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + id = sb.toString(); + } + + value.setId(id); + //String type = registry.getString( prefix + "type", value.getType() ); + + List<String> typeList = registry.getList(prefix + "type"); + String type = value.getType(); + if (typeList != null && !typeList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = typeList.size(); i < size; i++) { + sb.append(typeList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + type = sb.toString(); + } + + value.setType(type); + //String name = registry.getString( prefix + "name", value.getName() ); + + List<String> nameList = registry.getList(prefix + "name"); + String name = value.getName(); + if (nameList != null && !nameList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = nameList.size(); i < size; i++) { + sb.append(nameList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + name = sb.toString(); + } + + value.setName(name); + //String layout = registry.getString( prefix + "layout", value.getLayout() ); + + List<String> layoutList = registry.getList(prefix + "layout"); + String layout = value.getLayout(); + if (layoutList != null && !layoutList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = layoutList.size(); i < size; i++) { + sb.append(layoutList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + layout = sb.toString(); + } + + value.setLayout(layout); + //String indexDir = registry.getString( prefix + "indexDir", value.getIndexDir() ); + + List<String> indexDirList = registry.getList(prefix + "indexDir"); + String indexDir = value.getIndexDir(); + if (indexDirList != null && !indexDirList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = indexDirList.size(); i < size; i++) { + sb.append(indexDirList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + indexDir = sb.toString(); + } + + value.setIndexDir(indexDir); + //String packedIndexDir = registry.getString( prefix + "packedIndexDir", value.getPackedIndexDir() ); + + List<String> packedIndexDirList = registry.getList(prefix + "packedIndexDir"); + String packedIndexDir = value.getPackedIndexDir(); + if (packedIndexDirList != null && !packedIndexDirList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = packedIndexDirList.size(); i < size; i++) { + sb.append(packedIndexDirList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + packedIndexDir = sb.toString(); + } + + value.setPackedIndexDir(packedIndexDir); + //String description = registry.getString( prefix + "description", value.getDescription() ); + + List<String> descriptionList = registry.getList(prefix + "description"); + String description = value.getDescription(); + if (descriptionList != null && !descriptionList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = descriptionList.size(); i < size; i++) { + sb.append(descriptionList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + description = sb.toString(); + } + + value.setDescription(description); + + return value; + } + + private RemoteRepositoryConfiguration readRemoteRepositoryConfiguration(String prefix, Registry registry) { + RemoteRepositoryConfiguration value = new RemoteRepositoryConfiguration(); + + //String url = registry.getString( prefix + "url", value.getUrl() ); + + List<String> urlList = registry.getList(prefix + "url"); + String url = value.getUrl(); + if (urlList != null && !urlList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = urlList.size(); i < size; i++) { + sb.append(urlList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + url = sb.toString(); + } + + value.setUrl(url); + //String username = registry.getString( prefix + "username", value.getUsername() ); + + List<String> usernameList = registry.getList(prefix + "username"); + String username = value.getUsername(); + if (usernameList != null && !usernameList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = usernameList.size(); i < size; i++) { + sb.append(usernameList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + username = sb.toString(); + } + + value.setUsername(username); + //String password = registry.getString( prefix + "password", value.getPassword() ); + + List<String> passwordList = registry.getList(prefix + "password"); + String password = value.getPassword(); + if (passwordList != null && !passwordList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = passwordList.size(); i < size; i++) { + sb.append(passwordList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + password = sb.toString(); + } + + value.setPassword(password); + int timeout = registry.getInt(prefix + "timeout", value.getTimeout()); + value.setTimeout(timeout); + //String refreshCronExpression = registry.getString( prefix + "refreshCronExpression", value.getRefreshCronExpression() ); + + List<String> refreshCronExpressionList = registry.getList(prefix + "refreshCronExpression"); + String refreshCronExpression = value.getRefreshCronExpression(); + if (refreshCronExpressionList != null && !refreshCronExpressionList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = refreshCronExpressionList.size(); i < size; i++) { + sb.append(refreshCronExpressionList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + refreshCronExpression = sb.toString(); + } + + value.setRefreshCronExpression(refreshCronExpression); + boolean downloadRemoteIndex = registry.getBoolean(prefix + "downloadRemoteIndex", value.isDownloadRemoteIndex()); + value.setDownloadRemoteIndex(downloadRemoteIndex); + //String remoteIndexUrl = registry.getString( prefix + "remoteIndexUrl", value.getRemoteIndexUrl() ); + + List<String> remoteIndexUrlList = registry.getList(prefix + "remoteIndexUrl"); + String remoteIndexUrl = value.getRemoteIndexUrl(); + if (remoteIndexUrlList != null && !remoteIndexUrlList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = remoteIndexUrlList.size(); i < size; i++) { + sb.append(remoteIndexUrlList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + remoteIndexUrl = sb.toString(); + } + + value.setRemoteIndexUrl(remoteIndexUrl); + //String remoteDownloadNetworkProxyId = registry.getString( prefix + "remoteDownloadNetworkProxyId", value.getRemoteDownloadNetworkProxyId() ); + + List<String> remoteDownloadNetworkProxyIdList = registry.getList(prefix + "remoteDownloadNetworkProxyId"); + String remoteDownloadNetworkProxyId = value.getRemoteDownloadNetworkProxyId(); + if (remoteDownloadNetworkProxyIdList != null && !remoteDownloadNetworkProxyIdList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = remoteDownloadNetworkProxyIdList.size(); i < size; i++) { + sb.append(remoteDownloadNetworkProxyIdList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + remoteDownloadNetworkProxyId = sb.toString(); + } + + value.setRemoteDownloadNetworkProxyId(remoteDownloadNetworkProxyId); + int remoteDownloadTimeout = registry.getInt(prefix + "remoteDownloadTimeout", value.getRemoteDownloadTimeout()); + value.setRemoteDownloadTimeout(remoteDownloadTimeout); + boolean downloadRemoteIndexOnStartup = registry.getBoolean(prefix + "downloadRemoteIndexOnStartup", value.isDownloadRemoteIndexOnStartup()); + value.setDownloadRemoteIndexOnStartup(downloadRemoteIndexOnStartup); + java.util.Map extraParameters = registry.getProperties(prefix + "extraParameters"); + value.setExtraParameters(extraParameters); + java.util.Map extraHeaders = registry.getProperties(prefix + "extraHeaders"); + value.setExtraHeaders(extraHeaders); + //String checkPath = registry.getString( prefix + "checkPath", value.getCheckPath() ); + + List<String> checkPathList = registry.getList(prefix + "checkPath"); + String checkPath = value.getCheckPath(); + if (checkPathList != null && !checkPathList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = checkPathList.size(); i < size; i++) { + sb.append(checkPathList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + checkPath = sb.toString(); + } + + value.setCheckPath(checkPath); + //String id = registry.getString( prefix + "id", value.getId() ); + + List<String> idList = registry.getList(prefix + "id"); + String id = value.getId(); + if (idList != null && !idList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = idList.size(); i < size; i++) { + sb.append(idList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + id = sb.toString(); + } + + value.setId(id); + //String type = registry.getString( prefix + "type", value.getType() ); + + List<String> typeList = registry.getList(prefix + "type"); + String type = value.getType(); + if (typeList != null && !typeList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = typeList.size(); i < size; i++) { + sb.append(typeList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + type = sb.toString(); + } + + value.setType(type); + //String name = registry.getString( prefix + "name", value.getName() ); + + List<String> nameList = registry.getList(prefix + "name"); + String name = value.getName(); + if (nameList != null && !nameList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = nameList.size(); i < size; i++) { + sb.append(nameList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + name = sb.toString(); + } + + value.setName(name); + //String layout = registry.getString( prefix + "layout", value.getLayout() ); + + List<String> layoutList = registry.getList(prefix + "layout"); + String layout = value.getLayout(); + if (layoutList != null && !layoutList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = layoutList.size(); i < size; i++) { + sb.append(layoutList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + layout = sb.toString(); + } + + value.setLayout(layout); + //String indexDir = registry.getString( prefix + "indexDir", value.getIndexDir() ); + + List<String> indexDirList = registry.getList(prefix + "indexDir"); + String indexDir = value.getIndexDir(); + if (indexDirList != null && !indexDirList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = indexDirList.size(); i < size; i++) { + sb.append(indexDirList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + indexDir = sb.toString(); + } + + value.setIndexDir(indexDir); + //String packedIndexDir = registry.getString( prefix + "packedIndexDir", value.getPackedIndexDir() ); + + List<String> packedIndexDirList = registry.getList(prefix + "packedIndexDir"); + String packedIndexDir = value.getPackedIndexDir(); + if (packedIndexDirList != null && !packedIndexDirList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = packedIndexDirList.size(); i < size; i++) { + sb.append(packedIndexDirList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + packedIndexDir = sb.toString(); + } + + value.setPackedIndexDir(packedIndexDir); + //String description = registry.getString( prefix + "description", value.getDescription() ); + + List<String> descriptionList = registry.getList(prefix + "description"); + String description = value.getDescription(); + if (descriptionList != null && !descriptionList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = descriptionList.size(); i < size; i++) { + sb.append(descriptionList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + description = sb.toString(); + } + + value.setDescription(description); + + return value; + } + + private ManagedRepositoryConfiguration readManagedRepositoryConfiguration(String prefix, Registry registry) { + ManagedRepositoryConfiguration value = new ManagedRepositoryConfiguration(); + + //String location = registry.getString( prefix + "location", value.getLocation() ); + + List<String> locationList = registry.getList(prefix + "location"); + String location = value.getLocation(); + if (locationList != null && !locationList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = locationList.size(); i < size; i++) { + sb.append(locationList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + location = sb.toString(); + } + + value.setLocation(location); + boolean releases = registry.getBoolean(prefix + "releases", value.isReleases()); + value.setReleases(releases); + boolean blockRedeployments = registry.getBoolean(prefix + "blockRedeployments", value.isBlockRedeployments()); + value.setBlockRedeployments(blockRedeployments); + boolean snapshots = registry.getBoolean(prefix + "snapshots", value.isSnapshots()); + value.setSnapshots(snapshots); + boolean scanned = registry.getBoolean(prefix + "scanned", value.isScanned()); + value.setScanned(scanned); + //String refreshCronExpression = registry.getString( prefix + "refreshCronExpression", value.getRefreshCronExpression() ); + + List<String> refreshCronExpressionList = registry.getList(prefix + "refreshCronExpression"); + String refreshCronExpression = value.getRefreshCronExpression(); + if (refreshCronExpressionList != null && !refreshCronExpressionList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = refreshCronExpressionList.size(); i < size; i++) { + sb.append(refreshCronExpressionList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + refreshCronExpression = sb.toString(); + } + + value.setRefreshCronExpression(refreshCronExpression); + int retentionCount = registry.getInt(prefix + "retentionCount", value.getRetentionCount()); + value.setRetentionCount(retentionCount); + int retentionPeriod = registry.getInt(prefix + "retentionPeriod", value.getRetentionPeriod()); + value.setRetentionPeriod(retentionPeriod); + boolean deleteReleasedSnapshots = registry.getBoolean(prefix + "deleteReleasedSnapshots", value.isDeleteReleasedSnapshots()); + value.setDeleteReleasedSnapshots(deleteReleasedSnapshots); + boolean skipPackedIndexCreation = registry.getBoolean(prefix + "skipPackedIndexCreation", value.isSkipPackedIndexCreation()); + value.setSkipPackedIndexCreation(skipPackedIndexCreation); + boolean stageRepoNeeded = registry.getBoolean(prefix + "stageRepoNeeded", value.isStageRepoNeeded()); + value.setStageRepoNeeded(stageRepoNeeded); + //String id = registry.getString( prefix + "id", value.getId() ); + + List<String> idList = registry.getList(prefix + "id"); + String id = value.getId(); + if (idList != null && !idList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = idList.size(); i < size; i++) { + sb.append(idList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + id = sb.toString(); + } + + value.setId(id); + //String type = registry.getString( prefix + "type", value.getType() ); + + List<String> typeList = registry.getList(prefix + "type"); + String type = value.getType(); + if (typeList != null && !typeList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = typeList.size(); i < size; i++) { + sb.append(typeList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + type = sb.toString(); + } + + value.setType(type); + //String name = registry.getString( prefix + "name", value.getName() ); + + List<String> nameList = registry.getList(prefix + "name"); + String name = value.getName(); + if (nameList != null && !nameList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = nameList.size(); i < size; i++) { + sb.append(nameList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + name = sb.toString(); + } + + value.setName(name); + //String layout = registry.getString( prefix + "layout", value.getLayout() ); + + List<String> layoutList = registry.getList(prefix + "layout"); + String layout = value.getLayout(); + if (layoutList != null && !layoutList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = layoutList.size(); i < size; i++) { + sb.append(layoutList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + layout = sb.toString(); + } + + value.setLayout(layout); + //String indexDir = registry.getString( prefix + "indexDir", value.getIndexDir() ); + + List<String> indexDirList = registry.getList(prefix + "indexDir"); + String indexDir = value.getIndexDir(); + if (indexDirList != null && !indexDirList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = indexDirList.size(); i < size; i++) { + sb.append(indexDirList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + indexDir = sb.toString(); + } + + value.setIndexDir(indexDir); + //String packedIndexDir = registry.getString( prefix + "packedIndexDir", value.getPackedIndexDir() ); + + List<String> packedIndexDirList = registry.getList(prefix + "packedIndexDir"); + String packedIndexDir = value.getPackedIndexDir(); + if (packedIndexDirList != null && !packedIndexDirList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = packedIndexDirList.size(); i < size; i++) { + sb.append(packedIndexDirList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + packedIndexDir = sb.toString(); + } + + value.setPackedIndexDir(packedIndexDir); + //String description = registry.getString( prefix + "description", value.getDescription() ); + + List<String> descriptionList = registry.getList(prefix + "description"); + String description = value.getDescription(); + if (descriptionList != null && !descriptionList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = descriptionList.size(); i < size; i++) { + sb.append(descriptionList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + description = sb.toString(); + } + + value.setDescription(description); + + return value; + } + + private LegacyArtifactPath readLegacyArtifactPath(String prefix, Registry registry) { + LegacyArtifactPath value = new LegacyArtifactPath(); + + //String path = registry.getString( prefix + "path", value.getPath() ); + + List<String> pathList = registry.getList(prefix + "path"); + String path = value.getPath(); + if (pathList != null && !pathList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = pathList.size(); i < size; i++) { + sb.append(pathList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + path = sb.toString(); + } + + value.setPath(path); + //String artifact = registry.getString( prefix + "artifact", value.getArtifact() ); + + List<String> artifactList = registry.getList(prefix + "artifact"); + String artifact = value.getArtifact(); + if (artifactList != null && !artifactList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = artifactList.size(); i < size; i++) { + sb.append(artifactList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + artifact = sb.toString(); + } + + value.setArtifact(artifact); + + return value; + } + + private RepositoryGroupConfiguration readRepositoryGroupConfiguration(String prefix, Registry registry) { + RepositoryGroupConfiguration value = new RepositoryGroupConfiguration(); + + //String id = registry.getString( prefix + "id", value.getId() ); + + List<String> idList = registry.getList(prefix + "id"); + String id = value.getId(); + if (idList != null && !idList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = idList.size(); i < size; i++) { + sb.append(idList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + id = sb.toString(); + } + + value.setId(id); + + value.setName(registry.getString(prefix + "name")); + value.setType(registry.getString(prefix + "type")); + + //String mergedIndexPath = registry.getString( prefix + "mergedIndexPath", value.getMergedIndexPath() ); + + List<String> mergedIndexPathList = registry.getList(prefix + "mergedIndexPath"); + String mergedIndexPath = value.getMergedIndexPath(); + if (mergedIndexPathList != null && !mergedIndexPathList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = mergedIndexPathList.size(); i < size; i++) { + sb.append(mergedIndexPathList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + mergedIndexPath = sb.toString(); + } + + value.setMergedIndexPath(mergedIndexPath); + int mergedIndexTtl = registry.getInt(prefix + "mergedIndexTtl", value.getMergedIndexTtl()); + value.setMergedIndexTtl(mergedIndexTtl); + //String cronExpression = registry.getString( prefix + "cronExpression", value.getCronExpression() ); + + value.setLocation( registry.getString( prefix + "location" ) ); + + List<String> cronExpressionList = registry.getList(prefix + "cronExpression"); + String cronExpression = value.getCronExpression(); + if (cronExpressionList != null && !cronExpressionList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = cronExpressionList.size(); i < size; i++) { + sb.append(cronExpressionList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + cronExpression = sb.toString(); + } + + value.setCronExpression(cronExpression); + java.util.List repositories = new java.util.ArrayList/*<String>*/(); + repositories.addAll(registry.getList(prefix + "repositories.repository")); + value.setRepositories(repositories); + + return value; + } + + private RepositoryCheckPath readRepositoryCheckPath( String prefix, Registry registry) { + RepositoryCheckPath value = new RepositoryCheckPath(); + + //String url = registry.getString( prefix + "url", value.getUrl() ); + + List<String> urlList = registry.getList(prefix + "url"); + String url = value.getUrl(); + if (urlList != null && !urlList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = urlList.size(); i < size; i++) { + sb.append(urlList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + url = sb.toString(); + } + + value.setUrl(url); + //String path = registry.getString( prefix + "path", value.getPath() ); + + List<String> pathList = registry.getList(prefix + "path"); + String path = value.getPath(); + if (pathList != null && !pathList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = pathList.size(); i < size; i++) { + sb.append(pathList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + path = sb.toString(); + } + + value.setPath(path); + + return value; + } + + private AbstractRepositoryConnectorConfiguration readAbstractRepositoryConnectorConfiguration( String prefix, Registry registry) { + AbstractRepositoryConnectorConfiguration value = new AbstractRepositoryConnectorConfiguration(); + + //String sourceRepoId = registry.getString( prefix + "sourceRepoId", value.getSourceRepoId() ); + + List<String> sourceRepoIdList = registry.getList(prefix + "sourceRepoId"); + String sourceRepoId = value.getSourceRepoId(); + if (sourceRepoIdList != null && !sourceRepoIdList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = sourceRepoIdList.size(); i < size; i++) { + sb.append(sourceRepoIdList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + sourceRepoId = sb.toString(); + } + + value.setSourceRepoId(sourceRepoId); + //String targetRepoId = registry.getString( prefix + "targetRepoId", value.getTargetRepoId() ); + + List<String> targetRepoIdList = registry.getList(prefix + "targetRepoId"); + String targetRepoId = value.getTargetRepoId(); + if (targetRepoIdList != null && !targetRepoIdList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = targetRepoIdList.size(); i < size; i++) { + sb.append(targetRepoIdList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + targetRepoId = sb.toString(); + } + + value.setTargetRepoId(targetRepoId); + //String proxyId = registry.getString( prefix + "proxyId", value.getProxyId() ); + + List<String> proxyIdList = registry.getList(prefix + "proxyId"); + String proxyId = value.getProxyId(); + if (proxyIdList != null && !proxyIdList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = proxyIdList.size(); i < size; i++) { + sb.append(proxyIdList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + proxyId = sb.toString(); + } + + value.setProxyId(proxyId); + java.util.List blackListPatterns = new java.util.ArrayList/*<String>*/(); + blackListPatterns.addAll(registry.getList(prefix + "blackListPatterns.blackListPattern")); + value.setBlackListPatterns(blackListPatterns); + java.util.List whiteListPatterns = new java.util.ArrayList/*<String>*/(); + whiteListPatterns.addAll(registry.getList(prefix + "whiteListPatterns.whiteListPattern")); + value.setWhiteListPatterns(whiteListPatterns); + java.util.Map policies = registry.getProperties(prefix + "policies"); + value.setPolicies(policies); + java.util.Map properties = registry.getProperties(prefix + "properties"); + value.setProperties(properties); + boolean disabled = registry.getBoolean(prefix + "disabled", value.isDisabled()); + value.setDisabled(disabled); + + return value; + } + + private ProxyConnectorRuleConfiguration readProxyConnectorRuleConfiguration(String prefix, Registry registry) { + ProxyConnectorRuleConfiguration value = new ProxyConnectorRuleConfiguration(); + + //String ruleType = registry.getString( prefix + "ruleType", value.getRuleType() ); + + List<String> ruleTypeList = registry.getList(prefix + "ruleType"); + String ruleType = value.getRuleType(); + if (ruleTypeList != null && !ruleTypeList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = ruleTypeList.size(); i < size; i++) { + sb.append(ruleTypeList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + ruleType = sb.toString(); + } + + value.setRuleType(ruleType); + //String pattern = registry.getString( prefix + "pattern", value.getPattern() ); + + List<String> patternList = registry.getList(prefix + "pattern"); + String pattern = value.getPattern(); + if (patternList != null && !patternList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = patternList.size(); i < size; i++) { + sb.append(patternList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + pattern = sb.toString(); + } + + value.setPattern(pattern); + java.util.List proxyConnectors = new java.util.ArrayList/*<ProxyConnectorConfiguration>*/(); + List proxyConnectorsSubsets = registry.getSubsetList(prefix + "proxyConnectors.proxyConnector"); + for (Iterator i = proxyConnectorsSubsets.iterator(); i.hasNext(); ) { + ProxyConnectorConfiguration v = readProxyConnectorConfiguration("", (Registry) i.next()); + proxyConnectors.add(v); + } + value.setProxyConnectors(proxyConnectors); + + return value; + } + + private ProxyConnectorConfiguration readProxyConnectorConfiguration(String prefix, Registry registry) { + ProxyConnectorConfiguration value = new ProxyConnectorConfiguration(); + + int order = registry.getInt(prefix + "order", value.getOrder()); + value.setOrder(order); + //String sourceRepoId = registry.getString( prefix + "sourceRepoId", value.getSourceRepoId() ); + + List<String> sourceRepoIdList = registry.getList(prefix + "sourceRepoId"); + String sourceRepoId = value.getSourceRepoId(); + if (sourceRepoIdList != null && !sourceRepoIdList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = sourceRepoIdList.size(); i < size; i++) { + sb.append(sourceRepoIdList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + sourceRepoId = sb.toString(); + } + + value.setSourceRepoId(sourceRepoId); + //String targetRepoId = registry.getString( prefix + "targetRepoId", value.getTargetRepoId() ); + + List<String> targetRepoIdList = registry.getList(prefix + "targetRepoId"); + String targetRepoId = value.getTargetRepoId(); + if (targetRepoIdList != null && !targetRepoIdList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = targetRepoIdList.size(); i < size; i++) { + sb.append(targetRepoIdList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + targetRepoId = sb.toString(); + } + + value.setTargetRepoId(targetRepoId); + //String proxyId = registry.getString( prefix + "proxyId", value.getProxyId() ); + + List<String> proxyIdList = registry.getList(prefix + "proxyId"); + String proxyId = value.getProxyId(); + if (proxyIdList != null && !proxyIdList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = proxyIdList.size(); i < size; i++) { + sb.append(proxyIdList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + proxyId = sb.toString(); + } + + value.setProxyId(proxyId); + java.util.List blackListPatterns = new java.util.ArrayList/*<String>*/(); + blackListPatterns.addAll(registry.getList(prefix + "blackListPatterns.blackListPattern")); + value.setBlackListPatterns(blackListPatterns); + java.util.List whiteListPatterns = new java.util.ArrayList/*<String>*/(); + whiteListPatterns.addAll(registry.getList(prefix + "whiteListPatterns.whiteListPattern")); + value.setWhiteListPatterns(whiteListPatterns); + java.util.Map policies = registry.getProperties(prefix + "policies"); + value.setPolicies(policies); + java.util.Map properties = registry.getProperties(prefix + "properties"); + value.setProperties(properties); + boolean disabled = registry.getBoolean(prefix + "disabled", value.isDisabled()); + value.setDisabled(disabled); + + return value; + } + + private SyncConnectorConfiguration readSyncConnectorConfiguration( String prefix, Registry registry) { + SyncConnectorConfiguration value = new SyncConnectorConfiguration(); + + //String cronExpression = registry.getString( prefix + "cronExpression", value.getCronExpression() ); + + List<String> cronExpressionList = registry.getList(prefix + "cronExpression"); + String cronExpression = value.getCronExpression(); + if (cronExpressionList != null && !cronExpressionList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = cronExpressionList.size(); i < size; i++) { + sb.append(cronExpressionList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + cronExpression = sb.toString(); + } + + value.setCronExpression(cronExpression); + //String method = registry.getString( prefix + "method", value.getMethod() ); + + List<String> methodList = registry.getList(prefix + "method"); + String method = value.getMethod(); + if (methodList != null && !methodList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = methodList.size(); i < size; i++) { + sb.append(methodList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + method = sb.toString(); + } + + value.setMethod(method); + //String sourceRepoId = registry.getString( prefix + "sourceRepoId", value.getSourceRepoId() ); + + List<String> sourceRepoIdList = registry.getList(prefix + "sourceRepoId"); + String sourceRepoId = value.getSourceRepoId(); + if (sourceRepoIdList != null && !sourceRepoIdList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = sourceRepoIdList.size(); i < size; i++) { + sb.append(sourceRepoIdList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + sourceRepoId = sb.toString(); + } + + value.setSourceRepoId(sourceRepoId); + //String targetRepoId = registry.getString( prefix + "targetRepoId", value.getTargetRepoId() ); + + List<String> targetRepoIdList = registry.getList(prefix + "targetRepoId"); + String targetRepoId = value.getTargetRepoId(); + if (targetRepoIdList != null && !targetRepoIdList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = targetRepoIdList.size(); i < size; i++) { + sb.append(targetRepoIdList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + targetRepoId = sb.toString(); + } + + value.setTargetRepoId(targetRepoId); + //String proxyId = registry.getString( prefix + "proxyId", value.getProxyId() ); + + List<String> proxyIdList = registry.getList(prefix + "proxyId"); + String proxyId = value.getProxyId(); + if (proxyIdList != null && !proxyIdList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = proxyIdList.size(); i < size; i++) { + sb.append(proxyIdList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + proxyId = sb.toString(); + } + + value.setProxyId(proxyId); + java.util.List blackListPatterns = new java.util.ArrayList/*<String>*/(); + blackListPatterns.addAll(registry.getList(prefix + "blackListPatterns.blackListPattern")); + value.setBlackListPatterns(blackListPatterns); + java.util.List whiteListPatterns = new java.util.ArrayList/*<String>*/(); + whiteListPatterns.addAll(registry.getList(prefix + "whiteListPatterns.whiteListPattern")); + value.setWhiteListPatterns(whiteListPatterns); + java.util.Map policies = registry.getProperties(prefix + "policies"); + value.setPolicies(policies); + java.util.Map properties = registry.getProperties(prefix + "properties"); + value.setProperties(properties); + boolean disabled = registry.getBoolean(prefix + "disabled", value.isDisabled()); + value.setDisabled(disabled); + + return value; + } + + private NetworkProxyConfiguration readNetworkProxyConfiguration(String prefix, Registry registry) { + NetworkProxyConfiguration value = new NetworkProxyConfiguration(); + + //String id = registry.getString( prefix + "id", value.getId() ); + + List<String> idList = registry.getList(prefix + "id"); + String id = value.getId(); + if (idList != null && !idList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = idList.size(); i < size; i++) { + sb.append(idList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + id = sb.toString(); + } + + value.setId(id); + //String protocol = registry.getString( prefix + "protocol", value.getProtocol() ); + + List<String> protocolList = registry.getList(prefix + "protocol"); + String protocol = value.getProtocol(); + if (protocolList != null && !protocolList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = protocolList.size(); i < size; i++) { + sb.append(protocolList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + protocol = sb.toString(); + } + + value.setProtocol(protocol); + //String host = registry.getString( prefix + "host", value.getHost() ); + + List<String> hostList = registry.getList(prefix + "host"); + String host = value.getHost(); + if (hostList != null && !hostList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = hostList.size(); i < size; i++) { + sb.append(hostList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + host = sb.toString(); + } + + value.setHost(host); + int port = registry.getInt(prefix + "port", value.getPort()); + value.setPort(port); + //String username = registry.getString( prefix + "username", value.getUsername() ); + + List<String> usernameList = registry.getList(prefix + "username"); + String username = value.getUsername(); + if (usernameList != null && !usernameList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = usernameList.size(); i < size; i++) { + sb.append(usernameList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + username = sb.toString(); + } + + value.setUsername(username); + //String password = registry.getString( prefix + "password", value.getPassword() ); + + List<String> passwordList = registry.getList(prefix + "password"); + String password = value.getPassword(); + if (passwordList != null && !passwordList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = passwordList.size(); i < size; i++) { + sb.append(passwordList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + password = sb.toString(); + } + + value.setPassword(password); + boolean useNtlm = registry.getBoolean(prefix + "useNtlm", value.isUseNtlm()); + value.setUseNtlm(useNtlm); + + return value; + } + + private RepositoryScanningConfiguration readRepositoryScanningConfiguration(String prefix, Registry registry) { + RepositoryScanningConfiguration value = new RepositoryScanningConfiguration(); + + java.util.List fileTypes = new java.util.ArrayList/*<FileType>*/(); + List fileTypesSubsets = registry.getSubsetList(prefix + "fileTypes.fileType"); + for (Iterator i = fileTypesSubsets.iterator(); i.hasNext(); ) { + FileType v = readFileType("", (Registry) i.next()); + fileTypes.add(v); + } + value.setFileTypes(fileTypes); + java.util.List knownContentConsumers = new java.util.ArrayList/*<String>*/(); + knownContentConsumers.addAll(registry.getList(prefix + "knownContentConsumers.knownContentConsumer")); + value.setKnownContentConsumers(knownContentConsumers); + java.util.List invalidContentConsumers = new java.util.ArrayList/*<String>*/(); + invalidContentConsumers.addAll(registry.getList(prefix + "invalidContentConsumers.invalidContentConsumer")); + value.setInvalidContentConsumers(invalidContentConsumers); + + return value; + } + + private FileType readFileType(String prefix, Registry registry) { + FileType value = new FileType(); + + //String id = registry.getString( prefix + "id", value.getId() ); + + List<String> idList = registry.getList(prefix + "id"); + String id = value.getId(); + if (idList != null && !idList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = idList.size(); i < size; i++) { + sb.append(idList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + id = sb.toString(); + } + + value.setId(id); + java.util.List patterns = new java.util.ArrayList/*<String>*/(); + patterns.addAll(registry.getList(prefix + "patterns.pattern")); + value.setPatterns(patterns); + + return value; + } + + private OrganisationInformation readOrganisationInformation(String prefix, Registry registry) { + OrganisationInformation value = new OrganisationInformation(); + + //String name = registry.getString( prefix + "name", value.getName() ); + + List<String> nameList = registry.getList(prefix + "name"); + String name = value.getName(); + if (nameList != null && !nameList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = nameList.size(); i < size; i++) { + sb.append(nameList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + name = sb.toString(); + } + + value.setName(name); + //String url = registry.getString( prefix + "url", value.getUrl() ); + + List<String> urlList = registry.getList(prefix + "url"); + String url = value.getUrl(); + if (urlList != null && !urlList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = urlList.size(); i < size; i++) { + sb.append(urlList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + url = sb.toString(); + } + + value.setUrl(url); + //String logoLocation = registry.getString( prefix + "logoLocation", value.getLogoLocation() ); + + List<String> logoLocationList = registry.getList(prefix + "logoLocation"); + String logoLocation = value.getLogoLocation(); + if (logoLocationList != null && !logoLocationList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = logoLocationList.size(); i < size; i++) { + sb.append(logoLocationList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + logoLocation = sb.toString(); + } + + value.setLogoLocation(logoLocation); + + return value; + } + + private WebappConfiguration readWebappConfiguration(String prefix, Registry registry) { + WebappConfiguration value = new WebappConfiguration(); + + UserInterfaceOptions ui = readUserInterfaceOptions(prefix + "ui.", registry); + value.setUi(ui); + + return value; + } + + private UserInterfaceOptions readUserInterfaceOptions(String prefix, Registry registry) { + UserInterfaceOptions value = new UserInterfaceOptions(); + + boolean showFindArtifacts = registry.getBoolean(prefix + "showFindArtifacts", value.isShowFindArtifacts()); + value.setShowFindArtifacts(showFindArtifacts); + boolean appletFindEnabled = registry.getBoolean(prefix + "appletFindEnabled", value.isAppletFindEnabled()); + value.setAppletFindEnabled(appletFindEnabled); + boolean disableEasterEggs = registry.getBoolean(prefix + "disableEasterEggs", value.isDisableEasterEggs()); + value.setDisableEasterEggs(disableEasterEggs); + //String applicationUrl = registry.getString( prefix + "applicationUrl", value.getApplicationUrl() ); + + List<String> applicationUrlList = registry.getList(prefix + "applicationUrl"); + String applicationUrl = value.getApplicationUrl(); + if (applicationUrlList != null && !applicationUrlList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = applicationUrlList.size(); i < size; i++) { + sb.append(applicationUrlList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + applicationUrl = sb.toString(); + } + + value.setApplicationUrl(applicationUrl); + boolean disableRegistration = registry.getBoolean(prefix + "disableRegistration", value.isDisableRegistration()); + value.setDisableRegistration(disableRegistration); + + return value; + } + + private NetworkConfiguration readNetworkConfiguration(String prefix, Registry registry) { + NetworkConfiguration value = new NetworkConfiguration(); + + int maxTotal = registry.getInt(prefix + "maxTotal", value.getMaxTotal()); + value.setMaxTotal(maxTotal); + int maxTotalPerHost = registry.getInt(prefix + "maxTotalPerHost", value.getMaxTotalPerHost()); + value.setMaxTotalPerHost(maxTotalPerHost); + boolean usePooling = registry.getBoolean(prefix + "usePooling", value.isUsePooling()); + value.setUsePooling(usePooling); + + return value; + } + + private ArchivaRuntimeConfiguration readArchivaRuntimeConfiguration(String prefix, Registry registry) { + ArchivaRuntimeConfiguration value = new ArchivaRuntimeConfiguration(); + + CacheConfiguration urlFailureCacheConfiguration = readCacheConfiguration(prefix + "urlFailureCacheConfiguration.", registry); + value.setUrlFailureCacheConfiguration(urlFailureCacheConfiguration); + FileLockConfiguration fileLockConfiguration = readFileLockConfiguration(prefix + "fileLockConfiguration.", registry); + value.setFileLockConfiguration(fileLockConfiguration); + //String dataDirectory = registry.getString( prefix + "dataDirectory", value.getDataDirectory() ); + + List<String> dataDirectoryList = registry.getList(prefix + "dataDirectory"); + String dataDirectory = value.getDataDirectory(); + if (dataDirectoryList != null && !dataDirectoryList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = dataDirectoryList.size(); i < size; i++) { + sb.append(dataDirectoryList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + dataDirectory = sb.toString(); + } + + value.setDataDirectory(dataDirectory); + //String repositoryBaseDirectory = registry.getString( prefix + "repositoryBaseDirectory", value.getRepositoryBaseDirectory() ); + + List<String> repositoryBaseDirectoryList = registry.getList(prefix + "repositoryBaseDirectory"); + String repositoryBaseDirectory = value.getRepositoryBaseDirectory(); + if (repositoryBaseDirectoryList != null && !repositoryBaseDirectoryList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = repositoryBaseDirectoryList.size(); i < size; i++) { + sb.append(repositoryBaseDirectoryList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + repositoryBaseDirectory = sb.toString(); + } + + value.setRepositoryBaseDirectory(repositoryBaseDirectory); + //String remoteRepositoryBaseDirectory = registry.getString( prefix + "remoteRepositoryBaseDirectory", value.getRemoteRepositoryBaseDirectory() ); + + List<String> remoteRepositoryBaseDirectoryList = registry.getList(prefix + "remoteRepositoryBaseDirectory"); + String remoteRepositoryBaseDirectory = value.getRemoteRepositoryBaseDirectory(); + if (remoteRepositoryBaseDirectoryList != null && !remoteRepositoryBaseDirectoryList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = remoteRepositoryBaseDirectoryList.size(); i < size; i++) { + sb.append(remoteRepositoryBaseDirectoryList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + remoteRepositoryBaseDirectory = sb.toString(); + } + + value.setRemoteRepositoryBaseDirectory(remoteRepositoryBaseDirectory); + //String defaultLanguage = registry.getString( prefix + "defaultLanguage", value.getDefaultLanguage() ); + + + List<String> repositoryGroupBaseDirectoryList = registry.getList(prefix + "repositoryGroupBaseDirectory"); + String repositoryGroupBaseDirectory = value.getRepositoryGroupBaseDirectory(); + if (repositoryGroupBaseDirectoryList != null && !repositoryGroupBaseDirectoryList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = repositoryGroupBaseDirectoryList.size(); i < size; i++) { + sb.append(repositoryGroupBaseDirectoryList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + repositoryGroupBaseDirectory = sb.toString(); + } + + value.setRepositoryGroupBaseDirectory(repositoryGroupBaseDirectory); + + List<String> defaultLanguageList = registry.getList(prefix + "defaultLanguage"); + String defaultLanguage = value.getDefaultLanguage(); + if (defaultLanguageList != null && !defaultLanguageList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = defaultLanguageList.size(); i < size; i++) { + sb.append(defaultLanguageList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + defaultLanguage = sb.toString(); + } + + value.setDefaultLanguage(defaultLanguage); + //String languageRange = registry.getString( prefix + "languageRange", value.getLanguageRange() ); + + List<String> languageRangeList = registry.getList(prefix + "languageRange"); + String languageRange = value.getLanguageRange(); + if (languageRangeList != null && !languageRangeList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = languageRangeList.size(); i < size; i++) { + sb.append(languageRangeList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + languageRange = sb.toString(); + } + + value.setLanguageRange(languageRange); + + List<String> checksumTypeList = registry.getList(prefix + "checksumTypes.type"); + value.setChecksumTypes(checksumTypeList); + + return value; + } + + private RedbackRuntimeConfiguration readRedbackRuntimeConfiguration(String prefix, Registry registry) { + RedbackRuntimeConfiguration value = new RedbackRuntimeConfiguration(); + + boolean migratedFromRedbackConfiguration = registry.getBoolean(prefix + "migratedFromRedbackConfiguration", value.isMigratedFromRedbackConfiguration()); + value.setMigratedFromRedbackConfiguration(migratedFromRedbackConfiguration); + java.util.List userManagerImpls = new java.util.ArrayList/*<String>*/(); + userManagerImpls.addAll(registry.getList(prefix + "userManagerImpls.userManagerImpl")); + value.setUserManagerImpls(userManagerImpls); + java.util.List rbacManagerImpls = new java.util.ArrayList/*<String>*/(); + rbacManagerImpls.addAll(registry.getList(prefix + "rbacManagerImpls.rbacManagerImpl")); + value.setRbacManagerImpls(rbacManagerImpls); + LdapConfiguration ldapConfiguration = readLdapConfiguration(prefix + "ldapConfiguration.", registry); + value.setLdapConfiguration(ldapConfiguration); + java.util.List ldapGroupMappings = new java.util.ArrayList/*<LdapGroupMapping>*/(); + List ldapGroupMappingsSubsets = registry.getSubsetList(prefix + "ldapGroupMappings.ldapGroupMapping"); + for (Iterator i = ldapGroupMappingsSubsets.iterator(); i.hasNext(); ) { + LdapGroupMapping v = readLdapGroupMapping("", (Registry) i.next()); + ldapGroupMappings.add(v); + } + value.setLdapGroupMappings(ldapGroupMappings); + java.util.Map configurationProperties = registry.getProperties(prefix + "configurationProperties"); + value.setConfigurationProperties(configurationProperties); + boolean useUsersCache = registry.getBoolean(prefix + "useUsersCache", value.isUseUsersCache()); + value.setUseUsersCache(useUsersCache); + CacheConfiguration usersCacheConfiguration = readCacheConfiguration(prefix + "usersCacheConfiguration.", registry); + value.setUsersCacheConfiguration(usersCacheConfiguration); + + return value; + } + + private ArchivaDefaultConfiguration readArchivaDefaultConfiguration(String prefix, Registry registry) { + ArchivaDefaultConfiguration value = new ArchivaDefaultConfiguration(); + + java.util.List defaultCheckPaths = new java.util.ArrayList/*<RepositoryCheckPath>*/(); + List defaultCheckPathsSubsets = registry.getSubsetList(prefix + "defaultCheckPaths.defaultCheckPath"); + for (Iterator i = defaultCheckPathsSubsets.iterator(); i.hasNext(); ) { + RepositoryCheckPath v = readRepositoryCheckPath("", (Registry) i.next()); + defaultCheckPaths.add(v); + } + value.setDefaultCheckPaths(defaultCheckPaths); + + return value; + } + + private LdapConfiguration readLdapConfiguration(String prefix, Registry registry) { + LdapConfiguration value = new LdapConfiguration(); + + //String hostName = registry.getString( prefix + "hostName", value.getHostName() ); + + List<String> hostNameList = registry.getList(prefix + "hostName"); + String hostName = value.getHostName(); + if (hostNameList != null && !hostNameList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = hostNameList.size(); i < size; i++) { + sb.append(hostNameList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + hostName = sb.toString(); + } + + value.setHostName(hostName); + int port = registry.getInt(prefix + "port", value.getPort()); + value.setPort(port); + boolean ssl = registry.getBoolean(prefix + "ssl", value.isSsl()); + value.setSsl(ssl); + //String baseDn = registry.getString( prefix + "baseDn", value.getBaseDn() ); + + List<String> baseDnList = registry.getList(prefix + "baseDn"); + String baseDn = value.getBaseDn(); + if (baseDnList != null && !baseDnList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = baseDnList.size(); i < size; i++) { + sb.append(baseDnList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + baseDn = sb.toString(); + } + + value.setBaseDn(baseDn); + //String baseGroupsDn = registry.getString( prefix + "baseGroupsDn", value.getBaseGroupsDn() ); + + List<String> baseGroupsDnList = registry.getList(prefix + "baseGroupsDn"); + String baseGroupsDn = value.getBaseGroupsDn(); + if (baseGroupsDnList != null && !baseGroupsDnList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = baseGroupsDnList.size(); i < size; i++) { + sb.append(baseGroupsDnList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + baseGroupsDn = sb.toString(); + } + + value.setBaseGroupsDn(baseGroupsDn); + //String contextFactory = registry.getString( prefix + "contextFactory", value.getContextFactory() ); + + List<String> contextFactoryList = registry.getList(prefix + "contextFactory"); + String contextFactory = value.getContextFactory(); + if (contextFactoryList != null && !contextFactoryList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = contextFactoryList.size(); i < size; i++) { + sb.append(contextFactoryList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + contextFactory = sb.toString(); + } + + value.setContextFactory(contextFactory); + //String bindDn = registry.getString( prefix + "bindDn", value.getBindDn() ); + + List<String> bindDnList = registry.getList(prefix + "bindDn"); + String bindDn = value.getBindDn(); + if (bindDnList != null && !bindDnList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = bindDnList.size(); i < size; i++) { + sb.append(bindDnList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + bindDn = sb.toString(); + } + + value.setBindDn(bindDn); + //String password = registry.getString( prefix + "password", value.getPassword() ); + + List<String> passwordList = registry.getList(prefix + "password"); + String password = value.getPassword(); + if (passwordList != null && !passwordList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = passwordList.size(); i < size; i++) { + sb.append(passwordList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + password = sb.toString(); + } + + value.setPassword(password); + //String authenticationMethod = registry.getString( prefix + "authenticationMethod", value.getAuthenticationMethod() ); + + List<String> authenticationMethodList = registry.getList(prefix + "authenticationMethod"); + String authenticationMethod = value.getAuthenticationMethod(); + if (authenticationMethodList != null && !authenticationMethodList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = authenticationMethodList.size(); i < size; i++) { + sb.append(authenticationMethodList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + authenticationMethod = sb.toString(); + } + + value.setAuthenticationMethod(authenticationMethod); + boolean bindAuthenticatorEnabled = registry.getBoolean(prefix + "bindAuthenticatorEnabled", value.isBindAuthenticatorEnabled()); + value.setBindAuthenticatorEnabled(bindAuthenticatorEnabled); + boolean writable = registry.getBoolean(prefix + "writable", value.isWritable()); + value.setWritable(writable); + boolean useRoleNameAsGroup = registry.getBoolean(prefix + "useRoleNameAsGroup", value.isUseRoleNameAsGroup()); + value.setUseRoleNameAsGroup(useRoleNameAsGroup); + java.util.Map extraProperties = registry.getProperties(prefix + "extraProperties"); + value.setExtraProperties(extraProperties); + + return value; + } + + private FileLockConfiguration readFileLockConfiguration(String prefix, Registry registry) { + FileLockConfiguration value = new FileLockConfiguration(); + + boolean skipLocking = registry.getBoolean(prefix + "skipLocking", value.isSkipLocking()); + value.setSkipLocking(skipLocking); + int lockingTimeout = registry.getInt(prefix + "lockingTimeout", value.getLockingTimeout()); + value.setLockingTimeout(lockingTimeout); + + return value; + } + + private CacheConfiguration readCacheConfiguration(String prefix, Registry registry) { + CacheConfiguration value = new CacheConfiguration(); + + int timeToIdleSeconds = registry.getInt(prefix + "timeToIdleSeconds", value.getTimeToIdleSeconds()); + value.setTimeToIdleSeconds(timeToIdleSeconds); + int timeToLiveSeconds = registry.getInt(prefix + "timeToLiveSeconds", value.getTimeToLiveSeconds()); + value.setTimeToLiveSeconds(timeToLiveSeconds); + int maxElementsInMemory = registry.getInt(prefix + "maxElementsInMemory", value.getMaxElementsInMemory()); + value.setMaxElementsInMemory(maxElementsInMemory); + int maxElementsOnDisk = registry.getInt(prefix + "maxElementsOnDisk", value.getMaxElementsOnDisk()); + value.setMaxElementsOnDisk(maxElementsOnDisk); + + return value; + } + + private LdapGroupMapping readLdapGroupMapping(String prefix, Registry registry) { + LdapGroupMapping value = new LdapGroupMapping(); + + //String group = registry.getString( prefix + "group", value.getGroup() ); + + List<String> groupList = registry.getList(prefix + "group"); + String group = value.getGroup(); + if (groupList != null && !groupList.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = groupList.size(); i < size; i++) { + sb.append(groupList.get(i)); + if (i < size - 1) { + sb.append(','); + } + } + group = sb.toString(); + } + + value.setGroup(group); + java.util.List roleNames = new java.util.ArrayList/*<String>*/(); + roleNames.addAll(registry.getList(prefix + "roleNames.roleName")); + value.setRoleNames(roleNames); + + return value; + } + +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/io/registry/ConfigurationRegistryWriter.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/io/registry/ConfigurationRegistryWriter.java new file mode 100644 index 000000000..253eae897 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/io/registry/ConfigurationRegistryWriter.java @@ -0,0 +1,1141 @@ + +package org.apache.archiva.configuration.provider.io.registry; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.components.registry.Registry; +import org.apache.archiva.configuration.model.AbstractRepositoryConfiguration; +import org.apache.archiva.configuration.model.AbstractRepositoryConnectorConfiguration; +import org.apache.archiva.configuration.model.ArchivaDefaultConfiguration; +import org.apache.archiva.configuration.model.ArchivaRuntimeConfiguration; +import org.apache.archiva.configuration.model.CacheConfiguration; +import org.apache.archiva.configuration.model.Configuration; +import org.apache.archiva.configuration.model.FileLockConfiguration; +import org.apache.archiva.configuration.model.FileType; +import org.apache.archiva.configuration.model.LdapConfiguration; +import org.apache.archiva.configuration.model.LdapGroupMapping; +import org.apache.archiva.configuration.model.LegacyArtifactPath; +import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.model.NetworkConfiguration; +import org.apache.archiva.configuration.model.NetworkProxyConfiguration; +import org.apache.archiva.configuration.model.OrganisationInformation; +import org.apache.archiva.configuration.model.ProxyConnectorConfiguration; +import org.apache.archiva.configuration.model.ProxyConnectorRuleConfiguration; +import org.apache.archiva.configuration.model.RedbackRuntimeConfiguration; +import org.apache.archiva.configuration.model.RemoteRepositoryConfiguration; +import org.apache.archiva.configuration.model.RepositoryCheckPath; +import org.apache.archiva.configuration.model.RepositoryGroupConfiguration; +import org.apache.archiva.configuration.model.RepositoryScanningConfiguration; +import org.apache.archiva.configuration.model.SyncConnectorConfiguration; +import org.apache.archiva.configuration.model.UserInterfaceOptions; +import org.apache.archiva.configuration.model.WebappConfiguration; + +import java.util.Iterator; +import java.util.List; + +// Util imports +// Model class imports + + +/** + * Generate Plexus Registry output mechanism for model 'Configuration'. + */ +public class ConfigurationRegistryWriter { + public void write( Configuration model, Registry registry) { + writeConfiguration("", model, registry); + } + + private void writeList(Registry registry, List<String> subList, String subsetPath, String elementName) { + if (subList != null && subList.size() > 0 + ) { + registry.removeSubset(subsetPath); + + int count = 0; + for (Iterator<String> iter = subList.iterator(); iter.hasNext(); count++) { + String name = subsetPath + "." + elementName + "(" + count + ")"; + String value = iter.next(); + registry.setString(name, value); + } + } + } + + private void writeConfiguration(String prefix, Configuration value, Registry registry) { + if (value != null) { + if (value.getVersion() != null + ) { + String version = "version"; + registry.setString(prefix + version, value.getVersion()); + } + if (value.getMetadataStore() != null && !value.getMetadataStore().equals("jcr") + ) { + String metadataStore = "metadataStore"; + registry.setString(prefix + metadataStore, value.getMetadataStore()); + } + if (value.getRepositoryGroups() != null && value.getRepositoryGroups().size() > 0 + ) { + registry.removeSubset(prefix + "repositoryGroups"); + + int count = 0; + for (Iterator iter = value.getRepositoryGroups().iterator(); iter.hasNext(); count++) { + String name = "repositoryGroups.repositoryGroup(" + count + ")"; + RepositoryGroupConfiguration o = (RepositoryGroupConfiguration) iter.next(); + writeRepositoryGroupConfiguration(prefix + name + ".", o, registry); + } + } + if (value.getManagedRepositories() != null && value.getManagedRepositories().size() > 0 + ) { + registry.removeSubset(prefix + "managedRepositories"); + + int count = 0; + for (Iterator iter = value.getManagedRepositories().iterator(); iter.hasNext(); count++) { + String name = "managedRepositories.managedRepository(" + count + ")"; + ManagedRepositoryConfiguration o = (ManagedRepositoryConfiguration) iter.next(); + writeManagedRepositoryConfiguration(prefix + name + ".", o, registry); + } + } + if (value.getRemoteRepositories() != null && value.getRemoteRepositories().size() > 0 + ) { + registry.removeSubset(prefix + "remoteRepositories"); + + int count = 0; + for (Iterator iter = value.getRemoteRepositories().iterator(); iter.hasNext(); count++) { + String name = "remoteRepositories.remoteRepository(" + count + ")"; + RemoteRepositoryConfiguration o = (RemoteRepositoryConfiguration) iter.next(); + writeRemoteRepositoryConfiguration(prefix + name + ".", o, registry); + } + } + if (value.getProxyConnectors() != null && value.getProxyConnectors().size() > 0 + ) { + registry.removeSubset(prefix + "proxyConnectors"); + + int count = 0; + for (Iterator iter = value.getProxyConnectors().iterator(); iter.hasNext(); count++) { + String name = "proxyConnectors.proxyConnector(" + count + ")"; + ProxyConnectorConfiguration o = (ProxyConnectorConfiguration) iter.next(); + writeProxyConnectorConfiguration(prefix + name + ".", o, registry); + } + } + if (value.getNetworkProxies() != null && value.getNetworkProxies().size() > 0 + ) { + registry.removeSubset(prefix + "networkProxies"); + + int count = 0; + for (Iterator iter = value.getNetworkProxies().iterator(); iter.hasNext(); count++) { + String name = "networkProxies.networkProxy(" + count + ")"; + NetworkProxyConfiguration o = (NetworkProxyConfiguration) iter.next(); + writeNetworkProxyConfiguration(prefix + name + ".", o, registry); + } + } + if (value.getLegacyArtifactPaths() != null && value.getLegacyArtifactPaths().size() > 0 + ) { + registry.removeSubset(prefix + "legacyArtifactPaths"); + + int count = 0; + for (Iterator iter = value.getLegacyArtifactPaths().iterator(); iter.hasNext(); count++) { + String name = "legacyArtifactPaths.legacyArtifactPath(" + count + ")"; + LegacyArtifactPath o = (LegacyArtifactPath) iter.next(); + writeLegacyArtifactPath(prefix + name + ".", o, registry); + } + } + if (value.getRepositoryScanning() != null + ) { + writeRepositoryScanningConfiguration(prefix + "repositoryScanning.", value.getRepositoryScanning(), registry); + } + if (value.getWebapp() != null + ) { + writeWebappConfiguration(prefix + "webapp.", value.getWebapp(), registry); + } + if (value.getOrganisationInfo() != null + ) { + writeOrganisationInformation(prefix + "organisationInfo.", value.getOrganisationInfo(), registry); + } + if (value.getNetworkConfiguration() != null + ) { + writeNetworkConfiguration(prefix + "networkConfiguration.", value.getNetworkConfiguration(), registry); + } + if (value.getRedbackRuntimeConfiguration() != null + ) { + writeRedbackRuntimeConfiguration(prefix + "redbackRuntimeConfiguration.", value.getRedbackRuntimeConfiguration(), registry); + } + if (value.getArchivaRuntimeConfiguration() != null + ) { + writeArchivaRuntimeConfiguration(prefix + "archivaRuntimeConfiguration.", value.getArchivaRuntimeConfiguration(), registry); + } + if (value.getProxyConnectorRuleConfigurations() != null && value.getProxyConnectorRuleConfigurations().size() > 0 + ) { + registry.removeSubset(prefix + "proxyConnectorRuleConfigurations"); + + int count = 0; + for (Iterator iter = value.getProxyConnectorRuleConfigurations().iterator(); iter.hasNext(); count++) { + String name = "proxyConnectorRuleConfigurations.proxyConnectorRuleConfiguration(" + count + ")"; + ProxyConnectorRuleConfiguration o = (ProxyConnectorRuleConfiguration) iter.next(); + writeProxyConnectorRuleConfiguration(prefix + name + ".", o, registry); + } + } + if (value.getArchivaDefaultConfiguration() != null + ) { + writeArchivaDefaultConfiguration(prefix + "archivaDefaultConfiguration.", value.getArchivaDefaultConfiguration(), registry); + } + } + } + + private void writeAbstractRepositoryConfiguration( String prefix, AbstractRepositoryConfiguration value, Registry registry) { + if (value != null) { + if (value.getId() != null + ) { + String id = "id"; + registry.setString(prefix + id, value.getId()); + } + if (value.getType() != null && !value.getType().equals("MAVEN") + ) { + String type = "type"; + registry.setString(prefix + type, value.getType()); + } + if (value.getName() != null + ) { + String name = "name"; + registry.setString(prefix + name, value.getName()); + } + if (value.getLayout() != null && !value.getLayout().equals("default") + ) { + String layout = "layout"; + registry.setString(prefix + layout, value.getLayout()); + } + if (value.getIndexDir() != null && !value.getIndexDir().equals("") + ) { + String indexDir = "indexDir"; + registry.setString(prefix + indexDir, value.getIndexDir()); + } + if (value.getPackedIndexDir() != null && !value.getPackedIndexDir().equals("") + ) { + String packedIndexDir = "packedIndexDir"; + registry.setString(prefix + packedIndexDir, value.getPackedIndexDir()); + } + if (value.getDescription() != null && !value.getDescription().equals("") + ) { + String description = "description"; + registry.setString(prefix + description, value.getDescription()); + } + } + } + + private void writeRemoteRepositoryConfiguration(String prefix, RemoteRepositoryConfiguration value, Registry registry) { + if (value != null) { + if (value.getUrl() != null + ) { + String url = "url"; + registry.setString(prefix + url, value.getUrl()); + } + if (value.getUsername() != null + ) { + String username = "username"; + registry.setString(prefix + username, value.getUsername()); + } + if (value.getPassword() != null + ) { + String password = "password"; + registry.setString(prefix + password, value.getPassword()); + } + if (value.getTimeout() != 60 + ) { + String timeout = "timeout"; + registry.setInt(prefix + timeout, value.getTimeout()); + } + if (value.getRefreshCronExpression() != null && !value.getRefreshCronExpression().equals("0 0 08 ? * SUN") + ) { + String refreshCronExpression = "refreshCronExpression"; + registry.setString(prefix + refreshCronExpression, value.getRefreshCronExpression()); + } + String downloadRemoteIndex = "downloadRemoteIndex"; + registry.setBoolean(prefix + downloadRemoteIndex, value.isDownloadRemoteIndex()); + if (value.getRemoteIndexUrl() != null + ) { + String remoteIndexUrl = "remoteIndexUrl"; + registry.setString(prefix + remoteIndexUrl, value.getRemoteIndexUrl()); + } + if (value.getRemoteDownloadNetworkProxyId() != null + ) { + String remoteDownloadNetworkProxyId = "remoteDownloadNetworkProxyId"; + registry.setString(prefix + remoteDownloadNetworkProxyId, value.getRemoteDownloadNetworkProxyId()); + } + if (value.getRemoteDownloadTimeout() != 300 + ) { + String remoteDownloadTimeout = "remoteDownloadTimeout"; + registry.setInt(prefix + remoteDownloadTimeout, value.getRemoteDownloadTimeout()); + } + String downloadRemoteIndexOnStartup = "downloadRemoteIndexOnStartup"; + registry.setBoolean(prefix + downloadRemoteIndexOnStartup, value.isDownloadRemoteIndexOnStartup()); + if (value.getExtraParameters() != null && value.getExtraParameters().size() > 0 + ) { + registry.removeSubset(prefix + "extraParameters"); + + for (Iterator iter = value.getExtraParameters().keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + String v = (String) value.getExtraParameters().get(key); + + registry.setString(prefix + "extraParameters." + key, v); + } + } + if (value.getExtraHeaders() != null && value.getExtraHeaders().size() > 0 + ) { + registry.removeSubset(prefix + "extraHeaders"); + + for (Iterator iter = value.getExtraHeaders().keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + String v = (String) value.getExtraHeaders().get(key); + + registry.setString(prefix + "extraHeaders." + key, v); + } + } + if (value.getCheckPath() != null + ) { + String checkPath = "checkPath"; + registry.setString(prefix + checkPath, value.getCheckPath()); + } + if (value.getId() != null + ) { + String id = "id"; + registry.setString(prefix + id, value.getId()); + } + if (value.getType() != null && !value.getType().equals("MAVEN") + ) { + String type = "type"; + registry.setString(prefix + type, value.getType()); + } + if (value.getName() != null + ) { + String name = "name"; + registry.setString(prefix + name, value.getName()); + } + if (value.getLayout() != null && !value.getLayout().equals("default") + ) { + String layout = "layout"; + registry.setString(prefix + layout, value.getLayout()); + } + if (value.getIndexDir() != null && !value.getIndexDir().equals("") + ) { + String indexDir = "indexDir"; + registry.setString(prefix + indexDir, value.getIndexDir()); + } + if (value.getPackedIndexDir() != null && !value.getPackedIndexDir().equals("") + ) { + String packedIndexDir = "packedIndexDir"; + registry.setString(prefix + packedIndexDir, value.getPackedIndexDir()); + } + if (value.getDescription() != null && !value.getDescription().equals("") + ) { + String description = "description"; + registry.setString(prefix + description, value.getDescription()); + } + } + } + + private void writeManagedRepositoryConfiguration(String prefix, ManagedRepositoryConfiguration value, Registry registry) { + if (value != null) { + if (value.getLocation() != null + ) { + String location = "location"; + registry.setString(prefix + location, value.getLocation()); + } + String releases = "releases"; + registry.setBoolean(prefix + releases, value.isReleases()); + String blockRedeployments = "blockRedeployments"; + registry.setBoolean(prefix + blockRedeployments, value.isBlockRedeployments()); + String snapshots = "snapshots"; + registry.setBoolean(prefix + snapshots, value.isSnapshots()); + String scanned = "scanned"; + registry.setBoolean(prefix + scanned, value.isScanned()); + if (value.getRefreshCronExpression() != null && !value.getRefreshCronExpression().equals("0 0 * * * ?") + ) { + String refreshCronExpression = "refreshCronExpression"; + registry.setString(prefix + refreshCronExpression, value.getRefreshCronExpression()); + } + if (value.getRetentionCount() != 2 + ) { + String retentionCount = "retentionCount"; + registry.setInt(prefix + retentionCount, value.getRetentionCount()); + } + if (value.getRetentionPeriod() != 100 + ) { + String retentionPeriod = "retentionPeriod"; + registry.setInt(prefix + retentionPeriod, value.getRetentionPeriod()); + } + String deleteReleasedSnapshots = "deleteReleasedSnapshots"; + registry.setBoolean(prefix + deleteReleasedSnapshots, value.isDeleteReleasedSnapshots()); + String skipPackedIndexCreation = "skipPackedIndexCreation"; + registry.setBoolean(prefix + skipPackedIndexCreation, value.isSkipPackedIndexCreation()); + String stageRepoNeeded = "stageRepoNeeded"; + registry.setBoolean(prefix + stageRepoNeeded, value.isStageRepoNeeded()); + if (value.getId() != null + ) { + String id = "id"; + registry.setString(prefix + id, value.getId()); + } + if (value.getType() != null && !value.getType().equals("MAVEN") + ) { + String type = "type"; + registry.setString(prefix + type, value.getType()); + } + if (value.getName() != null + ) { + String name = "name"; + registry.setString(prefix + name, value.getName()); + } + if (value.getLayout() != null && !value.getLayout().equals("default") + ) { + String layout = "layout"; + registry.setString(prefix + layout, value.getLayout()); + } + if (value.getIndexDir() != null && !value.getIndexDir().equals("") + ) { + String indexDir = "indexDir"; + registry.setString(prefix + indexDir, value.getIndexDir()); + } + if (value.getPackedIndexDir() != null && !value.getPackedIndexDir().equals("") + ) { + String packedIndexDir = "packedIndexDir"; + registry.setString(prefix + packedIndexDir, value.getPackedIndexDir()); + } + if (value.getDescription() != null && !value.getDescription().equals("") + ) { + String description = "description"; + registry.setString(prefix + description, value.getDescription()); + } + } + } + + private void writeLegacyArtifactPath(String prefix, LegacyArtifactPath value, Registry registry) { + if (value != null) { + if (value.getPath() != null + ) { + String path = "path"; + registry.setString(prefix + path, value.getPath()); + } + if (value.getArtifact() != null + ) { + String artifact = "artifact"; + registry.setString(prefix + artifact, value.getArtifact()); + } + } + } + + private void writeRepositoryGroupConfiguration(String prefix, RepositoryGroupConfiguration value, Registry registry) { + if (value != null) { + if (value.getId() != null + ) { + String id = "id"; + registry.setString(prefix + id, value.getId()); + } + if (value.getName() != null) { + registry.setString(prefix + "name", value.getName()); + } + if (value.getType() != null) { + registry.setString(prefix + "type", value.getType()); + } + if (value.getLocation()!=null) { + registry.setString( prefix+"location", value.getType( ) ); + } + if (value.getMergedIndexPath() != null && !value.getMergedIndexPath().equals(".indexer") + ) { + String mergedIndexPath = "mergedIndexPath"; + registry.setString(prefix + mergedIndexPath, value.getMergedIndexPath()); + } + if (value.getMergedIndexTtl() != 30 + ) { + String mergedIndexTtl = "mergedIndexTtl"; + registry.setInt(prefix + mergedIndexTtl, value.getMergedIndexTtl()); + } + if (value.getCronExpression() != null && !value.getCronExpression().equals("") + ) { + String cronExpression = "cronExpression"; + registry.setString(prefix + cronExpression, value.getCronExpression()); + } + if (value.getRepositories() != null && value.getRepositories().size() > 0 + ) { + registry.removeSubset(prefix + "repositories"); + + int count = 0; + for (Iterator iter = value.getRepositories().iterator(); iter.hasNext(); count++) { + String name = "repositories.repository(" + count + ")"; + String repository = (String) iter.next(); + registry.setString(prefix + name, repository); + } + } + } + } + + private void writeRepositoryCheckPath( String prefix, RepositoryCheckPath value, Registry registry) { + if (value != null) { + if (value.getUrl() != null + ) { + String url = "url"; + registry.setString(prefix + url, value.getUrl()); + } + if (value.getPath() != null + ) { + String path = "path"; + registry.setString(prefix + path, value.getPath()); + } + } + } + + private void writeAbstractRepositoryConnectorConfiguration( String prefix, AbstractRepositoryConnectorConfiguration value, Registry registry) { + if (value != null) { + if (value.getSourceRepoId() != null + ) { + String sourceRepoId = "sourceRepoId"; + registry.setString(prefix + sourceRepoId, value.getSourceRepoId()); + } + if (value.getTargetRepoId() != null + ) { + String targetRepoId = "targetRepoId"; + registry.setString(prefix + targetRepoId, value.getTargetRepoId()); + } + if (value.getProxyId() != null + ) { + String proxyId = "proxyId"; + registry.setString(prefix + proxyId, value.getProxyId()); + } + if (value.getBlackListPatterns() != null && value.getBlackListPatterns().size() > 0 + ) { + registry.removeSubset(prefix + "blackListPatterns"); + + int count = 0; + for (Iterator iter = value.getBlackListPatterns().iterator(); iter.hasNext(); count++) { + String name = "blackListPatterns.blackListPattern(" + count + ")"; + String blackListPattern = (String) iter.next(); + registry.setString(prefix + name, blackListPattern); + } + } + if (value.getWhiteListPatterns() != null && value.getWhiteListPatterns().size() > 0 + ) { + registry.removeSubset(prefix + "whiteListPatterns"); + + int count = 0; + for (Iterator iter = value.getWhiteListPatterns().iterator(); iter.hasNext(); count++) { + String name = "whiteListPatterns.whiteListPattern(" + count + ")"; + String whiteListPattern = (String) iter.next(); + registry.setString(prefix + name, whiteListPattern); + } + } + if (value.getPolicies() != null && value.getPolicies().size() > 0 + ) { + registry.removeSubset(prefix + "policies"); + + for (Iterator iter = value.getPolicies().keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + String v = (String) value.getPolicies().get(key); + + registry.setString(prefix + "policies." + key, v); + } + } + if (value.getProperties() != null && value.getProperties().size() > 0 + ) { + registry.removeSubset(prefix + "properties"); + + for (Iterator iter = value.getProperties().keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + String v = (String) value.getProperties().get(key); + + registry.setString(prefix + "properties." + key, v); + } + } + String disabled = "disabled"; + registry.setBoolean(prefix + disabled, value.isDisabled()); + } + } + + private void writeProxyConnectorRuleConfiguration(String prefix, ProxyConnectorRuleConfiguration value, Registry registry) { + if (value != null) { + if (value.getRuleType() != null + ) { + String ruleType = "ruleType"; + registry.setString(prefix + ruleType, value.getRuleType()); + } + if (value.getPattern() != null + ) { + String pattern = "pattern"; + registry.setString(prefix + pattern, value.getPattern()); + } + if (value.getProxyConnectors() != null && value.getProxyConnectors().size() > 0 + ) { + registry.removeSubset(prefix + "proxyConnectors"); + + int count = 0; + for (Iterator iter = value.getProxyConnectors().iterator(); iter.hasNext(); count++) { + String name = "proxyConnectors.proxyConnector(" + count + ")"; + ProxyConnectorConfiguration o = (ProxyConnectorConfiguration) iter.next(); + writeProxyConnectorConfiguration(prefix + name + ".", o, registry); + } + } + } + } + + private void writeProxyConnectorConfiguration(String prefix, ProxyConnectorConfiguration value, Registry registry) { + if (value != null) { + if (value.getOrder() != 0 + ) { + String order = "order"; + registry.setInt(prefix + order, value.getOrder()); + } + if (value.getSourceRepoId() != null + ) { + String sourceRepoId = "sourceRepoId"; + registry.setString(prefix + sourceRepoId, value.getSourceRepoId()); + } + if (value.getTargetRepoId() != null + ) { + String targetRepoId = "targetRepoId"; + registry.setString(prefix + targetRepoId, value.getTargetRepoId()); + } + if (value.getProxyId() != null + ) { + String proxyId = "proxyId"; + registry.setString(prefix + proxyId, value.getProxyId()); + } + if (value.getBlackListPatterns() != null && value.getBlackListPatterns().size() > 0 + ) { + registry.removeSubset(prefix + "blackListPatterns"); + + int count = 0; + for (Iterator iter = value.getBlackListPatterns().iterator(); iter.hasNext(); count++) { + String name = "blackListPatterns.blackListPattern(" + count + ")"; + String blackListPattern = (String) iter.next(); + registry.setString(prefix + name, blackListPattern); + } + } + if (value.getWhiteListPatterns() != null && value.getWhiteListPatterns().size() > 0 + ) { + registry.removeSubset(prefix + "whiteListPatterns"); + + int count = 0; + for (Iterator iter = value.getWhiteListPatterns().iterator(); iter.hasNext(); count++) { + String name = "whiteListPatterns.whiteListPattern(" + count + ")"; + String whiteListPattern = (String) iter.next(); + registry.setString(prefix + name, whiteListPattern); + } + } + if (value.getPolicies() != null && value.getPolicies().size() > 0 + ) { + registry.removeSubset(prefix + "policies"); + + for (Iterator iter = value.getPolicies().keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + String v = (String) value.getPolicies().get(key); + + registry.setString(prefix + "policies." + key, v); + } + } + if (value.getProperties() != null && value.getProperties().size() > 0 + ) { + registry.removeSubset(prefix + "properties"); + + for (Iterator iter = value.getProperties().keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + String v = (String) value.getProperties().get(key); + + registry.setString(prefix + "properties." + key, v); + } + } + String disabled = "disabled"; + registry.setBoolean(prefix + disabled, value.isDisabled()); + } + } + + private void writeSyncConnectorConfiguration( String prefix, SyncConnectorConfiguration value, Registry registry) { + if (value != null) { + if (value.getCronExpression() != null && !value.getCronExpression().equals("0 0 * * * ?") + ) { + String cronExpression = "cronExpression"; + registry.setString(prefix + cronExpression, value.getCronExpression()); + } + if (value.getMethod() != null && !value.getMethod().equals("rsync") + ) { + String method = "method"; + registry.setString(prefix + method, value.getMethod()); + } + if (value.getSourceRepoId() != null + ) { + String sourceRepoId = "sourceRepoId"; + registry.setString(prefix + sourceRepoId, value.getSourceRepoId()); + } + if (value.getTargetRepoId() != null + ) { + String targetRepoId = "targetRepoId"; + registry.setString(prefix + targetRepoId, value.getTargetRepoId()); + } + if (value.getProxyId() != null + ) { + String proxyId = "proxyId"; + registry.setString(prefix + proxyId, value.getProxyId()); + } + if (value.getBlackListPatterns() != null && value.getBlackListPatterns().size() > 0 + ) { + registry.removeSubset(prefix + "blackListPatterns"); + + int count = 0; + for (Iterator iter = value.getBlackListPatterns().iterator(); iter.hasNext(); count++) { + String name = "blackListPatterns.blackListPattern(" + count + ")"; + String blackListPattern = (String) iter.next(); + registry.setString(prefix + name, blackListPattern); + } + } + if (value.getWhiteListPatterns() != null && value.getWhiteListPatterns().size() > 0 + ) { + registry.removeSubset(prefix + "whiteListPatterns"); + + int count = 0; + for (Iterator iter = value.getWhiteListPatterns().iterator(); iter.hasNext(); count++) { + String name = "whiteListPatterns.whiteListPattern(" + count + ")"; + String whiteListPattern = (String) iter.next(); + registry.setString(prefix + name, whiteListPattern); + } + } + if (value.getPolicies() != null && value.getPolicies().size() > 0 + ) { + registry.removeSubset(prefix + "policies"); + + for (Iterator iter = value.getPolicies().keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + String v = (String) value.getPolicies().get(key); + + registry.setString(prefix + "policies." + key, v); + } + } + if (value.getProperties() != null && value.getProperties().size() > 0 + ) { + registry.removeSubset(prefix + "properties"); + + for (Iterator iter = value.getProperties().keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + String v = (String) value.getProperties().get(key); + + registry.setString(prefix + "properties." + key, v); + } + } + String disabled = "disabled"; + registry.setBoolean(prefix + disabled, value.isDisabled()); + } + } + + private void writeNetworkProxyConfiguration(String prefix, NetworkProxyConfiguration value, Registry registry) { + if (value != null) { + if (value.getId() != null + ) { + String id = "id"; + registry.setString(prefix + id, value.getId()); + } + if (value.getProtocol() != null && !value.getProtocol().equals("http") + ) { + String protocol = "protocol"; + registry.setString(prefix + protocol, value.getProtocol()); + } + if (value.getHost() != null + ) { + String host = "host"; + registry.setString(prefix + host, value.getHost()); + } + if (value.getPort() != 8080 + ) { + String port = "port"; + registry.setInt(prefix + port, value.getPort()); + } + if (value.getUsername() != null + ) { + String username = "username"; + registry.setString(prefix + username, value.getUsername()); + } + if (value.getPassword() != null + ) { + String password = "password"; + registry.setString(prefix + password, value.getPassword()); + } + String useNtlm = "useNtlm"; + registry.setBoolean(prefix + useNtlm, value.isUseNtlm()); + } + } + + private void writeRepositoryScanningConfiguration( String prefix, RepositoryScanningConfiguration value, Registry registry) { + if (value != null) { + if (value.getFileTypes() != null && value.getFileTypes().size() > 0 + ) { + registry.removeSubset(prefix + "fileTypes"); + + int count = 0; + for (Iterator iter = value.getFileTypes().iterator(); iter.hasNext(); count++) { + String name = "fileTypes.fileType(" + count + ")"; + FileType o = (FileType) iter.next(); + writeFileType(prefix + name + ".", o, registry); + } + } + if (value.getKnownContentConsumers() != null && value.getKnownContentConsumers().size() > 0 + ) { + registry.removeSubset(prefix + "knownContentConsumers"); + + int count = 0; + for (Iterator iter = value.getKnownContentConsumers().iterator(); iter.hasNext(); count++) { + String name = "knownContentConsumers.knownContentConsumer(" + count + ")"; + String knownContentConsumer = (String) iter.next(); + registry.setString(prefix + name, knownContentConsumer); + } + } + if (value.getInvalidContentConsumers() != null && value.getInvalidContentConsumers().size() > 0 + ) { + registry.removeSubset(prefix + "invalidContentConsumers"); + + int count = 0; + for (Iterator iter = value.getInvalidContentConsumers().iterator(); iter.hasNext(); count++) { + String name = "invalidContentConsumers.invalidContentConsumer(" + count + ")"; + String invalidContentConsumer = (String) iter.next(); + registry.setString(prefix + name, invalidContentConsumer); + } + } + } + } + + private void writeFileType(String prefix, FileType value, Registry registry) { + if (value != null) { + if (value.getId() != null + ) { + String id = "id"; + registry.setString(prefix + id, value.getId()); + } + if (value.getPatterns() != null && value.getPatterns().size() > 0 + ) { + registry.removeSubset(prefix + "patterns"); + + int count = 0; + for (Iterator iter = value.getPatterns().iterator(); iter.hasNext(); count++) { + String name = "patterns.pattern(" + count + ")"; + String pattern = (String) iter.next(); + registry.setString(prefix + name, pattern); + } + } + } + } + + private void writeOrganisationInformation( String prefix, OrganisationInformation value, Registry registry) { + if (value != null) { + if (value.getName() != null + ) { + String name = "name"; + registry.setString(prefix + name, value.getName()); + } + if (value.getUrl() != null + ) { + String url = "url"; + registry.setString(prefix + url, value.getUrl()); + } + if (value.getLogoLocation() != null + ) { + String logoLocation = "logoLocation"; + registry.setString(prefix + logoLocation, value.getLogoLocation()); + } + } + } + + private void writeWebappConfiguration( String prefix, WebappConfiguration value, Registry registry) { + if (value != null) { + if (value.getUi() != null + ) { + writeUserInterfaceOptions(prefix + "ui.", value.getUi(), registry); + } + } + } + + private void writeUserInterfaceOptions( String prefix, UserInterfaceOptions value, Registry registry) { + if (value != null) { + String showFindArtifacts = "showFindArtifacts"; + registry.setBoolean(prefix + showFindArtifacts, value.isShowFindArtifacts()); + String appletFindEnabled = "appletFindEnabled"; + registry.setBoolean(prefix + appletFindEnabled, value.isAppletFindEnabled()); + String disableEasterEggs = "disableEasterEggs"; + registry.setBoolean(prefix + disableEasterEggs, value.isDisableEasterEggs()); + if (value.getApplicationUrl() != null + ) { + String applicationUrl = "applicationUrl"; + registry.setString(prefix + applicationUrl, value.getApplicationUrl()); + } + String disableRegistration = "disableRegistration"; + registry.setBoolean(prefix + disableRegistration, value.isDisableRegistration()); + } + } + + private void writeNetworkConfiguration( String prefix, NetworkConfiguration value, Registry registry) { + if (value != null) { + if (value.getMaxTotal() != 30 + ) { + String maxTotal = "maxTotal"; + registry.setInt(prefix + maxTotal, value.getMaxTotal()); + } + if (value.getMaxTotalPerHost() != 30 + ) { + String maxTotalPerHost = "maxTotalPerHost"; + registry.setInt(prefix + maxTotalPerHost, value.getMaxTotalPerHost()); + } + String usePooling = "usePooling"; + registry.setBoolean(prefix + usePooling, value.isUsePooling()); + } + } + + private void writeArchivaRuntimeConfiguration( String prefix, ArchivaRuntimeConfiguration value, Registry registry) { + if (value != null) { + if (value.getUrlFailureCacheConfiguration() != null + ) { + writeCacheConfiguration(prefix + "urlFailureCacheConfiguration.", value.getUrlFailureCacheConfiguration(), registry); + } + if (value.getFileLockConfiguration() != null + ) { + writeFileLockConfiguration(prefix + "fileLockConfiguration.", value.getFileLockConfiguration(), registry); + } + if (value.getDataDirectory() != null + ) { + String dataDirectory = "dataDirectory"; + registry.setString(prefix + dataDirectory, value.getDataDirectory()); + } + if (value.getRepositoryBaseDirectory() != null + ) { + String repositoryBaseDirectory = "repositoryBaseDirectory"; + registry.setString(prefix + repositoryBaseDirectory, value.getRepositoryBaseDirectory()); + } + if (value.getRemoteRepositoryBaseDirectory() != null + ) { + String remoteRepositoryBaseDirectory = "remoteRepositoryBaseDirectory"; + registry.setString(prefix + remoteRepositoryBaseDirectory, value.getRemoteRepositoryBaseDirectory()); + } + if (value.getRepositoryGroupBaseDirectory() != null + ) { + String repositoryGroupBaseDirectory = "repositoryGroupBaseDirectory"; + registry.setString(prefix + repositoryGroupBaseDirectory, value.getRepositoryGroupBaseDirectory()); + } + + if (value.getDefaultLanguage() != null && !value.getDefaultLanguage().equals("en-US") + ) { + String defaultLanguage = "defaultLanguage"; + registry.setString(prefix + defaultLanguage, value.getDefaultLanguage()); + } + if (value.getLanguageRange() != null && !value.getLanguageRange().equals("en,fr,de") + ) { + String languageRange = "languageRange"; + registry.setString(prefix + languageRange, value.getLanguageRange()); + } + writeList(registry, value.getChecksumTypes(), prefix+"checksumTypes", "type"); + } + } + + private void writeRedbackRuntimeConfiguration( String prefix, RedbackRuntimeConfiguration value, Registry registry) { + if (value != null) { + String migratedFromRedbackConfiguration = "migratedFromRedbackConfiguration"; + registry.setBoolean(prefix + migratedFromRedbackConfiguration, value.isMigratedFromRedbackConfiguration()); + if (value.getUserManagerImpls() != null && value.getUserManagerImpls().size() > 0 + ) { + registry.removeSubset(prefix + "userManagerImpls"); + + int count = 0; + for (Iterator iter = value.getUserManagerImpls().iterator(); iter.hasNext(); count++) { + String name = "userManagerImpls.userManagerImpl(" + count + ")"; + String userManagerImpl = (String) iter.next(); + registry.setString(prefix + name, userManagerImpl); + } + } + if (value.getRbacManagerImpls() != null && value.getRbacManagerImpls().size() > 0 + ) { + registry.removeSubset(prefix + "rbacManagerImpls"); + + int count = 0; + for (Iterator iter = value.getRbacManagerImpls().iterator(); iter.hasNext(); count++) { + String name = "rbacManagerImpls.rbacManagerImpl(" + count + ")"; + String rbacManagerImpl = (String) iter.next(); + registry.setString(prefix + name, rbacManagerImpl); + } + } + if (value.getLdapConfiguration() != null + ) { + writeLdapConfiguration(prefix + "ldapConfiguration.", value.getLdapConfiguration(), registry); + } + if (value.getLdapGroupMappings() != null && value.getLdapGroupMappings().size() > 0 + ) { + registry.removeSubset(prefix + "ldapGroupMappings"); + + int count = 0; + for (Iterator iter = value.getLdapGroupMappings().iterator(); iter.hasNext(); count++) { + String name = "ldapGroupMappings.ldapGroupMapping(" + count + ")"; + LdapGroupMapping o = (LdapGroupMapping) iter.next(); + writeLdapGroupMapping(prefix + name + ".", o, registry); + } + } + if (value.getConfigurationProperties() != null && value.getConfigurationProperties().size() > 0 + ) { + registry.removeSubset(prefix + "configurationProperties"); + + for (Iterator iter = value.getConfigurationProperties().keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + String v = (String) value.getConfigurationProperties().get(key); + + registry.setString(prefix + "configurationProperties." + key, v); + } + } + String useUsersCache = "useUsersCache"; + registry.setBoolean(prefix + useUsersCache, value.isUseUsersCache()); + if (value.getUsersCacheConfiguration() != null + ) { + writeCacheConfiguration(prefix + "usersCacheConfiguration.", value.getUsersCacheConfiguration(), registry); + } + } + } + + private void writeArchivaDefaultConfiguration( String prefix, ArchivaDefaultConfiguration value, Registry registry) { + if (value != null) { + if (value.getDefaultCheckPaths() != null && value.getDefaultCheckPaths().size() > 0 + ) { + registry.removeSubset(prefix + "defaultCheckPaths"); + + int count = 0; + for (Iterator iter = value.getDefaultCheckPaths().iterator(); iter.hasNext(); count++) { + String name = "defaultCheckPaths.defaultCheckPath(" + count + ")"; + RepositoryCheckPath o = (RepositoryCheckPath) iter.next(); + writeRepositoryCheckPath(prefix + name + ".", o, registry); + } + } + } + } + + private void writeLdapConfiguration( String prefix, LdapConfiguration value, Registry registry) { + if (value != null) { + if (value.getHostName() != null + ) { + String hostName = "hostName"; + registry.setString(prefix + hostName, value.getHostName()); + } + if (value.getPort() != 0 + ) { + String port = "port"; + registry.setInt(prefix + port, value.getPort()); + } + String ssl = "ssl"; + registry.setBoolean(prefix + ssl, value.isSsl()); + if (value.getBaseDn() != null + ) { + String baseDn = "baseDn"; + registry.setString(prefix + baseDn, value.getBaseDn()); + } + if (value.getBaseGroupsDn() != null + ) { + String baseGroupsDn = "baseGroupsDn"; + registry.setString(prefix + baseGroupsDn, value.getBaseGroupsDn()); + } + if (value.getContextFactory() != null + ) { + String contextFactory = "contextFactory"; + registry.setString(prefix + contextFactory, value.getContextFactory()); + } + if (value.getBindDn() != null + ) { + String bindDn = "bindDn"; + registry.setString(prefix + bindDn, value.getBindDn()); + } + if (value.getPassword() != null + ) { + String password = "password"; + registry.setString(prefix + password, value.getPassword()); + } + if (value.getAuthenticationMethod() != null + ) { + String authenticationMethod = "authenticationMethod"; + registry.setString(prefix + authenticationMethod, value.getAuthenticationMethod()); + } + String bindAuthenticatorEnabled = "bindAuthenticatorEnabled"; + registry.setBoolean(prefix + bindAuthenticatorEnabled, value.isBindAuthenticatorEnabled()); + String writable = "writable"; + registry.setBoolean(prefix + writable, value.isWritable()); + String useRoleNameAsGroup = "useRoleNameAsGroup"; + registry.setBoolean(prefix + useRoleNameAsGroup, value.isUseRoleNameAsGroup()); + if (value.getExtraProperties() != null && value.getExtraProperties().size() > 0 + ) { + registry.removeSubset(prefix + "extraProperties"); + + for (Iterator iter = value.getExtraProperties().keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + String v = (String) value.getExtraProperties().get(key); + + registry.setString(prefix + "extraProperties." + key, v); + } + } + } + } + + private void writeFileLockConfiguration( String prefix, FileLockConfiguration value, Registry registry) { + if (value != null) { + String skipLocking = "skipLocking"; + registry.setBoolean(prefix + skipLocking, value.isSkipLocking()); + if (value.getLockingTimeout() != 0 + ) { + String lockingTimeout = "lockingTimeout"; + registry.setInt(prefix + lockingTimeout, value.getLockingTimeout()); + } + } + } + + private void writeCacheConfiguration( String prefix, CacheConfiguration value, Registry registry) { + if (value != null) { + if (value.getTimeToIdleSeconds() != -1 + ) { + String timeToIdleSeconds = "timeToIdleSeconds"; + registry.setInt(prefix + timeToIdleSeconds, value.getTimeToIdleSeconds()); + } + if (value.getTimeToLiveSeconds() != -1 + ) { + String timeToLiveSeconds = "timeToLiveSeconds"; + registry.setInt(prefix + timeToLiveSeconds, value.getTimeToLiveSeconds()); + } + if (value.getMaxElementsInMemory() != -1 + ) { + String maxElementsInMemory = "maxElementsInMemory"; + registry.setInt(prefix + maxElementsInMemory, value.getMaxElementsInMemory()); + } + if (value.getMaxElementsOnDisk() != -1 + ) { + String maxElementsOnDisk = "maxElementsOnDisk"; + registry.setInt(prefix + maxElementsOnDisk, value.getMaxElementsOnDisk()); + } + } + } + + private void writeLdapGroupMapping(String prefix, LdapGroupMapping value, Registry registry) { + if (value != null) { + if (value.getGroup() != null + ) { + String group = "group"; + registry.setString(prefix + group, value.getGroup()); + } + if (value.getRoleNames() != null && value.getRoleNames().size() > 0 + ) { + registry.removeSubset(prefix + "roleNames"); + + int count = 0; + for (Iterator iter = value.getRoleNames().iterator(); iter.hasNext(); count++) { + String name = "roleNames.roleName(" + count + ")"; + String roleName = (String) iter.next(); + registry.setString(prefix + name, roleName); + } + } + } + } + +}
\ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/util/ConfigMapper.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/util/ConfigMapper.java new file mode 100644 index 000000000..d03137a95 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/java/org/apache/archiva/configuration/provider/util/ConfigMapper.java @@ -0,0 +1,117 @@ +package org.apache.archiva.configuration.provider.util; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * Helper class that can be used for mapping configuration keys (e.g. user configuration keys) to + * archiva configuration objects. + * + * @param <T> The class used to retrieve the attribute data + * @param <K> The class used to retrieve the data that is for prefix matching + * @author Martin Stockhammer <martin_s@apache.org> + * @since 3.0 + */ +public class ConfigMapper<T, K> +{ + private final Map<String, Function<T, String>> stringFunctionMap = new HashMap<>( ); + private final Map<String, Function<T, Integer>> intFunctionMap = new HashMap<>( ); + private final Map<String, Function<T, Boolean>> booleanFunctionMap = new HashMap<>( ); + private final Map<String, BiFunction<String, K, String>> prefixStringFunctionMap = new HashMap<>( ); + + public void addStringMapping( String attributeName, Function<T, String> mapping) { + this.stringFunctionMap.put( attributeName, mapping ); + } + + public void addPrefixStringMapping(String prefix, BiFunction<String, K, String> mapping) { + prefixStringFunctionMap.put( prefix, mapping ); + } + + public String getString( String attributeName, T instance) { + return stringFunctionMap.get( attributeName ).apply( instance ); + } + + public String getPrefixString(String attributeName, K instance) { + BiFunction<String, K, String> function = prefixStringFunctionMap.entrySet( ).stream( ).filter( entry -> attributeName.startsWith( entry.getKey( ) ) ).findFirst( ) + .map( entry -> entry.getValue( ) ) + .get( ); + return function.apply( attributeName, instance ); + } + + public boolean isStringMapping(String attributeName) { + return stringFunctionMap.containsKey( attributeName ); + } + + public boolean isIntMapping(String attributeName) { + return intFunctionMap.containsKey( attributeName ); + } + + public boolean isBooleanMapping(String attributeName) { + return booleanFunctionMap.containsKey( attributeName ); + } + + public boolean isPrefixMapping(String attributeName) { + return prefixStringFunctionMap.keySet( ).stream( ).anyMatch( prefix -> attributeName.startsWith( prefix ) ); + } + + public boolean isMapping(String attributeName) { + return isStringMapping( attributeName ) || isIntMapping( attributeName ) || isBooleanMapping( attributeName ); + } + + public void addIntMapping( String attributeName, Function<T, Integer> mapping) { + this.intFunctionMap.put( attributeName, mapping ); + } + + public int getInt( String attributeName, T instance) { + return this.intFunctionMap.get( attributeName ).apply( instance ); + } + + public void addBooleanMapping( String attributeName, Function<T, Boolean> mapping) { + this.booleanFunctionMap.put( attributeName, mapping ); + } + + public boolean getBoolean( String attributeName, T instance) { + return this.booleanFunctionMap.get( attributeName ).apply( instance ); + } + + public List<String> getStringAttributes() { + return new ArrayList<>( stringFunctionMap.keySet( ) ); + } + + public List<String> getIntAttributes() { + return new ArrayList<>( intFunctionMap.keySet( ) ); + } + + public List<String> getBooleanAttributes() { + return new ArrayList<>( booleanFunctionMap.keySet( ) ); + } + + public List<String> getAllAttributes() { + return Arrays.asList( stringFunctionMap,intFunctionMap, booleanFunctionMap).stream() + .flatMap( map->map.keySet().stream() ).collect( Collectors.toList()); + } + +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/resources/META-INF/spring-context.xml new file mode 100644 index 000000000..3fe1e381d --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/resources/META-INF/spring-context.xml @@ -0,0 +1,35 @@ +<?xml version="1.0"?> + +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-3.0.xsd" + default-lazy-init="true"> + + <context:annotation-config/> + <context:component-scan base-package="org.apache.archiva.configuration"/> + <!-- olamy could be removed as only here temporary for plexus-spring --> + <alias name="archivaConfiguration#default" alias="archivaConfiguration"/> + +</beans>
\ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/resources/org/apache/archiva/configuration/default-archiva.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/resources/org/apache/archiva/configuration/default-archiva.xml new file mode 100644 index 000000000..5f3731dab --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/main/resources/org/apache/archiva/configuration/default-archiva.xml @@ -0,0 +1,175 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + <version>3.0.0</version> + <managedRepositories> + <managedRepository> + <id>internal</id> + <name>Archiva Managed Internal Repository</name> + <location>${appserver.base}/repositories/internal</location> + <indexDir>${appserver.base}/repositories/internal/.indexer</indexDir> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <blockRedeployments>true</blockRedeployments> + <scanned>true</scanned> + <refreshCronExpression>0 0 * * * ?</refreshCronExpression> + <retentionPeriod>30</retentionPeriod> + </managedRepository> + <managedRepository> + <id>snapshots</id> + <name>Archiva Managed Snapshot Repository</name> + <location>${appserver.base}/repositories/snapshots</location> + <indexDir>${appserver.base}/repositories/snapshots/.indexer</indexDir> + <layout>default</layout> + <releases>false</releases> + <snapshots>true</snapshots> + <blockRedeployments>false</blockRedeployments> + <scanned>true</scanned> + <refreshCronExpression>0 0\,30 * * * ?</refreshCronExpression> + <retentionPeriod>30</retentionPeriod> + </managedRepository> + </managedRepositories> + <remoteRepositories> + <remoteRepository> + <id>central</id> + <name>Central Repository</name> + <url>https://repo.maven.apache.org/maven2</url> + <layout>default</layout> + </remoteRepository> + </remoteRepositories> + + <proxyConnectors> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>central</targetRepoId> + <proxyId/> + <policies> + <snapshots>disabled</snapshots> + <releases>once</releases> + <checksum>fix</checksum> + <cache-failures>cached</cache-failures> + </policies> + <whiteListPatterns> + <whiteListPattern>**/*</whiteListPattern> + </whiteListPatterns> + </proxyConnector> + </proxyConnectors> + + <legacyArtifactPaths> + <legacyArtifactPath> + <path>jaxen/jars/jaxen-1.0-FCS-full.jar</path> + <artifact>jaxen:jaxen:1.0-FCS:full:jar</artifact> + </legacyArtifactPath> + </legacyArtifactPaths> + + <repositoryScanning> + <fileTypes> + <fileType> + <id>artifacts</id> + <patterns> + <pattern>**/*.pom</pattern> + <pattern>**/*.jar</pattern> + <pattern>**/*.ear</pattern> + <pattern>**/*.war</pattern> + <pattern>**/*.car</pattern> + <pattern>**/*.sar</pattern> + <pattern>**/*.mar</pattern> + <pattern>**/*.rar</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + <pattern>**/*.tar.gz</pattern> + <pattern>**/*.tar.bz2</pattern> + <pattern>**/*.zip</pattern> + </patterns> + </fileType> + <fileType> + <id>indexable-content</id> + <patterns> + <pattern>**/*.txt</pattern> + <pattern>**/*.TXT</pattern> + <pattern>**/*.block</pattern> + <pattern>**/*.config</pattern> + <pattern>**/*.pom</pattern> + <pattern>**/*.xml</pattern> + <pattern>**/*.xsd</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + </patterns> + </fileType> + <fileType> + <id>auto-remove</id> + <patterns> + <pattern>**/*.bak</pattern> + <pattern>**/*~</pattern> + <pattern>**/*-</pattern> + </patterns> + </fileType> + <fileType> + <id>ignored</id> + <patterns> + <pattern>**/.htaccess</pattern> + <pattern>**/KEYS</pattern> + <pattern>**/*.rb</pattern> + <pattern>**/*.sh</pattern> + <pattern>**/.svn/**</pattern> + <pattern>**/.DAV/**</pattern> + <pattern>.index/**</pattern> + <pattern>.indexer/**</pattern> + </patterns> + </fileType> + </fileTypes> + <knownContentConsumers> + <knownContentConsumer>create-missing-checksums</knownContentConsumer> + <knownContentConsumer>validate-checksum</knownContentConsumer> + <knownContentConsumer>validate-signature</knownContentConsumer> + <knownContentConsumer>index-content</knownContentConsumer> + <knownContentConsumer>auto-remove</knownContentConsumer> + <knownContentConsumer>auto-rename</knownContentConsumer> + <knownContentConsumer>metadata-updater</knownContentConsumer> + <knownContentConsumer>create-archiva-metadata</knownContentConsumer> + <knownContentConsumer>duplicate-artifacts</knownContentConsumer> + <!--knownContentConsumer>repository-purge</knownContentConsumer--> + </knownContentConsumers> + <invalidContentConsumers> + <invalidContentConsumer>update-db-bad-content</invalidContentConsumer> + </invalidContentConsumers> + </repositoryScanning> + + <webapp> + <ui> + <showFindArtifacts>true</showFindArtifacts> + <appletFindEnabled>true</appletFindEnabled> + </ui> + </webapp> + + <archivaRuntimeConfiguration> + <checksumTypes> + <type>MD5</type> + <type>SHA1</type> + <type>SHA256</type> + </checksumTypes> + </archivaRuntimeConfiguration> + + <redbackRuntimeConfiguration> + <userManagerImpls> + <userManagerImpl>jpa</userManagerImpl> + </userManagerImpls> + <rbacManagerImpls> + <rbacManagerImpl>cached</rbacManagerImpl> + </rbacManagerImpls> + </redbackRuntimeConfiguration> + + <archivaDefaultConfiguration> + <defaultCheckPaths> + <defaultCheckPath> + <url>http://download.oracle.com/maven</url> + <path>com/sleepycat/je/license.txt</path> + </defaultCheckPath> + <defaultCheckPath> + <url>https://download.oracle.com/maven</url> + <path>com/sleepycat/je/license.txt</path> + </defaultCheckPath> + </defaultCheckPaths> + </archivaDefaultConfiguration> + +</configuration> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/archiva-0.9.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/archiva-0.9.xml new file mode 100644 index 000000000..c8032436a --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/archiva-0.9.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +<configuration> + <repositories> + <repository> + <directory>managed-repository</directory> + <id>local</id> + <name>local</name> + </repository> + </repositories> + <proxiedRepositories> + <proxiedRepository> + <url>http://www.ibiblio.org/maven2/</url> + <managedRepository>local</managedRepository> + <useNetworkProxy>true</useNetworkProxy> + <id>ibiblio</id> + <name>Ibiblio</name> + </proxiedRepository> + <proxiedRepository> + <url>http://repository.codehaus.org/</url> + <managedRepository>local</managedRepository> + <id>codehaus</id> + <name>Codehaus</name> + </proxiedRepository> + </proxiedRepositories> +</configuration> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/archiva-1.3.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/archiva-1.3.xml new file mode 100644 index 000000000..8575ebd12 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/archiva-1.3.xml @@ -0,0 +1,172 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> +<configuration> +<version>2</version> +<repositoryScanning> +<fileTypes> +<fileType> +<id>artifacts</id> +<patterns> +<pattern>**/*.pom</pattern> +<pattern>**/*.jar</pattern> +<pattern>**/*.ear</pattern> +<pattern>**/*.war</pattern> +<pattern>**/*.car</pattern> +<pattern>**/*.sar</pattern> +<pattern>**/*.mar</pattern> +<pattern>**/*.rar</pattern> +<pattern>**/*.dtd</pattern> +<pattern>**/*.tld</pattern> +<pattern>**/*.tar.gz</pattern> +<pattern>**/*.tar.bz2</pattern> +<pattern>**/*.zip</pattern> +</patterns> +</fileType> +<fileType> +<id>indexable-content</id> +<patterns> +<pattern>**/*.txt</pattern> +<pattern>**/*.TXT</pattern> +<pattern>**/*.block</pattern> +<pattern>**/*.config</pattern> +<pattern>**/*.pom</pattern> +<pattern>**/*.xml</pattern> +<pattern>**/*.xsd</pattern> +<pattern>**/*.dtd</pattern> +<pattern>**/*.tld</pattern> +</patterns> +</fileType> +<fileType> +<id>auto-remove</id> +<patterns> +<pattern>**/*.bak</pattern> +<pattern>**/*~</pattern> +<pattern>**/*-</pattern> +</patterns> +</fileType> +<fileType> +<id>ignored</id> +<patterns> +<pattern>**/.htaccess</pattern> +<pattern>**/KEYS</pattern> +<pattern>**/*.rb</pattern> +<pattern>**/*.sh</pattern> +<pattern>**/.svn/**</pattern> +<pattern>**/.DAV/**</pattern> +</patterns> +</fileType> +</fileTypes> +<knownContentConsumers> +<knownContentConsumer>update-db-artifact</knownContentConsumer> +<knownContentConsumer>create-missing-checksums</knownContentConsumer> +<knownContentConsumer>update-db-repository-metadata</knownContentConsumer> +<knownContentConsumer>validate-checksum</knownContentConsumer> +<knownContentConsumer>validate-signature</knownContentConsumer> +<knownContentConsumer>index-content</knownContentConsumer> +<knownContentConsumer>auto-remove</knownContentConsumer> +<knownContentConsumer>auto-rename</knownContentConsumer> +<knownContentConsumer>metadata-updater</knownContentConsumer> +</knownContentConsumers> +<invalidContentConsumers> +<invalidContentConsumer>update-db-bad-content</invalidContentConsumer> +</invalidContentConsumers> +</repositoryScanning> +<databaseScanning> +<cronExpression>0 0 * * * ?</cronExpression> +<unprocessedConsumers> +<unprocessedConsumer>update-db-project</unprocessedConsumer> +</unprocessedConsumers> +<cleanupConsumers> +<cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer> +<cleanupConsumer>not-present-remove-db-project</cleanupConsumer> +<cleanupConsumer>not-present-remove-indexed</cleanupConsumer> +</cleanupConsumers> +</databaseScanning> +<managedRepositories> +<managedRepository> +<location>${appserver.base}/data/repositories/internal</location> +<blockRedeployments>true</blockRedeployments> +<retentionPeriod>30</retentionPeriod> +<id>internal</id> +<name>Archiva Managed Internal Repository</name> +</managedRepository> +<managedRepository> +<location>${appserver.base}/data/repositories/snapshots</location> +<releases>false</releases> +<snapshots>true</snapshots> +<refreshCronExpression>0 0\,30 * * * ?</refreshCronExpression> +<retentionPeriod>30</retentionPeriod> +<id>snapshots</id> +<name>Archiva Managed Snapshot Repository</name> +</managedRepository> +</managedRepositories> +<remoteRepositories> +<remoteRepository> +<url>http://repo1.maven.org/maven2</url> +<id>central</id> +<name>Central Repository</name> +</remoteRepository> +<remoteRepository> +<url>http://download.java.net/maven/2/</url> +<id>maven2-repository.dev.java.net</id> +<name>Java.net Repository for Maven 2</name> +</remoteRepository> +</remoteRepositories> +<proxyConnectors> +<proxyConnector> +<order>1</order> +<sourceRepoId>internal</sourceRepoId> +<targetRepoId>central</targetRepoId> +<proxyId/> +<whiteListPatterns> +<whiteListPattern>**/*</whiteListPattern> +</whiteListPatterns> +<policies> +<releases>once</releases> +<checksum>fix</checksum> +<snapshots>never</snapshots> +<cache-failures>yes</cache-failures> +</policies> +</proxyConnector> +<proxyConnector> +<order>2</order> +<sourceRepoId>internal</sourceRepoId> +<targetRepoId>maven2-repository.dev.java.net</targetRepoId> +<proxyId/> +<whiteListPatterns> +<whiteListPattern>javax/**</whiteListPattern> +<whiteListPattern>org/jvnet/**</whiteListPattern> +<whiteListPattern>com/sun/**</whiteListPattern> +</whiteListPatterns> +<policies> +<releases>once</releases> +<checksum>fix</checksum> +<snapshots>never</snapshots> +<cache-failures>yes</cache-failures> +</policies> +</proxyConnector> +</proxyConnectors> +<legacyArtifactPaths> +<legacyArtifactPath> +<path>jaxen/jars/jaxen-1.0-FCS-full.jar</path> +<artifact>jaxen:jaxen:1.0-FCS:full:jar</artifact> +</legacyArtifactPath> +</legacyArtifactPaths> +</configuration> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/archiva-v1.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/archiva-v1.xml new file mode 100644 index 000000000..2b05c9251 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/archiva-v1.xml @@ -0,0 +1,191 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +<configuration> + <repositories> + <repository> + <id>internal</id> + <name>Archiva Managed Internal Repository</name> + <url>file://${appserver.base}/repositories/internal</url> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <indexed>true</indexed> + <refreshCronExpression>0 0 * * * ?</refreshCronExpression> + </repository> + <repository> + <id>snapshots</id> + <name>Archiva Managed Snapshot Repository</name> + <url>file://${appserver.base}/repositories/snapshots</url> + <layout>default</layout> + <releases>false</releases> + <snapshots>true</snapshots> + <indexed>false</indexed> + <refreshCronExpression>0 0,30 * * * ?</refreshCronExpression> + </repository> + <repository> + <id>central</id> + <name>Central Repository</name> + <url>http://repo1.maven.org/maven2</url> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <indexed>false</indexed> + </repository> + <repository> + <id>maven2-repository.dev.java.net</id> + <name>Java.net Repository for Maven 2</name> + <url>https://maven2-repository.dev.java.net/nonav/repository</url> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <indexed>false</indexed> + </repository> + </repositories> + + <proxyConnectors> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>central</targetRepoId> + <proxyId/> + <snapshotsPolicy>disabled</snapshotsPolicy> + <releasePolicy>never</releasePolicy> + <failurePolicy>not-found</failurePolicy> + </proxyConnector> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>maven2-repository.dev.java.net</targetRepoId> + <proxyId/> + <snapshotsPolicy>disabled</snapshotsPolicy> + <releasePolicy>never</releasePolicy> + <failurePolicy>not-found</failurePolicy> + <whiteListPatterns> + <whiteListPattern>javax/**</whiteListPattern> + </whiteListPatterns> + </proxyConnector> + </proxyConnectors> + + <networkProxies> + <networkProxy> + <id>example</id> + <protocol>http</protocol> + <host>proxy.mycompany.com</host> + <port>8080</port> + <username>myself</username> + <password>mypass</password> + </networkProxy> + </networkProxies> + + <repositoryScanning> + <fileTypes> + <fileType> + <id>artifacts</id> + <patterns> + <pattern>**/*.pom</pattern> + <pattern>**/*.jar</pattern> + <pattern>**/*.ear</pattern> + <pattern>**/*.war</pattern> + <pattern>**/*.car</pattern> + <pattern>**/*.sar</pattern> + <pattern>**/*.mar</pattern> + <pattern>**/*.rar</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + <pattern>**/*.tar.gz</pattern> + <pattern>**/*.tar.bz2</pattern> + <pattern>**/*.zip</pattern> + </patterns> + </fileType> + <fileType> + <id>indexable-content</id> + <patterns> + <pattern>**/*.txt</pattern> + <pattern>**/*.TXT</pattern> + <pattern>**/*.block</pattern> + <pattern>**/*.config</pattern> + <pattern>**/*.pom</pattern> + <pattern>**/*.xml</pattern> + <pattern>**/*.xsd</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + </patterns> + </fileType> + <fileType> + <id>auto-remove</id> + <patterns> + <pattern>**/*.bak</pattern> + <pattern>**/*~</pattern> + <pattern>**/*-</pattern> + </patterns> + </fileType> + <fileType> + <id>ignored</id> + <patterns> + <pattern>**/.htaccess</pattern> + <pattern>**/KEYS</pattern> + <pattern>**/*.rb</pattern> + <pattern>**/*.sh</pattern> + <pattern>**/.svn/**</pattern> + <pattern>**/.DAV/**</pattern> + </patterns> + </fileType> + </fileTypes> + <knownContentConsumers> + <knownContentConsumer>update-db-artifact</knownContentConsumer> + <knownContentConsumer>create-missing-checksums</knownContentConsumer> + <knownContentConsumer>update-db-repository-metadata</knownContentConsumer> + <knownContentConsumer>validate-checksum</knownContentConsumer> + <knownContentConsumer>validate-signature</knownContentConsumer> + <knownContentConsumer>index-content</knownContentConsumer> + <knownContentConsumer>auto-remove</knownContentConsumer> + <knownContentConsumer>auto-rename</knownContentConsumer> + <knownContentConsumer>metadata-updater</knownContentConsumer> + <!--knownContentConsumer>repository-purge</knownContentConsumer--> + </knownContentConsumers> + <invalidContentConsumers> + <invalidContentConsumer>update-db-bad-content</invalidContentConsumer> + </invalidContentConsumers> + </repositoryScanning> + + <databaseScanning> + <cronExpression>0 0 * * * ?</cronExpression> + <unprocessedConsumers> + <unprocessedConsumer>index-artifact</unprocessedConsumer> + <unprocessedConsumer>update-db-project</unprocessedConsumer> + <unprocessedConsumer>validate-repository-metadata</unprocessedConsumer> + <unprocessedConsumer>index-archive-toc</unprocessedConsumer> + <unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer> + <unprocessedConsumer>index-public-methods</unprocessedConsumer> + </unprocessedConsumers> + <cleanupConsumers> + <cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer> + <cleanupConsumer>not-present-remove-db-project</cleanupConsumer> + <cleanupConsumer>not-present-remove-indexed</cleanupConsumer> + </cleanupConsumers> + </databaseScanning> + + <webapp> + <ui> + <showFindArtifacts>true</showFindArtifacts> + <appletFindEnabled>true</appletFindEnabled> + </ui> + </webapp> + +</configuration> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/autodetect-v1.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/autodetect-v1.xml new file mode 100644 index 000000000..29f3775bb --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/autodetect-v1.xml @@ -0,0 +1,190 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +<configuration> + <repositories> + <repository> + <id>internal</id> + <name>Archiva Managed Internal Repository</name> + <url>file://${appserver.base}/repositories/internal</url> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <indexed>true</indexed> + <refreshCronExpression>0 0 * * * ?</refreshCronExpression> + </repository> + <repository> + <id>snapshots</id> + <name>Archiva Managed Snapshot Repository</name> + <url>file:${appserver.base}/repositories/snapshots</url> + <layout>default</layout> + <releases>false</releases> + <snapshots>true</snapshots> + <indexed>true</indexed> + <refreshCronExpression>0 0,30 * * * ?</refreshCronExpression> + </repository> + <repository> + <id>central</id> + <name>Central Repository</name> + <url>http://repo1.maven.org/maven2</url> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <indexed>false</indexed> + </repository> + <repository> + <id>maven2-repository.dev.java.net</id> + <name>Java.net Repository for Maven 2</name> + <url>https://maven2-repository.dev.java.net/nonav/repository</url> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <indexed>false</indexed> + </repository> + </repositories> + + <proxyConnectors> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>central</targetRepoId> + <proxyId/> + <snapshotsPolicy>disabled</snapshotsPolicy> + <releasePolicy>never</releasePolicy> + <failurePolicy>not-found</failurePolicy> + </proxyConnector> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>maven2-repository.dev.java.net</targetRepoId> + <proxyId/> + <snapshotsPolicy>disabled</snapshotsPolicy> + <releasePolicy>never</releasePolicy> + <failurePolicy>not-found</failurePolicy> + <whiteListPatterns> + <whiteListPattern>javax/**</whiteListPattern> + </whiteListPatterns> + </proxyConnector> + </proxyConnectors> + + <networkProxies> + <networkProxy> + <id>example</id> + <protocol>http</protocol> + <host>proxy.mycompany.com</host> + <port>8080</port> + <username>myself</username> + <password>mypass</password> + </networkProxy> + </networkProxies> + + <repositoryScanning> + <fileTypes> + <fileType> + <id>artifacts</id> + <patterns> + <pattern>**/*.pom</pattern> + <pattern>**/*.jar</pattern> + <pattern>**/*.ear</pattern> + <pattern>**/*.war</pattern> + <pattern>**/*.car</pattern> + <pattern>**/*.sar</pattern> + <pattern>**/*.mar</pattern> + <pattern>**/*.rar</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + <pattern>**/*.tar.gz</pattern> + <pattern>**/*.tar.bz2</pattern> + <pattern>**/*.zip</pattern> + </patterns> + </fileType> + <fileType> + <id>indexable-content</id> + <patterns> + <pattern>**/*.txt</pattern> + <pattern>**/*.TXT</pattern> + <pattern>**/*.block</pattern> + <pattern>**/*.config</pattern> + <pattern>**/*.pom</pattern> + <pattern>**/*.xml</pattern> + <pattern>**/*.xsd</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + </patterns> + </fileType> + <fileType> + <id>auto-remove</id> + <patterns> + <pattern>**/*.bak</pattern> + <pattern>**/*~</pattern> + <pattern>**/*-</pattern> + </patterns> + </fileType> + <fileType> + <id>ignored</id> + <patterns> + <pattern>**/.htaccess</pattern> + <pattern>**/KEYS</pattern> + <pattern>**/*.rb</pattern> + <pattern>**/*.sh</pattern> + <pattern>**/.svn/**</pattern> + <pattern>**/.DAV/**</pattern> + </patterns> + </fileType> + </fileTypes> + <knownContentConsumers> + <knownContentConsumer>update-db-artifact</knownContentConsumer> + <knownContentConsumer>create-missing-checksums</knownContentConsumer> + <knownContentConsumer>update-db-repository-metadata</knownContentConsumer> + <knownContentConsumer>validate-checksum</knownContentConsumer> + <knownContentConsumer>validate-signature</knownContentConsumer> + <knownContentConsumer>index-content</knownContentConsumer> + <knownContentConsumer>auto-remove</knownContentConsumer> + <knownContentConsumer>auto-rename</knownContentConsumer> + <knownContentConsumer>metadata-updater</knownContentConsumer> + </knownContentConsumers> + <invalidContentConsumers> + <invalidContentConsumer>update-db-bad-content</invalidContentConsumer> + </invalidContentConsumers> + </repositoryScanning> + + <databaseScanning> + <cronExpression>0 0 * * * ?</cronExpression> + <unprocessedConsumers> + <unprocessedConsumer>index-artifact</unprocessedConsumer> + <unprocessedConsumer>update-db-project</unprocessedConsumer> + <unprocessedConsumer>validate-repository-metadata</unprocessedConsumer> + <unprocessedConsumer>index-archive-toc</unprocessedConsumer> + <unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer> + <unprocessedConsumer>index-public-methods</unprocessedConsumer> + </unprocessedConsumers> + <cleanupConsumers> + <cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer> + <cleanupConsumer>not-present-remove-db-project</cleanupConsumer> + <cleanupConsumer>not-present-remove-indexed</cleanupConsumer> + </cleanupConsumers> + </databaseScanning> + + <webapp> + <ui> + <showFindArtifacts>true</showFindArtifacts> + <appletFindEnabled>true</appletFindEnabled> + </ui> + </webapp> + +</configuration> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/conf-base.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/conf-base.xml new file mode 100644 index 000000000..84ab085d0 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/conf-base.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +<configuration> + <version>2</version> + <managedRepositories> + <managedRepository> + <id>internal</id> + <name>Archiva Managed Internal Repository</name> + <location>${appserver.base}/repositories/internal</location> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <scanned>true</scanned> + <refreshCronExpression>0 0 * * * ?</refreshCronExpression> + </managedRepository> + <managedRepository> + <id>snapshots</id> + <name>Archiva Managed Snapshot Repository</name> + <location>${appserver.base}/repositories/snapshots</location> + <layout>default</layout> + <releases>false</releases> + <snapshots>true</snapshots> + <scanned>true</scanned> + <refreshCronExpression>0 0,30 * * * ?</refreshCronExpression> + </managedRepository> + </managedRepositories> + <remoteRepositories> + <remoteRepository> + <id>central</id> + <name>Central Repository</name> + <url>http://repo1.maven.org/maven2</url> + <layout>default</layout> + </remoteRepository> + <remoteRepository> + <id>maven2-repository.dev.java.net</id> + <name>Java.net Repository for Maven 2</name> + <url>https://maven2-repository.dev.java.net/nonav/repository</url> + <layout>default</layout> + </remoteRepository> + </remoteRepositories> + + <webapp> + <ui> + <showFindArtifacts>false</showFindArtifacts> + </ui> + </webapp> +</configuration> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/conf-single-list-elements.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/conf-single-list-elements.xml new file mode 100644 index 000000000..3e3d4dc97 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/conf-single-list-elements.xml @@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +<configuration> + <version>2</version> + <repositoryGroups> + <repositoryGroup> + <id>default</id> + <repositories> + <repository>snapshots</repository> + </repositories> + </repositoryGroup> + </repositoryGroups> + <managedRepositories> + <managedRepository> + <id>snapshots</id> + <name>Archiva Managed Snapshot Repository</name> + <location>${appserver.base}/repositories/snapshots</location> + <layout>default</layout> + <releases>false</releases> + <snapshots>true</snapshots> + <scanned>true</scanned> + <refreshCronExpression>0 0,30 * * * ?</refreshCronExpression> + </managedRepository> + </managedRepositories> + <remoteRepositories> + <remoteRepository> + <id>central</id> + <name>Central Repository</name> + <url>http://repo1.maven.org/maven2</url> + <layout>default</layout> + </remoteRepository> + </remoteRepositories> + <proxyConnectors> + <proxyConnector> + <order>2</order> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>maven2-repository.dev.java.net</targetRepoId> + <proxyId/> + <whiteListPatterns> + <whiteListPattern>javax/**</whiteListPattern> + </whiteListPatterns> + <policies> + <releases>once</releases> + <checksum>fix</checksum> + <snapshots>never</snapshots> + <cache-failures>yes</cache-failures> + </policies> + </proxyConnector> + </proxyConnectors> + <networkProxies> + <networkProxy> + <id>proxy</id> + <host>proxy</host> + <port>8080</port> + </networkProxy> + </networkProxies> + <legacyArtifactPaths> + <legacyArtifactPath> + <path>jaxen/jars/jaxen-1.0-FCS-full.jar</path> + <artifact>jaxen:jaxen:1.0-FCS:full:jar</artifact> + </legacyArtifactPath> + </legacyArtifactPaths> + <repositoryScanning> + <knownContentConsumers> + <knownContentConsumer>auto-remove</knownContentConsumer> + </knownContentConsumers> + <invalidContentConsumers> + <invalidContentConsumer>update-db-bad-content</invalidContentConsumer> + </invalidContentConsumers> + </repositoryScanning> + <databaseScanning> + <unprocessedConsumers> + <unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer> + </unprocessedConsumers> + <cleanupConsumers> + <cleanupConsumer>not-present-remove-db-project</cleanupConsumer> + </cleanupConsumers> + </databaseScanning> +</configuration> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/conf-user.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/conf-user.xml new file mode 100644 index 000000000..61c4dadc2 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/conf-user.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> +<configuration> + <version>2</version> + <proxyConnectors> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>central</targetRepoId> + <proxyId/> + <snapshotsPolicy>disabled</snapshotsPolicy> + <releasePolicy>never</releasePolicy> + <failurePolicy>not-found</failurePolicy> + </proxyConnector> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>maven2-repository.dev.java.net</targetRepoId> + <proxyId/> + <snapshotsPolicy>disabled</snapshotsPolicy> + <releasePolicy>never</releasePolicy> + <failurePolicy>not-found</failurePolicy> + <whiteListPatterns> + <whiteListPattern>javax/**</whiteListPattern> + </whiteListPatterns> + </proxyConnector> + </proxyConnectors> + + <webapp> + <ui> + <appletFindEnabled>false</appletFindEnabled> + </ui> + </webapp> +</configuration> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/corrupt.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/corrupt.xml new file mode 100644 index 000000000..b4469289a --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/corrupt.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/escape-cron-expressions.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/escape-cron-expressions.xml new file mode 100644 index 000000000..547e8c0b5 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/escape-cron-expressions.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> +<configuration> + <version>2</version> + <managedRepositories> + <managedRepository> + <id>snapshots</id> + <name>Archiva Managed Snapshot Repository</name> + <location>file://${appserver.base}/repositories/internal</location> + <releases>false</releases> + <snapshots>true</snapshots> + <refreshCronExpression>0 0\,30 * * * ?</refreshCronExpression> + </managedRepository> + </managedRepositories> + <databaseScanning> + <cronExpression>0 0 0 * * ?</cronExpression> + <unprocessedConsumers> + <unprocessedConsumer>index-artifact</unprocessedConsumer> + <unprocessedConsumer>update-db-project</unprocessedConsumer> + <unprocessedConsumer>validate-repository-metadata</unprocessedConsumer> + <unprocessedConsumer>index-archive-toc</unprocessedConsumer> + <unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer> + <unprocessedConsumer>index-public-methods</unprocessedConsumer> + </unprocessedConsumers> + <cleanupConsumers> + <cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer> + <cleanupConsumer>not-present-remove-db-project</cleanupConsumer> + <cleanupConsumer>not-present-remove-indexed</cleanupConsumer> + </cleanupConsumers> + </databaseScanning> + + <webapp> + <ui> + <showFindArtifacts>false</showFindArtifacts> + </ui> + </webapp> +</configuration> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/maven-proxy-complete.conf b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/maven-proxy-complete.conf new file mode 100644 index 000000000..dd98bba12 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/maven-proxy-complete.conf @@ -0,0 +1,144 @@ +################ GLOBAL SETTINGS +# This is where maven-proxy stores files it has downloaded +repo.local.store=target + +#The port to listen on - not used if loaded as a webapp +port=9999 + +#This is the base area that all files are loaded from. While it is possible to leave this blank, this behaviour +#is deprecated and will be disabled in version 2.0. There are too many namespace conflicts caused by not using +#a prefix. +#The repository will be shown at http://localhost:9999/repository/ +#for the .war loaded into a webapp server, the default prefix is "repository" (edit the web.xml to change) +# As maven doesn't like a trailing slash, this address shouldn't have one either. +prefix=repository + +#This is the simple date format used to display the last modified date while browsing the repository. +lastModifiedDateFormat=yyyy/MM/dd HH:mm:ss + +################ SNAPSHOT HANDLING +#If you want the proxy to look for newer snapshots, set to true +snapshot.update=true + +################ M2 METADATA HANDLING +#If you want the proxy to prevent looking for newer metadata, set to false (default is true) +#metadata.update=false + +################ M2 POM HANDLING +#If you want the proxy to look for newer POMs, set to true (default is false) +pom.update=true + +################ PROMOTION HANDLING +# ***** NOT CURRENTLY IMPLEMENTED ***** +#Promotion describes the process by which new artifacts are loaded to global maven-proxy repository. It +# is designed to be used by "higher security installations" that do not want to acquire artifacts from +# remote repositories without approval. +# +#If promotion handling is enabled, then the proxy will not download remote artifacts without permission +# (local repositories with copy=false are considered to be local) +# +#Permission to download is granted via the Promotion menu which will be enabled +# when promotion handling is enabled. +# +#If promotion is false, artifacts are sourced from any repository as per normal. +# +#Promotion and snapshots: If promotion is enabled, snapshots are not downloadable. The concept of using +# a snapshot in a production build (which is primarily what promotion is for) is counterintuitive. +## +promotion=false + +################ WEB INTERFACE +# This defines the absolute URL the server should use to identify itself. +# This can often be determined automatically, but we recommend you specify +# it explicitly to prevent problems during startup. +# The prefix will be added to this for the actual repository +# i.e. proxy available at http://localhost:9999/, repository at http://localhost:9999/repository +serverName=http://localhost:9999 + +#If true, the repository can be browsed +browsable=true + +#If true, the repository can be searched +searchable=true + +#Not currently implemented. Will allow webdav access to the repository at some point. +webdav=true + +#Stylesheet - if configured, will override the default stylesheet shipped with maven-proxy - absolute URLs only +#eg. /maven-proxy/style.css, http://www.example.com/style.css +stylesheet=/maven-proxy/style.css + +#bgColor / bgColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. +#If a stylesheet is set, these are not used. +bgColor=#14B +bgColorHighlight=#94B + +#rowColor / rowColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. +#If a stylesheet is set, these are not used. +rowColor=#CCF +rowColorHighlight=#DDF + + +################ PROXIES +#This is just a hack, it should auto discover them +proxy.list=one,two,three + +#Unauthenticated proxy +proxy.one.host=proxy1.example.com +proxy.one.port=3128 + +#Authenticated proxy +proxy.two.host=proxy2.example.org +proxy.two.port=80 +proxy.two.username=username2 +proxy.two.password=password2 + +#Authenticated proxy +proxy.three.host=proxy3.example.net +proxy.three.port=3129 +proxy.three.username=username3 +proxy.three.password=password3 + + +################# REPOSITORIES +#This is not just a hack, it specifies the order repositories should be checked +#Note that the proxy adds a "/" which is why the urls aren't suffixed with a "/" +repo.list=local-repo,www-ibiblio-org,dist-codehaus-org,private-example-com + +#local-store +# The local store represents a location that local jars you host can be located. +# This could also be achieved by having a local http repository, but this is less cumbersome +repo.local-repo.url=file://target +repo.local-repo.description=Super Secret Custom Repository +#If copy is true, jars are copied from the store to the proxy-repo. Only configurable for file:/// repos +repo.local-repo.copy=false +#If hardfail is true, any unexpected errors from the repository will cause +#the client download to fail (typically with a 500 error) +repo.local-repo.hardfail=true +#Don't cache a file repository +repo.local-repo.cache.period=0 + + +#www.ibiblio.org +repo.www-ibiblio-org.url=http://www.ibiblio.org/maven2 +repo.www-ibiblio-org.description=www.ibiblio.org +repo.www-ibiblio-org.proxy=one +repo.www-ibiblio-org.hardfail=true +#Cache this repository for 1 hour +repo.www-ibiblio-org.cache.period=3600 +repo.www-ibiblio-org.cache.failures=true + +#dist.codehaus.org +repo.dist-codehaus-org.url=http://dist.codehaus.org +repo.dist-codehaus-org.proxy=two +repo.dist-codehaus-org.hardfail=false +repo.dist-codehaus-org.cache.period=3600 +repo.dist-codehaus-org.cache.failures=true + +#private.example.com +repo.private-example-com.url=http://private.example.com/internal +repo.private-example-com.description=Commercial In Confidence Repository +repo.private-example-com.username=username1 +repo.private-example-com.password=password1 +repo.private-example-com.proxy=three +repo.private-example-com.cache.period=3600 diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/repository-manager.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/repository-manager.xml new file mode 100644 index 000000000..8fabacf5b --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/conf/repository-manager.xml @@ -0,0 +1,193 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +<configuration> + <version>2</version> + <managedRepositories> + <managedRepository> + <id>internal</id> + <name>Archiva Managed Internal Repository</name> + <location>${appserver.base}/repositories/internal</location> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <scanned>true</scanned> + <refreshCronExpression>0 0 * * * ?</refreshCronExpression> + </managedRepository> + <managedRepository> + <id>snapshots</id> + <name>Archiva Managed Snapshot Repository</name> + <location>${appserver.base}/repositories/internal</location> + <layout>default</layout> + <releases>false</releases> + <snapshots>true</snapshots> + <scanned>true</scanned> + <refreshCronExpression>0 0,30 * * * ?</refreshCronExpression> + </managedRepository> + </managedRepositories> + <remoteRepositories> + <remoteRepository> + <id>central</id> + <name>Central Repository</name> + <url>http://repo1.maven.org/maven2</url> + <layout>default</layout> + </remoteRepository> + <remoteRepository> + <id>maven2-repository.dev.java.net</id> + <name>Java.net Repository for Maven 2</name> + <url>https://maven2-repository.dev.java.net/nonav/repository</url> + <layout>default</layout> + <username></username> + <password></password> + </remoteRepository> + </remoteRepositories> + + <proxyConnectors> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>central</targetRepoId> + <proxyId/> + <policies> + <releases>ignored</releases> + <snapshots>disabled</snapshots> + <cache-failures>cached</cache-failures> + </policies> + </proxyConnector> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>maven2-repository.dev.java.net</targetRepoId> + <proxyId/> + <policies> + <releases>ignored</releases> + <snapshots>disabled</snapshots> + <cache-failures>cached</cache-failures> + </policies> + <whiteListPatterns> + <whiteListPattern>javax/**</whiteListPattern> + </whiteListPatterns> + </proxyConnector> + </proxyConnectors> + + <networkProxies> + <networkProxy> + <id>example</id> + <protocol>http</protocol> + <host>proxy.mycompany.com</host> + <port>8080</port> + <username>myself</username> + <password>mypass</password> + </networkProxy> + </networkProxies> + + <repositoryScanning> + <fileTypes> + <fileType> + <id>artifacts</id> + <patterns> + <pattern>**/*.pom</pattern> + <pattern>**/*.jar</pattern> + <pattern>**/*.ear</pattern> + <pattern>**/*.war</pattern> + <pattern>**/*.car</pattern> + <pattern>**/*.sar</pattern> + <pattern>**/*.mar</pattern> + <pattern>**/*.rar</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + <pattern>**/*.tar.gz</pattern> + <pattern>**/*.tar.bz2</pattern> + <pattern>**/*.zip</pattern> + </patterns> + </fileType> + <fileType> + <id>indexable-content</id> + <patterns> + <pattern>**/*.txt</pattern> + <pattern>**/*.TXT</pattern> + <pattern>**/*.block</pattern> + <pattern>**/*.config</pattern> + <pattern>**/*.pom</pattern> + <pattern>**/*.xml</pattern> + <pattern>**/*.xsd</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + </patterns> + </fileType> + <fileType> + <id>auto-remove</id> + <patterns> + <pattern>**/*.bak</pattern> + <pattern>**/*~</pattern> + <pattern>**/*-</pattern> + </patterns> + </fileType> + <fileType> + <id>ignored</id> + <patterns> + <pattern>**/.htaccess</pattern> + <pattern>**/KEYS</pattern> + <pattern>**/*.rb</pattern> + <pattern>**/*.sh</pattern> + <pattern>**/.svn/**</pattern> + <pattern>**/.DAV/**</pattern> + </patterns> + </fileType> + </fileTypes> + <knownContentConsumers> + <knownContentConsumer>update-db-artifact</knownContentConsumer> + <knownContentConsumer>create-missing-checksums</knownContentConsumer> + <knownContentConsumer>update-db-repository-metadata</knownContentConsumer> + <knownContentConsumer>validate-checksum</knownContentConsumer> + <knownContentConsumer>validate-signature</knownContentConsumer> + <knownContentConsumer>index-content</knownContentConsumer> + <knownContentConsumer>auto-remove</knownContentConsumer> + <knownContentConsumer>auto-rename</knownContentConsumer> + <knownContentConsumer>metadata-updater</knownContentConsumer> + </knownContentConsumers> + <invalidContentConsumers> + <invalidContentConsumer>update-db-bad-content</invalidContentConsumer> + </invalidContentConsumers> + </repositoryScanning> + + <databaseScanning> + <cronExpression>0 0 * * * ?</cronExpression> + <unprocessedConsumers> + <unprocessedConsumer>index-artifact</unprocessedConsumer> + <unprocessedConsumer>update-db-project</unprocessedConsumer> + <unprocessedConsumer>validate-repository-metadata</unprocessedConsumer> + <unprocessedConsumer>index-archive-toc</unprocessedConsumer> + <unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer> + <unprocessedConsumer>index-public-methods</unprocessedConsumer> + </unprocessedConsumers> + <cleanupConsumers> + <cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer> + <cleanupConsumer>not-present-remove-db-project</cleanupConsumer> + <cleanupConsumer>not-present-remove-indexed</cleanupConsumer> + </cleanupConsumers> + </databaseScanning> + + <webapp> + <ui> + <showFindArtifacts>true</showFindArtifacts> + <appletFindEnabled>true</appletFindEnabled> + </ui> + </webapp> + +</configuration> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/ArchivaConfigurationMRM789Test.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/ArchivaConfigurationMRM789Test.java new file mode 100644 index 000000000..606749692 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/ArchivaConfigurationMRM789Test.java @@ -0,0 +1,140 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.configuration.model.Configuration; +import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.model.RepositoryScanningConfiguration; +import org.apache.archiva.configuration.model.UserInterfaceOptions; +import org.apache.archiva.configuration.model.WebappConfiguration; +import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; + +import javax.inject.Inject; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Test the configuration store. + */ +@RunWith( ArchivaSpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) +public class ArchivaConfigurationMRM789Test +{ + + private static String FILE_ENCODING = "UTF-8"; + + @Inject + protected ApplicationContext applicationContext; + + @Inject + FileTypes filetypes; + + public static Path getTestFile( String path ) + { + return Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), path ); + } + + @SuppressWarnings( "unchecked" ) + protected <T> T lookup( Class<T> clazz, String hint ) + { + return (T) applicationContext.getBean( "archivaConfiguration#" + hint, ArchivaConfiguration.class ); + } + + // test for [MRM-789] + @Test + public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting() + throws Exception + { + Path repo = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-classes/existing_snapshots" ); + Files.createDirectories(repo); + + repo = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-classes/existing_internal" ); + Files.createDirectories(repo); + + String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString( + getTestFile( "target/test-classes/org/apache/archiva/configuration/test-default-archiva.xml" ).toFile(), FILE_ENCODING ); + existingTestDefaultArchivaConfigFile = + StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", org.apache.archiva.common.utils.FileUtils.getBasedir() ); + + Path generatedTestDefaultArchivaConfigFile = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), + "target/test-classes/org/apache/archiva/configuration/default-archiva.xml" ); + + FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile.toFile(), existingTestDefaultArchivaConfigFile, + Charset.forName(FILE_ENCODING) ); + + ArchivaConfiguration archivaConfiguration = + lookup( ArchivaConfiguration.class, "test-defaults-default-repo-location-exists" ); + Configuration configuration = archivaConfiguration.getConfiguration(); + assertConfiguration( configuration, 2, 2, 2 ); + + ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 ); + assertTrue( "check managed repositories", repository.getLocation().endsWith( "data/repositories/internal" ) ); + + Files.deleteIfExists(generatedTestDefaultArchivaConfigFile); + assertFalse( Files.exists(generatedTestDefaultArchivaConfigFile) ); + } + + + /** + * Ensures that the provided configuration matches the details present in the archiva-default.xml file. + */ + private void assertConfiguration( Configuration configuration, int managedExpected, int remoteExpected, + int proxyConnectorExpected ) + throws Exception + { + + assertEquals( "check managed repositories: " + configuration.getManagedRepositories(), managedExpected, + configuration.getManagedRepositories().size() ); + assertEquals( "check remote repositories: " + configuration.getRemoteRepositories(), remoteExpected, + configuration.getRemoteRepositories().size() ); + assertEquals( "check proxy connectors:" + configuration.getProxyConnectors(), proxyConnectorExpected, + configuration.getProxyConnectors().size() ); + + RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning(); + assertNotNull( "check repository scanning", repoScanning ); + assertEquals( "check file types", 4, repoScanning.getFileTypes().size() ); + assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() ); + assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() ); + + List<String> patterns = filetypes.getFileTypePatterns( "artifacts" ); + assertNotNull( "check 'artifacts' file type", patterns ); + assertEquals( "check 'artifacts' patterns", 13, patterns.size() ); + + WebappConfiguration webapp = configuration.getWebapp(); + assertNotNull( "check webapp", webapp ); + + UserInterfaceOptions ui = webapp.getUi(); + assertNotNull( "check webapp ui", ui ); + assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() ); + assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() ); + } + + +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/ArchivaConfigurationTest.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/ArchivaConfigurationTest.java new file mode 100644 index 000000000..ae2079b19 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/ArchivaConfigurationTest.java @@ -0,0 +1,742 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.components.registry.RegistryException; +import org.apache.archiva.configuration.model.Configuration; +import org.apache.archiva.configuration.model.LegacyArtifactPath; +import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.model.NetworkProxyConfiguration; +import org.apache.archiva.configuration.model.ProxyConnectorConfiguration; +import org.apache.archiva.configuration.model.RemoteRepositoryConfiguration; +import org.apache.archiva.configuration.model.RepositoryGroupConfiguration; +import org.apache.archiva.configuration.model.RepositoryScanningConfiguration; +import org.apache.archiva.configuration.model.UserInterfaceOptions; +import org.apache.archiva.configuration.model.WebappConfiguration; +import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.annotation.DirtiesContext.ClassMode; +import org.springframework.test.context.ContextConfiguration; + +import javax.inject.Inject; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +/** + * Test the configuration store. + */ +@RunWith(ArchivaSpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" }) +@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) +public class ArchivaConfigurationTest +{ + + private Logger log = LoggerFactory.getLogger( getClass() ); + + @Inject + protected ApplicationContext applicationContext; + + @Inject + FileTypes filetypes; + + public static Path getTestFile( String path ) + { + return Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), path ); + } + + @SuppressWarnings( "unchecked" ) + protected <T> T lookup( Class<T> clazz, String hint ) + { + return (T) applicationContext.getBean( "archivaConfiguration#" + hint, ArchivaConfiguration.class ); + } + + @Test + public void testGetConfigurationFromDefaults() + throws Exception + { + ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-defaults" ); + Configuration configuration = archivaConfiguration.getConfiguration(); + + assertConfiguration( configuration, 2, 1, 1 ); + assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() ); + + ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 ); + + assertEquals( "check managed repositories", "${appserver.base}/repositories/internal", + repository.getLocation() ); + assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() ); + assertEquals( "check managed repositories", "internal", repository.getId() ); + assertEquals( "check managed repositories", "default", repository.getLayout() ); + assertTrue( "check managed repositories", repository.isScanned() ); + } + + @Test + public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource() + throws Exception + { + ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" ); + Configuration configuration = archivaConfiguration.getConfiguration(); + assertConfiguration( configuration, 2, 2, 2 ); + assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() ); + + ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 ); + + assertEquals( "check managed repositories", "${appserver.base}/repositories/internal", + repository.getLocation() ); + assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() ); + assertEquals( "check managed repositories", "internal", repository.getId() ); + assertEquals( "check managed repositories", "default", repository.getLayout() ); + assertTrue( "check managed repositories", repository.isScanned() ); + } + + /** + * Ensures that the provided configuration matches the details present in the archiva-default.xml file. + */ + private void assertConfiguration( Configuration configuration, int managedExpected, int remoteExpected, + int proxyConnectorExpected ) + throws Exception + { + + assertEquals( "check managed repositories: " + configuration.getManagedRepositories(), managedExpected, + configuration.getManagedRepositories().size() ); + assertEquals( "check remote repositories: " + configuration.getRemoteRepositories(), remoteExpected, + configuration.getRemoteRepositories().size() ); + assertEquals( "check proxy connectors:" + configuration.getProxyConnectors(), proxyConnectorExpected, + configuration.getProxyConnectors().size() ); + + RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning(); + assertNotNull( "check repository scanning", repoScanning ); + assertEquals( "check file types", 4, repoScanning.getFileTypes().size() ); + assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() ); + assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() ); + + List<String> patterns = filetypes.getFileTypePatterns( "artifacts" ); + assertNotNull( "check 'artifacts' file type", patterns ); + assertEquals( "check 'artifacts' patterns", 13, patterns.size() ); + + WebappConfiguration webapp = configuration.getWebapp(); + assertNotNull( "check webapp", webapp ); + + UserInterfaceOptions ui = webapp.getUi(); + assertNotNull( "check webapp ui", ui ); + assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() ); + assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() ); + } + + @Test + public void testGetConfigurationFromRegistryWithTwoConfigurationResources() + throws Exception + { + ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration-both" ); + + Configuration configuration = archivaConfiguration.getConfiguration(); + + // from base + assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() ); + assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() ); + // from user + assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() ); + + WebappConfiguration webapp = configuration.getWebapp(); + assertNotNull( "check webapp", webapp ); + + UserInterfaceOptions ui = webapp.getUi(); + assertNotNull( "check webapp ui", ui ); + // from base + assertFalse( "check showFindArtifacts", ui.isShowFindArtifacts() ); + // from user + assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled() ); + } + + @Test + public void testGetConfigurationSystemOverride() + throws Exception + { + + System.setProperty( "org.apache.archiva.webapp.ui.appletFindEnabled", "false" ); + + ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" ); + + archivaConfiguration.reload(); + + try + { + Configuration configuration = archivaConfiguration.getConfiguration(); + + assertFalse( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() ); + } + finally + { + System.getProperties().remove( "org.apache.archiva.webapp.ui.appletFindEnabled" ); + archivaConfiguration.reload(); + Configuration configuration = archivaConfiguration.getConfiguration(); + assertTrue( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() ); + } + } + + @Test + public void testStoreConfiguration() + throws Exception + { + Path file = getTestFile( "target/test/test-file.xml" ); + Files.deleteIfExists(file); + assertFalse( Files.exists(file) ); + + // TODO: remove with commons-configuration 1.4 + //file.getParentFile().mkdirs(); + //FileUtils.writeStringToFile( file, "<configuration/>", null ); + + DefaultArchivaConfiguration archivaConfiguration = + (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save" ); + + archivaConfiguration.reload(); + + Configuration configuration = new Configuration(); + configuration.setVersion( "1" ); + configuration.setWebapp( new WebappConfiguration() ); + configuration.getWebapp().setUi( new UserInterfaceOptions() ); + configuration.getWebapp().getUi().setAppletFindEnabled( false ); + + // add a change listener + ConfigurationListener listener = mock( ConfigurationListener.class ); + archivaConfiguration.addListener( listener ); + + listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) ); + + archivaConfiguration.save( configuration ); + + assertTrue( "Check file exists", Files.exists(file) ); + + // check it + configuration = archivaConfiguration.getConfiguration(); + assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() ); + + // read it back + archivaConfiguration = (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" ); + + archivaConfiguration.reload(); + configuration = archivaConfiguration.getConfiguration(); + assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() ); + } + + private static ConfigurationListener createConfigurationListenerMockControl() + { + return mock( ConfigurationListener.class );// MockControl.createControl( ConfigurationListener.class ); + } + + @Test + public void testStoreConfigurationUser() + throws Exception + { + Path baseFile = getTestFile( "target/test/test-file.xml" ); + Files.deleteIfExists( baseFile ); + assertFalse( Files.exists(baseFile) ); + + Path userFile = getTestFile( "target/test/test-file-user.xml" ); + Files.deleteIfExists( userFile ); + assertFalse( Files.exists(userFile) ); + + Files.createDirectories(userFile.getParent()); + FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) ); + + ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" ); + + Configuration configuration = new Configuration(); + configuration.setWebapp( new WebappConfiguration() ); + configuration.getWebapp().setUi( new UserInterfaceOptions() ); + configuration.getWebapp().getUi().setAppletFindEnabled( false ); + + archivaConfiguration.save( configuration ); + + assertTrue( "Check file exists", Files.exists(userFile) ); + assertFalse( "Check file not created", Files.exists(baseFile) ); + + // check it + configuration = archivaConfiguration.getConfiguration(); + assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() ); + } + + @Test + public void testStoreConfigurationLoadedFromDefaults() + throws Exception + { + Path baseFile = getTestFile( "target/test/test-file.xml" ); + Files.delete(baseFile); + assertFalse( Files.exists(baseFile) ); + + Path userFile = getTestFile( "target/test/test-file-user.xml" ); + Files.deleteIfExists(userFile); + assertFalse( Files.exists(userFile) ); + + ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user-defaults" ); + + archivaConfiguration.reload(); + + Configuration configuration = new Configuration(); + configuration.setWebapp( new WebappConfiguration() ); + configuration.getWebapp().setUi( new UserInterfaceOptions() ); + configuration.getWebapp().getUi().setAppletFindEnabled( false ); + + // add a change listener + ConfigurationListener listener = createConfigurationListenerMockControl(); + archivaConfiguration.addListener( listener ); + + listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) ); + + archivaConfiguration.save( configuration ); + + assertTrue( "Check file exists", Files.exists(userFile) ); + assertFalse( "Check file not created", Files.exists(baseFile) ); + + // check it + configuration = archivaConfiguration.getConfiguration(); + assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() ); + } + + @Test + public void testDefaultUserConfigFilename() + throws Exception + { + DefaultArchivaConfiguration archivaConfiguration = + (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" ); + String expectedFile = System.getProperty( "user.home" ) + "/.m2/archiva.xml"; + String systemFile = System.getProperty(ArchivaConfiguration.USER_CONFIG_PROPERTY); + if (StringUtils.isNotEmpty( systemFile )) { + expectedFile = systemFile; + } else + { + String envFile = System.getenv( ArchivaConfiguration.USER_CONFIG_ENVVAR ); + if ( StringUtils.isNotEmpty( envFile ) ) + expectedFile = envFile; + } + + archivaConfiguration.reload(); + + assertEquals( expectedFile, + archivaConfiguration.getUserConfigFilename() ); + assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml", + archivaConfiguration.getAltConfigFilename() ); + } + + @Test + public void testStoreConfigurationFallback() + throws Exception + { + Path baseFile = getTestFile( "target/test/test-file.xml" ); + Files.deleteIfExists(baseFile); + assertFalse( Files.exists(baseFile) ); + + Path userFile = getTestFile( "target/test/test-file-user.xml" ); + Files.deleteIfExists(userFile); + assertFalse( Files.exists(userFile) ); + + Files.createDirectories( baseFile.getParent()); + FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) ); + + ArchivaConfiguration archivaConfiguration = + (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" ); + + archivaConfiguration.reload(); + + Configuration configuration = new Configuration(); + configuration.setWebapp( new WebappConfiguration() ); + configuration.getWebapp().setUi( new UserInterfaceOptions() ); + configuration.getWebapp().getUi().setAppletFindEnabled( false ); + + archivaConfiguration.save( configuration ); + + assertTrue( "Check file exists", Files.exists(baseFile) ); + assertFalse( "Check file not created", Files.exists(userFile) ); + + // check it + configuration = archivaConfiguration.getConfiguration(); + assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() ); + } + + @Test + public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists() + throws Exception + { + Path baseFile = getTestFile( "target/test/test-file.xml" ); + Files.deleteIfExists(baseFile); + assertFalse( Files.exists(baseFile) ); + + Path userFile = getTestFile( "target/test/test-file-user.xml" ); + Files.deleteIfExists(userFile); + assertFalse( Files.exists(userFile) ); + + Files.createDirectories( baseFile.getParent() ); + FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) ); + + Files.createDirectories( userFile.getParent()); + FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) ); + + ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" ); + + archivaConfiguration.reload(); + + Configuration configuration = archivaConfiguration.getConfiguration(); + assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() ); + + configuration.getWebapp().getUi().setAppletFindEnabled( false ); + + archivaConfiguration.save( configuration ); + + assertTrue( "Check file exists", Files.exists(baseFile) ); + assertEquals( "Check base file is unchanged", "<configuration/>", + FileUtils.readFileToString( baseFile.toFile(), Charset.forName( "UTF-8" ) ) ); + assertTrue( "Check file exists", Files.exists(userFile) ); + assertFalse( "Check base file is changed", + "<configuration/>".equals( FileUtils.readFileToString( userFile.toFile(), Charset.forName( "UTF-8" ) ) ) ); + + // check it + configuration = archivaConfiguration.getConfiguration(); + assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() ); + } + + @Test + public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists() + throws Exception + { + Path baseFile = getTestFile( "target/test/test-file.xml" ); + Files.deleteIfExists(baseFile); + assertFalse( Files.exists(baseFile) ); + + Path userFile = getTestFile( "target/test/test-file-user.xml" ); + Files.deleteIfExists(userFile); + assertFalse( Files.exists(userFile) ); + + Files.createDirectories( userFile.getParent() ); + FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ).toFile(), userFile.toFile() ); + + Files.createDirectories(baseFile.getParent()); + FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) ); + + ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" ); + + archivaConfiguration.reload(); + + Configuration configuration = archivaConfiguration.getConfiguration(); + assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() ); + + configuration.getWebapp().getUi().setShowFindArtifacts( false ); + + archivaConfiguration.save( configuration ); + + assertTrue( "Check file exists", Files.exists(baseFile) ); + assertEquals( "Check base file is unchanged", "<configuration/>", + FileUtils.readFileToString( baseFile.toFile(), Charset.forName( "UTF-8" ) ) ); + assertTrue( "Check file exists", Files.exists(userFile) ); + assertFalse( "Check base file is changed", + "<configuration/>".equals( FileUtils.readFileToString( userFile.toFile(), Charset.forName( "UTF-8" ) ) ) ); + + // check it + configuration = archivaConfiguration.getConfiguration(); + assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() ); + } + + @Test + public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists() + throws Exception + { + Path baseFile = getTestFile( "target/test/test-file.xml" ); + Files.deleteIfExists(baseFile); + assertFalse( Files.exists(baseFile) ); + + Path userFile = getTestFile( "target/test/test-file-user.xml" ); + Files.deleteIfExists(userFile); + assertFalse( Files.exists(userFile) ); + + Files.createDirectories(baseFile.getParent()); + FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ).toFile(), baseFile.toFile() ); + + Files.createDirectories(userFile.getParent()); + FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) ); + + ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" ); + + archivaConfiguration.reload(); + + Configuration configuration = archivaConfiguration.getConfiguration(); + assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() ); + + configuration.getWebapp().getUi().setAppletFindEnabled( false ); + + try + { + archivaConfiguration.save( configuration ); + fail( "Configuration saving should not succeed if it was loaded from two locations" ); + } + catch ( IndeterminateConfigurationException e ) + { + // check it was reverted + configuration = archivaConfiguration.getConfiguration(); + assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() ); + } + } + + @Test + public void testLoadConfigurationFromInvalidBothLocationsOnDisk() + throws Exception + { + String propFile = System.getProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY ); + System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, "/../../..//*intentionally:invalid*/.m2/archiva-user.xml" ); + ArchivaConfiguration archivaConfiguration = + lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" ); + Configuration config = archivaConfiguration.getConfiguration(); + + try + { + archivaConfiguration.save( config ); + fail( "Should have thrown a RegistryException because the configuration can't be saved." ); + } + catch ( RegistryException e ) + { + /* expected exception */ + } + if (propFile!=null) + { + System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, propFile ); + } + } + + @Test + public void testLoadConfigurationFromInvalidUserLocationOnDisk() + throws Exception + { + Path testConfDir = getTestFile( "target/test-appserver-base/conf/" ); + Files.createDirectories( testConfDir ); + + ArchivaConfiguration archivaConfiguration = + lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" ); + Configuration config = archivaConfiguration.getConfiguration(); + archivaConfiguration.save( config ); + // No Exception == test passes. + // Expected Path is: Should not have thrown an exception. + } + + + @Test + public void testConfigurationUpgradeFrom13() + throws Exception + { + ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-1.3" ); + + // we just use the defaults when upgrading from 1.3 at this point. + Configuration configuration = archivaConfiguration.getConfiguration(); + assertConfiguration( configuration, 2, 2, 2 ); + assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() ); + + ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 ); + + assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal", + repository.getLocation() ); + assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() ); + assertEquals( "check managed repositories", "internal", repository.getId() ); + assertEquals( "check managed repositories", "default", repository.getLayout() ); + assertTrue( "check managed repositories", repository.isScanned() ); + + log.info( "knowContentConsumers {}", configuration.getRepositoryScanning().getKnownContentConsumers() ); + + assertFalse( + configuration.getRepositoryScanning().getKnownContentConsumers().contains( "update-db-artifact" ) ); + assertFalse( configuration.getRepositoryScanning().getKnownContentConsumers().contains( + "update-db-repository-metadata" ) ); + + assertTrue( + configuration.getRepositoryScanning().getKnownContentConsumers().contains( "create-archiva-metadata" ) ); + + assertTrue( + configuration.getRepositoryScanning().getKnownContentConsumers().contains( "duplicate-artifacts" ) ); + } + + + @Test + public void testCronExpressionsWithComma() + throws Exception + { + Path baseFile = getTestFile( "target/test/test-file.xml" ); + Files.deleteIfExists(baseFile); + assertFalse( Files.exists(baseFile) ); + + Path userFile = getTestFile( "target/test/test-file-user.xml" ); + Files.deleteIfExists(userFile); + assertFalse( Files.exists(userFile) ); + + Files.createDirectories(baseFile.getParent()); + FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ).toFile(), baseFile.toFile() ); + + Files.createDirectories(userFile.getParent()); + FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.defaultCharset() ); + + final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" ); + + archivaConfiguration.reload(); + + Configuration configuration = archivaConfiguration.getConfiguration(); + + ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 ); + + assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() ); + + // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls, + // etc. as it's done in other tests + archivaConfiguration.addListener( new ConfigurationListener() + { + @Override + public void configurationEvent( ConfigurationEvent event ) + { + assertEquals( ConfigurationEvent.SAVED, event.getType() ); + + } + } ); + + archivaConfiguration.save( configuration ); + + configuration = archivaConfiguration.getConfiguration(); + + // test for the escape character '\' showing up on repositories.jsp + repository.setRefreshCronExpression( "0 0,20 0 * * ?" ); + + archivaConfiguration.save( configuration ); + + repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" ); + + assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() ); + } + + @Test + public void testRemoveLastElements() + throws Exception + { + Path baseFile = getTestFile( "target/test/test-file.xml" ); + Files.deleteIfExists(baseFile); + assertFalse( Files.exists(baseFile) ); + + Path userFile = getTestFile( "target/test/test-file-user.xml" ); + Files.deleteIfExists(userFile); + assertFalse( Files.exists(userFile) ); + + Files.createDirectories( baseFile.getParent() ); + FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ).toFile(), baseFile.toFile() ); + + Files.createDirectories( userFile.getParent()); + FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) ); + + ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" ); + + archivaConfiguration.reload(); + + Configuration configuration = archivaConfiguration.getConfiguration(); + + RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get( 0 ); + assertNotNull( repositoryGroup ); + configuration.removeRepositoryGroup( repositoryGroup ); + assertTrue( configuration.getRepositoryGroups().isEmpty() ); + + RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" ); + assertNotNull( repository ); + configuration.removeRemoteRepository( repository ); + assertTrue( configuration.getRemoteRepositories().isEmpty() ); + + ManagedRepositoryConfiguration managedRepository = + configuration.getManagedRepositoriesAsMap().get( "snapshots" ); + assertNotNull( managedRepository ); + configuration.removeManagedRepository( managedRepository ); + assertTrue( configuration.getManagedRepositories().isEmpty() ); + + ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get( 0 ); + assertNotNull( proxyConnector ); + configuration.removeProxyConnector( proxyConnector ); + assertTrue( configuration.getProxyConnectors().isEmpty() ); + + NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" ); + assertNotNull( networkProxy ); + configuration.removeNetworkProxy( networkProxy ); + assertTrue( configuration.getNetworkProxies().isEmpty() ); + + LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get( 0 ); + assertNotNull( path ); + configuration.removeLegacyArtifactPath( path ); + assertTrue( configuration.getLegacyArtifactPaths().isEmpty() ); + + RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning(); + String consumer = scanning.getKnownContentConsumers().get( 0 ); + assertNotNull( consumer ); + scanning.removeKnownContentConsumer( consumer ); + // default values + assertFalse( scanning.getKnownContentConsumers().isEmpty() ); + consumer = scanning.getInvalidContentConsumers().get( 0 ); + assertNotNull( consumer ); + scanning.removeInvalidContentConsumer( consumer ); + assertTrue( scanning.getInvalidContentConsumers().isEmpty() ); + + archivaConfiguration.save( configuration ); + + archivaConfiguration = lookup( ArchivaConfiguration.class, "test-read-saved" ); + configuration = archivaConfiguration.getConfiguration(); + assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) ); + assertTrue( configuration.getRepositoryGroups().isEmpty() ); + assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) ); + assertTrue( configuration.getProxyConnectors().isEmpty() ); + assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) ); + assertTrue( configuration.getLegacyArtifactPaths().isEmpty() ); + scanning = configuration.getRepositoryScanning(); + assertFalse( scanning.getKnownContentConsumers().isEmpty() ); + assertTrue( scanning.getInvalidContentConsumers().isEmpty() ); + } + + /** + * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration. + */ + @Test + public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword() + throws Exception + { + ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" ); + + Configuration configuration = archivaConfiguration.getConfiguration(); + assertConfiguration( configuration, 2, 2, 2 ); + assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() ); + + RemoteRepositoryConfiguration repository = + configuration.getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" ); + + assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository", + repository.getUrl() ); + assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() ); + assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() ); + assertEquals( "remote repository.layout", "default", repository.getLayout() ); + assertNull( "remote repository.username == null", repository.getUsername() ); + assertNull( "remote repository.password == null", repository.getPassword() ); + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/ConfigurationTest.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/ConfigurationTest.java new file mode 100644 index 000000000..599bf92e5 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/ConfigurationTest.java @@ -0,0 +1,157 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.configuration.model.Configuration; +import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.model.NetworkProxyConfiguration; +import org.apache.archiva.configuration.model.RemoteRepositoryConfiguration; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; + +import static org.junit.Assert.*; + +/** + * Test the generated Configuration class from Modello. This is primarily to test the hand coded methods. + */ +@RunWith( ArchivaBlockJUnit4ClassRunner.class ) +public class ConfigurationTest +{ + private Configuration configuration = new Configuration(); + + @Test + public void testNetworkProxyRetrieval() + { + NetworkProxyConfiguration proxy1 = createNetworkProxy( "id1", "host1", 8080 ); + configuration.addNetworkProxy( proxy1 ); + NetworkProxyConfiguration proxy2 = createNetworkProxy( "id2", "host2", 9090 ); + configuration.addNetworkProxy( proxy2 ); + + Map<String, NetworkProxyConfiguration> map = configuration.getNetworkProxiesAsMap(); + assertNotNull( map ); + assertEquals( 2, map.size() ); + assertEquals( new HashSet<String>( Arrays.asList( "id1", "id2" ) ), map.keySet() ); + assertEquals( new HashSet<NetworkProxyConfiguration>( Arrays.asList( proxy1, proxy2 ) ), + new HashSet<NetworkProxyConfiguration>( map.values() ) ); + } + + private NetworkProxyConfiguration createNetworkProxy( String id, String host, int port ) + { + NetworkProxyConfiguration proxy = new NetworkProxyConfiguration(); + proxy.setId( id ); + proxy.setHost( host ); + proxy.setPort( port ); + proxy.setProtocol( "http" ); + return proxy; + } + + @Test + public void testRemoteRepositoryRetrieval() + { + RemoteRepositoryConfiguration repo1 = createRemoteRepository( "id1", "name 1", "url 1" ); + configuration.addRemoteRepository( repo1 ); + RemoteRepositoryConfiguration repo2 = createRemoteRepository( "id2", "name 2", "url 2" ); + configuration.addRemoteRepository( repo2 ); + + Map<String, RemoteRepositoryConfiguration> map = configuration.getRemoteRepositoriesAsMap(); + assertNotNull( map ); + assertEquals( 2, map.size() ); + assertEquals( new HashSet<String>( Arrays.asList( "id1", "id2" ) ), map.keySet() ); + assertEquals( new HashSet<RemoteRepositoryConfiguration>( Arrays.asList( repo1, repo2 ) ), + new HashSet<RemoteRepositoryConfiguration>( map.values() ) ); + + assertEquals( repo1, configuration.findRemoteRepositoryById( "id1" ) ); + assertEquals( repo2, configuration.findRemoteRepositoryById( "id2" ) ); + assertNull( configuration.findRemoteRepositoryById( "id3" ) ); + } + + private RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String url ) + { + RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration(); + repo.setId( id ); + repo.setName( name ); + repo.setLayout( "default" ); + repo.setUrl( url ); + return repo; + } + + @Test + public void testManagedRepositoryRetrieval() + { + ManagedRepositoryConfiguration repo1 = createManagedRepository( "id1", "name 1", "path 1", false ); + configuration.addManagedRepository( repo1 ); + ManagedRepositoryConfiguration repo2 = createManagedRepository( "id2", "name 2", "path 2", true ); + configuration.addManagedRepository( repo2 ); + + Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap(); + assertNotNull( map ); + assertEquals( 2, map.size() ); + assertEquals( new HashSet<String>( Arrays.asList( "id1", "id2" ) ), map.keySet() ); + assertEquals( new HashSet<ManagedRepositoryConfiguration>( Arrays.asList( repo1, repo2 ) ), + new HashSet<ManagedRepositoryConfiguration>( map.values() ) ); + + assertEquals( repo1, configuration.findManagedRepositoryById( "id1" ) ); + assertEquals( repo2, configuration.findManagedRepositoryById( "id2" ) ); + assertNull( configuration.findManagedRepositoryById( "id3" ) ); + } + + private ManagedRepositoryConfiguration createManagedRepository( String id, String name, String location, + boolean scanned ) + { + ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration(); + repo.setId( id ); + repo.setName( name ); + repo.setLocation( location ); + repo.setScanned( scanned ); + return repo; + } + + @Test + public void testNetworkProxyRetrievalWhenEmpty() + { + Map<String, NetworkProxyConfiguration> map = configuration.getNetworkProxiesAsMap(); + assertNotNull( map ); + assertTrue( map.isEmpty() ); + } + + @Test + public void testRemoteRepositoryRetrievalWhenEmpty() + { + Map<String, RemoteRepositoryConfiguration> map = configuration.getRemoteRepositoriesAsMap(); + assertNotNull( map ); + assertTrue( map.isEmpty() ); + + assertNull( configuration.findRemoteRepositoryById( "id" ) ); + } + + @Test + public void testManagedRepositoryRetrievalWhenEmpty() + { + Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap(); + assertNotNull( map ); + assertTrue( map.isEmpty() ); + + assertNull( configuration.findManagedRepositoryById( "id" ) ); + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/FileTypesTest.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/FileTypesTest.java new file mode 100644 index 000000000..38921e3e2 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/FileTypesTest.java @@ -0,0 +1,79 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; + +import javax.inject.Inject; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +@RunWith( ArchivaSpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml" } ) +public class FileTypesTest +{ + @Inject + private FileTypes filetypes; + + @Test + public void testIsArtifact() + { + assertTrue( filetypes.matchesArtifactPattern( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); + assertTrue( filetypes.matchesArtifactPattern( + "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); + assertTrue( filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) ); + + assertFalse( + filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) ); + assertFalse( + filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) ); + assertFalse( + filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ) ); + assertFalse( + filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) ); + assertFalse( filetypes.matchesArtifactPattern( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) ); + assertFalse( filetypes.matchesArtifactPattern( "org/apache/derby/derby/maven-metadata.xml" ) ); + } + + @Test + public void testDefaultExclusions() + { + assertTrue( filetypes.matchesDefaultExclusions( "repository/test/.index/nexus-maven-repository-index.gz" ) ); + assertTrue( filetypes.matchesDefaultExclusions( "repository/test/.index/nexus-maven-repository-index.zip" ) ); + assertTrue( filetypes.matchesDefaultExclusions( + "repository/test/org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) ); + assertTrue( filetypes.matchesDefaultExclusions( + "repository/test/org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) ); + assertTrue( filetypes.matchesDefaultExclusions( + "repository/test/org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) ); + assertTrue( filetypes.matchesDefaultExclusions( + "repository/test/org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) ); + assertTrue( filetypes.matchesDefaultExclusions( + "repository/test/org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) ); + + assertFalse( filetypes.matchesDefaultExclusions( + "repository/test/org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.zip" ) ); + assertFalse( filetypes.matchesDefaultExclusions( + "repository/test/org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) ); + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/LegacyArtifactPathTest.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/LegacyArtifactPathTest.java new file mode 100644 index 000000000..38e7dfb60 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/LegacyArtifactPathTest.java @@ -0,0 +1,63 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.configuration.model.LegacyArtifactPath; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +/** + * Test the generated LegacyArtifactPath class from Modello. This is primarily to test the hand coded methods. + * + * @since 1.1 + */ +@RunWith( ArchivaBlockJUnit4ClassRunner.class ) +public class LegacyArtifactPathTest +{ + + private LegacyArtifactPath legacyArtifactPath = new LegacyArtifactPath(); + + @Test + public void testLegacyArtifactPathWithClassifierResolution() + { + legacyArtifactPath.setArtifact( "groupId:artifactId:version:classifier:type" ); + + assertEquals( "groupId", legacyArtifactPath.getGroupId() ); + assertEquals( "artifactId", legacyArtifactPath.getArtifactId() ); + assertEquals( "version", legacyArtifactPath.getVersion() ); + assertEquals( "classifier", legacyArtifactPath.getClassifier() ); + assertEquals( "type", legacyArtifactPath.getType() ); + } + + @Test + public void testLegacyArtifactPathWithoutClassifierResolution() + { + legacyArtifactPath.setArtifact( "groupId:artifactId:version::type" ); + + assertEquals( "groupId", legacyArtifactPath.getGroupId() ); + assertEquals( "artifactId", legacyArtifactPath.getArtifactId() ); + assertEquals( "version", legacyArtifactPath.getVersion() ); + assertNull( legacyArtifactPath.getClassifier() ); + assertEquals( "type", legacyArtifactPath.getType() ); + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/MavenProxyPropertyLoaderTest.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/MavenProxyPropertyLoaderTest.java new file mode 100644 index 000000000..892cf322e --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/MavenProxyPropertyLoaderTest.java @@ -0,0 +1,103 @@ +package org.apache.archiva.configuration.provider; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.configuration.model.Configuration; +import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.model.NetworkProxyConfiguration; +import org.apache.archiva.configuration.model.RemoteRepositoryConfiguration; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Map; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + */ +@RunWith( ArchivaBlockJUnit4ClassRunner.class ) +public class MavenProxyPropertyLoaderTest +{ + private MavenProxyPropertyLoader loader; + + @Test + public void testLoadValidMavenProxyConfiguration() + throws IOException, InvalidConfigurationException + { + Path confFile = ArchivaConfigurationTest.getTestFile( "src/test/conf/maven-proxy-complete.conf" ); + + Configuration configuration = new Configuration(); + NetworkProxyConfiguration proxy = new NetworkProxyConfiguration(); + proxy.setHost( "original-host" ); + configuration.addNetworkProxy( proxy ); // overwritten + + loader.load( Files.newInputStream(confFile), configuration ); + + Map<String, ManagedRepositoryConfiguration> repositoryIdMap = configuration.getManagedRepositoriesAsMap(); + assertEquals( "Count repositories", 1, repositoryIdMap.size() ); + assertRepositoryExists( "maven-proxy", "target", repositoryIdMap.get( "maven-proxy" ) ); + + Map<String, RemoteRepositoryConfiguration> remoteRepositoryMap = configuration.getRemoteRepositoriesAsMap(); + assertEquals( "Count repositories", 4, remoteRepositoryMap.size() ); + assertRepositoryExists( "local-repo", "file://target", remoteRepositoryMap.get( "local-repo" ) ); + assertRepositoryExists( "www-ibiblio-org", "http://www.ibiblio.org/maven2", + remoteRepositoryMap.get( "www-ibiblio-org" ) ); + assertRepositoryExists( "dist-codehaus-org", "http://dist.codehaus.org", + remoteRepositoryMap.get( "dist-codehaus-org" ) ); + assertRepositoryExists( "private-example-com", "http://private.example.com/internal", + remoteRepositoryMap.get( "private-example-com" ) ); + } + + private void assertRepositoryExists( String id, String expectedLocation, ManagedRepositoryConfiguration repo ) + { + assertNotNull( "Repository id [" + id + "] should not be null", repo ); + assertEquals( "Repository id", id, repo.getId() ); + assertEquals( "Repository url", expectedLocation, repo.getLocation() ); + } + + private void assertRepositoryExists( String id, String expectedUrl, RemoteRepositoryConfiguration repo ) + { + assertNotNull( "Repository id [" + id + "] should not be null", repo ); + assertEquals( "Repository id", id, repo.getId() ); + assertEquals( "Repository url", expectedUrl, repo.getUrl() ); + } + + @Test( expected=InvalidConfigurationException.class ) + public void testInvalidConfiguration() + throws InvalidConfigurationException + { + Configuration configuration = new Configuration(); + loader.load( new Properties(), configuration ); + //fail( "Incomplete config should have failed" ); + } + + @Before + public void setUp() + throws Exception + { + loader = new MavenProxyPropertyLoader(); + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/functors/ProxyConnectorConfigurationOrderComparatorTest.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/functors/ProxyConnectorConfigurationOrderComparatorTest.java new file mode 100644 index 000000000..b5873f52b --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/functors/ProxyConnectorConfigurationOrderComparatorTest.java @@ -0,0 +1,138 @@ +package org.apache.archiva.configuration.provider.functors; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.configuration.model.ProxyConnectorConfiguration; +import org.apache.archiva.configuration.model.functors.ProxyConnectorConfigurationOrderComparator; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * ProxyConnectorConfigurationOrderComparatorTest + * + * + */ +@SuppressWarnings( "deprecation" ) +@RunWith( ArchivaBlockJUnit4ClassRunner.class ) +public class ProxyConnectorConfigurationOrderComparatorTest +{ + @Test + public void testSortOfAllZeros() + { + List<ProxyConnectorConfiguration> proxies = new ArrayList<>(); + + proxies.add( createConnector( "corporate", 0 ) ); + proxies.add( createConnector( "snapshots", 0 ) ); + proxies.add( createConnector( "3rdparty", 0 ) ); + proxies.add( createConnector( "sandbox", 0 ) ); + + Collections.sort( proxies, ProxyConnectorConfigurationOrderComparator.getInstance() ); + + assertProxyOrder( new String[]{ "corporate", "snapshots", "3rdparty", "sandbox" }, proxies ); + } + + @Test + public void testSortNormal() + { + List<ProxyConnectorConfiguration> proxies = new ArrayList<>(); + + proxies.add( createConnector( "corporate", 3 ) ); + proxies.add( createConnector( "snapshots", 1 ) ); + proxies.add( createConnector( "3rdparty", 2 ) ); + proxies.add( createConnector( "sandbox", 4 ) ); + + Collections.sort( proxies, new ProxyConnectorConfigurationOrderComparator() ); + + assertProxyOrder( new String[]{ "snapshots", "3rdparty", "corporate", "sandbox" }, proxies ); + } + + @Test + public void testSortPartial() + { + List<ProxyConnectorConfiguration> proxies = new ArrayList<>(); + + proxies.add( createConnector( "corporate", 3 ) ); + proxies.add( createConnector( "snapshots", 0 ) ); + proxies.add( createConnector( "3rdparty", 2 ) ); + proxies.add( createConnector( "sandbox", 0 ) ); + + Collections.sort( proxies, new ProxyConnectorConfigurationOrderComparator() ); + + assertProxyOrder( new String[]{ "3rdparty", "corporate", "snapshots", "sandbox" }, proxies ); + } + + private void assertProxyOrder( String[] ids, List<ProxyConnectorConfiguration> proxies ) + { + assertEquals( "Proxies.size() == ids.length", ids.length, proxies.size() ); + + int orderFailedAt = -1; + + for ( int i = 0; i < ids.length; i++ ) + { + if ( !StringUtils.equals( ids[i], proxies.get( i ).getProxyId() ) ) + { + orderFailedAt = i; + break; + } + } + + if ( orderFailedAt >= 0 ) + { + StringBuilder msg = new StringBuilder(); + + msg.append( "Failed expected order of the proxies <" ); + msg.append( StringUtils.join( ids, ", " ) ); + msg.append( ">, actual <" ); + + boolean needsComma = false; + for ( ProxyConnectorConfiguration proxy : proxies ) + { + if ( needsComma ) + { + msg.append( ", " ); + } + msg.append( proxy.getProxyId() ); + needsComma = true; + } + msg.append( "> failure at index <" ).append( orderFailedAt ).append( ">." ); + + fail( msg.toString() ); + } + } + + private ProxyConnectorConfiguration createConnector( String id, int order ) + { + ProxyConnectorConfiguration proxy = new ProxyConnectorConfiguration(); + proxy.setProxyId( id ); + proxy.setOrder( order ); + proxy.setSourceRepoId( id + "_m" ); + proxy.setTargetRepoId( id + "_r" ); + + return proxy; + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/functors/RepositoryConfigurationComparatorTest.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/functors/RepositoryConfigurationComparatorTest.java new file mode 100644 index 000000000..0423351ac --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/java/org/apache/archiva/configuration/provider/functors/RepositoryConfigurationComparatorTest.java @@ -0,0 +1,57 @@ +package org.apache.archiva.configuration.provider.functors; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.configuration.model.AbstractRepositoryConfiguration; +import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.model.functors.RepositoryConfigurationComparator; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Comparator; + +import static org.junit.Assert.assertEquals; + +/** + * Test the repositry comparator. + */ +@RunWith( ArchivaBlockJUnit4ClassRunner.class ) +public class RepositoryConfigurationComparatorTest +{ + @Test + public void testComparator() + { + Comparator<AbstractRepositoryConfiguration> comparator = new RepositoryConfigurationComparator(); + + assertEquals( 0, comparator.compare( null, null ) ); + assertEquals( 1, comparator.compare( createRepository( "id" ), null ) ); + assertEquals( -1, comparator.compare( null, createRepository( "id" ) ) ); + assertEquals( 0, comparator.compare( createRepository( "id1" ), createRepository( "id1" ) ) ); + assertEquals( -1, comparator.compare( createRepository( "id1" ), createRepository( "id2" ) ) ); + assertEquals( 1, comparator.compare( createRepository( "id2" ), createRepository( "id1" ) ) ); + } + + private ManagedRepositoryConfiguration createRepository( String id ) + { + ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration(); + repo.setId( id ); + return repo; + } +} diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/resources/log4j2-test.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/resources/log4j2-test.xml new file mode 100644 index 000000000..03547df43 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/resources/log4j2-test.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> +<configuration> + <Properties> + + </Properties> + <appenders> + <Console name="console" target="SYSTEM_OUT"> + <PatternLayout pattern="%d{ISO8601_PERIOD} [%L] [%t] %-5level %logger{3} - %msg%n"/> + </Console> + <!-- + <RandomAccessFile name="LogFile" fileName="target/test.log"> + <PatternLayout pattern="%d{ISO8601_PERIOD} [%L] [%t] %-5level %logger{3} - %msg%n"/> + </RandomAccessFile> + --> + </appenders> + <loggers> + <logger name="org.apache.archiva" level="info"/> + <logger name="org.apache.archiva.repository.scanner" level="info"/> + <root level="error" includeLocation="true"> + <appender-ref ref="console"/> + </root> + </loggers> +</configuration> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/resources/org/apache/archiva/configuration/test-default-archiva.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/resources/org/apache/archiva/configuration/test-default-archiva.xml new file mode 100755 index 000000000..dc1215e69 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/resources/org/apache/archiva/configuration/test-default-archiva.xml @@ -0,0 +1,176 @@ +<configuration> + <version>3.0.0</version> + <managedRepositories> + <managedRepository> + <id>internal</id> + <name>Archiva Managed Internal Repository</name> + <location>${appserver.base}/target/test-classes/existing_internal</location> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <scanned>true</scanned> + <refreshCronExpression>0 0 * * * ?</refreshCronExpression> + <retentionPeriod>30</retentionPeriod> + </managedRepository> + <managedRepository> + <id>snapshots</id> + <name>Archiva Managed Snapshot Repository</name> + <location>${appserver.base}/target/test-classes/existing_snapshots</location> + <layout>default</layout> + <releases>false</releases> + <snapshots>true</snapshots> + <scanned>true</scanned> + <refreshCronExpression>0 0\,30 * * * ?</refreshCronExpression> + <retentionPeriod>30</retentionPeriod> + </managedRepository> + </managedRepositories> + <remoteRepositories> + <remoteRepository> + <id>central</id> + <name>Central Repository</name> + <url>http://repo1.maven.org/maven2</url> + <layout>default</layout> + </remoteRepository> + <remoteRepository> + <id>maven2-repository.dev.java.net</id> + <name>Java.net Repository for Maven 2</name> + <url>http://download.java.net/maven/2/</url> + <layout>default</layout> + </remoteRepository> + </remoteRepositories> + + <proxyConnectors> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>central</targetRepoId> + <proxyId/> + <policies> + <snapshots>disabled</snapshots> + <releases>once</releases> + <checksum>fix</checksum> + <cache-failures>cached</cache-failures> + </policies> + <whiteListPatterns> + <whiteListPattern>**/*</whiteListPattern> + </whiteListPatterns> + </proxyConnector> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>maven2-repository.dev.java.net</targetRepoId> + <proxyId/> + <policies> + <snapshots>disabled</snapshots> + <releases>once</releases> + <checksum>fix</checksum> + <cache-failures>cached</cache-failures> + </policies> + <whiteListPatterns> + <whiteListPattern>javax/**</whiteListPattern> + <whiteListPattern>org/jvnet/**</whiteListPattern> + <whiteListPattern>com/sun/**</whiteListPattern> + </whiteListPatterns> + </proxyConnector> + </proxyConnectors> + + <legacyArtifactPaths> + <legacyArtifactPath> + <path>jaxen/jars/jaxen-1.0-FCS-full.jar</path> + <artifact>jaxen:jaxen:1.0-FCS:full:jar</artifact> + </legacyArtifactPath> + </legacyArtifactPaths> + + <repositoryScanning> + <fileTypes> + <fileType> + <id>artifacts</id> + <patterns> + <pattern>**/*.pom</pattern> + <pattern>**/*.jar</pattern> + <pattern>**/*.ear</pattern> + <pattern>**/*.war</pattern> + <pattern>**/*.car</pattern> + <pattern>**/*.sar</pattern> + <pattern>**/*.mar</pattern> + <pattern>**/*.rar</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + <pattern>**/*.tar.gz</pattern> + <pattern>**/*.tar.bz2</pattern> + <pattern>**/*.zip</pattern> + </patterns> + </fileType> + <fileType> + <id>indexable-content</id> + <patterns> + <pattern>**/*.txt</pattern> + <pattern>**/*.TXT</pattern> + <pattern>**/*.block</pattern> + <pattern>**/*.config</pattern> + <pattern>**/*.pom</pattern> + <pattern>**/*.xml</pattern> + <pattern>**/*.xsd</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + </patterns> + </fileType> + <fileType> + <id>auto-remove</id> + <patterns> + <pattern>**/*.bak</pattern> + <pattern>**/*~</pattern> + <pattern>**/*-</pattern> + </patterns> + </fileType> + <fileType> + <id>ignored</id> + <patterns> + <pattern>**/.htaccess</pattern> + <pattern>**/KEYS</pattern> + <pattern>**/*.rb</pattern> + <pattern>**/*.sh</pattern> + <pattern>**/.svn/**</pattern> + <pattern>**/.DAV/**</pattern> + </patterns> + </fileType> + </fileTypes> + <knownContentConsumers> + <knownContentConsumer>update-db-artifact</knownContentConsumer> + <knownContentConsumer>create-missing-checksums</knownContentConsumer> + <knownContentConsumer>update-db-repository-metadata</knownContentConsumer> + <knownContentConsumer>validate-checksum</knownContentConsumer> + <knownContentConsumer>validate-signature</knownContentConsumer> + <knownContentConsumer>index-content</knownContentConsumer> + <knownContentConsumer>auto-remove</knownContentConsumer> + <knownContentConsumer>auto-rename</knownContentConsumer> + <knownContentConsumer>metadata-updater</knownContentConsumer> + <!--knownContentConsumer>repository-purge</knownContentConsumer--> + </knownContentConsumers> + <invalidContentConsumers> + <invalidContentConsumer>update-db-bad-content</invalidContentConsumer> + </invalidContentConsumers> + </repositoryScanning> + + <databaseScanning> + <cronExpression>0 0 * * * ?</cronExpression> + <unprocessedConsumers> + <unprocessedConsumer>index-artifact</unprocessedConsumer> + <unprocessedConsumer>update-db-project</unprocessedConsumer> + <unprocessedConsumer>validate-repository-metadata</unprocessedConsumer> + <unprocessedConsumer>index-archive-toc</unprocessedConsumer> + <unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer> + <unprocessedConsumer>index-public-methods</unprocessedConsumer> + </unprocessedConsumers> + <cleanupConsumers> + <cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer> + <cleanupConsumer>not-present-remove-db-project</cleanupConsumer> + <cleanupConsumer>not-present-remove-indexed</cleanupConsumer> + </cleanupConsumers> + </databaseScanning> + + <webapp> + <ui> + <showFindArtifacts>true</showFindArtifacts> + <appletFindEnabled>true</appletFindEnabled> + </ui> + </webapp> +</configuration> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/resources/spring-context.xml new file mode 100755 index 000000000..4f63c9839 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-provider/src/test/resources/spring-context.xml @@ -0,0 +1,340 @@ +<?xml version="1.0"?> + +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-3.0.xsd" + default-lazy-init="true"> + + <context:property-placeholder system-properties-mode="OVERRIDE"/> + + <bean name="archivaConfiguration#test-defaults-default-repo-location-exists" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#empty"/> + </bean> + <bean name="registry#empty" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"/> + + <bean name="archivaConfiguration#test-defaults" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#emptydef"/> + </bean> + <bean name="registry#emptydef" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"/> + + <bean name="archivaConfiguration#test-upgrade-09" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-upgrade-09"/> + </bean> + + + + <bean name="registry#test-upgrade-09" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <xml fileName="${basedir}/src/test/conf/archiva-0.9.xml" + config-name="org.apache.archiva" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + <bean name="archivaConfiguration#test-upgrade-1.3" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-upgrade-1.3"/> + </bean> + + <bean name="registry#test-upgrade-1.3" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <xml fileName="${basedir}/src/test/conf/archiva-1.3.xml" + config-name="org.apache.archiva" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + <bean name="archivaConfiguration#test-configuration" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#configured"/> + </bean> + + <bean name="registry#configured" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <system/> + <xml fileName="${basedir}/src/test/conf/repository-manager.xml" + config-name="org.apache.archiva" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + + <bean name="archivaConfiguration#test-autodetect-v1" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-autodetect-v1"/> + </bean> + + <bean name="registry#test-autodetect-v1" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <system/> + <xml fileName="${basedir}/target/test-autodetect-v1/archiva-user.xml" config-optional="true" + config-name="org.apache.archiva.user" + config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + <bean name="archivaConfiguration#test-archiva-v1" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-archiva-v1"/> + </bean> + + <bean name="registry#test-archiva-v1" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <system/> + <xml fileName="${basedir}/src/test/conf/archiva-v1.xml" + config-name="org.apache.archiva" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + <bean name="archivaConfiguration#test-save" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-save"/> + </bean> + + <bean name="registry#test-save" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="true" + config-name="org.apache.archiva.base" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + <bean name="archivaConfiguration#test-save-user-defaults" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-save-user-defaults"/> + </bean> + + <bean name="registry#test-save-user-defaults" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <xml fileName="${basedir}/target/test/test-file-user.xml" config-optional="true" config-forceCreate="true" + config-name="org.apache.archiva.user" config-at="org.apache.archiva"/> + <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="false" + config-name="org.apache.archiva.base" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + <bean name="archivaConfiguration#test-save-user-fallback" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-save-user-fallback"/> + </bean> + + <bean name="registry#test-save-user-fallback" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <xml fileName="${basedir}/target/test/test-file-user.xml" config-optional="true" config-forceCreate="false" + config-name="org.apache.archiva.user" config-at="org.apache.archiva"/> + <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="true" + config-name="org.apache.archiva.base" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + <bean name="archivaConfiguration#test-save-user" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-save-user"/> + </bean> + + <bean name="registry#test-save-user" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <xml fileName="${basedir}/target/test/test-file-user.xml" config-optional="true" config-forceCreate="true" + config-name="org.apache.archiva.user" config-at="org.apache.archiva"/> + <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="false" + config-name="org.apache.archiva.base" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + + <bean name="archivaConfiguration#test-configuration-both" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-configuration-both"/> + </bean> + + <bean name="registry#test-configuration-both" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <xml fileName="${basedir}/src/test/conf/conf-user.xml" config-optional="true" config-forceCreate="true" + config-name="org.apache.archiva.user" config-at="org.apache.archiva"/> + <xml fileName="${basedir}/src/test/conf/conf-base.xml" config-optional="true" config-forceCreate="true" + config-name="org.apache.archiva.base" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + + <bean name="archivaConfiguration#test-read-saved" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-read-saved"/> + </bean> + + <bean name="registry#test-read-saved" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="true" + config-name="org.apache.archiva.base" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + + <bean name="archivaConfiguration#test-cron-expressions" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-cron-expressions"/> + <property name="userConfigFilename" value="${basedir}/target/test/test-file.xml"/> + </bean> + + <bean name="registry#test-cron-expressions" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="true" + config-name="org.apache.archiva.base" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + + <bean name="archivaConfiguration#test-remove-central" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-remove-central"/> + </bean> + + <bean name="registry#test-remove-central" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="true" + config-name="org.apache.archiva.base" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + + <bean name="archivaConfiguration#test-not-allowed-to-write-to-both" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-not-allowed-to-write-to-both"/> + <property name="userConfigFilename" value="/../../..//target/*intentionally:invalid*/.m2/archiva-user.xml"/> + <property name="altConfigFilename" value="/../../..//target/*intentionally:invalid*/conf/archiva.xml"/> + </bean> + + <bean name="registry#test-not-allowed-to-write-to-both" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <xml fileName="/../../..//*intentionally:invalid*/.m2/archiva-user.xml" config-optional="true" + config-name="org.apache.archiva.user" config-at="org.apache.archiva"/> + <xml fileName="/../../..//*intentionally:invalid*/conf/archiva.xml" config-optional="true" + config-name="org.apache.archiva.user" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + <bean name="archivaConfiguration#test-not-allowed-to-write-to-user" class="org.apache.archiva.configuration.provider.DefaultArchivaConfiguration"> + <property name="registry" ref="registry#test-not-allowed-to-write-to-user"/> + <property name="userConfigFilename" value="${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml"/> + <property name="altConfigFilename" value="${basedir}/target/test-appserver-base/conf/archiva.xml"/> + </bean> + + <bean name="registry#test-not-allowed-to-write-to-user" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"> + <property name="initialConfiguration"> + <value> + <![CDATA[ + <configuration> + <xml fileName="${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml" config-optional="true" + config-name="org.apache.archiva.user" config-at="org.apache.archiva"/> + <xml fileName="${basedir}/target/test-appserver-base/conf/archiva.xml" config-optional="true" + config-name="org.apache.archiva.user" config-at="org.apache.archiva"/> + </configuration> + ]]> + </value> + </property> + </bean> + + <bean name="cache#url-failures-cache" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"> + <constructor-arg index="0" value="java.lang.String"/> + <constructor-arg index="1" value="java.util.Date"/> + <property name="diskExpiryThreadIntervalSeconds" value="600"/> + <property name="diskPersistent" value="false"/> + <property name="eternal" value="false"/> + <property name="maxElementsInMemory" value="1000"/> + <property name="memoryEvictionPolicy" value="LRU"/> + <property name="name" value="url-failures-cache"/> + <property name="overflowToDisk" value="false"/> + <property name="timeToIdleSeconds" value="2700"/> + <property name="timeToLiveSeconds" value="1800"/> + </bean> + +</beans>
\ No newline at end of file |