Search in sources :

Example 6 with StringSearchInterpolator

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

the class CacheProducer method interpolateStrFromStream.

private String interpolateStrFromStream(InputStream inputStream, String path) {
    String configuration;
    try {
        configuration = IOUtils.toString(inputStream);
    } catch (IOException e) {
        throw new RuntimeException("Cannot read infinispan configuration from : " + path, 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 from: " + path, e);
    }
    return configuration;
}
Also used : StringSearchInterpolator(org.codehaus.plexus.interpolation.StringSearchInterpolator) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.PropertiesBasedValueSource)

Example 7 with StringSearchInterpolator

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

the class KojiContentManagerDecorator method getRepositoryName.

private String getRepositoryName(final KojiBuildInfo build, final boolean isBinaryBuild) {
    StringSearchInterpolator interpolator = new StringSearchInterpolator();
    interpolator.addValueSource(new ObjectBasedValueSource(build));
    try {
        return interpolator.interpolate(isBinaryBuild ? config.getBinayNamingFormat() : config.getNamingFormat());
    } catch (InterpolationException e) {
        throw new RuntimeException("Cannot resolve expressions in Koji configuration.", e);
    }
}
Also used : StringSearchInterpolator(org.codehaus.plexus.interpolation.StringSearchInterpolator) ObjectBasedValueSource(org.codehaus.plexus.interpolation.ObjectBasedValueSource) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException)

Example 8 with StringSearchInterpolator

use of org.codehaus.plexus.interpolation.StringSearchInterpolator 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 9 with StringSearchInterpolator

use of org.codehaus.plexus.interpolation.StringSearchInterpolator 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 10 with StringSearchInterpolator

use of org.codehaus.plexus.interpolation.StringSearchInterpolator 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

StringSearchInterpolator (org.codehaus.plexus.interpolation.StringSearchInterpolator)12 InterpolationException (org.codehaus.plexus.interpolation.InterpolationException)9 PropertiesBasedValueSource (org.codehaus.plexus.interpolation.PropertiesBasedValueSource)6 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)4 IOException (java.io.IOException)3 PlexusConfiguration (org.codehaus.plexus.configuration.PlexusConfiguration)3 MapBasedValueSource (org.codehaus.plexus.interpolation.MapBasedValueSource)3 ValueSource (org.codehaus.plexus.interpolation.ValueSource)3 File (java.io.File)2 ObjectBasedValueSource (org.codehaus.plexus.interpolation.ObjectBasedValueSource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 PostConstruct (javax.annotation.PostConstruct)1 Settings (org.apache.maven.settings.Settings)1 PrefixAwareRecursionInterceptor (org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor)1 PrefixedObjectValueSource (org.codehaus.plexus.interpolation.PrefixedObjectValueSource)1 RecursionInterceptor (org.codehaus.plexus.interpolation.RecursionInterceptor)1 SimpleRecursionInterceptor (org.codehaus.plexus.interpolation.SimpleRecursionInterceptor)1 MarshallableTypeHints (org.infinispan.commons.marshall.MarshallableTypeHints)1