-
Notifications
You must be signed in to change notification settings - Fork 363
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
Implement support for multiple locations in CxxReportSensor #1447
Implement support for multiple locations in CxxReportSensor #1447
Conversation
} | ||
} | ||
} | ||
|
||
private void addFileLocations(final SensorContext context, DrMemoryError error, List<CxxReportLocation> locations) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same logic is implemented in CxxValgrindSensor
For each CxxReportLocation CxxReportSensor will check if path belongs to the project or not. If it doesn't - this [secondary] location will be ignored. So finally we will have
- a primary location which is guaranteed to belong to the project (same as before)
>= 0
additional locations, which reference files from the analyzed project;
/** | ||
* Issue with one or multiple locations | ||
*/ | ||
public class CxxReportIssue { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no logic here - CxxReportIssue and CxxReportLocation (1:n) were introduced more or less in order to implement the proper semantics of ::equals() and ::hashCode() methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivangalkin thanks for your update.
Think interface would be easier to use if you would move CxxReportLocation
inside of CxxReportIssue
.
First issue with location would be with ctor:
// instead of this:
public CxxReportIssue(String ruleRepoKey, String ruleId, CxxReportLocation primaryLocation) {
this(ruleRepoKey, ruleId, Collections.singletonList(primaryLocation));
}
// this one for first issue/location:
public CxxReportIssue(String ruleRepoKey, String ruleId,
String file, String line, String info) {
super();
this.ruleRepoKey = ruleRepoKey;
this.ruleId = ruleId;
addLocation(file, line, info)
}
// remove this one
public CxxReportIssue(String ruleRepoKey, String ruleId, List<CxxReportLocation> locations) {
super();
this.ruleRepoKey = ruleRepoKey;
this.ruleId = ruleId;
this.locations = locations;
}
Second locations with method:
void addLocation(String file, String line, String info) {
locations.add(CxxReportLocation(file, line, info));
}
There would be no need for users (sensors) of the interface to create and handle own CxxReportLocation
.
What do you think?
import javax.xml.stream.XMLStreamException; | ||
import org.codehaus.staxmate.in.SMHierarchicCursor; | ||
import org.codehaus.staxmate.in.SMInputCursor; | ||
import org.sonar.api.batch.sensor.SensorContext; | ||
import org.sonar.api.utils.log.Logger; | ||
import org.sonar.api.utils.log.Loggers; | ||
import org.sonar.cxx.sensors.utils.CxxReportIssue; | ||
import org.sonar.cxx.sensors.utils.CxxReportLocation;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this empty statement ";;"
String line = null; | ||
String id = Objects.requireNonNull(errorCursor.getAttrValue("id"), | ||
"Missing mandatory attribute /results/errors/error[@id]"); | ||
String msg = Objects.requireNonNull(errorCursor.getAttrValue("msg"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this useless assignment to local variable "msg"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx! done
@guwirth Thank you for your proposal. I started to implement the
Creation of an Also there is a (minor) performance aspect (or rather memory footprint). Since the most of sensors support only primary location we can benefit from the usage of |
@Bertk please review manually, GitHub doesn't notice, that I've changed the SonarQube finding. I've fixed an issue, but in an other line as reviewed. |
No location means issue on module/project level.
Maybe ctor without location and only this |
@guwirth I'll try to apply the comments in the next few days. |
a18082b
to
5700223
Compare
* CxxDrMemorySensor * CppcheckParserV2 * CxxValgrindSensor * enable the new interface for all remaining sensors see also issue SonarOpenCommunity#1440
5700223
to
b27e698
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. @Bertk what do you think?
enable multiple locations for
enable the new interface for all remaining sensors
this pull request is replacement for #1436
see also issue #1440
This change is