Skip to content

Commit

Permalink
Issue #80 Associate issues with project / directory instead of file
Browse files Browse the repository at this point in the history
  • Loading branch information
Waleri Enns authored and Bertk committed Dec 21, 2013
1 parent aa9f3a1 commit a73375e
Showing 1 changed file with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,39 +153,38 @@ protected void saveViolation(Project project, SensorContext context, String rule
.withKey(ruleId);
Rule rule = ruleFinder.find(ruleQuery);
if (rule != null) {
Violation violation = null;
if (file != null){
org.sonar.api.resources.File resource =
org.sonar.api.resources.File.fromIOFile(new File(file), project);
if (context.getResource(resource) != null) {
// file level violation
violation = Violation.create(rule, resource);

// considering the line information for file level violations only
if (line != null){
try{
int linenr = Integer.parseInt(line);
violation.setLineId(linenr);
} catch(java.lang.NumberFormatException nfe){
CxxUtils.LOG.warn("Skipping invalid line number: {}", line);
Violation violation = null;
if (file != null){
org.sonar.api.resources.File resource =
org.sonar.api.resources.File.fromIOFile(new File(file), project);
if (context.getResource(resource) != null) {
// file level violation
violation = Violation.create(rule, resource);

// considering the line information for file level violations only
if (line != null){
try{
int linenr = Integer.parseInt(line);
violation.setLineId(linenr);
} catch(java.lang.NumberFormatException nfe){
CxxUtils.LOG.warn("Skipping invalid line number: {}", line);
}
}
} else {
CxxUtils.LOG.warn("Cannot find the file '{}', skipping violation '{}'", file, msg);
}
} else {
CxxUtils.LOG.warn("Cannot find the file '{}', skipping violation '{}'", file, msg);
// project level violation
violation = Violation.create(rule, project);
}
} else {
// project level violation
violation = Violation.create(rule, project);
}

if (violation != null){
violation.setMessage(msg);
context.saveViolation(violation);
}
} else {
CxxUtils.LOG.warn("Cannot find the rule {}, skipping violation", ruleId);
} else {
CxxUtils.LOG.warn("Cannot find the rule {}, skipping violation", ruleId);
}
}



protected void processReport(Project project, SensorContext context, File report)
Expand Down

0 comments on commit a73375e

Please sign in to comment.