Skip to content

SONARJAVA-6854 Externalize ruling test project definitions to JSON - #6041

Open
romainbrenguier wants to merge 3 commits into
masterfrom
romain/project-mapping
Open

SONARJAVA-6854 Externalize ruling test project definitions to JSON#6041
romainbrenguier wants to merge 3 commits into
masterfrom
romain/project-mapping

Conversation

@romainbrenguier

Copy link
Copy Markdown
Contributor

Summary

This change externalizes the hardcoded project name-to-path mappings from JavaRulingTest into a JSON resource file.

Benefits

  • Single source of truth: Project definitions are now in one place
  • External tool support: External tools can discover available projects by reading the JSON file
  • Type safety: RulingProject record provides compile-time type checking
  • Centralized assertions: requireProject() method combines lookup with assertion

Changes

  • Added ruling-projects.json with all 12 project configurations
  • Added RulingProject record with Gson annotations for JSON serialization
  • Added ProjectConfigLoader utility with findByProjectName() and requireProject() methods
  • Updated JavaRulingTest to use the new loader
  • Added unit tests for the new loader classes

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Externalize ruling test project definitions to JSON SONARJAVA-6854 Externalize ruling test project definitions to JSON Aug 25, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

SONARJAVA-6854

- Add ruling-projects.json with project name-to-path mappings
- Add RulingProject record for type-safe access
- Add ProjectConfigLoader utility with requireProject() method
- Update JavaRulingTest to use centralized project definitions
- Add unit tests for ProjectConfigLoader
@datadog-sonarsource

This comment has been minimized.

Comment thread its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java
Comment thread its/ruling/src/test/java/org/sonar/java/it/ProjectConfigLoader.java
gitar-bot[bot]

This comment was marked as resolved.

Pass project.path() to the 3-arg test_project() in executeMavenBuild() so
that projects with a path different from their name (e.g. sonar-server under
sonarqube-6.5/server) resolve the correct pom.xml location.

In ProjectConfigLoader.loadProjects(), replace Objects.requireNonNull with
an explicit null check that throws IllegalStateException, and catch
JsonParseException alongside IOException for consistent error handling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gitar-bot
gitar-bot Bot dismissed their stale review August 26, 2026 07:00

✅ All code review findings resolved.

Configure merge blocking

…te issue

The test_project method was concatenating path + projectName, causing
doubled paths (e.g. sources/guava/guava/pom.xml) when they are identical.
Changed to use path as the full directory when provided. Updated
sonar-server's JSON path to include the projectName subdirectory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gitar-bot

gitar-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 resolved / 2 findings

Externalizes ruling test project definitions to a JSON configuration file and introduces the RulingProject record for improved type safety. Addressed the wrong pom path resolution and outdated javadoc during the review.

✅ 2 resolved
Bug: sonarqube_server now resolves the wrong pom path, breaking the test

📄 its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java:383-386 📄 its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java:425-436 📄 its/ruling/src/test/resources/ruling-projects.json:50-55
sonarqube_server previously called the 3-arg test_project("org.sonarsource.sonarqube:sonar-server", "sonarqube-6.5/server", "sonar-server"), producing pom location ../sources/sonarqube-6.5/server/sonar-server/pom.xml. The new executeMavenBuild only calls the 2-arg test_project(projectKey, projectName), which resolves ../sources/sonar-server/pom.xml — a path that does not exist in the its/sources submodule — so the Maven build fails and the only-sonarqube-project CI job (build.yml matrix) fails with "Build failure for project: sonar-server". Note also that path in the JSON is inconsistent between entries (a parent prefix for sonar-server, the full source directory everywhere else, and used as "../sources/" + path in jboss_ejb3_tutorial), and executeMavenBuild ignores path entirely; make path uniformly the full directory under ../sources and have executeMavenBuild use it.

Quality: loadProjects() javadoc contradicts the exceptions it actually throws

📄 its/ruling/src/test/java/org/sonar/java/it/ProjectConfigLoader.java:46-60
The javadoc states @throws IllegalStateException if the resource cannot be found or parsed, but a missing resource throws NullPointerException from Objects.requireNonNull and a malformed JSON file throws Gson's JsonSyntaxException; only the (practically unreachable) IOException from close() is wrapped. Wrap both cases in IllegalStateException so failures surface with the documented type and message.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

Copy link
Copy Markdown
Contributor

@romainbrenguier
romainbrenguier marked this pull request as ready for review August 26, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant