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