use of org.apache.archiva.redback.components.registry.RegistryException 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());
}
}
}
use of org.apache.archiva.redback.components.registry.RegistryException in project archiva by apache.
the class DefaultArchivaConfiguration method createDefaultConfigurationFile.
private Registry createDefaultConfigurationFile() 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)) {
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).setProperties(contents);
registry.initialize();
for (RegistryListener regListener : registryListeners) {
addRegistryChangeListener(regListener);
}
triggerEvent(ConfigurationEvent.SAVED);
Registry section = registry.getSection(KEY + ".user");
return section == null ? new CommonsConfigurationRegistry(new BaseConfiguration()) : section;
}
use of org.apache.archiva.redback.components.registry.RegistryException in project archiva by apache.
the class DefaultArchivaConfiguration method initialize.
@PostConstruct
public void initialize() {
this.postPolicies = componentContainer.buildMapWithRole(PostDownloadPolicy.class);
this.prePolicies = componentContainer.buildMapWithRole(PreDownloadPolicy.class);
this.downloadErrorPolicies = componentContainer.buildMapWithRole(DownloadErrorPolicy.class);
// Resolve expressions in the userConfigFilename and altConfigFilename
try {
ExpressionEvaluator expressionEvaluator = new DefaultExpressionEvaluator();
expressionEvaluator.addExpressionSource(new SystemPropertyExpressionSource());
String userConfigFileNameSysProps = System.getProperty("archiva.user.configFileName");
if (StringUtils.isNotBlank(userConfigFileNameSysProps)) {
userConfigFilename = userConfigFileNameSysProps;
} 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);
}
use of org.apache.archiva.redback.components.registry.RegistryException in project archiva by apache.
the class DefaultRedbackRuntimeConfigurationAdmin method updateRedbackRuntimeConfiguration.
@Override
public void updateRedbackRuntimeConfiguration(RedbackRuntimeConfiguration redbackRuntimeConfiguration) throws RepositoryAdminException {
org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration = build(redbackRuntimeConfiguration);
Configuration configuration = archivaConfiguration.getConfiguration();
configuration.setRedbackRuntimeConfiguration(runtimeConfiguration);
try {
archivaConfiguration.save(configuration);
} catch (RegistryException e) {
throw new RepositoryAdminException(e.getMessage(), e);
} catch (IndeterminateConfigurationException e) {
throw new RepositoryAdminException(e.getMessage(), e);
}
}
use of org.apache.archiva.redback.components.registry.RegistryException in project archiva by apache.
the class RepositoryRegistry method putRepository.
/**
* Adds a new repository or updates the repository with the same id, if it exists already.
* The configuration is saved immediately.
*
* @param managedRepositoryConfiguration the repository configuration
* @return the updated or created repository
* @throws RepositoryException if an error occurs, or the configuration is not valid.
*/
public ManagedRepository putRepository(ManagedRepositoryConfiguration managedRepositoryConfiguration) throws RepositoryException {
rwLock.writeLock().lock();
try {
final String id = managedRepositoryConfiguration.getId();
final RepositoryType repositoryType = RepositoryType.valueOf(managedRepositoryConfiguration.getType());
Configuration configuration = getArchivaConfiguration().getConfiguration();
ManagedRepository repo = managedRepositories.get(id);
ManagedRepositoryConfiguration oldCfg = repo != null ? getProvider(repositoryType).getManagedConfiguration(repo) : null;
repo = putRepository(managedRepositoryConfiguration, configuration);
try {
getArchivaConfiguration().save(configuration);
} catch (IndeterminateConfigurationException | RegistryException e) {
if (oldCfg != null) {
getProvider(repositoryType).updateManagedInstance((EditableManagedRepository) repo, oldCfg);
}
log.error("Could not save the configuration for repository {}: {}", id, e.getMessage(), e);
throw new RepositoryException("Could not save the configuration for repository " + id + ": " + e.getMessage());
}
return repo;
} finally {
rwLock.writeLock().unlock();
}
}
Aggregations