JavaSonarWayProfile implements BuiltInQualityProfilesDefinition { @Override public void define(Context context) { NewBuiltInQualityProfile sonarWay = context.createBuiltInQualityProfile("Sonar way", Java.KEY); sonarWay.activateRule("common-" + Java.KEY, "DuplicatedBlocks"); Profile jsonProfile = readProfile(); Map<String, String> keys = legacyKeys(); for (String key : jsonProfile.ruleKeys) { sonarWay.activateRule(CheckList.REPOSITORY_KEY, keys.get(key)); } getSecurityRuleKeys(isSonarSecurityBefore78()).forEach(key -> sonarWay.activateRule(key.repository(), key.rule())); sonarWay.done(); }  @Override void define(Context context);  }
@Test void should_create_sonar_way_profile() { ValidationMessages validation = ValidationMessages.create(); JavaSonarWayProfile profileDef = new JavaSonarWayProfile(); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); profileDef.define(context); BuiltInQualityProfilesDefinition.BuiltInQualityProfile profile = context.profile("java", "Sonar way"); assertThat(profile.language()).isEqualTo(Java.KEY); List<BuiltInQualityProfilesDefinition.BuiltInActiveRule> activeRules = profile.rules(); assertThat(activeRules.stream().filter(r -> r.repoKey().equals("common-java"))).hasSize(1); assertThat(activeRules.size()).as("Expected number of rules in profile").isGreaterThanOrEqualTo(268); assertThat(profile.name()).isEqualTo("Sonar way"); Set<String> keys = new HashSet<>(); for (BuiltInQualityProfilesDefinition.BuiltInActiveRule activeRule : activeRules) { keys.add(activeRule.ruleKey()); } assertThat(keys.contains("S00116")).isFalse(); assertThat(keys).contains("S116"); assertThat(validation.hasErrors()).isFalse(); assertThat(activeRules.get(0).overriddenSeverity()).isNull(); }
@Test void should_activate_hotspots_when_supported() { JavaSonarWayProfile profileDef = new JavaSonarWayProfile(); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); profileDef.define(context); BuiltInQualityProfilesDefinition.BuiltInQualityProfile profile = context.profile("java", "Sonar way"); BuiltInQualityProfilesDefinition.BuiltInActiveRule rule = profile.rule(RuleKey.of("java", "S2092")); assertThat(rule).isNotNull(); }