Search in sources :

Example 6 with MojoDescriptor

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

the class Maven method createMojoExecution.

public MojoExecution createMojoExecution(Plugin plugin, String goal, MavenProject project) throws Exception {
    if (plugin.getVersion() == null) {
        plugin.setVersion(plexusContainer.lookup(PluginVersionResolver.class).resolve(new DefaultPluginVersionRequest(plugin, session)).getVersion());
    }
    MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor(plugin, goal, project.getRemotePluginRepositories(), session.getRepositorySession());
    List<PluginExecution> executions = plugin.getExecutions();
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, executions.isEmpty() ? null : executions.get(executions.size() - 1).getId(), MojoExecution.Source.CLI);
    plexusContainer.lookup(LifecycleExecutionPlanCalculator.class).setupMojoExecution(session, project, mojoExecution);
    return mojoExecution;
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) PluginVersionResolver(org.apache.maven.plugin.version.PluginVersionResolver) MojoExecution(org.apache.maven.plugin.MojoExecution) DefaultPluginVersionRequest(org.apache.maven.plugin.version.DefaultPluginVersionRequest) LifecycleExecutionPlanCalculator(org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator)

Example 7 with MojoDescriptor

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

the class DescribeMojoTest method testValidExpression.

public void testValidExpression() throws Exception {
    StringBuilder sb = new StringBuilder();
    MojoDescriptor md = new MojoDescriptor();
    Parameter parameter = new Parameter();
    parameter.setName("name");
    parameter.setExpression("${valid.expression}");
    md.addParameter(parameter);
    String ls = System.getProperty("line.separator");
    try {
        PrivateAccessor.invoke(new DescribeMojo(), "describeMojoParameters", new Class[] { MojoDescriptor.class, StringBuilder.class }, new Object[] { md, sb });
        assertEquals("  Available parameters:" + ls + ls + "    name" + ls + "      User property: valid.expression" + ls + "      (no description available)" + ls, sb.toString());
    } catch (Throwable e) {
        fail(e.getMessage());
    }
}
Also used : MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) Parameter(org.apache.maven.plugin.descriptor.Parameter)

Example 8 with MojoDescriptor

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

the class DescribeMojo method describeCommand.

/**
     * Describe the <code>cmd</code> parameter
     *
     * @param descriptionBuffer not null
     * @return <code>true</code> if it implies to describe a plugin, <code>false</code> otherwise.
     * @throws MojoFailureException   if any reflection exceptions occur or missing components.
     * @throws MojoExecutionException if any
     */
private boolean describeCommand(StringBuilder descriptionBuffer) throws MojoFailureException, MojoExecutionException {
    if (cmd.indexOf(':') == -1) {
        // phase
        Lifecycle lifecycle = defaultLifecycles.getPhaseToLifecycleMap().get(cmd);
        if (lifecycle == null) {
            throw new MojoExecutionException("The given phase '" + cmd + "' is an unknown phase.");
        }
        Map<String, String> defaultLifecyclePhases = lifecycleMappings.get(project.getPackaging()).getLifecycles().get("default").getPhases();
        List<String> phases = lifecycle.getPhases();
        if (lifecycle.getDefaultPhases() == null) {
            descriptionBuffer.append("'").append(cmd);
            descriptionBuffer.append("' is a phase corresponding to this plugin:").append(LS);
            for (String key : phases) {
                if (!key.equals(cmd)) {
                    continue;
                }
                if (defaultLifecyclePhases.get(key) != null) {
                    descriptionBuffer.append(defaultLifecyclePhases.get(key));
                    descriptionBuffer.append(LS);
                }
            }
            descriptionBuffer.append(LS);
            descriptionBuffer.append("It is a part of the lifecycle for the POM packaging '");
            descriptionBuffer.append(project.getPackaging());
            descriptionBuffer.append("'. This lifecycle includes the following phases:");
            descriptionBuffer.append(LS);
            for (String key : phases) {
                descriptionBuffer.append("* ").append(key).append(": ");
                String value = defaultLifecyclePhases.get(key);
                if (StringUtils.isNotEmpty(value)) {
                    for (StringTokenizer tok = new StringTokenizer(value, ","); tok.hasMoreTokens(); ) {
                        descriptionBuffer.append(tok.nextToken().trim());
                        if (!tok.hasMoreTokens()) {
                            descriptionBuffer.append(LS);
                        } else {
                            descriptionBuffer.append(", ");
                        }
                    }
                } else {
                    descriptionBuffer.append(NOT_DEFINED).append(LS);
                }
            }
        } else {
            descriptionBuffer.append("'").append(cmd);
            descriptionBuffer.append("' is a lifecycle with the following phases: ");
            descriptionBuffer.append(LS);
            for (String key : phases) {
                descriptionBuffer.append("* ").append(key).append(": ");
                if (lifecycle.getDefaultPhases().get(key) != null) {
                    descriptionBuffer.append(lifecycle.getDefaultPhases().get(key)).append(LS);
                } else {
                    descriptionBuffer.append(NOT_DEFINED).append(LS);
                }
            }
        }
        return false;
    }
    // goals
    MojoDescriptor mojoDescriptor;
    try {
        mojoDescriptor = mojoDescriptorCreator.getMojoDescriptor(cmd, session, project);
    } catch (Exception e) {
        throw new MojoExecutionException("Unable to get descriptor for " + cmd, e);
    }
    descriptionBuffer.append("'").append(cmd).append("' is a plugin goal (aka mojo)").append(".");
    descriptionBuffer.append(LS);
    plugin = mojoDescriptor.getPluginDescriptor().getId();
    goal = mojoDescriptor.getGoal();
    return true;
}
Also used : StringTokenizer(java.util.StringTokenizer) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Lifecycle(org.apache.maven.lifecycle.Lifecycle) PluginVersionResolutionException(org.apache.maven.plugin.version.PluginVersionResolutionException) NoPluginFoundForPrefixException(org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 9 with MojoDescriptor

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

the class DescribeMojoTest method testInvalidExpression.

public void testInvalidExpression() throws Exception {
    StringBuilder sb = new StringBuilder();
    MojoDescriptor md = new MojoDescriptor();
    Parameter parameter = new Parameter();
    parameter.setName("name");
    //this is a defaultValue
    parameter.setExpression("${project.build.directory}/generated-sources/foobar");
    md.addParameter(parameter);
    String ls = System.getProperty("line.separator");
    try {
        PrivateAccessor.invoke(new DescribeMojo(), "describeMojoParameters", new Class[] { MojoDescriptor.class, StringBuilder.class }, new Object[] { md, sb });
        assertEquals("  Available parameters:" + ls + ls + "    name" + ls + "      Expression: ${project.build.directory}/generated-sources/foobar" + ls + "      (no description available)" + ls, sb.toString());
    } catch (Throwable e) {
        fail(e.getMessage());
    }
}
Also used : MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) Parameter(org.apache.maven.plugin.descriptor.Parameter)

Example 10 with MojoDescriptor

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

the class CompilerMojoTestCase method getMockMojoExecution.

private MojoExecution getMockMojoExecution() {
    MojoDescriptor md = new MojoDescriptor();
    md.setGoal("compile");
    MojoExecution me = new MojoExecution(md);
    PluginDescriptor pd = new PluginDescriptor();
    pd.setArtifactId("maven-compiler-plugin");
    md.setPluginDescriptor(pd);
    return me;
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) MojoExecution(org.apache.maven.plugin.MojoExecution)

Aggregations

MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)11 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)4 IOException (java.io.IOException)3 MojoExecution (org.apache.maven.plugin.MojoExecution)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 Parameter (org.apache.maven.plugin.descriptor.Parameter)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 NoPluginFoundForPrefixException (org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException)2 PluginVersionResolutionException (org.apache.maven.plugin.version.PluginVersionResolutionException)2 File (java.io.File)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1 Artifact (org.apache.maven.artifact.Artifact)1 Lifecycle (org.apache.maven.lifecycle.Lifecycle)1 LifecycleExecutionPlanCalculator (org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator)1 MailingList (org.apache.maven.model.MailingList)1 PluginExecution (org.apache.maven.model.PluginExecution)1