Search in sources :

Example 36 with IOException2

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

the class ParseXML method parse.

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

Example 37 with IOException2

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

the class ViolationsCollector method invoke.

/**
     * Create a report.
     * 
     * @param workspace
     *            the current workspace.
     * @param channel
     *            the virtual channel.
     * @return the report.
     * @throws IOException
     *             if there is a problem.
     */
@Override
public ViolationsReport invoke(File workspace, VirtualChannel channel) throws IOException {
    this.workspace = workspace;
    // the given workspace
    if (!StringUtil.isBlank(config.getFauxProjectPath())) {
        this.workspace = new File(config.getFauxProjectPath());
        LOG.fine("Using faux workspace " + this.workspace);
    }
    String[] sourcePaths = null;
    if (mavenProject) {
        sourcePaths = new String[] { workspace.toString() + "/src/main/java" };
    } else {
        // get the source path directories (if any)
        sourcePaths = findAbsoluteDirs(workspace, config.getSourcePathPattern());
    }
    for (String sp : sourcePaths) {
        LOG.fine("Using extra sourcePath " + sp);
    }
    // Create the report
    ViolationsReport report = new ViolationsReport();
    report.setConfig(config);
    // Build up the model
    this.model = new FullBuildModel();
    for (String type : config.getTypeConfigs().keySet()) {
        TypeConfig c = config.getTypeConfigs().get(type);
        TypeDescriptor typeDescriptor = TypeDescriptor.TYPES.get(type);
        if (typeDescriptor == null) {
            continue;
        }
        if (mavenProject && (typeDescriptor.getMavenTargets() != null)) {
            doType(c, typeDescriptor, sourcePaths, report);
            continue;
        }
        if (empty(c.getPattern())) {
            continue;
        }
        doType(c, typeDescriptor, sourcePaths, report);
    }
    model.cleanup();
    // ----
    try {
        new GenerateXML(targetDir, model, config).execute();
    } catch (InterruptedException ex) {
        throw new IOException2(ex);
    }
    // ----
    for (String type : model.getTypeMap().keySet()) {
        report.getViolations().put(type, model.getCountNumber(type));
        doSeverities(report, type);
    }
    return report;
}
Also used : GenerateXML(hudson.plugins.violations.generate.GenerateXML) FullBuildModel(hudson.plugins.violations.model.FullBuildModel) 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