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;
}
Aggregations