Search in sources :

Example 1 with StringSearchInterpolator

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

the class MavenPomView method resolveExpressions.

public String resolveExpressions(final String value, RecursionInterceptor ri, final String... activeProfileIds) {
    if (null == ri) {
        List<String> prefixs = new ArrayList<>();
        prefixs.add(PrefixAwareRecursionInterceptor.DEFAULT_START_TOKEN);
        ri = new PrefixAwareRecursionInterceptor(prefixs);
    }
    StringSearchInterpolator ssi = new StringSearchInterpolator();
    ssi.addValueSource(new MavenPomViewVS(this, ri, activeProfileIds));
    try {
        String result = ssi.interpolate(value, ri);
        if (result == null || result.trim().length() < 1) {
            result = value;
        }
        return result;
    } catch (final InterpolationException e) {
        logger.error(String.format("Failed to resolve expressions in: '%s'. Reason: %s", value, e.getMessage()), e);
        return value;
    }
}
Also used : StringSearchInterpolator(org.codehaus.plexus.interpolation.StringSearchInterpolator) ArrayList(java.util.ArrayList) PrefixAwareRecursionInterceptor(org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException)

Example 2 with StringSearchInterpolator

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

the class BootOptions method resolve.

public String resolve(final String value) throws InterpolationException {
    if (value == null || value.trim().length() < 1) {
        return null;
    }
    if (bootProps == null) {
        if (indyHome == null) {
            return value;
        } else {
            bootProps = new Properties();
        }
    }
    bootProps.setProperty("indy.home", indyHome);
    if (interp == null) {
        interp = new StringSearchInterpolator();
        interp.addValueSource(new PropertiesBasedValueSource(bootProps));
    }
    return interp.interpolate(value);
}
Also used : StringSearchInterpolator(org.codehaus.plexus.interpolation.StringSearchInterpolator) Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.PropertiesBasedValueSource)

Example 3 with StringSearchInterpolator

use of org.codehaus.plexus.interpolation.StringSearchInterpolator in project maven-plugins by apache.

the class GenerateApplicationXmlMojo method buildEnvEntries.

/**
 * Builds the env-entries based on the configuration.
 *
 * @return a list of EnvEntry object(s)
 * @throws EarPluginException if the configuration is invalid
 */
private List<EnvEntry> buildEnvEntries() throws EarPluginException {
    final List<EnvEntry> result = new ArrayList<EnvEntry>();
    if (envEntries == null) {
        return result;
    }
    try {
        StringSearchInterpolator ssi = new StringSearchInterpolator();
        ValueSource vs = new MapBasedValueSource(project.getProperties());
        ssi.addValueSource(vs);
        final PlexusConfiguration[] allEnvEntries = envEntries.getChildren(EnvEntry.ENV_ENTRY);
        getLog().debug("buildEnvEntries: allEnvEntries:" + allEnvEntries);
        getLog().debug("buildEnvEntries: allEnvEntries size:" + allEnvEntries.length);
        for (PlexusConfiguration envEntry : allEnvEntries) {
            // CHECKSTYLE_OFF: LineLength
            final String childDescription = interpolate(ssi, envEntry.getChild(EnvEntry.DESCRIPTION).getValue());
            final String childEnvEntryName = interpolate(ssi, envEntry.getChild(EnvEntry.ENV_ENTRY_NAME).getValue());
            final String childEnvEntryType = interpolate(ssi, envEntry.getChild(EnvEntry.ENV_ENTRY_TYPE).getValue());
            final String childEnvEntryValue = interpolate(ssi, envEntry.getChild(EnvEntry.ENV_ENTRY_VALUE).getValue());
            final String childEnvLookupNameValue = interpolate(ssi, envEntry.getChild(EnvEntry.ENV_LOOKUP_NAME).getValue());
            try {
                result.add(new EnvEntry(childDescription, childEnvEntryName, childEnvEntryType, childEnvEntryValue, childEnvLookupNameValue));
            } catch (IllegalArgumentException e) {
                throw new EarPluginException("Invalid env-entry [" + envEntry + "]", e);
            }
        }
        return result;
    } catch (InterpolationException e) {
        throw new EarPluginException("Interpolation exception:", e);
    }
}
Also used : PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) StringSearchInterpolator(org.codehaus.plexus.interpolation.StringSearchInterpolator) ValueSource(org.codehaus.plexus.interpolation.ValueSource) MapBasedValueSource(org.codehaus.plexus.interpolation.MapBasedValueSource) ArrayList(java.util.ArrayList) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) MapBasedValueSource(org.codehaus.plexus.interpolation.MapBasedValueSource)

Example 4 with StringSearchInterpolator

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

the class KojiUtils method getRepositoryName.

public String getRepositoryName(final KojiBuildInfo build) {
    StringSearchInterpolator interpolator = new StringSearchInterpolator();
    interpolator.addValueSource(new ObjectBasedValueSource(build));
    try {
        return interpolator.interpolate(isBinaryBuild(build) ? 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 5 with StringSearchInterpolator

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

the class AbstractKojiIT method initTestConfig.

@Override
protected void initTestConfig(CoreServerFixture fixture) throws IOException {
    super.initTestConfig(fixture);
    withNewClient((client) -> {
        try {
            File clientKeyCertPem = getClientKeyCertPem(client);
            File serverCertsPem = getServerCertsPem(client);
            Properties properties = System.getProperties();
            properties.setProperty("client.pem", clientKeyCertPem.getAbsolutePath());
            properties.setProperty("server.pem", serverCertsPem.getAbsolutePath());
            properties.setProperty("hub.url", formatSSLUrl("kojihub"));
            properties.setProperty("storage.url", formatSSLUrl("kojifiles"));
            properties.setProperty("extra.config", getKojiExtraConfig());
            StringSearchInterpolator ssi = new StringSearchInterpolator();
            ssi.addValueSource(new PropertiesBasedValueSource(properties));
            RecursionInterceptor ri = new SimpleRecursionInterceptor();
            String kojiConf = readTestResource("test-koji.conf");
            try {
                kojiConf = ssi.interpolate(kojiConf, ri);
            } catch (InterpolationException e) {
                e.printStackTrace();
                fail("Interpolation of test koji.conf failed!");
            }
            writeConfigFile("conf.d/koji.conf", kojiConf);
        } catch (IOException e) {
            e.printStackTrace();
            fail("Cannot setup SSL config files for Koji.");
        }
    });
}
Also used : StringSearchInterpolator(org.codehaus.plexus.interpolation.StringSearchInterpolator) SimpleRecursionInterceptor(org.codehaus.plexus.interpolation.SimpleRecursionInterceptor) RecursionInterceptor(org.codehaus.plexus.interpolation.RecursionInterceptor) SimpleRecursionInterceptor(org.codehaus.plexus.interpolation.SimpleRecursionInterceptor) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) 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