Search in sources :

Example 1 with ParserNotFoundException

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();
}
Also used : IndexingSink(org.apache.maven.doxia.index.IndexingSink) ParserNotFoundException(org.apache.maven.doxia.parser.manager.ParserNotFoundException) IndexEntry(org.apache.maven.doxia.index.IndexEntry) XmlStreamReader(org.apache.commons.io.input.XmlStreamReader) Reader(java.io.Reader) DecorationXpp3Reader(org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader) StringReader(java.io.StringReader) ParseException(org.apache.maven.doxia.parser.ParseException)

Example 2 with ParserNotFoundException

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;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ParserNotFoundException(org.apache.maven.doxia.parser.manager.ParserNotFoundException) MailingList(org.apache.maven.model.MailingList) XmlStreamReader(org.apache.commons.io.input.XmlStreamReader) Reader(java.io.Reader) DecorationXpp3Reader(org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader) StringReader(java.io.StringReader) ParseException(org.apache.maven.doxia.parser.ParseException) IOException(java.io.IOException) SinkAdapter(org.apache.maven.doxia.sink.impl.SinkAdapter)

Aggregations

Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 XmlStreamReader (org.apache.commons.io.input.XmlStreamReader)2 ParseException (org.apache.maven.doxia.parser.ParseException)2 ParserNotFoundException (org.apache.maven.doxia.parser.manager.ParserNotFoundException)2 DecorationXpp3Reader (org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader)2 IOException (java.io.IOException)1 IndexEntry (org.apache.maven.doxia.index.IndexEntry)1 IndexingSink (org.apache.maven.doxia.index.IndexingSink)1 SinkAdapter (org.apache.maven.doxia.sink.impl.SinkAdapter)1 MailingList (org.apache.maven.model.MailingList)1 MavenProject (org.apache.maven.project.MavenProject)1