use of org.apache.maven.doxia.parser.manager.ParserNotFoundException in project maven-plugins by apache.
the class PdfMojo method getGeneratedDocumentTitle.
/**
* Parse a generated Doxia file and returns its title.
*
* @param f not null
* @return the xdoc file title or null if an error occurs.
* @throws IOException if any
* @since 1.1
*/
private String getGeneratedDocumentTitle(final File f) throws IOException {
final IndexEntry entry = new IndexEntry("index");
final IndexingSink titleSink = new IndexingSink(entry);
Reader reader = null;
try {
reader = ReaderFactory.newXmlReader(f);
doxia.parse(reader, f.getParentFile().getName(), titleSink);
reader.close();
reader = null;
} catch (ParseException e) {
getLog().error("ParseException: " + e.getMessage());
getLog().debug(e);
return null;
} catch (ParserNotFoundException e) {
getLog().error("ParserNotFoundException: " + e.getMessage());
getLog().debug(e);
return null;
} finally {
IOUtil.close(reader);
}
return titleSink.getTitle();
}
use of org.apache.maven.doxia.parser.manager.ParserNotFoundException in project maven-plugins by apache.
the class PdfMojo method isValidGeneratedReport.
/**
* Parsing the generated report to see if it is correct or not. Log the error for the user.
*
* @param mojoDescriptor not null
* @param generatedReport not null
* @param localReportName not null
* @return <code>true</code> if Doxia is able to parse the generated report, <code>false</code> otherwise.
* @since 1.1
*/
private boolean isValidGeneratedReport(Artifact pluginArtifact, File generatedReport, String localReportName) {
SinkAdapter sinkAdapter = new SinkAdapter();
Reader reader = null;
try {
reader = ReaderFactory.newXmlReader(generatedReport);
doxia.parse(reader, generatedReport.getParentFile().getName(), sinkAdapter);
reader.close();
reader = null;
} catch (ParseException e) {
StringBuilder sb = new StringBuilder(1024);
sb.append(EOL).append(EOL);
sb.append("Error when parsing the generated report: ").append(generatedReport.getAbsolutePath());
sb.append(EOL);
sb.append(e.getMessage());
sb.append(EOL).append(EOL);
sb.append("You could:").append(EOL);
sb.append(" * exclude all reports using -DincludeReports=false").append(EOL);
sb.append(" * remove the ");
sb.append(pluginArtifact.getGroupId());
sb.append(":");
sb.append(pluginArtifact.getArtifactId());
sb.append(":");
sb.append(pluginArtifact.getVersion());
sb.append(" from the <reporting/> part. To not affect the site generation, ");
sb.append("you could create a PDF profile.").append(EOL);
sb.append(EOL);
MavenProject pluginProject = getReportPluginProject(pluginArtifact);
if (pluginProject == null) {
sb.append("You could also contact the Plugin team.").append(EOL);
} else {
sb.append("You could also contact the Plugin team:").append(EOL);
if (pluginProject.getMailingLists() != null && !pluginProject.getMailingLists().isEmpty()) {
boolean appended = false;
for (Object o : pluginProject.getMailingLists()) {
MailingList mailingList = (MailingList) o;
if (StringUtils.isNotEmpty(mailingList.getName()) && StringUtils.isNotEmpty(mailingList.getPost())) {
if (!appended) {
sb.append(" Mailing Lists:").append(EOL);
appended = true;
}
sb.append(" ").append(mailingList.getName());
sb.append(": ").append(mailingList.getPost());
sb.append(EOL);
}
}
}
if (StringUtils.isNotEmpty(pluginProject.getUrl())) {
sb.append(" Web Site:").append(EOL);
sb.append(" ").append(pluginProject.getUrl());
sb.append(EOL);
}
if (pluginProject.getIssueManagement() != null && StringUtils.isNotEmpty(pluginProject.getIssueManagement().getUrl())) {
sb.append(" Issue Tracking:").append(EOL);
sb.append(" ").append(pluginProject.getIssueManagement().getUrl());
sb.append(EOL);
}
}
sb.append(EOL).append("Ignoring the \"").append(localReportName).append("\" report in the PDF.").append(EOL);
getLog().error(sb.toString());
getLog().debug(e);
return false;
} catch (ParserNotFoundException e) {
getLog().error("ParserNotFoundException: " + e.getMessage());
getLog().debug(e);
return false;
} catch (IOException e) {
getLog().error("IOException: " + e.getMessage());
getLog().debug(e);
return false;
} finally {
IOUtil.close(reader);
}
return true;
}
Aggregations