Search in sources :

Example 1 with PluginParameterExpressionEvaluator

use of org.apache.maven.plugin.PluginParameterExpressionEvaluator in project intellij-plugins by JetBrains.

the class AdditionalSourceRootUtil method addByBuildHelper.

public static void addByBuildHelper(MojoExecution mojoExecution, MavenSession session, MavenProject project, Logger logger) {
    final PlexusConfiguration parentConfiguration = new XmlPlexusConfiguration(mojoExecution.getConfiguration());
    final PlexusConfiguration configuration = parentConfiguration.getChild("sources");
    if (configuration == null) {
        return;
    }
    final PlexusConfiguration[] sources = configuration.getChildren();
    if (sources == null) {
        return;
    }
    final ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
    for (PlexusConfiguration source : sources) {
        addFile(evaluate(expressionEvaluator, source.getValue(), logger), project, expressionEvaluator);
    }
}
Also used : PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) ExpressionEvaluator(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)

Example 2 with PluginParameterExpressionEvaluator

use of org.apache.maven.plugin.PluginParameterExpressionEvaluator in project intellij-plugins by JetBrains.

the class AdditionalSourceRootUtil method addByGeneratorMojo.

public static void addByGeneratorMojo(MojoExecution mojoExecution, MavenSession session, MavenProject project, Logger logger) {
    final PluginParameterExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
    final PlexusConfiguration configuration = new XmlPlexusConfiguration(mojoExecution.getConfiguration());
    for (String parameterName : new String[] { "baseOutputDirectory", "outputDirectory" }) {
        collectGeneratedSource(configuration, parameterName, project, expressionEvaluator, logger);
    }
}
Also used : PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration)

Example 3 with PluginParameterExpressionEvaluator

use of org.apache.maven.plugin.PluginParameterExpressionEvaluator in project m2e-nar by maven-nar.

the class MavenUtils method getConfiguredMojo.

private static <T extends AbstractMojo> T getConfiguredMojo(MavenSession session, MojoExecution mojoExecution, Class<T> asType, Log log) throws CoreException {
    MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
    PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
    ClassRealm pluginRealm = getMyRealm(pluginDescriptor.getClassRealm().getWorld());
    T mojo;
    try {
        mojo = asType.newInstance();
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Problem when creating mojo", e));
    }
    mojo.setLog(log);
    logger.debug("Configuring mojo " + mojoDescriptor.getId() + " from plugin realm " + pluginRealm);
    Xpp3Dom dom = mojoExecution.getConfiguration();
    PlexusConfiguration pomConfiguration;
    if (dom == null) {
        pomConfiguration = new XmlPlexusConfiguration("configuration");
    } else {
        pomConfiguration = new XmlPlexusConfiguration(dom);
    }
    ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
    populatePluginFields(mojo, mojoDescriptor, pluginRealm, pomConfiguration, expressionEvaluator);
    return mojo;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) CoreException(org.eclipse.core.runtime.CoreException) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) ExpressionEvaluator(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator) DuplicateRealmException(org.codehaus.plexus.classworlds.realm.DuplicateRealmException) CoreException(org.eclipse.core.runtime.CoreException) ComponentConfigurationException(org.codehaus.plexus.component.configurator.ComponentConfigurationException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 4 with PluginParameterExpressionEvaluator

use of org.apache.maven.plugin.PluginParameterExpressionEvaluator in project tycho by eclipse.

the class AbstractTychoMojoTestCase method lookupMojoWithDefaultConfiguration.

/**
 * Returns a mojo configured with the mojo's default configuration.
 */
// workaround for MPLUGINTESTING-46 - see http://jira.codehaus.org/browse/MPLUGINTESTING-46
protected Mojo lookupMojoWithDefaultConfiguration(MavenProject project, MavenSession session, String goal) throws Exception {
    MojoExecution mojoExecution = newMojoExecution(goal);
    Xpp3Dom defaultConfiguration = mojoExecution.getConfiguration();
    // the ResolverExpressionEvaluatorStub of lookupMojo is not sufficient to evaluate the variables in the default configuration
    ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
    ComponentConfigurator configurator = getContainer().lookup(ComponentConfigurator.class, "basic");
    Mojo mojo = lookupEmptyMojo(goal, project.getFile());
    configurator.configureComponent(mojo, new XmlPlexusConfiguration(defaultConfiguration), expressionEvaluator, getContainer().getContainerRealm(), null);
    return mojo;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) Mojo(org.apache.maven.plugin.Mojo) MojoExecution(org.apache.maven.plugin.MojoExecution) ComponentConfigurator(org.codehaus.plexus.component.configurator.ComponentConfigurator) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) ExpressionEvaluator(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)

Example 5 with PluginParameterExpressionEvaluator

use of org.apache.maven.plugin.PluginParameterExpressionEvaluator in project maven-plugins by apache.

the class EvaluateMojo method getEvaluator.

/**
 * @return a lazy loading evaluator object.
 * @throws MojoExecutionException if any
 * @throws MojoFailureException if any reflection exceptions occur or missing components.
 */
private PluginParameterExpressionEvaluator getEvaluator() throws MojoExecutionException, MojoFailureException {
    if (evaluator == null) {
        MojoDescriptor mojoDescriptor;
        try {
            mojoDescriptor = mojoDescriptorCreator.getMojoDescriptor("help:evaluate", session, project);
        } catch (Exception e) {
            throw new MojoFailureException("Failure while evaluating.", e);
        }
        MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
        MavenProject currentProject = session.getCurrentProject();
        // synchronize in case another thread wants to fetch the real current project in between
        synchronized (session) {
            session.setCurrentProject(project);
            evaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
            session.setCurrentProject(currentProject);
        }
    }
    return evaluator;
}
Also used : MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ExpressionEvaluationException(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

PluginParameterExpressionEvaluator (org.apache.maven.plugin.PluginParameterExpressionEvaluator)5 XmlPlexusConfiguration (org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration)4 ExpressionEvaluator (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)3 PlexusConfiguration (org.codehaus.plexus.configuration.PlexusConfiguration)3 MojoExecution (org.apache.maven.plugin.MojoExecution)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)2 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)2 IOException (java.io.IOException)1 Mojo (org.apache.maven.plugin.Mojo)1 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)1 MavenProject (org.apache.maven.project.MavenProject)1 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)1 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)1 ClassRealm (org.codehaus.plexus.classworlds.realm.ClassRealm)1 DuplicateRealmException (org.codehaus.plexus.classworlds.realm.DuplicateRealmException)1 ComponentConfigurationException (org.codehaus.plexus.component.configurator.ComponentConfigurationException)1 ComponentConfigurator (org.codehaus.plexus.component.configurator.ComponentConfigurator)1 ExpressionEvaluationException (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException)1