What are you trying to accomplish?
I’m developing a custom SonarQube plugin. The main idea is to analyze the naming of new tests added in a pull request and check if they are valid. Additionally, I want to add a quality gate that evaluates the correctness of test names for new code, based on the percentage of correctly named tests. It should work similarly to how new code coverage is evaluated (i.e., it shouldn’t be less than a specified threshold, like x%).
What’s your specific coding challenge in developing your plugin?
The main challenge is that it’s unclear how to analyze only the new code. I know that I can analyze all project files using ProjectSensor
and FileSystem
(but that includes all project files and lines, not just the new ones), like:
public void execute(SensorContext context) {
for (InputFile inputFile : context.fileSystem().inputFiles(context.fileSystem().predicates().all()))
try {
try (InputStreamReader isr = new InputStreamReader(inputFile.inputStream(), inputFile.charset());
BufferedReader reader = new BufferedReader(isr)) {
reader.lines().forEachOrdered(lineStr -> {
...
PS I know how to:
- Setup the quality gate with appropriate measures.
- Parse lines and process it with format I need.
Would appreciate any suggestions!