Package org.sonar.api.rules

Examples of org.sonar.api.rules.Rule


  @Test
  public void failIfMissingProperty() {
    thrown.expect(SonarException.class);

    RulesProfile profile = RulesProfile.create("repo", "java");
    Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithStringProperty", "");
    rule.createParameter("unknown");

    ActiveRule activeRule = profile.activateRule(rule, null);
    activeRule.setParameter("unknown", "bar");
    AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithStringProperty.class));
  }
View Full Code Here


  }

  @Test
  public void createCheckWithPrimitiveProperties() {
    RulesProfile profile = RulesProfile.create("repo", "java");
    Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithPrimitiveProperties", "");
    rule.createParameter("max");
    rule.createParameter("ignore");

    ActiveRule activeRule = profile.activateRule(rule, null);
    activeRule.setParameter("max", "300");
    activeRule.setParameter("ignore", "true");
    AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithPrimitiveProperties.class));
View Full Code Here

  }

  @Test
  public void createCheckWithIntegerProperty() {
    RulesProfile profile = RulesProfile.create("repo", "java");
    Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithIntegerProperty", "");
    rule.createParameter("max");

    ActiveRule activeRule = profile.activateRule(rule, null);
    activeRule.setParameter("max", "300");
    AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithIntegerProperty.class));
View Full Code Here

   * SONAR-3164
   */
  @Test
  public void setValueOfInheritedField() {
    RulesProfile profile = RulesProfile.create("repo", "java");
    Rule rule = Rule.create("repo", "org.sonar.api.checks.ImplementedCheck", "");
    rule.createParameter("max");

    ActiveRule activeRule = profile.activateRule(rule, null);
    activeRule.setParameter("max", "300");
    AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(ImplementedCheck.class));

View Full Code Here

  @Test
  public void failIfPropertyTypeIsNotSupported() {
    thrown.expect(SonarException.class);

    RulesProfile profile = RulesProfile.create("repo", "java");
    Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithUnsupportedPropertyType", "");
    rule.createParameter("max");

    ActiveRule activeRule = profile.activateRule(rule, null);
    activeRule.setParameter("max", "300");
    AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithUnsupportedPropertyType.class));
  }
View Full Code Here

  }

  @Test
  public void shouldOverridePropertyKey() {
    RulesProfile profile = RulesProfile.create("repo", "java");
    Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithOverriddenPropertyKey", "");
    rule.createParameter("maximum");

    ActiveRule activeRule = profile.activateRule(rule, null);
    activeRule.setParameter("maximum", "300");
    AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithOverriddenPropertyKey.class));
View Full Code Here

  }

  @Test
  public void shouldWorkWithClonedRules() {
    RulesProfile profile = RulesProfile.create("repo", "java");
    Rule rule = Rule.create("repo", "CheckWithKey", "");
    Rule clonedRule = Rule.create("repo", "CheckWithKey_2", "").setConfigKey("CheckWithKey").setTemplate(rule);

    profile.activateRule(rule, null);
    profile.activateRule(clonedRule, null);
    AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithKey.class));
View Full Code Here

  }

  @Test
  public void create_instance_with_string_property() {
    RulesProfile profile = RulesProfile.create("repo", "java");
    Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithStringProperty", "");
    rule.createParameter("pattern");

    ActiveRule activeRule = profile.activateRule(rule, null);
    activeRule.setParameter("pattern", "foo");
    CheckWithStringProperty checkInstance = new CheckWithStringProperty();
    AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.asList(checkInstance));
View Full Code Here

        }
    }

    private void recordViolation(final org.sonar.api.resources.File resource,
            final SMInputCursor line) throws XMLStreamException {
        final Rule rule = Rule.create();
        final Violation violation = Violation.create(rule, resource);

        // PMD Priorities are 1, 2, 3, 4, 5 RulePriority[0] is INFO
        rule.setSeverity(RulePriority.values()[PMD_MINIMUM_PRIORITY
                - Integer.valueOf(line.getAttrValue("priority"))]);
        rule.setKey(line.getAttrValue("rule"));
        rule.setRepositoryKey(OCLintRuleRepository.REPOSITORY_KEY);

        violation.setLineId(Integer.valueOf(line.getAttrValue("beginline")));

        violation.setMessage(line.getElemStringValue());
View Full Code Here

        final List<Rule> rules = new ArrayList<Rule>();

        final List<String> listLines = IOUtils.readLines(reader);

        String previousLine = null;
        Rule rule = null;
        boolean inDescription = false;
        for (String line : listLines) {
            if (isLineIgnored(line)) {
                inDescription = false;
            } else if (line.matches("[\\-]{4,}.*")) {
                LOGGER.debug("Rule found : {}", previousLine);

                // remove the rule name from the description of the previous
                // rule
                if (rule != null) {
                    final int index = rule.getDescription().lastIndexOf(
                            previousLine);
                    if (index > 0) {
                        rule.setDescription(rule.getDescription().substring(0,
                                index));
                    }
                }

                rule = Rule.create();
                rules.add(rule);
                rule.setName(previousLine);
                rule.setKey(previousLine);
            } else if (line.matches("Summary:.*")) {
                inDescription = true;
                rule.setDescription(line.substring(line.indexOf(':') + 1));
            } else if (line.matches("Category:.*")) {
                inDescription = true;
            } else if (line.matches("Severity:.*")) {
                inDescription = false;
                final String severity = line.substring("Severity: ".length());
                // Rules are priority 1, 2 or 3 in OCLint files.
                rule.setSeverity(RulePriority.values()[OCLINT_MINIMUM_PRIORITY
                        - Integer.valueOf(severity)]);
            } else {
                if (inDescription) {
                    line = ruleDescriptionLink(line);
                    rule.setDescription(rule.getDescription() + "<br>" + line);
                }
            }
            previousLine = line;
        }
        return rules;
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.