public RuleDefinitionDto setRuleKey(RuleKey ruleKey) { this.repositoryKey = ruleKey.repository(); this.ruleKey = ruleKey.rule(); this.key = ruleKey; return this; }
@Override public ActiveRule find(RuleKey ruleKey) { return activeRulesByRepositoryAndKey.getOrDefault(ruleKey.repository(), Collections.emptyMap()) .get(ruleKey.rule()); }
@Override public DefaultExternalIssue forRule(RuleKey ruleKey) { this.engineId = ruleKey.repository(); this.ruleId = ruleKey.rule(); return this; }
RuleDefinitionDto setKey(RuleKey key) { this.key = key; setRepositoryKey(key.repository()); setRuleKey(key.rule()); return this; }
public ActiveRuleDto setKey(ActiveRuleKey key) { this.repository = key.getRuleKey().repository(); this.ruleField = key.getRuleKey().rule(); this.ruleProfileUuid = key.getRuleProfileUuid(); return this; }
public static RuleDto createFor(RuleKey key) { return new RuleDto() .setRepositoryKey(key.repository()) .setRuleKey(key.rule()); }
@Test public void parse_key_with_colons() { RuleKey key = RuleKey.parse("squid:Key:With:Some::Colons"); assertThat(key.repository()).isEqualTo("squid"); assertThat(key.rule()).isEqualTo("Key:With:Some::Colons"); }
@Test public void key_can_contain_colons() { RuleKey key = RuleKey.of("squid", "Key:With:Some::Colons"); assertThat(key.repository()).isEqualTo("squid"); assertThat(key.rule()).isEqualTo("Key:With:Some::Colons"); }
@Test public void testOf() throws Exception { RuleKey key = RuleKey.of("squid", "NullDeref"); assertThat(key.repository()).isEqualTo("squid"); assertThat(key.rule()).isEqualTo("NullDeref"); }
public static Set<SingleDeprecatedRuleKey> from(RulesDefinition.Rule rule) { return rule.deprecatedRuleKeys().stream() .map(r -> new SingleDeprecatedRuleKey() .setNewRepositoryKey(rule.repository().key()) .setNewRuleKey(rule.key()) .setOldRepositoryKey(r.repository()) .setOldRuleKey(r.rule())) .collect(MoreCollectors.toSet(rule.deprecatedRuleKeys().size())); }
@Test public void encode_and_decode_string() { RuleKey key = RuleKey.of("squid", "NullDeref"); String serialized = key.toString(); assertThat(serialized).isEqualTo("squid:NullDeref"); RuleKey parsed = RuleKey.parse(serialized); assertThat(parsed.repository()).isEqualTo("squid"); assertThat(parsed.rule()).isEqualTo("NullDeref"); assertThat(parsed.toString()).isEqualTo("squid:NullDeref"); }
@Test public void parse() { ActiveRuleKey key = ActiveRuleKey.parse("P1:xoo:R1"); assertThat(key.getRuleProfileUuid()).isEqualTo("P1"); assertThat(key.getRuleKey().repository()).isEqualTo("xoo"); assertThat(key.getRuleKey().rule()).isEqualTo("R1"); }
private static void assertRule(org.sonar.api.batch.rule.Rule r) { Rule testRule = getTestRule(); assertThat(r.name()).isEqualTo(testRule.getName()); assertThat(r.internalKey()).isEqualTo(testRule.getInternalKey()); assertThat(r.key().rule()).isEqualTo(testRule.getKey()); assertThat(r.key().repository()).isEqualTo(testRule.getRepository()); }
private static boolean noSonar(DefaultInputComponent inputComponent, Issue issue) { TextRange textRange = issue.primaryLocation().textRange(); return inputComponent.isFile() && textRange != null && ((DefaultInputFile) inputComponent).hasNoSonarAt(textRange.start().line()) && !StringUtils.containsIgnoreCase(issue.ruleKey().rule(), "nosonar"); }
private static DeprecatedRuleKeyDto deprecatedRuleKeyOf(int ruleId, RuleKey deprecatedRuleKey) { return new DeprecatedRuleKeyDto().setRuleId(ruleId) .setOldRepositoryKey(deprecatedRuleKey.repository()) .setOldRuleKey(deprecatedRuleKey.rule()); }
@Test public void ignore_not_found_rules() { ScannerReport.ActiveRule.Builder batch1 = ScannerReport.ActiveRule.newBuilder() .setRuleRepository(XOO_X1.repository()).setRuleKey(XOO_X1.rule()) .setSeverity(Constants.Severity.BLOCKER); batchReportReader.putActiveRules(asList(batch1.build())); underTest.execute(new TestComputationStepContext()); assertThat(activeRulesHolder.getAll()).isEmpty(); } }
@Test public void ignore_rules_with_status_REMOVED() { ruleRepository.add(new DumbRule(XOO_X1).setStatus(RuleStatus.REMOVED)); ScannerReport.ActiveRule.Builder batch1 = ScannerReport.ActiveRule.newBuilder() .setRuleRepository(XOO_X1.repository()).setRuleKey(XOO_X1.rule()) .setSeverity(Constants.Severity.BLOCKER); batchReportReader.putActiveRules(asList(batch1.build())); underTest.execute(new TestComputationStepContext()); assertThat(activeRulesHolder.getAll()).isEmpty(); }
private static RuleDto createABRuleDto() { RuleKey ruleKey = RuleKey.of("a", "b"); return new RuleDto() .setId(ruleKey.hashCode()) .setRepositoryKey(ruleKey.repository()) .setRuleKey(ruleKey.rule()) .setStatus(RuleStatus.REMOVED) .setType(RuleType.CODE_SMELL); }