SMInputFactory inputFactory = StaxParserUtils.initStax(); FileInputStream fileInputStream = null; try {
/** * Parses a processed violation file. * * @param file * the file to parse */ public void parse(File file) { this.repositoryKey = vsProject.isTest() ? GendarmeConstants.TEST_REPOSITORY_KEY : GendarmeConstants.REPOSITORY_KEY; if (!"cs".equals(project.getLanguageKey())) { // every repository key should be "fxcop-<language_key>", except for C# for which it is simply "fxcop" (for backward compatibility) repositoryKey += "-" + project.getLanguageKey(); } SMInputFactory inputFactory = StaxParserUtils.initStax(); FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); SMHierarchicCursor cursor = inputFactory.rootElementCursor(new InputStreamReader(fileInputStream, project.getFileSystem().getSourceCharset())); SMInputCursor rulesCursor = cursor.advance().descendantElementCursor("rule"); parseRuleBlocs(rulesCursor); cursor.getStreamReader().closeCompletely(); } catch (XMLStreamException e) { throw new SonarException("Error while reading Gendarme result file: " + file.getAbsolutePath(), e); } catch (FileNotFoundException e) { throw new SonarException("Cannot find Gendarme result file: " + file.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(fileInputStream); } }