use of org.apache.maven.plugin.MojoExecutionException in project maven-plugins by apache.
the class PdfMojo method generateMavenReport.
/**
* Generate the given Maven report only if it is not an external report and the report could be generated.
*
* @param mojoDescriptor not null, to catch linkage error
* @param report could be null
* @param locale not null
* @throws IOException if any
* @throws MojoExecutionException if any
* @see #isValidGeneratedReport(MojoDescriptor, File, String)
* @since 1.1
*/
private void generateMavenReport(MavenReport report, Artifact pluginArtifact, Locale locale) throws IOException, MojoExecutionException {
if (report == null) {
return;
}
String localReportName = report.getName(locale);
if (!report.canGenerateReport()) {
getLog().info("Skipped \"" + localReportName + "\" report.");
getLog().debug("canGenerateReport() was false.");
return;
}
if (report.isExternalReport()) {
getLog().info("Skipped external \"" + localReportName + "\" report.");
getLog().debug("isExternalReport() was false.");
return;
}
for (final MavenReport generatedReport : getGeneratedMavenReports(locale)) {
if (report.getName(locale).equals(generatedReport.getName(locale))) {
if (getLog().isDebugEnabled()) {
getLog().debug(report.getName(locale) + " was already generated.");
}
return;
}
}
File outDir = new File(getGeneratedSiteDirectoryTmp(), "xdoc");
if (!locale.getLanguage().equals(defaultLocale.getLanguage())) {
outDir = new File(new File(getGeneratedSiteDirectoryTmp(), locale.getLanguage()), "xdoc");
}
outDir.mkdirs();
File generatedReport = new File(outDir, report.getOutputName() + ".xml");
String excludes = getDefaultExcludesWithLocales(getAvailableLocales(), getDefaultLocale());
List<String> files = FileUtils.getFileNames(siteDirectory, "*/" + report.getOutputName() + ".*", excludes, false);
if (!locale.getLanguage().equals(defaultLocale.getLanguage())) {
files = FileUtils.getFileNames(new File(siteDirectory, locale.getLanguage()), "*/" + report.getOutputName() + ".*", excludes, false);
}
if (files.size() != 0) {
String displayLanguage = locale.getDisplayLanguage(Locale.ENGLISH);
if (getLog().isInfoEnabled()) {
getLog().info("Skipped \"" + report.getName(locale) + "\" report, file \"" + report.getOutputName() + "\" already exists for the " + displayLanguage + " version.");
}
return;
}
if (getLog().isInfoEnabled()) {
getLog().info("Generating \"" + localReportName + "\" report.");
}
StringWriter sw = new StringWriter();
PdfSink sink = null;
try {
sink = new PdfSink(sw);
org.codehaus.doxia.sink.Sink proxy = (org.codehaus.doxia.sink.Sink) Proxy.newProxyInstance(org.codehaus.doxia.sink.Sink.class.getClassLoader(), new Class[] { org.codehaus.doxia.sink.Sink.class }, new SinkDelegate(sink));
report.generate(proxy, locale);
} catch (MavenReportException e) {
throw new MojoExecutionException("MavenReportException: " + e.getMessage(), e);
} finally {
if (sink != null) {
sink.close();
}
}
writeGeneratedReport(sw.toString(), generatedReport);
if (isValidGeneratedReport(pluginArtifact, generatedReport, localReportName)) {
getGeneratedMavenReports(locale).add(report);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project maven-plugins by apache.
the class PdfMojo method getMavenReport.
/**
* @param mojoDescriptor not null
* @return the MavenReport instance for the given mojoDescriptor.
* @throws MojoExecutionException if any
* @since 1.1
*/
private MavenReport getMavenReport(MojoDescriptor mojoDescriptor) throws MojoExecutionException {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(mojoDescriptor.getPluginDescriptor().getClassRealm().getClassLoader());
MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
return pluginManager.getReport(project, mojoExecution, session);
} catch (ArtifactNotFoundException e) {
throw new MojoExecutionException("ArtifactNotFoundException: " + e.getMessage(), e);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("ArtifactResolutionException: " + e.getMessage(), e);
} catch (PluginConfigurationException e) {
throw new MojoExecutionException("PluginConfigurationException: " + e.getMessage(), e);
} catch (PluginManagerException e) {
throw new MojoExecutionException("PluginManagerException: " + e.getMessage(), e);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project maven-plugins by apache.
the class JavadocReportTest method testHeaderFooter.
/**
* Test newline in the header/footer parameter
*
* @throws Exception if any
*/
public void testHeaderFooter() throws Exception {
File testPom = new File(unit, "header-footer-test/header-footer-test-plugin-config.xml");
JavadocReport mojo = lookupMojo(testPom);
try {
mojo.execute();
} catch (MojoExecutionException e) {
assertTrue("Doesnt handle correctly newline for header or footer parameter", false);
}
assertTrue(true);
}
use of org.apache.maven.plugin.MojoExecutionException in project maven-plugins by apache.
the class JavadocReportTest method testValidateOptions.
/**
* Method to test error or conflict in Javadoc options and in standard doclet options.
*
* @throws Exception if any
*/
public void testValidateOptions() throws Exception {
// encoding
File testPom = new File(unit, "validate-options-test/wrong-encoding-test-plugin-config.xml");
JavadocReport mojo = lookupMojo(testPom);
try {
mojo.execute();
assertTrue("No wrong encoding catch", false);
} catch (MojoExecutionException e) {
assertTrue("No wrong encoding catch", e.getMessage().contains("Unsupported option <encoding/>"));
}
testPom = new File(unit, "validate-options-test/wrong-docencoding-test-plugin-config.xml");
mojo = lookupMojo(testPom);
try {
mojo.execute();
assertTrue("No wrong docencoding catch", false);
} catch (MojoExecutionException e) {
assertTrue("No wrong docencoding catch", e.getMessage().contains("Unsupported option <docencoding/>"));
}
testPom = new File(unit, "validate-options-test/wrong-charset-test-plugin-config.xml");
mojo = lookupMojo(testPom);
try {
mojo.execute();
assertTrue("No wrong charset catch", false);
} catch (MojoExecutionException e) {
assertTrue("No wrong charset catch", e.getMessage().contains("Unsupported option <charset/>"));
}
// locale
testPom = new File(unit, "validate-options-test/wrong-locale-test-plugin-config.xml");
mojo = lookupMojo(testPom);
try {
mojo.execute();
assertTrue("No wrong locale catch", false);
} catch (MojoExecutionException e) {
assertTrue("No wrong locale catch", e.getMessage().contains("Unsupported option <locale/>"));
}
testPom = new File(unit, "validate-options-test/wrong-locale-with-variant-test-plugin-config.xml");
mojo = lookupMojo(testPom);
mojo.execute();
assertTrue("No wrong locale catch", true);
// conflict options
testPom = new File(unit, "validate-options-test/conflict-options-test-plugin-config.xml");
mojo = lookupMojo(testPom);
try {
mojo.execute();
assertTrue("No conflict catch", false);
} catch (MojoExecutionException e) {
assertTrue("No conflict catch", e.getMessage().contains("Option <nohelp/> conflicts with <helpfile/>"));
}
}
use of org.apache.maven.plugin.MojoExecutionException in project maven-plugins by apache.
the class AbstractFixJavadocMojo method preCheck.
/**
* @return <code>true</code> if the user wants to proceed, <code>false</code> otherwise.
* @throws MojoExecutionException if any
*/
private boolean preCheck() throws MojoExecutionException {
if (force) {
return true;
}
if (outputDirectory != null && !outputDirectory.getAbsolutePath().equals(getProjectSourceDirectory().getAbsolutePath())) {
return true;
}
if (!settings.isInteractiveMode()) {
getLog().error("Maven is not attempt to interact with the user for input. " + "Verify the <interactiveMode/> configuration in your settings.");
return false;
}
getLog().warn("");
getLog().warn(" WARRANTY DISCLAIMER");
getLog().warn("");
getLog().warn("All warranties with regard to this Maven goal are disclaimed!");
getLog().warn("The changes will be done directly in the source code.");
getLog().warn("The Maven Team strongly recommends the use of a SCM software BEFORE executing this goal.");
getLog().warn("");
while (true) {
getLog().info("Are you sure to proceed? [Y]es [N]o");
try {
String userExpression = inputHandler.readLine();
if (userExpression == null || JavadocUtil.equalsIgnoreCase(userExpression, "Y", "Yes")) {
getLog().info("OK, let's proceed...");
break;
}
if (JavadocUtil.equalsIgnoreCase(userExpression, "N", "No")) {
getLog().info("No changes in your sources occur.");
return false;
}
} catch (IOException e) {
throw new MojoExecutionException("Unable to read from standard input.", e);
}
}
return true;
}
Aggregations