Tabnine Logo
RulesBuilder
Code IndexAdd Tabnine to your IDE (free)

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

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

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 no_rules() {
 RulesBuilder builder = new RulesBuilder();
 Rules rules = builder.build();
 assertThat(rules.findAll()).isEmpty();
}
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

@Test
public void use_severity_from_active_rule_if_no_severity_on_issue() {
 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("Foo"))
  .forRule(SQUID_RULE_KEY);
 when(filters.accept(any(InputComponent.class), any(ScannerReport.Issue.class))).thenReturn(true);
 moduleIssues.initAndAddIssue(issue);
 ArgumentCaptor<ScannerReport.Issue> argument = ArgumentCaptor.forClass(ScannerReport.Issue.class);
 verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.scannerId()), argument.capture());
 assertThat(argument.getValue().getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.INFO);
}
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 add_external_issue_to_cache() {
 ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
 initModuleIssues();
 DefaultExternalIssue issue = new DefaultExternalIssue(project)
  .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
  .type(RuleType.BUG)
  .forRule(SQUID_RULE_KEY)
  .severity(org.sonar.api.batch.rule.Severity.CRITICAL);
 moduleIssues.initAndAddExternalIssue(issue);
 ArgumentCaptor<ScannerReport.ExternalIssue> argument = ArgumentCaptor.forClass(ScannerReport.ExternalIssue.class);
 verify(reportPublisher.getWriter()).appendComponentExternalIssue(eq(file.scannerId()), argument.capture());
 assertThat(argument.getValue().getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.CRITICAL);
}
origin: SonarSource/sonarqube

@Before
public void before() throws Exception {
 moduleHierarchy = mock(InputModuleHierarchy.class);
 File projectBaseDir = temp.newFolder();
 fs = new DefaultFileSystem(projectBaseDir.toPath());
 SIMPLE_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+02:00"));
 when(server.getVersion()).thenReturn("3.6");
 ProjectDefinition def = ProjectDefinition.create().setBaseDir(projectBaseDir).setWorkDir(temp.newFolder()).setKey("struts");
 DefaultInputProject project = new DefaultInputProject(def, 1);
 InputComponentStore inputComponentStore = new InputComponentStore(mock(BranchConfiguration.class));
 DefaultInputFile inputFile = new TestInputFileBuilder("struts", "src/main/java/org/apache/struts/Action.java")
  .setModuleBaseDir(projectBaseDir.toPath()).build();
 inputFile.setStatus(InputFile.Status.CHANGED);
 inputFile.setPublished(true);
 inputComponentStore.put("struts", inputFile);
 RulesBuilder builder = new RulesBuilder();
 builder.add(RuleKey.of("squid", "AvoidCycles")).setName("Avoid Cycles");
 rules = builder.build();
 jsonReport = new JSONReport(settings.asConfig(), fs, server, rules, issueCache, project, inputComponentStore);
}
origin: SonarSource/sonarqube

@Test
public void add_issue_to_cache() {
 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("Foo"))
  .forRule(SQUID_RULE_KEY)
  .overrideSeverity(org.sonar.api.batch.rule.Severity.CRITICAL);
 when(filters.accept(any(InputComponent.class), any(ScannerReport.Issue.class))).thenReturn(true);
 boolean added = moduleIssues.initAndAddIssue(issue);
 assertThat(added).isTrue();
 ArgumentCaptor<ScannerReport.Issue> argument = ArgumentCaptor.forClass(ScannerReport.Issue.class);
 verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.scannerId()), argument.capture());
 assertThat(argument.getValue().getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.CRITICAL);
}
origin: SonarSource/sonarqube

@Test
public void build_rules() {
 RulesBuilder builder = new RulesBuilder();
 NewRule newSquid1 = builder.add(RuleKey.of("squid", "S0001"));
 newSquid1.setName("Detect bug");
 newSquid1.setDescription("Detect potential bug");
 newSquid1.addParam("max").setDescription("Maximum");
 builder.add(RuleKey.of("squid", "S0002"));
 builder.add(RuleKey.of("findbugs", "NPE"));
 Rules rules = builder.build();
origin: SonarSource/sonarqube

@Test
public void ignore_null_active_rule() {
 ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
 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: org.sonarsource.sonarqube/sonar-scanner-engine

 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 should_accept_issues_on_no_sonar_rules() {
 // The "No Sonar" rule logs violations on the lines that are flagged with "NOSONAR" !!
 ruleBuilder.add(NOSONAR_RULE_KEY).setName("No Sonar");
 activeRulesBuilder.addRule(new NewActiveRule.Builder()
  .setRuleKey(NOSONAR_RULE_KEY)
  .setSeverity(Severity.INFO)
  .setQProfileKey("qp-1")
  .build());
 initModuleIssues();
 file.noSonarAt(new HashSet<>(Collections.singletonList(3)));
 DefaultIssue issue = new DefaultIssue(project)
  .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message(""))
  .forRule(NOSONAR_RULE_KEY);
 when(filters.accept(any(InputComponent.class), any(ScannerReport.Issue.class))).thenReturn(true);
 boolean added = moduleIssues.initAndAddIssue(issue);
 assertThat(added).isTrue();
 verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.scannerId()), any());
}
origin: org.sonarsource.sonarqube/sonar-batch

 private static Rules load(RulesLoader ref) {
  Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
  MutableBoolean fromCache = new MutableBoolean();
  List<Rule> loadedRules = ref.load(fromCache);
  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(fromCache.booleanValue());

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

@Test
public void filter_issue() {
 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);
 when(filters.accept(any(InputComponent.class), any(ScannerReport.Issue.class))).thenReturn(false);
 boolean added = moduleIssues.initAndAddIssue(issue);
 assertThat(added).isFalse();
 verifyZeroInteractions(reportPublisher);
}
origin: SonarSource/sonarlint-core

public Rules provide(Sonarlint.Rules storageRules) {
 if (rules == null) {
  RulesBuilder builder = new RulesBuilder();
  for (Map.Entry<String, Sonarlint.Rules.Rule> entry : storageRules.getRulesByKeyMap().entrySet()) {
   Sonarlint.Rules.Rule r = entry.getValue();
   NewRule newRule = builder.add(RuleKey.of(r.getRepo(), r.getKey()))
    .setName(r.getName())
    .setInternalKey(r.getInternalKey())
    .setSeverity(r.getSeverity())
    .setDescription(r.getHtmlDesc());
   if (StringUtils.isNotEmpty(r.getType())) {
    newRule.setType(r.getType());
   }
  }
  rules = builder.build();
 }
 return rules;
}
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: org.codehaus.sonar/sonar-batch

private Rules load(RuleDao ruleDao, DefaultDebtModel debtModel, Durations durations) {
 RulesBuilder rulesBuilder = new RulesBuilder();
 List<RuleParamDto> ruleParamDtos = ruleDao.selectParameters();
 ListMultimap<Integer, RuleParamDto> paramDtosByRuleId = ArrayListMultimap.create();
 for (RuleParamDto dto : ruleParamDtos) {
  paramDtosByRuleId.put(dto.getRuleId(), dto);
 }
 for (RuleDto ruleDto : ruleDao.selectEnablesAndNonManual()) {
  RuleKey ruleKey = RuleKey.of(ruleDto.getRepositoryKey(), ruleDto.getRuleKey());
  NewRule newRule = rulesBuilder.add(ruleKey)
   .setId(ruleDto.getId())
   .setName(ruleDto.getName())
   .setSeverity(ruleDto.getSeverityString())
   .setDescription(ruleDto.getDescription())
   .setStatus(ruleDto.getStatus())
   .setInternalKey(ruleDto.getConfigKey());
  if (hasCharacteristic(ruleDto)) {
   newRule.setDebtSubCharacteristic(effectiveCharacteristic(ruleDto, ruleKey, debtModel).key());
   newRule.setDebtRemediationFunction(effectiveFunction(ruleDto, ruleKey, durations));
  }
  for (RuleParamDto ruleParamDto : paramDtosByRuleId.get(ruleDto.getId())) {
   newRule.addParam(ruleParamDto.getName())
    .setDescription(ruleParamDto.getDescription());
  }
 }
 return rulesBuilder.build();
}
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/sonarlint-core

 private static Rules createRules(StandaloneRuleDefinitionsLoader pluginRulesLoader) {
  RulesBuilder builder = new RulesBuilder();

  for (RulesDefinition.Repository repoDef : pluginRulesLoader.getContext().repositories()) {
   for (RulesDefinition.Rule ruleDef : repoDef.rules()) {
    if (ruleDef.type() == RuleType.SECURITY_HOTSPOT) {
     continue;
    }
    NewRule newRule = builder.add(RuleKey.of(ruleDef.repository().key(), ruleDef.key()))
     .setInternalKey(ruleDef.internalKey())
     .setDescription(ruleDef.htmlDescription() != null ? ruleDef.htmlDescription() : Markdown.convertToHtml(ruleDef.markdownDescription()))
     .setSeverity(ruleDef.severity())
     .setType(ruleDef.type() != null ? ruleDef.type().toString() : null)
     .setName(ruleDef.name());
    for (Param p : ruleDef.params()) {
     newRule.addParam(p.key())
      .setDescription(p.description());
    }
   }
  }

  return builder.build();
 }
}
org.sonar.api.batch.rule.internalRulesBuilder

Javadoc

For unit testing and internal use only.

Most used methods

  • <init>
  • add
  • build

Popular in Java

  • Parsing JSON documents to java classes using gson
  • onCreateOptionsMenu (Activity)
  • compareTo (BigDecimal)
  • putExtra (Intent)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Reference (javax.naming)
  • JButton (javax.swing)
  • JComboBox (javax.swing)
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • Best IntelliJ plugins
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