-
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
use real path in coverage sensors also #1688
use real path in coverage sensors also #1688
Conversation
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.
Reviewed 6 of 6 files at r1.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Bertk, @guwirth, and @jmecosta)
cxx-sensors/src/main/java/org/sonar/cxx/sensors/utils/CxxUtils.java, line 99 at r1 (raw file):
} public static InputFile getInputFileIfInProject(SensorContext sensorContext, String path, Set<String> notFoundFiles) {
TBH I don't really like this solution. CxxUtils
is not a good place for such implementation. I would suggest to move
- private final Set notFoundFiles = new HashSet<>();
- public InputFile getInputFileIfInProject(SensorContext sensorContext, String path);
- private InputFile getInputFileTryRealPath(SensorContext sensorContext, String path);
to the base class of all sensors: CxxReportSensor
. So each sensor could potentially benefit from this functionality. The only thing, which is hard to implement in an elegant way is the clean-up. An easy solution would be to provide a method
void CxxReportSensor::cleanNotFoundFiles();
But there will be always a risk, that someone forgets to call it. A better solution would be to implement some kind of "template method" (aka. "private interface") pattern. Like
public class CxxReportSensor implements Sensor {
private final Set<String> notFoundFiles = new HashSet<>();
protected abstract executeImpl(SensorContext context);
@Override
public void execute(SensorContext context) {
notFoundFiles.clear();
executeImpl(context);
}
}
All derived classes will be forced to override executeImpl()
instead of execute()
, but there will be no risk of inconsistency anymore.
@ivangalkin inst each sensor a own instance during the analysis stage. Even in a multi module scenario, each sensor is instantiated again and again? so the notFoundFiles is always empty when the sensor executes? If thats the case, maybe notFoundFiles could be injected in similar way we handle the coverage cache data. It makes sense since notFoundFiles should be constant for all sensor, so it should speed up the analysis? |
@jmecosta before #1522, all sensors were derived from
This could bring some optimization indeed. But again 1) the handling of |
So, for now just move the thing back to CxxReportSensor and leave optimization to some later stage? |
@jmecosta that would be the right solution in my opinion; |
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.
@jmecosta agree with @ivangalkin
@jmecosta how should we continue here? Do you make another PR with the proposal of @ivangalkin? |
replaced by #1701 |
- move getInputFileIfInProject to CxxReportSensor - introduce executeImpl (template method pattern) solution from @jmecosta SonarOpenCommunity#1688 with review comments from @ivangalkin
This change is