JS-1764 Re-enable rspec-maven-plugin for rule data generation#7059
JS-1764 Re-enable rspec-maven-plugin for rule data generation#7059zglicz wants to merge 13 commits into
Conversation
Ruling Report✅ No changes to ruling expected issues in this PR |
Agentic Analysis: Early ResultsAgentic Analysis and Context Augmentation are available on your project. Here are some issues that could have been prevented. Follow the links to learn how to put them into action. 1 issue(s) found across 1 file(s):
Analyzed by SonarQube Agentic Analysis in 2.2 s |
SummaryThis PR replaces the Node-based RSPEC sync path with Maven-backed rule data generation. Key changes: Generation orchestration: New Maven integration: The CI efficiency: Workflow refactored from per-job RSPEC sync to a centralized Removed: Old Local developer experience: Developers must now set What reviewers should knowStart here: Look at Understand the Maven profiles: In Workflow refactoring: Artifact layout: The uploaded artifact is structured as Validation to spot-check: The author's validation steps in the description cover the main scenarios—clean regeneration, prepared-data reuse, and downstream Maven reuse. These are good regression tests. Known gotcha: Each commit gets its own artifact via Breaking change for developers:
|
4c45ba5 to
abe6bdc
Compare
|
vdiez
left a comment
There was a problem hiding this comment.
I dug into why sync-rspec.ts existed on master, and I do not think this PR is functionally equivalent yet for local developer workflows.
Historical context first.
The TypeScript sync-rspec.ts tooling was introduced in PR #6492 (commit c164606ee45891c9174946437d97db99a5b325e3). The point of that change was not just to move logic around. It was added specifically to replace the rspec-maven-plugin path because the Maven flow was not robust enough for day-to-day development:
- it depended on
sonar-rule-apiauth behavior that requiredGITHUB_TOKENin the environment; - it was not as straightforward to run on developer machines as the existing Node-based workflow;
- SonarJS wanted the generated rule-data that feeds JS/TS builds to be reproducible locally with the normal repo tooling, without special Maven/plugin auth setup.
That history matters here, because the bar for removing sync-rspec.ts is not only “the build passes in CI” or “the generated files look mostly the same”. The replacement also needs to preserve the developer ergonomics we had on master: on a clean machine/worktree, a developer should be able to regenerate the RSPEC-derived outputs with the normal build flow as easily as before.
I tested that explicitly.
On this branch, using a clean worktree, npm ci + npm run bbf does regenerate the expected outputs, and the repository shape is aligned with the intended direction:
- RSPEC JSON/HTML and
rspec.shaare generated at build time and are not git-tracked; generated-meta.tsfiles are generated at build time and are not git-tracked;- generated Java check classes are generated at build time and are not git-tracked.
So the repository-layout goal is mostly correct.
However, there is still one important regression compared to master: if I delete the generated RSPEC outputs in a clean worktree and run the generation flow without exporting GITHUB_TOKEN, the Maven path fails. In practice that means the replacement is still not as easy to run on dev machines as the sync-rspec.ts flow it is removing.
The reason is upstream:
rspec-maven-pluginstill does not accept any explicit GitHub auth parameter. The plugin currently only exposesruleSubdirectory,targetDirectory, andvcsBranchName, and then constructsGitHubRuleMaker.create(branch)internally.- The released plugin version used here (
1.3.0.46) depends onsonar-rule-api2.18.0.5734, whereGitHubRuleMakeronly looks atSystem.getenv(GITHUB_TOKEN). - Even on current
sonar-rule-apimaster, whileGitHubRuleMakernow falls back togh auth token,CoverageLoaderstill hard-requiresGITHUB_TOKENfrom the environment.
So even if SonarJS switches back to the Maven-based generation flow, we are still missing the pieces needed to make that flow dev-machine-friendly in the same way master was.
For me, the minimum bar for functional equivalence is:
- a clean checkout/worktree can regenerate the RSPEC-derived outputs without requiring contributors to pre-export
GITHUB_TOKENin their shell; - the build can use existing developer auth state (for example
gh auth login) or an explicit parameter, instead of only ambient environment variables; - the generated HTML/JSON output matches the current TypeScript flow closely enough that we do not introduce content regressions.
Concretely, I think this means the upstream work is still required before SonarJS can safely remove sync-rspec.ts:
- In
sonar-rule-api, introduce a shared token resolution mechanism used everywhere GitHub access happens.
Precedence should be something like: explicit token parameter ->GITHUB_TOKENenv var ->gh auth token. - In
sonar-rule-api, expose APIs that allow callers to pass the token explicitly instead of forcing env lookup internally (for exampleGitHubRuleMaker.create(branch, token)and a correspondingCoverageLoaderconstructor/entry point). - In
rspec-maven-plugin, expose an optional auth parameter (or Maven settings-based credential lookup) and pass it explicitly tosonar-rule-api. - After that, SonarJS can bump to the new plugin/rule-api versions and keep this PR’s general repository policy: generated RSPEC outputs, generated TS meta, and generated Java checks should all be build-time artifacts and not be tracked in git.
There is also one output-level issue worth addressing before we treat the Maven flow as a drop-in replacement: I found a real HTML rendering delta on S7724.html where the generated output contains stray <strong> markup around the phrase after /* eslint-disable */. The JSON differences I saw were only ordering/newline noise, but this HTML difference looks substantive.
So my conclusion is:
- the repository cleanup direction in this PR is good;
- but the TypeScript
sync-rspec.tstooling was originally added for a concrete developer-workflow reason, not just implementation preference; - and we have not fully closed that gap yet, because the Maven path still depends on
GITHUB_TOKENbeing exported in the environment in scenarios wheremasterwas easier to use.
I would be comfortable with this switch once the Maven/plugin/rule-api stack is updated so that local generation works smoothly on developer machines without requiring manual env-token setup, and once the HTML rendering delta is understood/fixed.





Summary
rspec-maven-pluginfor JS/CSS rule-data generation and makenpm run generate-metainvoke the Maven-backed RSPEC refresh only when the generated JS/CSS outputs orrspec.shaare missingsync-rspecHTML/JSON generation path and drop the now-unused@asciidoctor/coredependencymvn installreuses them andmvn clean installrefreshes themsonar-plugin/, because the uploaded zip strips that leading path and needs to be re-expanded there to recreatesonar-plugin/javascript-checks/...andsonar-plugin/css/...generate-rule-data:mavenbootstrapsonar-plugin/apifirst, then run thejavascript-checkslifecycle with RSPEC generation enableddeploy-rule-datapublishsonar-plugin/javascript-checks/src/main/resources/rspec.shafrom the rule-api cache clone so the prepared artifact is completesonar-plugin/javascript-checks/src/main/resources/rspec.shain the prepared artifact and makecleanremove the generated JS/CSS plugin resource copies as part of the refresh pathValidation
rm -rf sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript sonar-plugin/css/src/main/resources/org/sonar/l10n/css/rules/css sonar-plugin/javascript-checks/src/main/resources/rspec.sha resources/rule-data sonar-plugin/javascript-checks/targetGITHUB_TOKEN="$(gh auth token 2>/dev/null)" npm run generate-rule-data:mavensonar-plugin/javascript-checks/src/main/resources/rspec.shaenv -u GITHUB_TOKEN npm run generate-metagenerate-meta:rawenv -u GITHUB_TOKEN mvn -B -ntp -pl sonar-plugin/sonar-javascript-plugin -am -DskipTests packagegenerate-rspec,generate-rule-data,deploy-rule-data, ororg.sonarsource.rspecexecutions in the Maven logorg/sonar/l10n/javascript/rules/javascript/**,org/sonar/l10n/css/rules/css/**, andrspec.sha531JS json,528JS html,32CSS json,30CSS htmlsonar-plugin/recreates the expectedsonar-plugin/javascript-checks/...,sonar-plugin/css/..., andsonar-plugin/javascript-checks/src/main/resources/rspec.shapaths.github/workflows/build.ymlsuccessfully after the workflow refactorNotes
rule-apidid not need a companion change for this branch; the current plugin already readsGITHUB_TOKENmvn clean, local RSPEC refresh still needsGITHUB_TOKENQA on Windows (2)around.github/workflows/build.ymlline931/fromJSON(...licenses_token); that also reproduces onmaster