Search in sources :

Example 1 with ExpressionEvaluator

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

the class EvaluateMojoTest method testEvaluateWithoutExpressionWithOutput.

/**
     * Tests evaluation of an expression in interactive mode with a mock input handler, when "output" is set.
     * @throws Exception in case of errors.
     */
public void testEvaluateWithoutExpressionWithOutput() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/evaluate/plugin-config-output.xml");
    EvaluateMojo mojo = (EvaluateMojo) lookupMojo("evaluate", testPom);
    InputHandler inputHandler = mock(InputHandler.class);
    when(inputHandler.readLine()).thenReturn("${project.artifactId}", "0");
    ExpressionEvaluator expressionEvaluator = mock(PluginParameterExpressionEvaluator.class);
    when(expressionEvaluator.evaluate(anyString())).thenReturn("My result");
    setUpMojo(mojo, inputHandler, expressionEvaluator);
    mojo.execute();
    String ls = System.getProperty("line.separator");
    assertTrue(interceptingLogger.infoLogs.contains(ls + "My result"));
    assertFalse(interceptingLogger.warnLogs.isEmpty());
    verify(expressionEvaluator).evaluate("${project.artifactId}");
    verify(inputHandler, times(2)).readLine();
}
Also used : InputHandler(org.codehaus.plexus.components.interactivity.InputHandler) Mockito.anyString(org.mockito.Mockito.anyString) File(java.io.File) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) ExpressionEvaluator(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)

Example 2 with ExpressionEvaluator

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

the class EvaluateMojoTest method testEvaluateWithoutExpression.

/**
     * Tests evaluation of an expression in interactive mode with a mock input handler.
     * @throws Exception in case of errors.
     */
public void testEvaluateWithoutExpression() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/evaluate/plugin-config.xml");
    EvaluateMojo mojo = (EvaluateMojo) lookupMojo("evaluate", testPom);
    InputHandler inputHandler = mock(InputHandler.class);
    when(inputHandler.readLine()).thenReturn("${project.groupId}", "0");
    ExpressionEvaluator expressionEvaluator = mock(PluginParameterExpressionEvaluator.class);
    when(expressionEvaluator.evaluate(anyString())).thenReturn("My result");
    setUpMojo(mojo, inputHandler, expressionEvaluator);
    mojo.execute();
    String ls = System.getProperty("line.separator");
    assertTrue(interceptingLogger.infoLogs.contains(ls + "My result"));
    assertTrue(interceptingLogger.warnLogs.isEmpty());
    verify(expressionEvaluator).evaluate("${project.groupId}");
    verify(inputHandler, times(2)).readLine();
}
Also used : InputHandler(org.codehaus.plexus.components.interactivity.InputHandler) Mockito.anyString(org.mockito.Mockito.anyString) File(java.io.File) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) ExpressionEvaluator(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)

Example 3 with ExpressionEvaluator

use of org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator 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 4 with ExpressionEvaluator

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

the class DefaultAssemblyArchiver method configureComponent.

private void configureComponent(final Object component, final Xpp3Dom config, final AssemblerConfigurationSource configSource) throws ComponentLookupException, ComponentConfigurationException {
    final ComponentConfigurator configurator = container.lookup(ComponentConfigurator.class, "basic");
    final ConfigurationListener listener = new DebugConfigurationListener(getLogger());
    final ExpressionEvaluator expressionEvaluator = new AssemblyExpressionEvaluator(configSource);
    final XmlPlexusConfiguration configuration = new XmlPlexusConfiguration(config);
    final Object[] containerRealm = getContainerRealm();
    /*
         * NOTE: The signature of configureComponent() has changed in Maven 3.x, the reflection prevents a linkage error
         * and makes the code work with both Maven 2 and 3.
         */
    try {
        final Method configureComponent = ComponentConfigurator.class.getMethod("configureComponent", Object.class, PlexusConfiguration.class, ExpressionEvaluator.class, (Class<?>) containerRealm[1], ConfigurationListener.class);
        configureComponent.invoke(configurator, component, configuration, expressionEvaluator, containerRealm[0], listener);
    } catch (final NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (final IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (final InvocationTargetException e) {
        if (e.getCause() instanceof ComponentConfigurationException) {
            throw (ComponentConfigurationException) e.getCause();
        }
        throw new RuntimeException(e.getCause());
    }
}
Also used : DebugConfigurationListener(org.apache.maven.plugin.DebugConfigurationListener) AssemblyExpressionEvaluator(org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator) ComponentConfigurator(org.codehaus.plexus.component.configurator.ComponentConfigurator) Method(java.lang.reflect.Method) AssemblyExpressionEvaluator(org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator) ExpressionEvaluator(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator) InvocationTargetException(java.lang.reflect.InvocationTargetException) DebugConfigurationListener(org.apache.maven.plugin.DebugConfigurationListener) ConfigurationListener(org.codehaus.plexus.component.configurator.ConfigurationListener) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) ComponentConfigurationException(org.codehaus.plexus.component.configurator.ComponentConfigurationException)

Aggregations

ExpressionEvaluator (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)4 PluginParameterExpressionEvaluator (org.apache.maven.plugin.PluginParameterExpressionEvaluator)3 File (java.io.File)2 InputHandler (org.codehaus.plexus.components.interactivity.InputHandler)2 XmlPlexusConfiguration (org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration)2 Mockito.anyString (org.mockito.Mockito.anyString)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 DebugConfigurationListener (org.apache.maven.plugin.DebugConfigurationListener)1 AssemblyExpressionEvaluator (org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator)1 ComponentConfigurationException (org.codehaus.plexus.component.configurator.ComponentConfigurationException)1 ComponentConfigurator (org.codehaus.plexus.component.configurator.ComponentConfigurator)1 ConfigurationListener (org.codehaus.plexus.component.configurator.ConfigurationListener)1 PlexusConfiguration (org.codehaus.plexus.configuration.PlexusConfiguration)1