use of org.apache.maven.plugin.descriptor.MojoDescriptor in project maven-plugins by apache.
the class CheckPluginDocumentationMojo method checkPackagingSpecificDocumentation.
protected void checkPackagingSpecificDocumentation(MavenProject project, DocumentationReporter reporter) {
PluginDescriptor descriptor = new PluginDescriptor();
try {
mojoScanner.populatePluginDescriptor(project, descriptor);
} catch (InvalidPluginDescriptorException e) {
reporter.error("Failed to parse mojo descriptors.\nError: " + e.getMessage());
descriptor = null;
} catch (ExtractionException e) {
reporter.error("Failed to parse mojo descriptors.\nError: " + e.getMessage());
descriptor = null;
}
if (descriptor != null) {
@SuppressWarnings("unchecked") List<MojoDescriptor> mojos = descriptor.getMojos();
// ensure that all mojo classes are documented
if (mojos != null && !mojos.isEmpty()) {
for (MojoDescriptor mojo : mojos) {
String mojoDescription = mojo.getDescription();
if (mojoDescription == null || mojoDescription.trim().length() < MIN_DESCRIPTION_LENGTH) {
reporter.error("Mojo: \'" + mojo.getGoal() + "\' is missing a description.");
}
@SuppressWarnings("unchecked") List<Parameter> params = mojo.getParameters();
// ensure that all parameters are documented
if (params != null && !params.isEmpty()) {
for (Parameter param : params) {
if (param.getRequirement() == null && param.isEditable()) {
String paramDescription = param.getDescription();
if (paramDescription == null || paramDescription.trim().length() < MIN_DESCRIPTION_LENGTH) {
reporter.error("Parameter: \'" + param.getName() + "\' in mojo: \'" + mojo.getGoal() + "\' is missing a description.");
}
}
}
}
}
}
}
checkConfiguredReportPlugins(project, reporter);
checkProjectSite(project, reporter);
}
use of org.apache.maven.plugin.descriptor.MojoDescriptor in project maven-plugins by apache.
the class PdfMojo method generateMavenReports.
/**
* Generate all Maven reports defined in <code>${project.reporting}</code> part
* only if <code>generateReports</code> is enabled.
*
* @param locale not null
* @throws MojoExecutionException if any
* @throws IOException if any
* @since 1.1
*/
private void generateMavenReports(Locale locale) throws MojoExecutionException, IOException {
if (!includeReports) {
getLog().info("Skipped report generation.");
return;
}
if (project.getReporting() == null) {
getLog().info("No report was specified.");
return;
}
for (final ReportPlugin reportPlugin : project.getReporting().getPlugins()) {
final PluginDescriptor pluginDescriptor = getPluginDescriptor(reportPlugin);
if (pluginDescriptor != null) {
List<String> goals = new ArrayList<String>(8);
for (final ReportSet reportSet : reportPlugin.getReportSets()) {
for (String goal : reportSet.getReports()) {
goals.add(goal);
}
}
List mojoDescriptors = pluginDescriptor.getMojos();
for (Object mojoDescriptor1 : mojoDescriptors) {
final MojoDescriptor mojoDescriptor = (MojoDescriptor) mojoDescriptor1;
if (goals.isEmpty() || (!goals.isEmpty() && goals.contains(mojoDescriptor.getGoal()))) {
MavenReport report = getMavenReport(mojoDescriptor);
generateMavenReport(report, mojoDescriptor.getPluginDescriptor().getPluginArtifact(), locale);
}
}
}
}
// generate project-info report
if (!getGeneratedMavenReports(locale).isEmpty()) {
File outDir = new File(getGeneratedSiteDirectoryTmp(), "xdoc");
if (!locale.getLanguage().equals(defaultLocale.getLanguage())) {
outDir = new File(new File(getGeneratedSiteDirectoryTmp(), locale.getLanguage()), "xdoc");
}
outDir.mkdirs();
File piReport = new File(outDir, "project-info.xml");
StringWriter sw = new StringWriter();
PdfSink sink = new PdfSink(sw);
ProjectInfoRenderer r = new ProjectInfoRenderer(sink, getGeneratedMavenReports(locale), i18n, locale);
r.render();
writeGeneratedReport(sw.toString(), piReport);
}
// copy generated site
copySiteDir(getGeneratedSiteDirectoryTmp(), getSiteDirectoryTmp());
copySiteDir(generatedSiteDirectory, getSiteDirectoryTmp());
}
use of org.apache.maven.plugin.descriptor.MojoDescriptor in project maven-plugins by apache.
the class EvaluateMojo method getEvaluator.
/**
* @return a lazy loading evaluator object.
* @throws MojoExecutionException if any
* @throws MojoFailureException if any reflection exceptions occur or missing components.
*/
private PluginParameterExpressionEvaluator getEvaluator() throws MojoExecutionException, MojoFailureException {
if (evaluator == null) {
MojoDescriptor mojoDescriptor;
try {
mojoDescriptor = mojoDescriptorCreator.getMojoDescriptor("help:evaluate", session, project);
} catch (Exception e) {
throw new MojoFailureException("Failure while evaluating.", e);
}
MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
MavenProject currentProject = session.getCurrentProject();
// synchronize in case another thread wants to fetch the real current project in between
synchronized (session) {
session.setCurrentProject(project);
evaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
session.setCurrentProject(currentProject);
}
}
return evaluator;
}
use of org.apache.maven.plugin.descriptor.MojoDescriptor in project maven-plugins by apache.
the class DescribeMojo method describePlugin.
/**
* Method for retrieving the plugin description
*
* @param pd contains the plugin description
* @param buffer contains the information to be displayed or printed
* @throws MojoFailureException if any reflection exceptions occur.
* @throws MojoExecutionException if any
*/
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)
ArtifactCoordinate coordinate = toArtifactCoordinate(pd, "jar");
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
pbr.setRemoteRepositories(remoteRepositories);
pbr.setProject(null);
pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
try {
Artifact artifact = artifactResolver.resolveArtifact(pbr, coordinate).getArtifact();
name = projectBuilder.build(artifact, 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", name, 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", pd.getGoalPrefix(), 0);
buffer.append(LS);
List<MojoDescriptor> mojos = pd.getMojos();
if (mojos == null) {
append(buffer, "This plugin has no goals.", 0);
return;
}
if ((detail || medium) && !minimal) {
append(buffer, "This plugin has " + mojos.size() + " goal" + (mojos.size() > 1 ? "s" : "") + ":", 0);
buffer.append(LS);
mojos = new ArrayList<MojoDescriptor>(mojos);
PluginUtils.sortMojos(mojos);
for (MojoDescriptor md : mojos) {
if (detail) {
describeMojoGuts(md, buffer, true);
} else {
describeMojoGuts(md, buffer, false);
}
buffer.append(LS);
}
}
if (!detail) {
buffer.append("For more information, run 'mvn help:describe [...] -Ddetail'");
buffer.append(LS);
}
}
use of org.apache.maven.plugin.descriptor.MojoDescriptor in project maven-plugins by apache.
the class DescribeMojo method execute.
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
/**
* {@inheritDoc}
*/
public void execute() throws MojoExecutionException, MojoFailureException {
validateParameters();
StringBuilder descriptionBuffer = new StringBuilder();
boolean describePlugin = true;
if (StringUtils.isNotEmpty(cmd)) {
describePlugin = describeCommand(descriptionBuffer);
}
if (describePlugin) {
PluginInfo pi = parsePluginLookupInfo();
PluginDescriptor descriptor = lookupPluginDescriptor(pi);
if (StringUtils.isNotEmpty(goal)) {
MojoDescriptor mojo = descriptor.getMojo(goal);
if (mojo == null) {
throw new MojoFailureException("The mojo '" + goal + "' does not exist in the plugin '" + pi.getPrefix() + "'");
}
describeMojo(mojo, descriptionBuffer);
} else {
describePlugin(descriptor, descriptionBuffer);
}
}
writeDescription(descriptionBuffer);
}
Aggregations