Tabnine Logo
org.sonar.api.batch.rule.internal
Code IndexAdd Tabnine to your IDE (free)

How to use org.sonar.api.batch.rule.internal

Best Java code snippets using org.sonar.api.batch.rule.internal (Showing top 20 results out of 315)

origin: SonarSource/sonarqube

 public NewActiveRule build() {
  return new NewActiveRule(this);
 }
}
origin: SonarSource/sonarqube

 public Rules build() {
  return new DefaultRules(map.values());
 }
}
origin: SonarSource/sonarqube

 public ActiveRules build() {
  return new DefaultActiveRules(map.values());
 }
}
origin: SonarSource/sonarqube

 @Test
 public void fail_to_add_twice_the_same_rule() {
  ActiveRulesBuilder builder = new ActiveRulesBuilder();
  NewActiveRule rule = new NewActiveRule.Builder()
   .setRuleKey(RuleKey.of("squid", "S0001"))
   .build();
  builder.addRule(rule);

  thrown.expect(IllegalStateException.class);
  thrown.expectMessage("Rule 'squid:S0001' is already activated");

  builder.addRule(rule);
 }
}
origin: SonarSource/sonarqube

@Test
public void ignore_null_rule_of_active_rule() {
 ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
 activeRulesBuilder.addRule(new NewActiveRule.Builder().setRuleKey(SQUID_RULE_KEY).setQProfileKey("qp-1").build());
 initModuleIssues();
 DefaultIssue issue = new DefaultIssue(project)
  .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
  .forRule(SQUID_RULE_KEY);
 boolean added = moduleIssues.initAndAddIssue(issue);
 assertThat(added).isFalse();
 verifyZeroInteractions(reportPublisher);
}
origin: SonarSource/sonarqube

@Test
public void fail_if_field_type_is_not_supported() {
 thrown.expect(SonarException.class);
 RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithUnsupportedPropertyType");
 NewActiveRule rule = new NewActiveRule.Builder()
  .setRuleKey(ruleKey)
  .setParam("max", "300")
  .build();
 builder.addRule(rule);
 CheckFactory checkFactory = new CheckFactory(builder.build());
 checkFactory.create("squid").addAnnotatedChecks(CheckWithUnsupportedPropertyType.class);
}
origin: SonarSource/sonarqube

 private static Rules load(RulesLoader ref) {
  Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
  List<Rule> loadedRules = ref.load();
  RulesBuilder builder = new RulesBuilder();

  for (Rule r : loadedRules) {
   NewRule newRule = builder.add(RuleKey.of(r.getRepository(), r.getKey()));
   newRule.setName(r.getName());
   newRule.setInternalKey(r.getInternalKey());
  }

  profiler.stopInfo();

  return builder.build();
 }
}
origin: SonarSource/sonarqube

 @Test
 public void fail_to_add_twice_the_same_param() {
  RulesBuilder builder = new RulesBuilder();
  NewRule newRule = builder.add(RuleKey.of("squid", "S0001"));
  newRule.addParam("min");
  newRule.addParam("max");

  thrown.expect(IllegalStateException.class);
  thrown.expectMessage("Parameter 'min' already exists on rule 'squid:S0001'");

  newRule.addParam("min");
 }
}
origin: SonarSource/sonarqube

@Test
public void fail_to_add_twice_the_same_rule() {
 RulesBuilder builder = new RulesBuilder();
 builder.add(RuleKey.of("squid", "S0001"));
 thrown.expect(IllegalStateException.class);
 thrown.expectMessage("Rule 'squid:S0001' already exists");
 builder.add(RuleKey.of("squid", "S0001"));
}
origin: SonarSource/sonarqube

/**
 * Every rules and active rules has to be added in builders before creating IssuePublisher
 */
private void initModuleIssues() {
 moduleIssues = new IssuePublisher(activeRulesBuilder.build(), filters, reportPublisher);
}
origin: SonarSource/sonarqube

 private NewRule createRule(String key, String repo, String internalKey) {
  RuleKey ruleKey = RuleKey.of(repo, key);
  NewRule newRule = new NewRule(ruleKey);
  newRule.setInternalKey(internalKey);
  
  return newRule;
 }
}
origin: SonarSource/sonarqube

@Test
public void testRepeatedInternalKey() {
 List<NewRule> newRules = new LinkedList<>();
 newRules.add(createRule("key1", "repo", "internal"));
 newRules.add(createRule("key2", "repo", "internal"));
 
 DefaultRules rules = new DefaultRules(newRules);
 assertThat(rules.findByInternalKey("repo", "internal")).hasSize(2);
 assertThat(rules.find(RuleKey.of("repo", "key1"))).isNotNull();
 assertThat(rules.find(RuleKey.of("repo", "key2"))).isNotNull();
 assertThat(rules.findByRepository("repo")).hasSize(2);
}

origin: SonarSource/sonarqube

@Test
public void testRepeatedRule() {
 List<NewRule> newRules = new LinkedList<>();
 newRules.add(createRule("key", "repo", "internal"));
 newRules.add(createRule("key", "repo", "internal"));
 
 DefaultRules rules = new DefaultRules(newRules);
 assertThat(rules.find(RuleKey.of("repo", "key"))).isNotNull();
}

origin: SonarSource/sonarqube

@Before
public void setBuilder() {
 builder = new NewActiveRule.Builder();
}
origin: SonarSource/sonarqube

public NewRule add(RuleKey key) {
 if (map.containsKey(key)) {
  throw new IllegalStateException(String.format("Rule '%s' already exists", key));
 }
 NewRule newRule = new NewRule(key);
 map.put(key, newRule);
 return newRule;
}
origin: SonarSource/sonarqube

 public NewRuleParam addParam(String paramKey) {
  if (params.containsKey(paramKey)) {
   throw new IllegalStateException(String.format("Parameter '%s' already exists on rule '%s'", paramKey, key));
  }
  NewRuleParam param = new NewRuleParam(paramKey);
  params.put(paramKey, param);
  return param;
 }
}
origin: SonarSource/sonarqube

@Test
public void testActiveRules() {
 NewActiveRule activeRule = new NewActiveRule.Builder()
  .setRuleKey(RuleKey.of("foo", "bar"))
  .build();
 ActiveRules activeRules = new ActiveRulesBuilder().addRule(activeRule).build();
 tester.setActiveRules(activeRules);
 assertThat(tester.activeRules().findAll()).hasSize(1);
}
origin: SonarSource/sonarqube

@Test
public void should_ignore_lines_commented_with_nosonar() {
 ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
 activeRulesBuilder.addRule(new NewActiveRule.Builder()
  .setRuleKey(SQUID_RULE_KEY)
  .setSeverity(Severity.INFO)
  .setQProfileKey("qp-1")
  .build());
 initModuleIssues();
 DefaultIssue issue = new DefaultIssue(project)
  .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message(""))
  .forRule(SQUID_RULE_KEY);
 file.noSonarAt(new HashSet<>(Collections.singletonList(3)));
 boolean added = moduleIssues.initAndAddIssue(issue);
 assertThat(added).isFalse();
 verifyZeroInteractions(reportPublisher);
}
origin: SonarSource/sonarqube

@Test
public void fail_if_missing_field() {
 thrown.expect(IllegalStateException.class);
 thrown.expectMessage("The field 'unknown' does not exist or is not annotated with @RuleProperty in the class org.sonar.api.batch.rule.CheckWithStringProperty");
 RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithStringProperty");
 NewActiveRule rule = new NewActiveRule.Builder()
  .setRuleKey(ruleKey)
  .setParam("unknown", "foo")
  .build();
 builder.addRule(rule);
 CheckFactory checkFactory = new CheckFactory(builder.build());
 checkFactory.create("squid").addAnnotatedChecks(CheckWithStringProperty.class);
}
origin: SonarSource/sonarqube

@Test
public void testNonExistingKey() {
 List<NewRule> newRules = new LinkedList<>();
 newRules.add(createRule("key1", "repo", "internal"));
 newRules.add(createRule("key2", "repo", "internal"));
 
 DefaultRules rules = new DefaultRules(newRules);
 assertThat(rules.findByInternalKey("xx", "xx")).hasSize(0);
 assertThat(rules.find(RuleKey.of("xxx", "xx"))).isNull();
 assertThat(rules.findByRepository("xxxx")).hasSize(0);
}

org.sonar.api.batch.rule.internal

Most used classes

  • ActiveRulesBuilder
    Builds instances of org.sonar.api.batch.rule.ActiveRules.For unit testing and internal use only.
  • NewRule
  • NewActiveRule
  • RulesBuilder
    For unit testing and internal use only.
  • DefaultActiveRule
  • DefaultRule,
  • NewActiveRule$Builder,
  • DefaultActiveRules,
  • DefaultRules,
  • DefaultRuleParam,
  • DefaultRulesTest
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now