PHPProfileDefinition implements BuiltInQualityProfilesDefinition { @Override public void define(Context context) { NewBuiltInQualityProfile sonarWay = context.createBuiltInQualityProfile(SONAR_WAY_PROFILE, Php.KEY); sonarWay.activateRule("common-" + Php.KEY, "DuplicatedBlocks"); BuiltInQualityProfileJsonLoader.load(sonarWay, CheckList.REPOSITORY_KEY, SONAR_WAY_PATH, RESOURCE_BASE_PATH, sonarRuntime); getSecurityRuleKeys().forEach(key -> sonarWay.activateRule(key.repository(), key.rule())); sonarWay.done(); } PHPProfileDefinition(SonarRuntime sonarRuntime); @Override void define(Context context); static final String SONAR_WAY_PROFILE; static final String SONAR_WAY_PATH; }
@Test public void should_create_sonar_way_profile() { ValidationMessages validation = ValidationMessages.create(); SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(7, 3), SonarQubeSide.SERVER, SonarEdition.COMMUNITY); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); PHPProfileDefinition definition = new PHPProfileDefinition(sonarRuntime); definition.define(context); BuiltInQualityProfilesDefinition.BuiltInQualityProfile profile = context.profile("php", "Sonar way"); assertThat(profile.language()).isEqualTo(Php.KEY); assertThat(profile.name()).isEqualTo(PHPProfileDefinition.SONAR_WAY_PROFILE); assertThat(profile.rules().size()).isGreaterThan(50); assertThat(profile.rules().size()).isLessThan(CheckList.getAllChecks().size()); assertThat(profile.rules()).extracting("ruleKey").contains("DuplicatedBlocks"); assertThat(validation.hasErrors()).isFalse(); }