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