While browsing the roadmap page on SonarSource website, I saw this improvement.
As it doesn’t seem to be available for all languages, I assume that “something” has to be done in language plugins. How is that handled in the SonarQube API ?
It would be extremely interesting for the language I’m working with to have faster PR analysis, as it’s very common to have large monolithic projects.
This has been implemented for several of the open source analysis engines: JS/TS, Java, Kotlin. It may be helpful to dig into one of those implementations.
I had a quick look at the Java and JS implementations, but there’s something I don’t understand for now. I’ll spend a bit of time on that next week. But does the SonarQube API rely on Git to detect which files are modified / unmodified in the current branch ? Is that provided by InputFile#status() ?
Ehm… I think that for incremental analysis it’s by file hash?
If you have a question that references specific analyzer code, I can refer it to the relevant team.
I assume that this requires a Developer Edition (or higher) ?
Yes. Good point. That’s only in PR analysis (and COBOL [EE]) for now.
My company has a Developer Edition instance, but I’d like to avoid testing in production
Beyond unit tests, is there a way to test in such an environment without paying a license just for tests ?
The only thing that breaks when you don’t have a license for a commercial edition is that - IIRC - server-side processing of your analysis reports is refused. Everything else works normally, I believe. And what you want to test is CI-side…
Good to know, thanks ! I’ll ask further questions here when I start working on that.
I’m having a look at the API, and at the source code of the JS and Java plugins. An example in the xoo plugin would be nice
The JS implementation seems to rely on SensorContext#canSkipUnchangedFiles, but Java doesn’t. The Javadoc of this method says:
In some situations, there is no need to analyze unchanged files, as reported by
InputFile.Status.SAME, and analyzers can skip reporting any data for those files. Plugins should be prepared for the flag to be always false in the future.
The first part of the doc makes me think that if this flag is true, and
SAME, then I can skip the analysis of this file. But what does the second part means ? Is that deprecated ?
I’ve changed a couple lines in the main sensor of my plugin to display the file status, and canSkipUnchangedFiles. The file status seems to match the files modified in the Git branch. Would that work with a different SCM ? Or does that rely on the Git plugin to flag some files to be unchanged ?
It also says that the method was introduced in 9.4. In a more general way, what is the minimum SonarQube version that is required ? And any requirement on sonar-scanner version ?
Ehm… We’re way past my depth here. Since this thread has meandered a bit, could you create a new
java plugin development thread that’s focused on the questions in your last post & I can flag that for the team?