Package org.sonar.api.rules

Examples of org.sonar.api.rules.Rule


      violation.setResource(currentProject);
    } else if (!Scopes.isHigherThanOrEquals(resource, Scopes.FILE)) {
      throw new IllegalArgumentException("Violations are only supported on files, directories and project");
    }

    Rule rule = violation.getRule();
    if (rule == null) {
      LOG.warn("Rule is null. Ignoring violation {}", violation);
      return;
    }
View Full Code Here


    }
    json.endArray();
  }

  private String getRuleName(RuleKey ruleKey) {
    Rule rule = ruleFinder.findByKey(ruleKey);
    return rule != null ? rule.getName() : null;
  }
View Full Code Here

    assertEquals(
        RuleMeasure.createForPriority(CoreMetrics.CLASSES, RulePriority.CRITICAL, 4.5),
        RuleMeasure.createForPriority(CoreMetrics.CLASSES, RulePriority.CRITICAL, 3.4));

    assertEquals(
        RuleMeasure.createForRule(CoreMetrics.CLASSES, new Rule("pmd", "abc1"), 4.5),
        RuleMeasure.createForRule(CoreMetrics.CLASSES, new Rule("pmd", "abc1"), 3.4));

  }
View Full Code Here

  }

  @Test
  public void shouldNotEquals() {
    assertNotEquals(
        RuleMeasure.createForRule(CoreMetrics.BLOCKER_VIOLATIONS, new Rule("pmd", "abc1"), 4.5),
        RuleMeasure.createForRule(CoreMetrics.BLOCKER_VIOLATIONS, new Rule("pmd", "def2"), 3.4));

    assertNotEquals(
        RuleMeasure.createForRule(CoreMetrics.INFO_VIOLATIONS, new Rule("pmd", "abc1"), 4.5),
        RuleMeasure.createForRule(CoreMetrics.BLOCKER_VIOLATIONS, new Rule("pmd", "abc1"), 3.4));
  }
View Full Code Here

  }

  @Test
  public void notEqualRuleMeasures() {
    Measure measure = new Measure(CoreMetrics.VIOLATIONS, 30.0);
    RuleMeasure ruleMeasure = new RuleMeasure(CoreMetrics.VIOLATIONS, new Rule("foo", "bar"), RulePriority.CRITICAL, 3);
    assertThat(measure.equals(ruleMeasure)).isFalse();
    assertThat(ruleMeasure.equals(measure)).isFalse();
  }
View Full Code Here

  @Test
  public void should_insert_rule_measure() {
    setupData("empty");

    Rule rule = Rule.create("pmd", "key");
    when(ruleFinder.findByKey(rule.ruleKey())).thenReturn(rule);

    Measure measure = new RuleMeasure(ncloc(), rule, RulePriority.MAJOR, 1).setValue(1234.0);
    when(measureCache.entries()).thenReturn(Arrays.asList(new Cache.Entry<Measure>(new String[] {"foo", "ncloc"}, measure)));

    measurePersister.persist();
View Full Code Here

  /**
   * See https://jira.codehaus.org/browse/SONAR-3583
   */
  @Test
  public void should_ignore_violation_on_unknown_rules() {
    Rule ruleWithoutID = Rule.create("repoKey", "ruleKey", "Rule");

    File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false);
    Violation violation = Violation.create(ruleWithoutID, file);
    index.addViolation(violation);

View Full Code Here

    assertThat(index.getViolations(file)).isEmpty();
  }

  @Test
  public void should_get_violation() {
    Rule rule = Rule.create("repoKey", "ruleKey", "Rule");
    File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false);
    Violation violation = Violation.create(rule, file);
    when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation));

    index.index(file);
View Full Code Here

    assertThat(index.getViolations(file)).hasSize(1);
  }

  @Test
  public void should_not_save_violation_if_resource_not_indexed() {
    Rule rule = Rule.create("repoKey", "ruleKey", "Rule");
    File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false);
    Violation violation = Violation.create(rule, file);
    when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation));

    index.addViolation(violation);
View Full Code Here

    assertThat(index.getViolations(file)).hasSize(0);
  }

  @Test
  public void should_get_filtered_violation_with_off_switch_mode() {
    Rule rule = Rule.create("repoKey", "ruleKey", "Rule");
    File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false);
    Violation violation = Violation.create(rule, file).setSwitchedOff(true);

    when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation));
View Full Code Here

TOP

Related Classes of org.sonar.api.rules.Rule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.