Search in sources :

Example 1 with CommonsConfigurationRegistry

use of org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry 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;
    }
}
Also used : CommonsConfigurationRegistry(org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry) RegistryListener(org.apache.archiva.components.registry.RegistryListener) CommonsConfigurationRegistry(org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry) Registry(org.apache.archiva.components.registry.Registry) RegistryException(org.apache.archiva.components.registry.RegistryException)

Aggregations

Registry (org.apache.archiva.components.registry.Registry)1 RegistryException (org.apache.archiva.components.registry.RegistryException)1 RegistryListener (org.apache.archiva.components.registry.RegistryListener)1 CommonsConfigurationRegistry (org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry)1