Search in sources :

Example 1 with CommonsConfigurationRegistry

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

Example 2 with CommonsConfigurationRegistry

use of org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry in project archiva by apache.

the class FileTypes method initialize.

@PostConstruct
public void initialize() {
    // TODO: why is this done by hand?
    // TODO: ideally, this would be instantiated by configuration instead, and not need to be a component
    String errMsg = "Unable to load default archiva configuration for FileTypes: ";
    try {
        CommonsConfigurationRegistry commonsRegistry = new CommonsConfigurationRegistry();
        // Configure commonsRegistry
        Field fld = commonsRegistry.getClass().getDeclaredField("configuration");
        fld.setAccessible(true);
        fld.set(commonsRegistry, new CombinedConfiguration());
        commonsRegistry.addConfigurationFromResource("org/apache/archiva/configuration/default-archiva.xml");
        // Read configuration as it was intended.
        ConfigurationRegistryReader configReader = new ConfigurationRegistryReader();
        Configuration defaultConfig = configReader.read(commonsRegistry);
        initialiseTypeMap(defaultConfig);
    } catch (RegistryException e) {
        throw new RuntimeException(errMsg + e.getMessage(), e);
    } catch (SecurityException e) {
        throw new RuntimeException(errMsg + e.getMessage(), e);
    } catch (NoSuchFieldException e) {
        throw new RuntimeException(errMsg + e.getMessage(), e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(errMsg + e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(errMsg + e.getMessage(), e);
    }
    this.archivaConfiguration.addChangeListener(this);
}
Also used : Field(java.lang.reflect.Field) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) CommonsConfigurationRegistry(org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry) ConfigurationRegistryReader(org.apache.archiva.configuration.io.registry.ConfigurationRegistryReader) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) RegistryException(org.apache.archiva.redback.components.registry.RegistryException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

RegistryException (org.apache.archiva.redback.components.registry.RegistryException)2 CommonsConfigurationRegistry (org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry)2 Field (java.lang.reflect.Field)1 PostConstruct (javax.annotation.PostConstruct)1 ConfigurationRegistryReader (org.apache.archiva.configuration.io.registry.ConfigurationRegistryReader)1 Registry (org.apache.archiva.redback.components.registry.Registry)1 RegistryListener (org.apache.archiva.redback.components.registry.RegistryListener)1 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)1 CombinedConfiguration (org.apache.commons.configuration.CombinedConfiguration)1