Search in sources :

Example 1 with ExpressionEvaluationException

use of org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException in project flyway by flyway.

the class IncludeProjectDependenciesComponentConfigurator method addProjectDependenciesToClassRealm.

@SuppressWarnings({ "unchecked" })
private void addProjectDependenciesToClassRealm(ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm) throws ComponentConfigurationException {
    List<String> classpathElements;
    try {
        classpathElements = (List<String>) expressionEvaluator.evaluate("${project.testClasspathElements}");
    } catch (ExpressionEvaluationException e) {
        throw new ComponentConfigurationException("There was a problem evaluating: ${project.testClasspathElements}", e);
    }
    // Add the project dependencies to the ClassRealm
    final URL[] urls = buildURLs(classpathElements);
    for (URL url : urls) {
        containerRealm.addConstituent(url);
    }
}
Also used : ExpressionEvaluationException(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException) URL(java.net.URL) ComponentConfigurationException(org.codehaus.plexus.component.configurator.ComponentConfigurationException)

Example 2 with ExpressionEvaluationException

use of org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException in project admin-console-beta by connexta.

the class ArtifactSizeEnforcerRule method getArtifactPath.

private String getArtifactPath(EnforcerRuleHelper helper) throws EnforcerRuleException {
    String convertedArtifactLocation = artifactLocation;
    if (StringUtils.isNotEmpty(convertedArtifactLocation)) {
        helper.getLog().info(String.format("Using specified artifactLocation %s", convertedArtifactLocation));
    } else {
        try {
            helper.getLog().info("artifactLocation property not specified. Looking up artifact using maven properties.");
            String artifactId = (String) helper.evaluate(PROJECT_ARTIFACT_ID_PROP);
            String version = (String) helper.evaluate(PROJECT_VERSION_PROP);
            String packaging = getPackaging(helper);
            String buildDir = (String) helper.evaluate(PROJECT_BUILD_DIR_PROP);
            helper.getLog().debug(String.format(DEFAULT_ARTIFACT_INFO_MSG, artifactId, version, packaging, buildDir));
            convertedArtifactLocation = buildDir + File.separator + artifactId + "-" + version + "." + packaging;
            helper.getLog().debug(String.format("Complete generated artifact path: %s", convertedArtifactLocation));
        } catch (ExpressionEvaluationException e) {
            throw new EnforcerRuleException(e.getMessage());
        }
    }
    return convertedArtifactLocation;
}
Also used : ExpressionEvaluationException(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException)

Example 3 with ExpressionEvaluationException

use of org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException in project swagger-core by swagger-api.

the class IncludeProjectDependenciesComponentConfigurator method addProjectDependenciesToClassRealm.

private void addProjectDependenciesToClassRealm(ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm) throws ComponentConfigurationException {
    List<String> compileClasspathElements;
    try {
        // noinspection unchecked
        compileClasspathElements = (List<String>) expressionEvaluator.evaluate("${project.compileClasspathElements}");
    } catch (ExpressionEvaluationException e) {
        throw new ComponentConfigurationException("There was a problem evaluating: ${project.compileClasspathElements}", e);
    }
    // Add the project dependencies to the ClassRealm
    final URL[] urls = buildURLs(compileClasspathElements);
    for (URL url : urls) {
        containerRealm.addURL(url);
    }
}
Also used : ExpressionEvaluationException(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException) URL(java.net.URL) ComponentConfigurationException(org.codehaus.plexus.component.configurator.ComponentConfigurationException)

Example 4 with ExpressionEvaluationException

use of org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException in project admin-console-beta by connexta.

the class ArtifactSizeEnforcerRule method getArtifactPath.

private String getArtifactPath(EnforcerRuleHelper helper) throws EnforcerRuleException {
    String convertedArtifactLocation = artifactLocation;
    if (StringUtils.isNotEmpty(convertedArtifactLocation)) {
        helper.getLog().info(String.format("Using specified artifactLocation %s", convertedArtifactLocation));
    } else {
        try {
            helper.getLog().info("artifactLocation property not specified. Looking up artifact using maven properties.");
            String artifactId = (String) helper.evaluate(PROJECT_ARTIFACT_ID_PROP);
            String version = (String) helper.evaluate(PROJECT_VERSION_PROP);
            String packaging = getPackaging(helper);
            String buildDir = (String) helper.evaluate(PROJECT_BUILD_DIR_PROP);
            helper.getLog().debug(String.format(DEFAULT_ARTIFACT_INFO_MSG, artifactId, version, packaging, buildDir));
            convertedArtifactLocation = buildDir + File.separator + artifactId + "-" + version + "." + packaging;
            helper.getLog().debug(String.format("Complete generated artifact path: %s", convertedArtifactLocation));
        } catch (ExpressionEvaluationException e) {
            throw new EnforcerRuleException(e.getMessage());
        }
    }
    return convertedArtifactLocation;
}
Also used : ExpressionEvaluationException(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException)

Example 5 with ExpressionEvaluationException

use of org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException in project maven-plugins by apache.

the class EvaluateMojo method handleResponse.

/**
 * @param expr the user expression asked.
 * @param output the file where to write the result, or <code>null</code> to print in standard output.
 * @throws MojoExecutionException if any
 * @throws MojoFailureException if any reflection exceptions occur or missing components.
 */
private void handleResponse(String expr, File output) throws MojoExecutionException, MojoFailureException {
    StringBuilder response = new StringBuilder();
    Object obj;
    try {
        obj = getEvaluator().evaluate(expr);
    } catch (ExpressionEvaluationException e) {
        throw new MojoExecutionException("Error when evaluating the Maven expression", e);
    }
    if (obj != null && expr.equals(obj.toString())) {
        getLog().warn("The Maven expression was invalid. Please use a valid expression.");
        return;
    }
    // handle null
    if (obj == null) {
        response.append("null object or invalid expression");
    } else // handle primitives objects
    if (obj instanceof String) {
        response.append(obj.toString());
    } else if (obj instanceof Boolean) {
        response.append(obj.toString());
    } else if (obj instanceof Byte) {
        response.append(obj.toString());
    } else if (obj instanceof Character) {
        response.append(obj.toString());
    } else if (obj instanceof Double) {
        response.append(obj.toString());
    } else if (obj instanceof Float) {
        response.append(obj.toString());
    } else if (obj instanceof Integer) {
        response.append(obj.toString());
    } else if (obj instanceof Long) {
        response.append(obj.toString());
    } else if (obj instanceof Short) {
        response.append(obj.toString());
    } else // handle specific objects
    if (obj instanceof File) {
        File f = (File) obj;
        response.append(f.getAbsolutePath());
    } else // handle Maven pom object
    if (obj instanceof MavenProject) {
        MavenProject projectAsked = (MavenProject) obj;
        StringWriter sWriter = new StringWriter();
        MavenXpp3Writer pomWriter = new MavenXpp3Writer();
        try {
            pomWriter.write(sWriter, projectAsked.getModel());
        } catch (IOException e) {
            throw new MojoExecutionException("Error when writing pom", e);
        }
        response.append(sWriter.toString());
    } else // handle Maven Settings object
    if (obj instanceof Settings) {
        Settings settingsAsked = (Settings) obj;
        StringWriter sWriter = new StringWriter();
        SettingsXpp3Writer settingsWriter = new SettingsXpp3Writer();
        try {
            settingsWriter.write(sWriter, settingsAsked);
        } catch (IOException e) {
            throw new MojoExecutionException("Error when writing settings", e);
        }
        response.append(sWriter.toString());
    } else {
        // others Maven objects
        response.append(toXML(expr, obj));
    }
    if (output != null) {
        try {
            writeFile(output, response);
        } catch (IOException e) {
            throw new MojoExecutionException("Cannot write evaluation of expression to output: " + output, e);
        }
        getLog().info("Result of evaluation written to: " + output);
    } else {
        getLog().info(LS + response.toString());
    }
}
Also used : ExpressionEvaluationException(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) MavenProject(org.apache.maven.project.MavenProject) StringWriter(java.io.StringWriter) File(java.io.File) Settings(org.apache.maven.settings.Settings) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer) SettingsXpp3Writer(org.apache.maven.settings.io.xpp3.SettingsXpp3Writer)

Aggregations

ExpressionEvaluationException (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException)5 URL (java.net.URL)2 EnforcerRuleException (org.apache.maven.enforcer.rule.api.EnforcerRuleException)2 ComponentConfigurationException (org.codehaus.plexus.component.configurator.ComponentConfigurationException)2 File (java.io.File)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 MavenXpp3Writer (org.apache.maven.model.io.xpp3.MavenXpp3Writer)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MavenProject (org.apache.maven.project.MavenProject)1 Settings (org.apache.maven.settings.Settings)1 SettingsXpp3Writer (org.apache.maven.settings.io.xpp3.SettingsXpp3Writer)1