Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,7 +36,7 @@ public class ViolationsCollector implements FileCallable<ViolationsReport> {

/**
* Constructor.
*
*
* @param mavenProject
* true if this a maven project, false otherwise
* @param targetDir
Expand All @@ -59,7 +58,7 @@ private boolean empty(String str) {

/**
* Create a report.
*
*
* @param workspace
* the current workspace.
* @param channel
Expand Down Expand Up @@ -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);
}

// -----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/hudson/plugins/violations/parse/ParseXML.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -45,7 +44,7 @@ public static void parse(
} catch (IOException ex) {
throw ex;
} catch (Exception ex) {
throw new IOException2(ex);
throw new IOException(ex);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,7 +15,7 @@
import org.w3c.dom.Element;

import hudson.plugins.violations.ViolationsParser;

public abstract class ViolationsDOMParser
implements ViolationsParser {

Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand All @@ -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 {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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("<a href=\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import hudson.plugins.violations.parse.ParseUtil;
import hudson.plugins.violations.types.fxcop.XmlElementUtil;
import hudson.plugins.violations.util.AbsoluteFileFinder;
import hudson.util.IOException2;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -38,46 +37,46 @@
public class GendarmeParser implements ViolationsParser {

static final Logger logger = Logger.getLogger(GendarmeParser.class.toString());

static final String TYPE_NAME = "gendarme";
private FullBuildModel model;
private File reportParentFile;
private File projectPath;
private String[] sourcePaths;
private HashMap<String, GendarmeRule> 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<Element> ruleElements) {
Expand All @@ -86,19 +85,19 @@ private void parseViolations(List<Element> 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<Element> targetElements = XmlElementUtil.getNamedChildElements(ruleElement, "target");

for(Element targetElement : targetElements){
//String targetName = targetElement.getAttribute("Name");
String targetAssembly = targetElement.getAttribute("Assembly");
Expand All @@ -113,12 +112,12 @@ private void parseViolations(List<Element> 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()) {
Expand All @@ -131,13 +130,13 @@ private void parseViolations(List<Element> 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){
Expand All @@ -148,14 +147,14 @@ private void parseViolations(List<Element> ruleElements) {
else {
messageBuilder.append(rule.getName());
}

messageBuilder.append(" - ").append(problem).append("<br/>");
messageBuilder.append("Solution: ").append(solution).append("<br/>");
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);
Expand All @@ -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;
Expand Down Expand Up @@ -220,12 +219,12 @@ else if(severityString.equals("Critical")){
}
}
}

private void parseRules(List<Element> ruleElements) {
rules = new HashMap<String, GendarmeRule>();

for(Element ruleElement : ruleElements){

// create the Gendarme rule
GendarmeRule rule = new GendarmeRule();
rule.setName(ruleElement.getAttribute("Name"));
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading