Search in sources :

Example 1 with PropertiesBasedValueSource

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

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

the class DoapUtil method interpolate.

/**
 * Interpolate a string with project and settings.
 *
 * @param value could be null
 * @param project not null
 * @param settings could be null
 * @return the value trimmed and interpolated or null if the interpolation doesn't work.
 * @since 1.1
 */
public static String interpolate(String value, final MavenProject project, Settings settings) {
    if (project == null) {
        throw new IllegalArgumentException("project is required");
    }
    if (value == null) {
        return value;
    }
    if (!value.contains("${")) {
        return value.trim();
    }
    RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
    try {
        interpolator.addValueSource(new EnvarBasedValueSource());
    } catch (IOException e) {
    // ignore
    }
    interpolator.addValueSource(new PropertiesBasedValueSource(System.getProperties()));
    interpolator.addValueSource(new PropertiesBasedValueSource(project.getProperties()));
    interpolator.addValueSource(new PrefixedObjectValueSource("project", project));
    interpolator.addValueSource(new PrefixedObjectValueSource("pom", project));
    interpolator.addValueSource(new ObjectBasedValueSource(project) {

        @Override
        public Object getValue(String expression) {
            try {
                return ReflectionValueExtractor.evaluate(expression, project, true);
            } catch (Exception e) {
                addFeedback("Failed to extract \'" + expression + "\' from: " + project, e);
            }
            return null;
        }
    });
    if (settings != null) {
        interpolator.addValueSource(new PrefixedObjectValueSource("settings", settings));
    }
    String interpolatedValue = value;
    try {
        interpolatedValue = interpolator.interpolate(value).trim();
    } catch (InterpolationException e) {
    // ignore
    }
    if (interpolatedValue.startsWith("${")) {
        return null;
    }
    return interpolatedValue;
}
Also used : RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) ObjectBasedValueSource(org.codehaus.plexus.interpolation.ObjectBasedValueSource) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) EnvarBasedValueSource(org.codehaus.plexus.interpolation.EnvarBasedValueSource) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.PropertiesBasedValueSource) FileNotFoundException(java.io.FileNotFoundException) SocketTimeoutException(java.net.SocketTimeoutException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) PrefixedObjectValueSource(org.codehaus.plexus.interpolation.PrefixedObjectValueSource)

Example 3 with PropertiesBasedValueSource

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

Example 4 with PropertiesBasedValueSource

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

use of org.codehaus.plexus.interpolation.PropertiesBasedValueSource in project spring-boot by spring-projects.

the class RepositoryConfigurationFactory method addActiveProfileRepositories.

private static void addActiveProfileRepositories(List<Profile> activeProfiles, List<RepositoryConfiguration> configurations) {
    for (Profile activeProfile : activeProfiles) {
        Interpolator interpolator = new RegexBasedInterpolator();
        interpolator.addValueSource(new PropertiesBasedValueSource(activeProfile.getProperties()));
        for (Repository repository : activeProfile.getRepositories()) {
            configurations.add(getRepositoryConfiguration(interpolator, repository));
        }
    }
}
Also used : Repository(org.apache.maven.settings.Repository) RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) Interpolator(org.codehaus.plexus.interpolation.Interpolator) RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.PropertiesBasedValueSource) Profile(org.apache.maven.settings.Profile)

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