use of org.apache.maven.plugin.MojoFailureException 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.MojoFailureException 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.MojoFailureException in project maven-plugins by apache.
the class DescribeMojo method toLines.
/**
* Invoke the following private method
* <code>HelpMojo#toLines(String, int, int, int)</code>
*
* @param text The text to split into lines, must not be <code>null</code>.
* @param indent The base indentation level of each line, must not be negative.
* @param indentSize The size of each indentation, must not be negative.
* @param lineLength The length of the line, must not be negative.
* @return The sequence of display lines, never <code>null</code>.
* @throws MojoFailureException if any can not invoke the method
* @throws MojoExecutionException if no line was found for <code>text</code>
* @see HelpMojo#toLines(String, int, int, int)
*/
private static List<String> toLines(String text, int indent, int indentSize, int lineLength) throws MojoFailureException, MojoExecutionException {
try {
Method m = HelpMojo.class.getDeclaredMethod("toLines", new Class[] { String.class, Integer.TYPE, Integer.TYPE, Integer.TYPE });
m.setAccessible(true);
@SuppressWarnings("unchecked") List<String> output = (List<String>) m.invoke(HelpMojo.class, text, indent, indentSize, lineLength);
if (output == null) {
throw new MojoExecutionException("No output was specified.");
}
return output;
} catch (SecurityException e) {
throw new MojoFailureException("SecurityException: " + e.getMessage());
} catch (IllegalArgumentException e) {
throw new MojoFailureException("IllegalArgumentException: " + e.getMessage());
} catch (NoSuchMethodException e) {
throw new MojoFailureException("NoSuchMethodException: " + e.getMessage());
} catch (IllegalAccessException e) {
throw new MojoFailureException("IllegalAccessException: " + e.getMessage());
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof NegativeArraySizeException) {
throw new MojoFailureException("NegativeArraySizeException: " + cause.getMessage());
}
throw new MojoFailureException("InvocationTargetException: " + e.getMessage());
}
}
use of org.apache.maven.plugin.MojoFailureException 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);
}
use of org.apache.maven.plugin.MojoFailureException in project maven-plugins by apache.
the class AbstractSiteRenderingMojo method createSiteRenderingContext.
protected SiteRenderingContext createSiteRenderingContext(Locale locale) throws MojoExecutionException, IOException, MojoFailureException {
DecorationModel decorationModel = prepareDecorationModel(locale);
if (attributes == null) {
attributes = new HashMap<String, Object>();
}
if (attributes.get("project") == null) {
attributes.put("project", project);
}
if (attributes.get("inputEncoding") == null) {
attributes.put("inputEncoding", getInputEncoding());
}
if (attributes.get("outputEncoding") == null) {
attributes.put("outputEncoding", getOutputEncoding());
}
// Put any of the properties in directly into the Velocity context
for (Map.Entry<Object, Object> entry : project.getProperties().entrySet()) {
attributes.put((String) entry.getKey(), entry.getValue());
}
SiteRenderingContext context;
if (templateFile != null) {
getLog().info("Rendering site with " + templateFile + " template file.");
if (!templateFile.exists()) {
throw new MojoFailureException("Template file '" + templateFile + "' does not exist");
}
context = siteRenderer.createContextForTemplate(templateFile, attributes, decorationModel, project.getName(), locale);
} else {
try {
Artifact skinArtifact = siteTool.getSkinArtifactFromRepository(localRepository, repositories, decorationModel);
getLog().info("Rendering site with " + skinArtifact.getId() + " skin.");
context = siteRenderer.createContextForSkin(skinArtifact, attributes, decorationModel, project.getName(), locale);
} catch (SiteToolException e) {
throw new MojoExecutionException("SiteToolException while preparing skin: " + e.getMessage(), e);
} catch (RendererException e) {
throw new MojoExecutionException("RendererException while preparing context for skin: " + e.getMessage(), e);
}
}
// Generate static site
if (!locale.getLanguage().equals(Locale.getDefault().getLanguage())) {
context.addSiteDirectory(new File(siteDirectory, locale.getLanguage()));
context.addModuleDirectory(new File(xdocDirectory, locale.getLanguage()), "xdoc");
context.addModuleDirectory(new File(xdocDirectory, locale.getLanguage()), "fml");
} else {
context.addSiteDirectory(siteDirectory);
context.addModuleDirectory(xdocDirectory, "xdoc");
context.addModuleDirectory(xdocDirectory, "fml");
}
if (moduleExcludes != null) {
context.setModuleExcludes(moduleExcludes);
}
if (saveProcessedContent) {
context.setProcessedContentOutput(new File(generatedSiteDirectory, "processed"));
}
return context;
}
Aggregations