|
| 1 | +/* |
| 2 | + * SonarQube Java |
| 3 | + * Copyright (C) 2012-2025 SonarSource Sàrl |
| 4 | + * mailto:info AT sonarsource DOT com |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | + * See the Sonar Source-Available License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the Sonar Source-Available License |
| 15 | + * along with this program; if not, see https://sonarsource.com/license/ssal/ |
| 16 | + */ |
| 17 | +package org.sonar.plugins.java; |
| 18 | + |
| 19 | +import java.util.HashSet; |
| 20 | +import java.util.Set; |
| 21 | +import java.util.stream.Collectors; |
| 22 | +import javax.annotation.Nullable; |
| 23 | +import org.sonar.api.rule.RuleKey; |
| 24 | +import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; |
| 25 | +import org.sonar.java.GeneratedCheckList; |
| 26 | +import org.sonar.plugins.java.api.ProfileRegistrar; |
| 27 | +import org.sonarsource.analyzer.commons.BuiltInQualityProfileJsonLoader; |
| 28 | +import org.sonarsource.api.sonarlint.SonarLintSide; |
| 29 | + |
| 30 | +@SonarLintSide |
| 31 | +public class JavaAgenticWayProfile implements BuiltInQualityProfilesDefinition { |
| 32 | + private static final String AGENTIC_WAY_PATH = "/org/sonar/l10n/java/rules/java/Agentic_way_profile.json"; |
| 33 | + |
| 34 | + private final ProfileRegistrar[] profileRegistrars; |
| 35 | + |
| 36 | + /** |
| 37 | + * Constructor used by Pico container (SC) when no ProfileRegistrar are available |
| 38 | + */ |
| 39 | + public JavaAgenticWayProfile() { |
| 40 | + this(null); |
| 41 | + } |
| 42 | + |
| 43 | + public JavaAgenticWayProfile(@Nullable ProfileRegistrar[] profileRegistrars) { |
| 44 | + this.profileRegistrars = profileRegistrars; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public void define(Context context) { |
| 49 | + NewBuiltInQualityProfile agenticWay = context.createBuiltInQualityProfile("Agentic way", Java.KEY); |
| 50 | + Set<RuleKey> ruleKeys = new HashSet<>(sonarJavaAgenticWayRuleKeys()); |
| 51 | + if (profileRegistrars != null) { |
| 52 | + for (ProfileRegistrar profileRegistrar : profileRegistrars) { |
| 53 | + profileRegistrar.register(ruleKeys::addAll); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + ruleKeys.forEach(ruleKey -> agenticWay.activateRule(ruleKey.repository(), ruleKey.rule())); |
| 58 | + agenticWay.done(); |
| 59 | + } |
| 60 | + |
| 61 | + static Set<RuleKey> sonarJavaAgenticWayRuleKeys() { |
| 62 | + return BuiltInQualityProfileJsonLoader.loadActiveKeysFromJsonProfile(AGENTIC_WAY_PATH).stream() |
| 63 | + .map(rule -> RuleKey.of(GeneratedCheckList.REPOSITORY_KEY, rule)) |
| 64 | + .collect(Collectors.toSet()); |
| 65 | + } |
| 66 | +} |
0 commit comments