Skip to content

SONARJAVA-6205 Add an agentic focused quality profile for Java#5531

Open
dorian-burihabwa-sonarsource wants to merge 3 commits intomasterfrom
SONARJAVA-6205
Open

SONARJAVA-6205 Add an agentic focused quality profile for Java#5531
dorian-burihabwa-sonarsource wants to merge 3 commits intomasterfrom
SONARJAVA-6205

Conversation

@dorian-burihabwa-sonarsource
Copy link
Contributor

No description provided.

@hashicorp-vault-sonar-prod
Copy link
Contributor

hashicorp-vault-sonar-prod bot commented Mar 20, 2026

SONARJAVA-6205

@dorian-burihabwa-sonarsource dorian-burihabwa-sonarsource force-pushed the SONARJAVA-6205 branch 2 times, most recently from 37eb8d7 to 0dab089 Compare March 20, 2026 15:29
@dorian-burihabwa-sonarsource dorian-burihabwa-sonarsource marked this pull request as ready for review March 20, 2026 15:56
@sonar-review-alpha
Copy link

sonar-review-alpha bot commented Mar 20, 2026

Summary

This PR introduces a new "AI Quality Profile" for Java code analysis that activates 467 specific rules, complementing the existing Sonar Way profile. The profile is designed for agentic/AI-focused quality checks and explicitly excludes 36 other rules.

The changes also refactor shared quality profile logic into a reusable utility class (QualityProfileUtils) to eliminate duplication between the existing JavaSonarWayProfile and the new JavaAgenticWayProfile. A commons-csv dependency is added to support test utilities for regenerating the profile from CSV inputs.

What reviewers should know

Where to start: Look at the new JavaAgenticWayProfile class first — it's straightforward and follows the same pattern as the existing JavaSonarWayProfile. Then review QualityProfileUtils to understand what logic was extracted.

Key points for review:

  • The JSON file Agentic_way_profile.json contains the actual rule list (467 rules) — verify these are appropriate for the AI-focused use case
  • The test method profile_is_registered_as_expected() explicitly checks that 36 specific rules are excluded (S100, S110, etc.) — confirm this list is intentional
  • The refactoring of JavaSonarWayProfile is purely mechanical (extract-replace) and shouldn't change behavior — verify the sonarJavaSonarWayRuleKeys() method still works the same
  • The disabled test method generate_ai_quality_profile() documents how to regenerate the profile from CSV — this is tooling, not production code
  • The commons-csv dependency is only used in the disabled test method; if you want production code only, this dependency could be test-only or removed

No architectural surprises: Registration in JavaPlugin is straightforward; test assertion counts were updated correctly (36→37, 37→38).


  • Generate Walkthrough
  • Generate Diagram

🗣️ Give feedback

Copy link

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conclusion

Clean, well-structured PR. The QualityProfileUtils extraction is the right call — it removes real duplication between the two profile classes and makes future profiles trivial to add.

🗣️ Give feedback

@rombirli rombirli self-requested a review March 23, 2026 06:52
Copy link
Contributor

@rombirli rombirli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I just have two questions about external rules inclusion mechanism and the purpose of profileRegistrars

Comment on lines +39 to +41
for (ProfileRegistrar profileRegistrar : profileRegistrars) {
profileRegistrar.register(ruleKeys::addAll);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In test JavaAgenticWayProfileTest, profileRegistrars is always null and this part is never covered, is there a reason ?

public void define(Context context) {
NewBuiltInQualityProfile agenticWay = context.createBuiltInQualityProfile("AI Quality Profile", Java.KEY);
Set<RuleKey> ruleKeys = QualityProfileUtils.registerRulesFromJson(
"/org/sonar/l10n/java/rules/java/Agentic_way_profile.json",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string constant could be extracted in a constant SONAR_AGENTIC_WAY_PATH like SONAR_WAY_PATH in JavaSonarWayProfile

Comment on lines +49 to +51
ruleKeys.forEach(ruleKey -> agenticWay.activateRule(ruleKey.repository(), ruleKey.rule()));
agenticWay.done();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines and the creation of agenticWay (or sonarWay) are repeated in JavaSonarWayProfile, maybe it could be refactored in QualityProfileUtils

static void createQualityProfile(String title, Set<RuleKey> ruleKeys) {
  NewBuiltInQualityProfile way = context.createBuiltInQualityProfile(title, Java.KEY);
  ruleKeys.forEach(ruleKey -> way.activateRule(ruleKey.repository(), ruleKey.rule()));
    way.done();
  }
}

Comment on lines 76 to 78
if (ruleKeys.stream().noneMatch(rule -> SECURITY_REPOSITORY_KEY.equals(rule.repository()))) {
ruleKeys.addAll(getSecurityRuleKeys());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this mechanism to include external rules is not present in JavaAgenticWayProfile? (Why the implementations diverge? Is there a justification?)

Copy link
Contributor

@rombirli rombirli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agentic_way_profile.json seems to be wrong

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file auto-generated from the CSV with a script? Could we add the script to the repo? It seems to be wrong!
S100 shouldn't be included according to the spreadsheet.

Image

@sonarqube-next
Copy link

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.

2 participants