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);
}
}
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);
}
}
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);
}
}
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
}
}
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);
}
}
Aggregations