diff --git a/src/main/java/hudson/plugins/violations/ViolationsCollector.java b/src/main/java/hudson/plugins/violations/ViolationsCollector.java index 3c9b118..95c8954 100644 --- a/src/main/java/hudson/plugins/violations/ViolationsCollector.java +++ b/src/main/java/hudson/plugins/violations/ViolationsCollector.java @@ -8,7 +8,6 @@ import hudson.plugins.violations.model.Violation; import hudson.plugins.violations.util.StringUtil; import hudson.remoting.VirtualChannel; -import hudson.util.IOException2; import java.io.File; import java.io.IOException; @@ -37,7 +36,7 @@ public class ViolationsCollector implements FileCallable { /** * Constructor. - * + * * @param mavenProject * true if this a maven project, false otherwise * @param targetDir @@ -59,7 +58,7 @@ private boolean empty(String str) { /** * Create a report. - * + * * @param workspace * the current workspace. * @param channel @@ -121,7 +120,7 @@ public ViolationsReport invoke(File workspace, VirtualChannel channel) throws IO try { new GenerateXML(targetDir, model, config).execute(); } catch (InterruptedException ex) { - throw new IOException2(ex); + throw new IOException(ex); } // ----- diff --git a/src/main/java/hudson/plugins/violations/parse/AbstractTypeParser.java b/src/main/java/hudson/plugins/violations/parse/AbstractTypeParser.java index 181beb4..db48320 100644 --- a/src/main/java/hudson/plugins/violations/parse/AbstractTypeParser.java +++ b/src/main/java/hudson/plugins/violations/parse/AbstractTypeParser.java @@ -7,8 +7,6 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserFactory; -import hudson.util.IOException2; - import hudson.plugins.violations.ViolationsParser; import hudson.plugins.violations.model.FullBuildModel; @@ -59,7 +57,7 @@ public void parse( } catch (IOException ex) { throw ex; } catch (Exception ex) { - throw new IOException2("Cannot parse " + fileName, ex); + throw new IOException("Cannot parse " + fileName, ex); } finally { CloseUtil.close(in, !success); } diff --git a/src/main/java/hudson/plugins/violations/parse/ParseTypeXML.java b/src/main/java/hudson/plugins/violations/parse/ParseTypeXML.java index 83c80b2..e9d6289 100644 --- a/src/main/java/hudson/plugins/violations/parse/ParseTypeXML.java +++ b/src/main/java/hudson/plugins/violations/parse/ParseTypeXML.java @@ -2,7 +2,6 @@ import hudson.plugins.violations.model.FullBuildModel; import hudson.plugins.violations.util.CloseUtil; -import hudson.util.IOException2; import java.io.File; import java.io.FileInputStream; @@ -57,7 +56,7 @@ public void parse( } catch (IOException ex) { throw ex; } catch (Exception ex) { - throw new IOException2(ex); + throw new IOException(ex); } finally { CloseUtil.close(in, !success); } diff --git a/src/main/java/hudson/plugins/violations/parse/ParseXML.java b/src/main/java/hudson/plugins/violations/parse/ParseXML.java index c4ff8ec..d3225f6 100644 --- a/src/main/java/hudson/plugins/violations/parse/ParseXML.java +++ b/src/main/java/hudson/plugins/violations/parse/ParseXML.java @@ -1,7 +1,6 @@ package hudson.plugins.violations.parse; import hudson.plugins.violations.util.CloseUtil; -import hudson.util.IOException2; import java.io.File; import java.io.FileInputStream; @@ -45,7 +44,7 @@ public static void parse( } catch (IOException ex) { throw ex; } catch (Exception ex) { - throw new IOException2(ex); + throw new IOException(ex); } } @@ -74,7 +73,7 @@ public static void parse( throw ex; } catch (Exception ex) { seenException = true; - throw new IOException2(ex); + throw new IOException(ex); } finally { CloseUtil.close(in, seenException); } diff --git a/src/main/java/hudson/plugins/violations/parse/ViolationsDOMParser.java b/src/main/java/hudson/plugins/violations/parse/ViolationsDOMParser.java index af3bd02..5a7272d 100644 --- a/src/main/java/hudson/plugins/violations/parse/ViolationsDOMParser.java +++ b/src/main/java/hudson/plugins/violations/parse/ViolationsDOMParser.java @@ -2,7 +2,6 @@ import hudson.plugins.violations.model.FullBuildModel; import hudson.plugins.violations.model.FullFileModel; -import hudson.util.IOException2; import java.io.IOException; import java.io.File; @@ -16,7 +15,7 @@ import org.w3c.dom.Element; import hudson.plugins.violations.ViolationsParser; - + public abstract class ViolationsDOMParser implements ViolationsParser { @@ -65,7 +64,7 @@ public void parse( } catch (IOException ex) { throw ex; } catch (Exception ex) { - throw new IOException2("Cannot parse " + fileName, ex); + throw new IOException("Cannot parse " + fileName, ex); } finally { // ? terminate the parser } diff --git a/src/main/java/hudson/plugins/violations/types/fxcop/FxCopParser.java b/src/main/java/hudson/plugins/violations/types/fxcop/FxCopParser.java index bde845d..c3f7316 100644 --- a/src/main/java/hudson/plugins/violations/types/fxcop/FxCopParser.java +++ b/src/main/java/hudson/plugins/violations/types/fxcop/FxCopParser.java @@ -5,7 +5,6 @@ import hudson.plugins.violations.model.FullFileModel; import hudson.plugins.violations.model.Severity; import hudson.plugins.violations.model.Violation; -import hudson.util.IOException2; import java.io.File; import java.io.FileInputStream; @@ -23,8 +22,8 @@ /** * Parses a fxcop xml report file. - * - * + * + * * This does not uses the XML Pull parser as it can not handle the FxCop XML * files. The bug is registered at Sun as http: //bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058 */ @@ -37,7 +36,7 @@ public class FxCopParser implements ViolationsParser { public void parse(FullBuildModel model, File projectPath, String fileName, String[] sourcePaths) throws IOException { this.projectPath = projectPath; this.model = model; - + DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder; try { @@ -52,9 +51,9 @@ public void parse(FullBuildModel model, File projectPath, String fileName, Strin parseTargets(XmlElementUtil.getFirstElementByTagName(rootElement, "Targets")); // TODO parse notes } catch (ParserConfigurationException pce) { - throw new IOException2(pce); + throw new IOException(pce); } catch (SAXException se) { - throw new IOException2(se); + throw new IOException(se); } } @@ -170,13 +169,13 @@ private void parseIssue(Element issue, Element parent, String parentName, String violation.setType("fxcop"); violation.setSource(category + "#" + checkId); setSeverityLevel(violation, getString(issue, "Level")); - + StringBuilder msgBuilder = new StringBuilder(); if (subName != null) { msgBuilder.append(subName); msgBuilder.append(" "); } - + FxCopRule rule = ruleSet.getRule(category, checkId); if (rule != null) { msgBuilder.append(" rules; - + public void parse(FullBuildModel model, File projectPath, String fileName, String[] sourcePaths) throws IOException { logger.info("Starting Gendarme parsing"); - + this.projectPath = projectPath; this.model = model; this.reportParentFile = new File(fileName).getParentFile(); this.sourcePaths = sourcePaths; - + DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder; + DocumentBuilder docBuilder; try { docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(new FileInputStream(new File(projectPath, fileName))); - + NodeList mainNode = doc.getElementsByTagName("gendarme-output"); - + Element rootElement = (Element) mainNode.item(0); Element resultsElement = (Element)rootElement.getElementsByTagName("results").item(0); Element rulesElement = (Element)rootElement.getElementsByTagName("rules").item(0); - + // load all rules into the cache parseRules(XmlElementUtil.getNamedChildElements(rulesElement, "rule")); - + // parse each violations parseViolations(XmlElementUtil.getNamedChildElements(resultsElement, "rule")); - + } catch (ParserConfigurationException pce) { - throw new IOException2(pce); + throw new IOException(pce); } catch (SAXException se) { - throw new IOException2(se); - } + throw new IOException(se); + } } private void parseViolations(List ruleElements) { @@ -86,19 +85,19 @@ private void parseViolations(List ruleElements) { AbsoluteFileFinder finder = new AbsoluteFileFinder(); // add the project path to the search source finder.addSourcePath(this.projectPath.getPath()); - // if there's additional paths, add them too + // if there's additional paths, add them too if (this.sourcePaths != null) { finder.addSourcePaths(this.sourcePaths); } - + for(Element ruleElement : ruleElements){ String ruleName = ruleElement.getAttribute("Name"); GendarmeRule rule = this.rules.get(ruleName); String problem = ruleElement.getElementsByTagName("problem").item(0).getTextContent(); String solution = ruleElement.getElementsByTagName("solution").item(0).getTextContent(); - + List targetElements = XmlElementUtil.getNamedChildElements(ruleElement, "target"); - + for(Element targetElement : targetElements){ //String targetName = targetElement.getAttribute("Name"); String targetAssembly = targetElement.getAttribute("Assembly"); @@ -113,12 +112,12 @@ private void parseViolations(List ruleElements) { String filePath = ""; String fileName = ""; int line = 0; - + if(rule.getType() != GendarmeRuleType.Assembly){ Pattern pattern = Pattern.compile("^(.*)\\(.([0-9]*)\\)$"); Matcher matcher = pattern.matcher(source); logger.info("matcher.groupCount() : "+matcher.groupCount()); - + logger.info("matcher.matches() : "+matcher.matches()); logger.info("source : "+source); if(matcher.matches()) { @@ -131,13 +130,13 @@ private void parseViolations(List ruleElements) { File sourceFile = new File(fullPath); fileName = sourceFile.getName(); filePath = sourceFile.getParent(); - line = Integer.parseInt(matcher.group(2)); + line = Integer.parseInt(matcher.group(2)); } } - + // create the violation Violation violation = new Violation(); - + // construct the error message StringBuilder messageBuilder = new StringBuilder(); if(rule.getUrl() != null){ @@ -148,14 +147,14 @@ private void parseViolations(List ruleElements) { else { messageBuilder.append(rule.getName()); } - + messageBuilder.append(" - ").append(problem).append("
"); messageBuilder.append("Solution: ").append(solution).append("
"); messageBuilder.append("Confidence: ").append(confidence); - + violation.setMessage(messageBuilder.toString()); - violation.setPopupMessage(problem); - + violation.setPopupMessage(problem); + // construct the severity if(severityString.equals("Low")){ violation.setSeverityLevel(Severity.LOW_VALUE); @@ -179,7 +178,7 @@ else if(severityString.equals("Critical")){ } violation.setType(TYPE_NAME); violation.setSource(rule.getName()); - + // try to get the file // TODO : test it with Linux Master => Windows Slave node. Unix/Windows path could be a problem. FullFileModel fileModel; @@ -220,12 +219,12 @@ else if(severityString.equals("Critical")){ } } } - + private void parseRules(List ruleElements) { rules = new HashMap(); - + for(Element ruleElement : ruleElements){ - + // create the Gendarme rule GendarmeRule rule = new GendarmeRule(); rule.setName(ruleElement.getAttribute("Name")); @@ -242,7 +241,7 @@ else if(typeString.equals("Assembly")) } catch (MalformedURLException e) { rule.setUrl(null); } - + // add the rule to the cache rules.put(rule.getName(), rule); } diff --git a/src/main/java/hudson/plugins/violations/types/resharper/ReSharperParser.java b/src/main/java/hudson/plugins/violations/types/resharper/ReSharperParser.java index 3144148..b5f215b 100644 --- a/src/main/java/hudson/plugins/violations/types/resharper/ReSharperParser.java +++ b/src/main/java/hudson/plugins/violations/types/resharper/ReSharperParser.java @@ -7,7 +7,6 @@ import hudson.plugins.violations.model.Violation; import hudson.plugins.violations.util.AbsoluteFileFinder; import hudson.plugins.violations.util.HashMapWithDefault; -import hudson.util.IOException2; import java.io.File; import java.io.FileInputStream; @@ -138,9 +137,9 @@ public void parse(final FullBuildModel model, final File projectPath, fullFileModel.addViolation(violation); } } catch (final ParserConfigurationException pce) { - throw new IOException2(pce); + throw new IOException(pce); } catch (final SAXException se) { - throw new IOException2(se); + throw new IOException(se); } } diff --git a/src/main/java/hudson/plugins/violations/types/stylecop/StyleCopParser.java b/src/main/java/hudson/plugins/violations/types/stylecop/StyleCopParser.java index 7bdac22..a39a8be 100644 --- a/src/main/java/hudson/plugins/violations/types/stylecop/StyleCopParser.java +++ b/src/main/java/hudson/plugins/violations/types/stylecop/StyleCopParser.java @@ -13,7 +13,6 @@ import hudson.FilePath; import hudson.plugins.violations.parse.ParseUtil; -import hudson.util.IOException2; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -29,10 +28,10 @@ /** * Parses a StyleCop (http://code.msdn.microsoft.com/sourceanalysis/) xml report file. - * + * */ public class StyleCopParser implements ViolationsParser { - + static final String TYPE_NAME = "stylecop"; private FullBuildModel model; private File reportParentFile; @@ -45,7 +44,7 @@ public void parse( this.reportParentFile = new File(fileName).getParentFile(); if (this.reportParentFile==null) this.reportParentFile = projectPath; - + DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder; try { @@ -61,15 +60,15 @@ public void parse( Element rootElement = (Element) mainNode.item(0); parseViolations(XmlElementUtil.getNamedChildElements(rootElement, "Violation")); - - findSourceFiles(model, projectPath.getPath(), sourcePaths); + + findSourceFiles(model, projectPath.getPath(), sourcePaths); } catch (ParserConfigurationException pce) { - throw new IOException2(pce); + throw new IOException(pce); } catch (SAXException se) { - throw new IOException2(se); - } + throw new IOException(se); + } } - + /** * Go through all violations and see if the source files can be found. * @param model model containing all violations @@ -82,7 +81,7 @@ private void findSourceFiles(FullBuildModel model, String workspace, String[] so if (sourcePaths != null) { finder.addSourcePaths(sourcePaths); } - + Map fileModelMap = model.getFileModelMap(); for (Map.Entry entry : fileModelMap.entrySet()) { FullFileModel fileModel = entry.getValue(); @@ -93,7 +92,7 @@ private void findSourceFiles(FullBuildModel model, String workspace, String[] so } } } - + /*** * Returns the value for the named attribute if it exists * @param element the element to check for an attribute @@ -114,22 +113,22 @@ private String getString(Element element, String name) { */ private void parseViolations(List elements) throws IOException { for (Element element : elements) { - + Violation violation = new Violation(); violation.setLine(getString(element, "LineNumber")); violation.setMessage(element.getTextContent() + " (" + getString(element, "RuleId") + ")"); violation.setSeverity(Severity.MEDIUM); violation.setSeverityLevel(Severity.MEDIUM_VALUE); violation.setType(TYPE_NAME); - + String temp = getString(element, "RuleNamespace"); int i = temp.lastIndexOf('.'); if (i != -1) { violation.setSource(temp.substring(i)); } else { violation.setSource(getString(element,"RuleId")); - } - + } + // Add the violation to the model String displayName = new FilePath(reportParentFile).child(getString(element,"Source")).getRemote(); displayName = ParseUtil.resolveAbsoluteName(reportParentFile,displayName);