Java Code Examples for org.eclipse.microprofile.config.spi.ConfigProviderResolver#instance()

The following examples show how to use org.eclipse.microprofile.config.spi.ConfigProviderResolver#instance() . 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: ApplicationYamlTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void doBefore() {
    SmallRyeConfigBuilder builder = new SmallRyeConfigBuilder();
    builder.addDefaultSources().addDiscoveredConverters().addDiscoveredSources();
    QuarkusConfigFactory.setConfig(config = builder.build());
    Config conf = ConfigProvider.getConfig();
    if (conf != config) {
        ConfigProviderResolver cpr = ConfigProviderResolver.instance();
        cpr.releaseConfig(conf);
        ConfigProvider.getConfig();
    }
    System.out.println(System.getProperty("user.dir"));
}
 
Example 2
Source File: NativeImageLauncher.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static Config installAndGetSomeConfig() {
    final SmallRyeConfig config = ConfigUtils.configBuilder(false).build();
    QuarkusConfigFactory.setConfig(config);
    final ConfigProviderResolver cpr = ConfigProviderResolver.instance();
    try {
        final Config installed = cpr.getConfig();
        if (installed != config) {
            cpr.releaseConfig(installed);
        }
    } catch (IllegalStateException ignored) {
    }
    return config;
}
 
Example 3
Source File: CustomInvokeWithJsonPProviderTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setupClient() throws Exception {
    SmallRyeConfig config = ConfigUtils.configBuilder(true).build();
    QuarkusConfigFactory.setConfig(config);
    ConfigProviderResolver cpr = ConfigProviderResolver.instance();
    try {
        Config old = cpr.getConfig();
        if (old != config) {
            cpr.releaseConfig(old);
        }
    } catch (IllegalStateException ignored) {
    }
    super.setupClient();
}
 
Example 4
Source File: CustomInvokeWithJsonPProviderTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@AfterTest
public void tearDownClient() {
    ConfigProviderResolver cpr = ConfigProviderResolver.instance();
    try {
        Config old = cpr.getConfig();
        cpr.releaseConfig(old);
    } catch (IllegalStateException ignored) {
    }
}
 
Example 5
Source File: CustomInvokeWithJsonBProviderTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setupClient() throws Exception {
    SmallRyeConfig config = ConfigUtils.configBuilder(true).build();
    QuarkusConfigFactory.setConfig(config);
    ConfigProviderResolver cpr = ConfigProviderResolver.instance();
    try {
        Config old = cpr.getConfig();
        if (old != config) {
            cpr.releaseConfig(old);
        }
    } catch (IllegalStateException ignored) {
    }
    super.setupClient();
}
 
Example 6
Source File: CustomInvokeWithJsonBProviderTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@AfterTest
public void tearDownClient() {
    ConfigProviderResolver cpr = ConfigProviderResolver.instance();
    try {
        Config old = cpr.getConfig();
        cpr.releaseConfig(old);
    } catch (IllegalStateException ignored) {
    }
}
 
Example 7
Source File: ApplicationYamlTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AfterAll
public static void doAfter() {
    ConfigProviderResolver cpr = ConfigProviderResolver.instance();
    cpr.releaseConfig(config);
    config = null;
}
 
Example 8
Source File: Application.java    From quarkus with Apache License 2.0 4 votes vote down vote up
/**
 * Start the application. If another thread is also trying to start the application, this method waits for that
 * thread to finish starting. Returns immediately if the application is started already. If the application
 * fails to start, an exception is thrown.
 *
 * @param args the command-line arguments
 * @implNote The command line args are not yet used, but at some point we'll want a facility for overriding config and/or
 *           letting the user hook into it.
 */
public final void start(String[] args) {
    currentApplication = this;
    final Lock stateLock = this.stateLock;
    stateLock.lock();
    try {
        loop: for (;;)
            switch (state) {
                case ST_INITIAL:
                    break loop; // normal startup
                case ST_STARTING: {
                    try {
                        stateCond.await();
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                        throw interruptedOnAwaitStart();
                    }
                    break;
                }
                case ST_STARTED:
                    return; // all good
                default: {
                    throw new IllegalStateException("The application is stopping");
                }
            }
        state = ST_STARTING;
    } finally {
        stateLock.unlock();
    }
    try {
        doStart(args);
    } catch (Throwable t) {
        stateLock.lock();
        final ConfigProviderResolver cpr = ConfigProviderResolver.instance();
        try {
            cpr.releaseConfig(cpr.getConfig());
        } catch (IllegalStateException ignored) {
            // just means no config was installed, which is fine
        }
        try {
            state = ST_STOPPED;
            stateCond.signalAll();
        } finally {
            stateLock.unlock();
        }
        ApplicationStateNotification.notifyStartupFailed(t);
        throw t;
    }
    stateLock.lock();
    try {
        state = ST_STARTED;
        stateCond.signalAll();
        ApplicationStateNotification.notifyStartupComplete();
    } finally {
        stateLock.unlock();
    }
}
 
Example 9
Source File: ConfigExpanderTestCase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BeforeAll
public static void initConfig() {
    classLoader = Thread.currentThread().getContextClassLoader();
    cpr = ConfigProviderResolver.instance();
}
 
Example 10
Source File: ConfigProfileTestCase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BeforeAll
public static void initConfig() {
    classLoader = Thread.currentThread().getContextClassLoader();
    cpr = ConfigProviderResolver.instance();
}
 
Example 11
Source File: DotEnvTestCase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BeforeAll
public static void initConfig() {
    classLoader = Thread.currentThread().getContextClassLoader();
    cpr = ConfigProviderResolver.instance();
}