Repository navigation
SONARJAVA-7253 Do not run Spring context collection in SonarLint or in projects without Spring dependencies - #6423
Conversation
…out Spring dependencies
asya-vorobeva
left a comment
There was a problem hiding this comment.
Also makes sense to clarify with user inhttps://community.sonarsource.com/t/sonarqube-for-ide-creates-sonar-spring-context-model-json-in-every-analyzed-module-in-eclipse/190547/6 how they analyze the project and understand why multiple files are created.
| } | ||
| SonarComponents components = createSonarComponentsMock(context); | ||
| if (sonarLint) { | ||
| when(components.getJavaClasspath()).thenReturn(TestClasspathUtils.DEFAULT_MODULE.getClassPath()); |
There was a problem hiding this comment.
Let's do it in the same block as context.setRuntime(TestSonarRuntime.forSonarLint...)
| void spring_context_model_is_reported_as_telemetry() { | ||
| var project = analyzeProject(Path.of("ambiguous-dependencies-should-be-resolved"), "S9352").getProject(); | ||
|
|
||
| assertThat(projectBaseDir.resolve(".sonar/spring-context-model.json")).exists(); |
There was a problem hiding this comment.
Let's also add checks that such files aren't created for sub-modules.
Yes, I've asked for more details here. |
Code Review ✅ Approved🟡 Medium risk · Gating Spring context collection on detected dependencies and product could omit context-based findings or saved models when Spring dependencies are missed. Gates Spring context collection so it only runs outside SonarLint and in projects with Spring dependencies, moving Verification Rules 1/1 met PRs 2 inspectedFunctional validation No results Rules 1 passed 2 not applicable
Broader impact PRs 2 inspectedCross-PR 2 PRs inspected 0 open impacts
Auto-approval Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|




Summary by Gitar
SpringContextModelSensorto run afterJavaSensor, skipping execution in SonarLint or when collection is disabledhasSpringDependencyintoSpringContextModelGatherersand reused it from gatherersJavaSensormain checks at analysis time instead of being registered in its constructorThis will update automatically on new commits.