Search in sources :

Example 1 with MarshallerException

use of com.cflint.xml.MarshallerException in project CFLint by cflint.

the class DefaultCFlintResultMarshaller method output.

@Override
public void output(BugList bugList, Writer writer, boolean showStats) throws MarshallerException {
    try {
        final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
        XMLStreamWriter xtw = new IndentingXMLStreamWriter(xmlOutputFactory.createXMLStreamWriter(writer));
        writeIssues(bugList, xtw, showStats);
        xtw.flush();
    } catch (XMLStreamException e) {
        throw new MarshallerException(e);
    }
}
Also used : IndentingXMLStreamWriter(javanet.staxutils.IndentingXMLStreamWriter) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) MarshallerException(com.cflint.xml.MarshallerException) XMLStreamException(javax.xml.stream.XMLStreamException) IndentingXMLStreamWriter(javanet.staxutils.IndentingXMLStreamWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 2 with MarshallerException

use of com.cflint.xml.MarshallerException in project CFLint by cflint.

the class FindBugsCFLintResultMarshaller method output.

@Override
public void output(BugList bugList, Writer writer, boolean showStats) throws MarshallerException {
    try {
        StringWriter sw = new StringWriter();
        DefaultCFlintResultMarshaller marshaller = new DefaultCFlintResultMarshaller();
        marshaller.output(bugList, sw, showStats);
        sw.flush();
        final Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(getClass().getResourceAsStream("/findbugs/cflint-to-findbugs.xsl")));
        transformer.transform(new StreamSource(new StringReader(sw.toString())), new StreamResult(writer));
    } catch (TransformerException e) {
        throw new MarshallerException(e);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) MarshallerException(com.cflint.xml.MarshallerException) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) TransformerException(javax.xml.transform.TransformerException)

Example 3 with MarshallerException

use of com.cflint.xml.MarshallerException in project CFLint by cflint.

the class CFLintMain method execute.

private void execute() throws IOException, TransformerException, JAXBException, MarshallerException {
    final CFLint cflint = new CFLint(buildConfigChain());
    cflint.setVerbose(verbose);
    cflint.setLogError(logerror);
    cflint.setQuiet(quiet);
    cflint.setShowProgress(showprogress);
    cflint.setProgressUsesThread(progressUsesThread);
    if (extensions != null && extensions.trim().length() > 0) {
        try {
            cflint.setAllowedExtensions(Arrays.asList(extensions.trim().split(",")));
        } catch (final Exception e) {
            System.err.println("Unable to use extensions (" + extensions + ") using default instead. " + e.getMessage());
        }
    }
    final CFLintFilter filter = createBaseFilter();
    cflint.getBugs().setFilter(filter);
    for (final String scanfolder : folder) {
        cflint.scan(scanfolder);
    }
    if (stdIn) {
        final StringBuilder source = new StringBuilder();
        final Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            final String nextLine = scanner.nextLine();
            source.append(nextLine);
            source.append(System.lineSeparator());
        }
        scanner.close();
        cflint.process(source.toString(), stdInFile);
    }
    if (xmlOutput) {
        final Writer xmlwriter = stdOut ? new OutputStreamWriter(System.out) : createWriter(xmlOutFile, StandardCharsets.UTF_8);
        if ("findbugs".equalsIgnoreCase(xmlstyle)) {
            if (verbose) {
                display("Writing XML findbugs style" + (stdOut ? "." : " to " + xmlOutFile));
            }
            new XMLOutput().outputFindBugs(cflint.getBugs(), xmlwriter, showStats);
        } else {
            if (verbose) {
                display("Writing XML" + (stdOut ? "." : " to " + xmlOutFile));
            }
            new DefaultCFlintResultMarshaller().output(cflint.getBugs(), xmlwriter, showStats);
        }
    }
    if (textOutput) {
        if (textOutFile != null && verbose) {
            display("Writing text" + (stdOut ? "." : " to " + textOutFile));
        }
        final Writer textwriter = stdOut || textOutFile == null ? new OutputStreamWriter(System.out) : new FileWriter(textOutFile);
        new TextOutput().output(cflint.getBugs(), textwriter, showStats);
    }
    if (htmlOutput) {
        try {
            if (verbose) {
                display("Writing HTML" + (stdOut ? "." : " to " + htmlOutFile));
            }
            final Writer htmlwriter = stdOut ? new OutputStreamWriter(System.out) : new FileWriter(htmlOutFile);
            new HTMLOutput(htmlStyle).output(cflint.getBugs(), htmlwriter, showStats);
        } catch (final TransformerException e) {
            throw new IOException(e);
        }
    }
    if (jsonOutput) {
        if (verbose) {
            display("Writing JSON" + (stdOut ? "." : " to " + jsonOutFile));
        }
        final Writer jsonwriter = stdOut ? new OutputStreamWriter(System.out) : new FileWriter(jsonOutFile);
        new JSONOutput().output(cflint.getBugs(), jsonwriter, showStats);
    }
}
Also used : TextOutput(com.cflint.TextOutput) Scanner(java.util.Scanner) FileWriter(java.io.FileWriter) XMLOutput(com.cflint.XMLOutput) HTMLOutput(com.cflint.HTMLOutput) JSONOutput(com.cflint.JSONOutput) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) MarshallerException(com.cflint.xml.MarshallerException) CFLint(com.cflint.CFLint) CFLintFilter(com.cflint.tools.CFLintFilter) DefaultCFlintResultMarshaller(com.cflint.xml.stax.DefaultCFlintResultMarshaller) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) TransformerException(javax.xml.transform.TransformerException)

Example 4 with MarshallerException

use of com.cflint.xml.MarshallerException in project CFLint by cflint.

the class CFLintCLI method execute.

private void execute(final CFLintConfiguration cfLintConfig) throws IOException, TransformerException, MarshallerException, JAXBException, CFLintScanException, CFLintConfigurationException {
    final CFLintAPI api = new CFLintAPI(cfLintConfig);
    api.setVerbose(verbose);
    api.setLogError(logerror);
    api.setQuiet(quiet);
    api.setDebug(debug);
    api.setStrictInclude(strictInclude);
    api.setEnvironmentName(environmentName);
    if (extensions != null && extensions.trim().length() > 0) {
        try {
            api.setExtensions(Arrays.asList(extensions.trim().split(",")));
        } catch (final Exception e) {
            if (!quiet) {
                System.err.println("Unable to use extensions (" + extensions + "), using default instead. " + e.getMessage());
            }
        }
    }
    api.setFilterFile(filterFile);
    CFLintResult lintResult = null;
    if (stdIn) {
        final StringWriter source = new StringWriter();
        IOUtils.copy(new InputStreamReader(System.in), source);
        lintResult = api.scan(source.toString(), stdInFile);
    } else {
        lintResult = api.scan(folder);
    }
    if (xmlOutput) {
        try (final Writer xmlwriter = stdOut ? new OutputStreamWriter(System.out) : createXMLWriter(xmlOutFile, StandardCharsets.UTF_8)) {
            if (FINDBUGS.equalsIgnoreCase(xmlstyle)) {
                if (verbose) {
                    display("Writing XML (style: findbugs)" + (stdOut ? "." : " to " + xmlOutFile));
                }
                lintResult.writeFindBugsXml(xmlwriter);
            } else {
                if (verbose) {
                    display("Writing XML" + (stdOut ? "." : " to " + xmlOutFile));
                }
                lintResult.writeXml(xmlwriter);
            }
        }
    }
    if (textOutput) {
        try (final Writer textwriter = stdOut ? new OutputStreamWriter(System.out) : new FileWriter(textOutFile)) {
            if (verbose) {
                display("Writing text" + (stdOut ? "." : " to " + textOutFile));
            }
            lintResult.writeText(textwriter);
        }
    }
    if (htmlOutput) {
        try (final Writer htmlwriter = stdOut ? new OutputStreamWriter(System.out) : new FileWriter(htmlOutFile)) {
            if (verbose) {
                display("Writing HTML (style: " + htmlStyle + ")" + (stdOut ? "." : " to " + htmlOutFile));
            }
            lintResult.writeHTML(htmlStyle, htmlwriter);
        }
    }
    if (jsonOutput) {
        try (final Writer jsonwriter = stdOut ? new OutputStreamWriter(System.out) : new FileWriter(jsonOutFile)) {
            if (verbose) {
                display("Writing JSON" + (stdOut ? "." : " to " + jsonOutFile));
            }
            lintResult.writeJSON(jsonwriter);
        }
    }
    if (verbose) {
        display("Total files scanned: " + lintResult.getStats().getFileCount());
        display("Total LOC scanned: " + lintResult.getStats().getTotalLines());
    }
}
Also used : CFLintAPI(com.cflint.api.CFLintAPI) StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) FileWriter(java.io.FileWriter) OutputStreamWriter(java.io.OutputStreamWriter) TransformerException(javax.xml.transform.TransformerException) CFLintConfigurationException(com.cflint.exception.CFLintConfigurationException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) CFLintScanException(com.cflint.exception.CFLintScanException) MarshallerException(com.cflint.xml.MarshallerException) CFLintResult(com.cflint.api.CFLintResult) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 5 with MarshallerException

use of com.cflint.xml.MarshallerException in project CFLint by cflint.

the class FindBugsCFLintResultMarshaller method output.

@Override
public void output(final BugList bugList, final Writer writer, final CFLintStats stats) throws MarshallerException {
    try {
        StringWriter sw = new StringWriter();
        DefaultCFlintResultMarshaller marshaller = new DefaultCFlintResultMarshaller();
        marshaller.output(bugList, sw, stats);
        sw.flush();
        final Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(getClass().getResourceAsStream("/findbugs/cflint-to-findbugs.xsl")));
        transformer.transform(new StreamSource(new StringReader(sw.toString())), new StreamResult(writer));
    } catch (TransformerException e) {
        throw new MarshallerException(e);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) MarshallerException(com.cflint.xml.MarshallerException) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) TransformerException(javax.xml.transform.TransformerException)

Aggregations

MarshallerException (com.cflint.xml.MarshallerException)6 TransformerException (javax.xml.transform.TransformerException)4 StringWriter (java.io.StringWriter)3 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 StringReader (java.io.StringReader)2 Writer (java.io.Writer)2 IndentingXMLStreamWriter (javanet.staxutils.IndentingXMLStreamWriter)2 JAXBException (javax.xml.bind.JAXBException)2 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 Transformer (javax.xml.transform.Transformer)2 StreamResult (javax.xml.transform.stream.StreamResult)2 StreamSource (javax.xml.transform.stream.StreamSource)2 CFLint (com.cflint.CFLint)1 HTMLOutput (com.cflint.HTMLOutput)1 JSONOutput (com.cflint.JSONOutput)1 TextOutput (com.cflint.TextOutput)1