Search in sources :

Example 6 with PropertiesBasedValueSource

use of org.codehaus.plexus.interpolation.PropertiesBasedValueSource in project indy by Commonjava.

the class CacheProducer method start.

@PostConstruct
public void start() {
    // FIXME This is just here to trigger shutdown hook init for embedded log4j in infinispan-embedded-query.
    // FIXES:
    //
    // Thread-15 ERROR Unable to register shutdown hook because JVM is shutting down.
    // java.lang.IllegalStateException: Cannot add new shutdown hook as this is not started. Current state: STOPPED
    //
    new MarshallableTypeHints().getBufferSizePredictor(CacheHandle.class);
    File confDir = indyConfiguration.getIndyConfDir();
    File ispnConf = new File(confDir, ISPN_XML);
    String configuration;
    if (ispnConf.exists()) {
        try {
            configuration = FileUtils.readFileToString(ispnConf);
        } catch (IOException e) {
            throw new RuntimeException("Cannot read infinispan configuration from file: " + ispnConf, e);
        }
    } else {
        try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(ISPN_XML)) {
            configuration = IOUtils.toString(stream);
        } catch (IOException e) {
            throw new RuntimeException("Cannot read infinispan configuration from classpath: " + ISPN_XML, e);
        }
    }
    StringSearchInterpolator interpolator = new StringSearchInterpolator();
    interpolator.addValueSource(new PropertiesBasedValueSource(System.getProperties()));
    try {
        configuration = interpolator.interpolate(configuration);
    } catch (InterpolationException e) {
        throw new RuntimeException("Cannot resolve expressions in infinispan configuration.", e);
    }
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.info("Using Infinispan configuration:\n\n{}\n\n", configuration);
    try {
        cacheManager = new DefaultCacheManager(new ByteArrayInputStream(configuration.getBytes(StandardCharsets.UTF_8)));
    } catch (IOException e) {
        throw new RuntimeException("Cannot read infinispan configuration.", e);
    }
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) StringSearchInterpolator(org.codehaus.plexus.interpolation.StringSearchInterpolator) MarshallableTypeHints(org.infinispan.commons.marshall.MarshallableTypeHints) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) Logger(org.slf4j.Logger) File(java.io.File) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.PropertiesBasedValueSource) PostConstruct(javax.annotation.PostConstruct)

Example 7 with PropertiesBasedValueSource

use of org.codehaus.plexus.interpolation.PropertiesBasedValueSource in project sling by apache.

the class BundleListUtils method createInterpolator.

public static Interpolator createInterpolator(MavenProject project, MavenSession mavenSession) {
    StringSearchInterpolator interpolator = new StringSearchInterpolator();
    final Properties props = new Properties();
    props.putAll(project.getProperties());
    props.putAll(mavenSession.getSystemProperties());
    props.putAll(mavenSession.getUserProperties());
    interpolator.addValueSource(new PropertiesBasedValueSource(props));
    // add ${project.foo}
    interpolator.addValueSource(new PrefixedObjectValueSource(Arrays.asList("project", "pom"), project, true));
    // add ${session.foo}
    interpolator.addValueSource(new PrefixedObjectValueSource("session", mavenSession));
    // add ${settings.foo}
    final Settings settings = mavenSession.getSettings();
    if (settings != null) {
        interpolator.addValueSource(new PrefixedObjectValueSource("settings", settings));
    }
    return interpolator;
}
Also used : StringSearchInterpolator(org.codehaus.plexus.interpolation.StringSearchInterpolator) Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.PropertiesBasedValueSource) Settings(org.apache.maven.settings.Settings) PrefixedObjectValueSource(org.codehaus.plexus.interpolation.PrefixedObjectValueSource)

Example 8 with PropertiesBasedValueSource

use of org.codehaus.plexus.interpolation.PropertiesBasedValueSource in project indy by Commonjava.

the class SecurityController method getInterpolator.

private StringSearchInterpolator getInterpolator() {
    final Properties props = new Properties();
    props.setProperty(KeycloakConfig.KEYCLOAK_REALM, config.getRealm());
    props.setProperty(KeycloakConfig.KEYCLOAK_URL, config.getUrl());
    if (config.getUiResource() != null) {
        props.setProperty(KeycloakConfig.KEYCLOAK_UI_RESOURCE, config.getUiResource());
    }
    if (config.getRealmPublicKey() != null) {
        props.setProperty(KeycloakConfig.KEYCLOAK_REALM_PUBLIC_KEY, config.getRealmPublicKey());
    }
    final StringSearchInterpolator interpolator = new StringSearchInterpolator();
    interpolator.addValueSource(new PropertiesBasedValueSource(props));
    return interpolator;
}
Also used : StringSearchInterpolator(org.codehaus.plexus.interpolation.StringSearchInterpolator) Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.PropertiesBasedValueSource)

Aggregations

PropertiesBasedValueSource (org.codehaus.plexus.interpolation.PropertiesBasedValueSource)8 StringSearchInterpolator (org.codehaus.plexus.interpolation.StringSearchInterpolator)6 IOException (java.io.IOException)4 Properties (java.util.Properties)4 InterpolationException (org.codehaus.plexus.interpolation.InterpolationException)4 File (java.io.File)2 PrefixedObjectValueSource (org.codehaus.plexus.interpolation.PrefixedObjectValueSource)2 RegexBasedInterpolator (org.codehaus.plexus.interpolation.RegexBasedInterpolator)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 PostConstruct (javax.annotation.PostConstruct)1 Profile (org.apache.maven.settings.Profile)1 Repository (org.apache.maven.settings.Repository)1 Settings (org.apache.maven.settings.Settings)1 EnvarBasedValueSource (org.codehaus.plexus.interpolation.EnvarBasedValueSource)1 Interpolator (org.codehaus.plexus.interpolation.Interpolator)1 ObjectBasedValueSource (org.codehaus.plexus.interpolation.ObjectBasedValueSource)1