Search in sources :

Example 1 with Lifecycle

use of org.apache.maven.lifecycle.Lifecycle 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)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 StringTokenizer (java.util.StringTokenizer)1 Lifecycle (org.apache.maven.lifecycle.Lifecycle)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)1 NoPluginFoundForPrefixException (org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException)1 PluginVersionResolutionException (org.apache.maven.plugin.version.PluginVersionResolutionException)1