Search in sources :

Example 11 with IOException2

use of hudson.util.IOException2 in project violations-plugin by jenkinsci.

the class AbstractTypeParser method parse.

/**
     * Parse a violations file.
     * @param model the model to store the violations in.
     * @param projectPath the project path used for resolving paths.
     * @param fileName the name of the violations file to parse
     *                       (relative to the projectPath).
     * @param sourcePaths a list of source paths to resolve classes against
     * @throws IOException if there is an error.
     */
public void parse(FullBuildModel model, File projectPath, String fileName, String[] sourcePaths) throws IOException {
    Reader in = null;
    boolean success = false;
    try {
        in = new XmlReader(new File(projectPath, fileName));
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser parser = factory.newPullParser();
        parser.setInput(in);
        setProjectPath(projectPath);
        setModel(model);
        setParser(parser);
        setSourcePaths(sourcePaths);
        execute();
        success = true;
    } catch (IOException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new IOException2("Cannot parse " + fileName, ex);
    } finally {
        CloseUtil.close(in, !success);
    }
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParser(org.xmlpull.v1.XmlPullParser) Reader(java.io.Reader) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) IOException2(hudson.util.IOException2)

Example 12 with IOException2

use of hudson.util.IOException2 in project violations-plugin by jenkinsci.

the class ParseTypeXML method parse.

/**
     * Parse a xml violation file.
     * @param model the model to store the violations in.
     * @param projectPath the project path used for resolving paths.
     * @param xmlFile the xml file to parse.
     * @param typeParser the parser to use.
     * @param sourcePaths a list of source paths to resolve classes against
     * @throws IOException if there is an error.
     */
public void parse(FullBuildModel model, File projectPath, String xmlFile, String[] sourcePaths, AbstractTypeParser typeParser) throws IOException {
    LOG.info("Parsing " + xmlFile);
    InputStream in = null;
    boolean success = false;
    try {
        in = projectPath == null ? new FileInputStream(new File(xmlFile)) : new FileInputStream(new File(projectPath, xmlFile));
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser parser = factory.newPullParser();
        parser.setInput(in, null);
        typeParser.setProjectPath(projectPath);
        typeParser.setModel(model);
        typeParser.setParser(parser);
        typeParser.setSourcePaths(sourcePaths);
        typeParser.execute();
        success = true;
    } catch (IOException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new IOException2(ex);
    } finally {
        CloseUtil.close(in, !success);
    }
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) IOException2(hudson.util.IOException2)

Example 13 with IOException2

use of hudson.util.IOException2 in project violations-plugin by jenkinsci.

the class ParseXML method parse.

/**
     * Parse an Input stream using a parser object.
     * @param in the stream to parse.
     * @param xmlParser the parser object.
     * @throws IOException if there is a problem.
     */
public static void parse(InputStream in, AbstractParser xmlParser) throws IOException {
    try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser parser = factory.newPullParser();
        parser.setInput(new XmlReader(in));
        xmlParser.setParser(parser);
        xmlParser.execute();
    } catch (IOException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new IOException2(ex);
    }
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) IOException(java.io.IOException) IOException2(hudson.util.IOException2)

Example 14 with IOException2

use of hudson.util.IOException2 in project violations-plugin by jenkinsci.

the class ViolationsDOMParser method parse.

/*
     * Parse a violations file.
     * @param model the model to store the violations in.
     * @param projectPath the project path used for resolving paths.
     * @param fileName the name of the violations file to parse
     *                       (relative to the projectPath).
     * @param sourcePaths a list of source paths to resolve classes against
     * @throws IOException if there is an error.
     */
public void parse(FullBuildModel model, File projectPath, String fileName, String[] sourcePaths) throws IOException {
    boolean success = false;
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        dom = db.parse(new File(projectPath, fileName));
        setProjectPath(projectPath);
        setModel(model);
        setSourcePaths(sourcePaths);
        execute();
        success = true;
    } catch (IOException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new IOException2("Cannot parse " + fileName, ex);
    } finally {
    // ? terminate the parser
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) IOException2(hudson.util.IOException2)

Example 15 with IOException2

use of hudson.util.IOException2 in project violations-plugin by jenkinsci.

the class ReSharperParser method parse.

public void parse(final FullBuildModel model, final File projectPath, final String fileName, final String[] sourcePaths) throws IOException {
    absoluteFileFinder.addSourcePath(projectPath.getAbsolutePath());
    absoluteFileFinder.addSourcePaths(sourcePaths);
    final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder;
    try {
        docBuilder = docBuilderFactory.newDocumentBuilder();
        final Document docElement = docBuilder.parse(new FileInputStream(new File(projectPath, fileName)));
        NodeList nl = docElement.getElementsByTagName("IssueType");
        if (nl == null)
            return;
        for (int i = 0; i < nl.getLength(); i++) {
            final Element issueTypeElement = (Element) nl.item(i);
            final IssueType issueType = parseIssueType(issueTypeElement);
            issueTypes.put(issueType.getId(), issueType);
        }
        nl = docElement.getElementsByTagName("Issue");
        if (nl == null)
            return;
        for (int i = 0; i < nl.getLength(); i++) {
            final Element issueElement = (Element) nl.item(i);
            final Issue issue = parseIssue(issueElement);
            final IssueType issueType = issueTypes.get(issue.getTypeId());
            if (// couldn't find the issue type, skip it
            issueType == null)
                continue;
            final Violation violation = new Violation();
            violation.setType("resharper");
            violation.setMessage(issue.getMessage());
            violation.setPopupMessage(issueType.getDescription() + " - " + issue.getMessage());
            violation.setSource(issueType.getCategory());
            violation.setLine(issue.getLine());
            violation.setSeverity(SEVERITIES.get(issueType.getSeverity()));
            violation.setSeverityLevel(Severity.getSeverityLevel(violation.getSeverity()));
            final File file = absoluteFileFinder.getFileForName(issue.getFile());
            final FullFileModel fullFileModel = getFileModel(model, issue.getFile().replace('\\', '/'), file);
            fullFileModel.addViolation(violation);
        }
    } catch (final ParserConfigurationException pce) {
        throw new IOException2(pce);
    } catch (final SAXException se) {
        throw new IOException2(se);
    }
}
Also used : Violation(hudson.plugins.violations.model.Violation) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) FullFileModel(hudson.plugins.violations.model.FullFileModel) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) IOException2(hudson.util.IOException2)

Aggregations

IOException2 (hudson.util.IOException2)37 IOException (java.io.IOException)20 File (java.io.File)16 FileInputStream (java.io.FileInputStream)10 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)5 InputStream (java.io.InputStream)4 ObjectInputStream (java.io.ObjectInputStream)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 TarInputStream (hudson.org.apache.tools.tar.TarInputStream)3 VirtualChannel (hudson.remoting.VirtualChannel)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 SAXException (org.xml.sax.SAXException)3 XmlPullParser (org.xmlpull.v1.XmlPullParser)3 XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)3 StreamException (com.thoughtworks.xstream.io.StreamException)2 ObjectInputStreamEx (hudson.remoting.ObjectInputStreamEx)2