Java Code Examples for org.apache.deltaspike.core.api.config.ConfigResolver#getConfigSources()

The following examples show how to use org.apache.deltaspike.core.api.config.ConfigResolver#getConfigSources() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeltaSpikeConfigInfo.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@Override
public String[] getConfigSourcesAsString()
{
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try
    {
        Thread.currentThread().setContextClassLoader(appConfigClassLoader);

        ConfigSource[] configSources = ConfigResolver.getConfigSources();
        List<String> configSourceInfo = new ArrayList<String>();
        for (ConfigSource configSource : configSources)
        {
            configSourceInfo.add(Integer.toString(configSource.getOrdinal())
                + " - " + configSource.getConfigName());
        }

        return configSourceInfo.toArray(new String[configSourceInfo.size()]);
    }
    finally
    {
        // set back the original TCCL
        Thread.currentThread().setContextClassLoader(originalCl);
    }

}
 
Example 2
Source File: DeltaSpikeConfigInfo.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
private List<ConfigEntry> calculateConfigEntries()
{
    Map<String, String> allProperties = ConfigResolver.getAllProperties();
    List<ConfigEntry> configEntries = new ArrayList<ConfigEntry>(allProperties.size());
    ConfigSource[] configSources = ConfigResolver.getConfigSources();

    for (Map.Entry<String, String> configEntry : allProperties.entrySet())
    {
        String key = configEntry.getKey();
        String value = ConfigResolver.filterConfigValueForLog(key,
                                ConfigResolver.getProjectStageAwarePropertyValue(key));

        String fromConfigSource = getFromConfigSource(configSources, key);
        configEntries.add(new ConfigEntry(key, value, fromConfigSource));
    }

    return configEntries;
}
 
Example 3
Source File: ConfigResolverTest.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
private void setTestConfigSourceValue(String key, String value)
{
    ConfigSource[] configSources = ConfigResolver.getConfigSources();
    for (ConfigSource configSource : configSources)
    {
        if (configSource instanceof TestConfigSource)
        {
            if (value == null)
            {
                configSource.getProperties().remove(key);
            }
            else
            {
                configSource.getProperties().put(key, value);
            }

            break;
        }
    }
}
 
Example 4
Source File: ServletConfigListener.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Override
public void contextInitialized(ServletContextEvent sce)
{
    ConfigSource[] configSources = ConfigResolver.getConfigSources();
    for (ConfigSource configSource : configSources)
    {
        if (configSource instanceof ServletConfigSource)
        {
            setServletConfig((ServletConfigSource) configSource, sce);
            return;
        }
    }
}
 
Example 5
Source File: DeltaSpikeConfigInfo.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Override
public TabularData getConfigSources()
{
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try
    {
        Thread.currentThread().setContextClassLoader(appConfigClassLoader);

        String typeName = "ConfigSources";
        OpenType<?>[] types = new OpenType<?>[]{SimpleType.INTEGER, SimpleType.STRING};
        String[] keys = new String[]{"Ordinal", "ConfigSource"};

        CompositeType ct = new CompositeType(typeName, typeName, keys, keys, types);
        TabularType type = new TabularType(typeName, typeName, ct, keys);
        TabularDataSupport configSourceInfo = new TabularDataSupport(type);

        ConfigSource[] configSources = ConfigResolver.getConfigSources();
        for (ConfigSource configSource : configSources)
        {
            configSourceInfo.put(
                new CompositeDataSupport(ct, keys,
                        new Object[]{configSource.getOrdinal(), configSource.getConfigName()}));
        }

        return configSourceInfo;
    }
    catch (OpenDataException e)
    {
        throw new RuntimeException(e);
    }
    finally
    {
        // set back the original TCCL
        Thread.currentThread().setContextClassLoader(originalCl);
    }
}
 
Example 6
Source File: ConfigurationExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private void logConfiguration()
{
    Boolean logConfig = ConfigResolver.resolve(ConfigResolver.DELTASPIKE_LOG_CONFIG).as(Boolean.class).getValue();
    if (logConfig != null && logConfig && LOG.isLoggable(Level.INFO))
    {
        StringBuilder sb = new StringBuilder(1 << 16);

        // first log out the config sources in descendent ordinal order
        sb.append("ConfigSources: ");
        ConfigSource[] configSources = ConfigResolver.getConfigSources();
        for (ConfigSource configSource : configSources)
        {
            sb.append("\n\t").append(configSource.getOrdinal()).append(" - ").append(configSource.getConfigName());
        }

        // and all the entries in no guaranteed order
        Map<String, String> allProperties = ConfigResolver.getAllProperties();
        sb.append("\n\nConfigured Values:");
        for (Map.Entry<String, String> entry : allProperties.entrySet())
        {
            sb.append("\n\t")
                .append(entry.getKey())
                .append(" = ")
                .append(ConfigResolver.filterConfigValueForLog(entry.getKey(), entry.getValue()));
        }

        LOG.info(sb.toString());
    }
}
 
Example 7
Source File: CdiTestSuiteRunner.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
private static void initTestEnvConfig(Class<?> testClass, String activeAlternativeLabel, TestControl testControl)
{
    if (ClassDeactivationUtils.isActivated(TestConfigSource.class))
    {
        TestConfigSource testConfigSource = null;

        for (ConfigSource configSource : ConfigResolver.getConfigSources())
        {
            if (configSource instanceof TestConfigSource)
            {
                //if it happens: parallel test-execution can't be supported with labeled alternatives
                testConfigSource = (TestConfigSource) configSource;
            }
        }

        if (testConfigSource == null)
        {
            testConfigSource = new TestConfigSource();
            ConfigResolver.addConfigSources(Arrays.<ConfigSource>asList(testConfigSource));
        }

        //always set it even if it is empty (it might overrule the value of the prev. test
        testConfigSource.getProperties().put("activeAlternativeLabel", activeAlternativeLabel);

        testConfigSource.getProperties().put("activeAlternativeLabelSource", testClass.getName());

        if (testControl != null)
        {
            testConfigSource.getProperties().put(TestControl.class.getName(), testClass.getName());
            testConfigSource.getProperties().put(ClassFilter.class.getName(), testControl.classFilter().getName());
        }
        else
        {
            //reset it to avoid leaks between tests
            testConfigSource.getProperties().put(TestControl.class.getName(), TestControl.class.getName());
            testConfigSource.getProperties().put(ClassFilter.class.getName(), ClassFilter.class.getName());
        }
    }
    else
    {
        //always set it even if it is empty (it might overrule the value of the prev. test
        System.setProperty("activeAlternativeLabel", activeAlternativeLabel); //will be picked up by ds-core

        System.setProperty("activeAlternativeLabelSource", testClass.getName()); //can be used for custom logic

        if (testControl != null) //can be used for custom logic
        {
            System.setProperty(TestControl.class.getName(), testClass.getName());
            System.setProperty(ClassFilter.class.getName(), testControl.classFilter().getName());
        }
        else
        {
            //reset it to avoid leaks between tests
            System.setProperty(TestControl.class.getName(), TestControl.class.getName());
            System.setProperty(ClassFilter.class.getName(), ClassFilter.class.getName());
        }
    }
}