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

use real path in coverage sensors also #1688

Conversation

jmecosta
Copy link
Member

@jmecosta jmecosta commented Feb 12, 2019

This change is Reviewable

@jmecosta jmecosta requested review from ivangalkin, guwirth and Bertk and removed request for guwirth and ivangalkin February 14, 2019 10:22
Copy link
Contributor

@ivangalkin ivangalkin left a 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.

@jmecosta
Copy link
Member Author

@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?

@ivangalkin
Copy link
Contributor

@jmecosta before #1522, all sensors were derived from CxxReportSensor and all of them had a copy of notFoundFiles. Unfortunately the logic of the methods CxxReportSensor::execute(), CxxReportSensor::executeReport() etc. was absolutely not applicable to the coverage sensors (among others). So I had to create a new class CxxIssuesReportSensor (CxxIssuesReportSensor extends CxxReportSensor) and move a large block of code to this new file. But if parts of logic became useful for all sensors again, why not to move these logic back? I prefer consistency over optimization so I personally don't see any problem.

If thats the case, maybe notFoundFiles could be injected in similar way we handle the coverage cache data.

This could bring some optimization indeed. But again 1) the handling of notFoundFiles should be available to all sensors (and therefore moved back to CxxReportSensor) 2) we'll introduced some shared state between sensors. Right now such shared state doesn't play any role (all sensors are executed successively), but it could hinder the future parallelization.

@jmecosta
Copy link
Member Author

So, for now just move the thing back to CxxReportSensor and leave optimization to some later stage?

@ivangalkin
Copy link
Contributor

@jmecosta that would be the right solution in my opinion;

Copy link
Collaborator

@guwirth guwirth left a 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

@guwirth
Copy link
Collaborator

guwirth commented Mar 26, 2019

@jmecosta how should we continue here? Do you make another PR with the proposal of @ivangalkin?

@guwirth
Copy link
Collaborator

guwirth commented Apr 14, 2019

replaced by #1701

@guwirth guwirth closed this Apr 14, 2019
haghighi pushed a commit to haghighi/sonar-cxx that referenced this pull request Jun 22, 2019
- move getInputFileIfInProject to CxxReportSensor
- introduce executeImpl (template method pattern)

solution from @jmecosta SonarOpenCommunity#1688 with review comments from @ivangalkin
@guwirth guwirth mentioned this pull request Jul 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants