Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associate issues with project / directory instead of file #80

Closed
guwirth opened this issue Dec 1, 2013 · 4 comments
Closed

Associate issues with project / directory instead of file #80

guwirth opened this issue Dec 1, 2013 · 4 comments
Assignees

Comments

@guwirth
Copy link
Collaborator

guwirth commented Dec 1, 2013

Hello,

This is a request to add violations without source code dependency.

Background is, that we are using analyzer generating project violations without source code or line information. We have the need to assign this violations to the project.

As an example - Clirr plugin does this: http://docs.codehaus.org/display/SONAR/Clirr+Plugin

context.saveViolation(Violation.create(activeRule,
resource).setMessage(violation.getMessage()));

This needs to be handled to all sensors, not only for the external sensor. I think at least the pc-lint also reports violations at project level.

See also
http://sonarqube.15.x6.nabble.com/Possible-to-add-violations-without-source-code-dependency-tp5014779.html

Regards

@jmecosta
Copy link
Member

jmecosta commented Dec 1, 2013

Tought there was already a pull request for this one, but his can be done easily in the save violation method and will be available for all sensors

@Bertk
Copy link
Contributor

Bertk commented Dec 1, 2013

PC-Lint sensor can write issues on Project level after adding additional function to CxxReportSensor class.

protected void saveViolation(Project project, SensorContext context, String ruleRepoKey, String ruleId, String msg) {
RuleQuery ruleQuery = RuleQuery.create()
        .withRepositoryKey(ruleRepoKey)
        .withKey(ruleId);
Rule rule = ruleFinder.find(ruleQuery);
    if (rule != null) {
        Violation violation = Violation.create(rule, project).setMessage(msg);
        context.saveViolation(violation);
        } else {
        CxxUtils.LOG.warn("Cannot find the rule {}, skipping violation", ruleId);
        }
  } ;

And modification of the PC-Lint sensor as well ( a snippet) :

      if (Integer.valueOf(line)==0) line = String.valueOf(1);
      String id = errorCursor.getAttrValue("number");
      String msg = errorCursor.getAttrValue("desc");
        if (isInputValid(file, line, id, msg)) {
          //remap MISRA IDs. Only Unique rules for MISRA 2004 and 2008 has been created in the rule repository
          if(msg.contains("MISRA 2004") || msg.contains("MISRA 2008")) {
              id = mapMisraRulesToUniqueSonarRules(msg);
          }
          String issue = file + line + id + msg;
          if (uniqueIssues.add(issue))
              if (StringUtils.isEmpty(file)) {
                  saveViolation(project, context, CxxPCLintRuleRepository.KEY, id, msg); 
              }
              else {
                  saveViolation(project, context, CxxPCLintRuleRepository.KEY, file, line, id, msg);
              }

        } else {
          CxxUtils.LOG.warn("PCLint warning ignored: {}", msg);

and the check for the rule looks now like this:

  private boolean isInputValid(String file, String line, String id, String msg) {

      if (StringUtils.isEmpty(file) && (Integer.valueOf(line)==1)) {
          // issue for project
          return !StringUtils.isEmpty(id) && !StringUtils.isEmpty(msg);
      }
    return !StringUtils.isEmpty(file) && !StringUtils.isEmpty(id) && !StringUtils.isEmpty(msg);
  }

I will run more tests for this improvement and create a pull request for PC-Lint plugin next weekend.

@wenns
Copy link
Contributor

wenns commented Dec 2, 2013

While at it, we should handle file-level violations as well.

@Bertk
Copy link
Contributor

Bertk commented Dec 17, 2013

This solution throws an NullPointerException for CppCheck, PC-Lint and Compiler (MSVC) results.

   org.sonar.runner.impl.RunnerException: Unable to execute Sonar
    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
    at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
    at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
    at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
    at org.sonar.runner.api.Runner.execute(Runner.java:90)
    at org.sonar.runner.Main.executeTask(Main.java:70)
    at org.sonar.runner.Main.execute(Main.java:59)
    at org.sonar.runner.Main.main(Main.java:41)
 Caused by: org.sonar.api.utils.SonarException: Cannot feed the data into sonar, details: 'java.lang.NullPointerException'
    at org.sonar.plugins.cxx.utils.CxxReportSensor.analyse(CxxReportSensor.java:96)
    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:72)
    at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:114)
    at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:150)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
    at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:190)
    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:185)
    at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:178)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
    at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:58)
    at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:45)
    at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:82)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
    at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapContainer.java:155)
    at org.sonar.batch.bootstrap.BootstrapContainer.doAfterStart(BootstrapContainer.java:143)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
    at org.sonar.batch.bootstrapper.Batch.startBatch(Batch.java:92)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:74)
    at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
    ... 9 more
   Caused by: java.lang.NullPointerException
    at org.sonar.plugins.cxx.utils.CxxReportSensor.saveViolation(CxxReportSensor.java:177)
    at org.sonar.plugins.cxx.cppcheck.CxxCppCheckSensor.access$0(CxxCppCheckSensor.java:1)
    at org.sonar.plugins.cxx.cppcheck.CxxCppCheckSensor$1.stream(CxxCppCheckSensor.java:102)
    at org.sonar.api.utils.StaxParser.parse(StaxParser.java:109)
    at org.sonar.api.utils.StaxParser.parse(StaxParser.java:89)
    at org.sonar.api.utils.StaxParser.parse(StaxParser.java:79)
    at org.sonar.plugins.cxx.cppcheck.CxxCppCheckSensor.processReport(CxxCppCheckSensor.java:114)
    at org.sonar.plugins.cxx.utils.CxxReportSensor.analyse(CxxReportSensor.java:80)
    ... 36 more

@Bertk Bertk reopened this Dec 17, 2013
Bertk referenced this issue in Bertk/sonar-cxx Dec 18, 2013
Handle file not found condition - skipping violation was not handle
correctly
Bertk referenced this issue in Bertk/sonar-cxx Dec 21, 2013
Handle file not found condition - skipping violation was not handle
correctly
@wenns wenns closed this as completed Dec 27, 2013
Bertk referenced this issue in Bertk/sonar-cxx Dec 27, 2013
Handle file not found condition - skipping violation was not handle
correctly
Bertk referenced this issue in Bertk/sonar-cxx Dec 27, 2013
Handle file not found condition - skipping violation was not handle
correctly
Bertk referenced this issue in Bertk/sonar-cxx Dec 28, 2013
Handle file not found condition - skipping violation was not handle
correctly
Bertk referenced this issue in Bertk/sonar-cxx Dec 28, 2013
Handle file not found condition - skipping violation was not handle
correctly
Bertk referenced this issue in Bertk/sonar-cxx Dec 28, 2013
Handle file not found condition - skipping violation was not handle
correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants