Comments (4)
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
from sonar-cxx.
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.
from sonar-cxx.
While at it, we should handle file-level violations as well.
from sonar-cxx.
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
from sonar-cxx.
Related Issues (20)
- Sonar read xml file of CppCheck check by MISRA2012;But there is no corresponding misra warning HOT 13
- Cppcheck 2.13.0 support HOT 3
- Unable to get coverage report when using Sonar.cxx plugin HOT 5
- plugin issue: The plugin [cxx] does not support Java 1.8.0_212 HOT 1
- Change rule keys containing non standard characters
- Builds failing with 'CXX-public_undocumented_api' does not exist error HOT 1
- SonarCloud: Java 11 is no longer supported as scanner runtime environment
- Very little security rules and security hotspot rules HOT 1
- can you update xx-custom-checks-example-plugin for Sonar 9.9 TLS HOT 2
- Verify deprecated Web API endpoints and parameters HOT 1
- Optimizing the execution of sensors
- C++ plugin causing an issue while running Java/python projects HOT 5
- How to define program language HOT 1
- cxx-custom-checks-example-plugin can not to report issue information HOT 8
- The SonarScanners download only required 3rd-party plugins HOT 1
- [Fix][cxx-custom-checks-example-plugin] the problem that sample rules could not be loaded and registerd normally HOT 1
- BREAKING CHANGE: Rename 'sonarQubeMinVersion' to 'pluginApiMinVersion'
- The property 'sonar.login' is deprecated
- False positive with cppcheck:passedByValue and std::move in constructor HOT 3
- Squid preprocessor error and the sonar scanner procedure will be stuck HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sonar-cxx.