Search in sources :

Example 1 with InterpolationException

use of org.codehaus.plexus.interpolation.InterpolationException in project intellij-community by JetBrains.

the class MyFileProfileActivator method isActive.

public boolean isActive(Profile profile) {
    Activation activation = profile.getActivation();
    ActivationFile actFile = activation.getFile();
    if (actFile != null) {
        // check if the file exists, if it does then the profile will be active
        String fileString = actFile.getExists();
        RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
        try {
            interpolator.addValueSource(new EnvarBasedValueSource());
        } catch (IOException e) {
        // ignored
        }
        interpolator.addValueSource(new MapBasedValueSource(System.getProperties()));
        try {
            if (StringUtils.isNotEmpty(fileString)) {
                fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
                return fileExists(fileString);
            }
            // check if the file is missing, if it is then the profile will be active
            fileString = actFile.getMissing();
            if (StringUtils.isNotEmpty(fileString)) {
                fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
                return !fileExists(fileString);
            }
        } catch (InterpolationException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to interpolate missing file location for profile activator: " + fileString, e);
            } else {
                logger.warn("Failed to interpolate missing file location for profile activator: " + fileString + ". Run in debug mode (-X) for more information.");
            }
        }
    }
    return false;
}
Also used : ActivationFile(org.apache.maven.model.ActivationFile) RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) Activation(org.apache.maven.model.Activation) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) EnvarBasedValueSource(org.codehaus.plexus.interpolation.EnvarBasedValueSource) MapBasedValueSource(org.codehaus.plexus.interpolation.MapBasedValueSource)

Example 2 with InterpolationException

use of org.codehaus.plexus.interpolation.InterpolationException in project intellij-community by JetBrains.

the class MyFileProfileActivator method isActive.

public boolean isActive(Profile profile) {
    Activation activation = profile.getActivation();
    ActivationFile actFile = activation.getFile();
    if (actFile != null) {
        // check if the file exists, if it does then the profile will be active
        String fileString = actFile.getExists();
        RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
        try {
            interpolator.addValueSource(new EnvarBasedValueSource());
        } catch (IOException e) {
        // ignored
        }
        interpolator.addValueSource(new MapBasedValueSource(System.getProperties()));
        try {
            if (StringUtils.isNotEmpty(fileString)) {
                fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
                return fileExists(fileString);
            }
            // check if the file is missing, if it is then the profile will be active
            fileString = actFile.getMissing();
            if (StringUtils.isNotEmpty(fileString)) {
                fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
                return !fileExists(fileString);
            }
        } catch (InterpolationException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to interpolate missing file location for profile activator: " + fileString, e);
            } else {
                logger.warn("Failed to interpolate missing file location for profile activator: " + fileString + ". Run in debug mode (-X) for more information.");
            }
        }
    }
    return false;
}
Also used : ActivationFile(org.apache.maven.model.ActivationFile) RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) Activation(org.apache.maven.model.Activation) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) EnvarBasedValueSource(org.codehaus.plexus.interpolation.EnvarBasedValueSource) MapBasedValueSource(org.codehaus.plexus.interpolation.MapBasedValueSource)

Example 3 with InterpolationException

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

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

the class BootOptions method loadFromSysprops.

public static BootOptions loadFromSysprops() throws IndyBootException {
    final String bootDef = System.getProperty(BootInterface.BOOT_DEFAULTS_PROP);
    File bootDefaults = null;
    if (bootDef != null) {
        bootDefaults = new File(bootDef);
    }
    try {
        final String indyHome = System.getProperty(BootInterface.INDY_HOME_PROP, new File(".").getCanonicalPath());
        return new BootOptions(bootDefaults, indyHome);
    } catch (final IOException e) {
        throw new IndyBootException("ERROR LOADING BOOT DEFAULTS: %s.\nReason: %s\n\n", e, bootDefaults, e.getMessage());
    } catch (final InterpolationException e) {
        throw new IndyBootException("ERROR RESOLVING BOOT DEFAULTS: %s.\nReason: %s\n\n", e, bootDefaults, e.getMessage());
    }
}
Also used : IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) File(java.io.File)

Example 5 with InterpolationException

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

the class AbstractInvokerMojo method getInvokerProperties.

/**
 * Gets the (interpolated) invoker properties for an integration test.
 *
 * @param projectDirectory The base directory of the IT project, must not be <code>null</code>.
 * @return The invoker properties, may be empty but never <code>null</code>.
 * @throws org.apache.maven.plugin.MojoExecutionException If an I/O error occurred during reading the properties.
 */
private InvokerProperties getInvokerProperties(final File projectDirectory) throws MojoExecutionException {
    Properties props = new Properties();
    if (invokerPropertiesFile != null) {
        File propertiesFile = new File(projectDirectory, invokerPropertiesFile);
        if (propertiesFile.isFile()) {
            InputStream in = null;
            try {
                in = new FileInputStream(propertiesFile);
                props.load(in);
                in.close();
                in = null;
            } catch (IOException e) {
                throw new MojoExecutionException("Failed to read invoker properties: " + propertiesFile, e);
            } finally {
                IOUtil.close(in);
            }
        }
        Interpolator interpolator = new RegexBasedInterpolator();
        interpolator.addValueSource(new MapBasedValueSource(getInterpolationValueSource(false)));
        // CHECKSTYLE_OFF: LineLength
        for (String key : props.stringPropertyNames()) {
            String value = props.getProperty(key);
            try {
                value = interpolator.interpolate(value, "");
            } catch (InterpolationException e) {
                throw new MojoExecutionException("Failed to interpolate invoker properties: " + propertiesFile, e);
            }
            props.setProperty(key, value);
        }
    // CHECKSTYLE_ON: LineLength
    }
    return new InvokerProperties(props);
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) Interpolator(org.codehaus.plexus.interpolation.Interpolator) RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) Properties(java.util.Properties) File(java.io.File) MapBasedValueSource(org.codehaus.plexus.interpolation.MapBasedValueSource) FileInputStream(java.io.FileInputStream)

Aggregations

InterpolationException (org.codehaus.plexus.interpolation.InterpolationException)19 IOException (java.io.IOException)11 StringSearchInterpolator (org.codehaus.plexus.interpolation.StringSearchInterpolator)10 MapBasedValueSource (org.codehaus.plexus.interpolation.MapBasedValueSource)7 File (java.io.File)6 RegexBasedInterpolator (org.codehaus.plexus.interpolation.RegexBasedInterpolator)5 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 EnvarBasedValueSource (org.codehaus.plexus.interpolation.EnvarBasedValueSource)4 ObjectBasedValueSource (org.codehaus.plexus.interpolation.ObjectBasedValueSource)4 PropertiesBasedValueSource (org.codehaus.plexus.interpolation.PropertiesBasedValueSource)4 PlexusConfiguration (org.codehaus.plexus.configuration.PlexusConfiguration)3 Interpolator (org.codehaus.plexus.interpolation.Interpolator)3 ValueSource (org.codehaus.plexus.interpolation.ValueSource)3 InputStream (java.io.InputStream)2 Artifact (org.apache.maven.artifact.Artifact)2 Activation (org.apache.maven.model.Activation)2 ActivationFile (org.apache.maven.model.ActivationFile)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1