use of org.apache.archiva.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.model.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.components.registry.RegistryException in project archiva by apache.
the class ManagedRepositoryHandler method put.
@Override
public ManagedRepository put(ManagedRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
final String id = repositoryConfiguration.getId();
final RepositoryType repositoryType = RepositoryType.valueOf(repositoryConfiguration.getType());
final RepositoryProvider provider = getProvider(repositoryType);
ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
configLock.lock();
ManagedRepository repo = null;
ManagedRepository oldRepository = null;
Configuration configuration = null;
try {
boolean updated = false;
configuration = getConfigurationHandler().getBaseConfiguration();
repo = getRepositories().get(id);
oldRepository = repo == null ? null : clone(repo, id);
if (repo == null) {
repo = put(repositoryConfiguration, configuration);
} else {
setRepositoryDefaults(repositoryConfiguration);
provider.updateManagedInstance((EditableManagedRepository) repo, repositoryConfiguration);
updated = true;
pushEvent(LifecycleEvent.UPDATED, repo);
}
registerNewRepository(repositoryConfiguration, repo, configuration, updated);
} catch (IndeterminateConfigurationException | RegistryException e) {
if (oldRepository != null) {
ManagedRepositoryConfiguration oldCfg = provider.getManagedConfiguration(oldRepository);
provider.updateManagedInstance((EditableManagedRepository) repo, oldCfg);
rollback(configuration, oldRepository, e, oldCfg);
} else {
getRepositories().remove(id);
}
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());
} finally {
configLock.unlock();
}
return repo;
}
use of org.apache.archiva.components.registry.RegistryException in project archiva by apache.
the class ArchivaConfigurationTest method testLoadConfigurationFromInvalidBothLocationsOnDisk.
@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);
}
}
use of org.apache.archiva.components.registry.RegistryException 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.RegistryException in project archiva by apache.
the class DefaultArchivaConfiguration method initialize.
@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);
}
Aggregations