-
Notifications
You must be signed in to change notification settings - Fork 721
SONARJAVA-6205 Add an agentic focused quality profile for Java #5531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
31312fc
472d1cc
35e7ca4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * SonarQube Java | ||
| * Copyright (C) 2012-2025 SonarSource Sàrl | ||
| * mailto:info AT sonarsource DOT com | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| * See the Sonar Source-Available License for more details. | ||
| * | ||
| * You should have received a copy of the Sonar Source-Available License | ||
| * along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
| */ | ||
| package org.sonar.plugins.java; | ||
|
|
||
| import java.util.Set; | ||
| import javax.annotation.Nullable; | ||
| import org.sonar.api.rule.RuleKey; | ||
| import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; | ||
| import org.sonar.plugins.java.api.ProfileRegistrar; | ||
| import org.sonarsource.api.sonarlint.SonarLintSide; | ||
|
|
||
| @SonarLintSide | ||
| public class JavaAgenticWayProfile implements BuiltInQualityProfilesDefinition { | ||
| private final ProfileRegistrar[] profileRegistrars; | ||
|
|
||
| /** | ||
| * Constructor used by Pico container (SC) when no ProfileRegistrar are available | ||
| */ | ||
| public JavaAgenticWayProfile() { | ||
| this(null); | ||
| } | ||
|
|
||
| public JavaAgenticWayProfile(@Nullable ProfileRegistrar[] profileRegistrars) { | ||
| this.profileRegistrars = profileRegistrars; | ||
| } | ||
|
|
||
| @Override | ||
| 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", | ||
| this.profileRegistrars | ||
| ); | ||
|
|
||
| ruleKeys.forEach(ruleKey -> agenticWay.activateRule(ruleKey.repository(), ruleKey.rule())); | ||
| agenticWay.done(); | ||
| } | ||
|
Comment on lines
+49
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines and the creation of 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();
}
} |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * SonarQube Java | ||
| * Copyright (C) 2012-2025 SonarSource Sàrl | ||
| * mailto:info AT sonarsource DOT com | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| * See the Sonar Source-Available License for more details. | ||
| * | ||
| * You should have received a copy of the Sonar Source-Available License | ||
| * along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
| */ | ||
| package org.sonar.plugins.java; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
| import javax.annotation.Nullable; | ||
| import org.sonar.api.rule.RuleKey; | ||
| import org.sonar.java.GeneratedCheckList; | ||
| import org.sonar.plugins.java.api.ProfileRegistrar; | ||
| import org.sonarsource.analyzer.commons.BuiltInQualityProfileJsonLoader; | ||
|
|
||
| class QualityProfileUtils { | ||
| private QualityProfileUtils() { | ||
| /* This utility class should not be instantiated */ | ||
| } | ||
|
|
||
| static Set<RuleKey> registerRulesFromJson( | ||
| String pathToJsonProfile, | ||
| @Nullable ProfileRegistrar[] profileRegistrars) { | ||
|
|
||
| Set<RuleKey> ruleKeys = new HashSet<>(loadRuleKeys(pathToJsonProfile)); | ||
| if (profileRegistrars != null) { | ||
| for (ProfileRegistrar profileRegistrar : profileRegistrars) { | ||
| profileRegistrar.register(ruleKeys::addAll); | ||
| } | ||
|
Comment on lines
+39
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? |
||
| } | ||
|
|
||
| return ruleKeys; | ||
| } | ||
|
|
||
| static Set<RuleKey> loadRuleKeys(final String pathToJsonProfile) { | ||
| return BuiltInQualityProfileJsonLoader.loadActiveKeysFromJsonProfile(pathToJsonProfile).stream() | ||
| .map(rule -> RuleKey.of(GeneratedCheckList.REPOSITORY_KEY, rule)) | ||
| .collect(Collectors.toSet()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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_PATHlikeSONAR_WAY_PATHinJavaSonarWayProfile