in src/main/java/org/apache/maven/plugins/help/DescribeMojo.java [374:437]
private void describePlugin(PluginDescriptor pd, StringBuilder buffer)
throws MojoFailureException, MojoExecutionException {
append(buffer, pd.getId(), 0);
buffer.append(LS);
String name = pd.getName();
if (name == null) {
// Can be null because of MPLUGIN-137 (and descriptors generated with maven-plugin-tools-api <= 2.4.3)
Artifact aetherArtifact = new DefaultArtifact(pd.getGroupId(), pd.getArtifactId(), "jar", pd.getVersion());
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
pbr.setRemoteRepositories(project.getRemoteArtifactRepositories());
pbr.setPluginArtifactRepositories(project.getPluginArtifactRepositories());
pbr.setProject(null);
pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
try {
Artifact artifactCopy = resolveArtifact(aetherArtifact).getArtifact();
name = projectBuilder
.build(RepositoryUtils.toArtifact(artifactCopy), pbr)
.getProject()
.getName();
} catch (Exception e) {
// oh well, we tried our best.
getLog().warn("Unable to get the name of the plugin " + pd.getId() + ": " + e.getMessage());
name = pd.getId();
}
}
append(buffer, "Name", MessageUtils.buffer().strong(name).toString(), 0);
appendAsParagraph(buffer, "Description", toDescription(pd.getDescription()), 0);
append(buffer, "Group Id", pd.getGroupId(), 0);
append(buffer, "Artifact Id", pd.getArtifactId(), 0);
append(buffer, "Version", pd.getVersion(), 0);
append(
buffer,
"Goal Prefix",
MessageUtils.buffer().strong(pd.getGoalPrefix()).toString(),
0);
buffer.append(LS);
List<MojoDescriptor> mojos = pd.getMojos();
if (mojos == null) {
append(buffer, "This plugin has no goals.", 0);
return;
}
if (!minimal) {
append(buffer, "This plugin has " + mojos.size() + " goal" + (mojos.size() > 1 ? "s" : "") + ":", 0);
buffer.append(LS);
mojos = mojos.stream()
.sorted((m1, m2) -> m1.getGoal().compareToIgnoreCase(m2.getGoal()))
.collect(Collectors.toList());
for (MojoDescriptor md : mojos) {
describeMojoGuts(md, buffer, detail);
buffer.append(LS);
}
}
if (!detail) {
buffer.append("For more information, run 'mvn help:describe [...] -Ddetail'");
buffer.append(LS);
}
}