コード例 #1
0
  @Test
  public void importParameters() {
    Reader reader =
        new StringReader(
            TestUtils.getResourceContent(
                "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/simple.xml"));
    RulesProfile profile = importer.importProfile(reader, messages);

    ActiveRule javadocCheck =
        profile.getActiveRuleByConfigKey("checkstyle", "Checker/JavadocPackage");
    assertThat(javadocCheck.getActiveRuleParams()).hasSize(2);
    assertThat(javadocCheck.getParameter("format")).isEqualTo("abcde");
    assertThat(javadocCheck.getParameter("ignore")).isEqualTo("true");
    assertThat(javadocCheck.getParameter("severity")).isNull(); // checkstyle internal parameter
  }
コード例 #2
0
ファイル: ProfilesManager.java プロジェクト: ricesorry/sonar
  /**
   * Deal with creation of ActiveRuleChange item when a rule is changed (severity and/or param(s))
   * on a profile
   */
  private void ruleChanged(
      RulesProfile profile, ActiveRule oldActiveRule, ActiveRule newActiveRule, String userName) {
    incrementProfileVersionIfNeeded(profile);
    ActiveRuleChange rc = new ActiveRuleChange(userName, profile, newActiveRule.getRule());

    if (oldActiveRule.getSeverity() != newActiveRule.getSeverity()) {
      rc.setOldSeverity(oldActiveRule.getSeverity());
      rc.setNewSeverity(newActiveRule.getSeverity());
    }
    if (oldActiveRule.getRule().getParams() != null) {
      for (RuleParam p : oldActiveRule.getRule().getParams()) {
        String oldParam = oldActiveRule.getParameter(p.getKey());
        String newParam = newActiveRule.getParameter(p.getKey());
        if (!StringUtils.equals(oldParam, newParam)) {
          rc.setParameterChange(p.getKey(), oldParam, newParam);
        }
      }
    }

    getSession().saveWithoutFlush(rc);
  }
コード例 #3
0
  @Test
  public void properties_should_be_inherited() {
    Reader reader =
        new StringReader(
            TestUtils.getResourceContent(
                "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/inheritance_of_properties.xml"));
    RulesProfile profile = importer.importProfile(reader, messages);

    ActiveRule activeRule =
        profile.getActiveRuleByConfigKey("checkstyle", "Checker/TreeWalker/MissingOverride");
    assertThat(activeRule.getSeverity()).isEqualTo(RulePriority.BLOCKER);
    assertThat(activeRule.getParameter("javaFiveCompatibility")).isEqualTo("true");
  }
コード例 #4
0
  @Test
  public void testImportingParameters() {
    Reader reader =
        new StringReader(
            TestUtils.getResourceContent("/org/sonar/plugins/php/pmd/simple-ruleset.xml"));
    RulesProfile profile = importer.importProfile(reader, messages);

    ActiveRule activeRule =
        profile.getActiveRuleByConfigKey(
            REPOSITORY_KEY, "rulesets/codesize.xml/CyclomaticComplexity");
    assertThat(activeRule.getActiveRuleParams().size(), is(1));
    assertThat(activeRule.getParameter("reportLevel"), is("30"));
  }
コード例 #5
0
ファイル: ProfilesManager.java プロジェクト: ricesorry/sonar
 /** Deal with creation of ActiveRuleChange item when a rule is disabled on a profile */
 private void ruleDisabled(RulesProfile profile, ActiveRule disabledRule, String userName) {
   incrementProfileVersionIfNeeded(profile);
   ActiveRuleChange rc = new ActiveRuleChange(userName, profile, disabledRule.getRule());
   rc.setEnabled(false);
   rc.setOldSeverity(disabledRule.getSeverity());
   if (disabledRule.getRule().getParams() != null) {
     for (RuleParam p : disabledRule.getRule().getParams()) {
       String oldParam = disabledRule.getParameter(p.getKey());
       if (oldParam != null) {
         rc.setParameterChange(p.getKey(), oldParam, null);
       }
     }
   }
   getSession().saveWithoutFlush(rc);
 }
コード例 #6
0
ファイル: ProfilesManager.java プロジェクト: ricesorry/sonar
 /** Deal with creation of ActiveRuleChange item when a rule is enabled on a profile */
 private void ruleEnabled(RulesProfile profile, ActiveRule newActiveRule, String userName) {
   incrementProfileVersionIfNeeded(profile);
   ActiveRuleChange rc = new ActiveRuleChange(userName, profile, newActiveRule.getRule());
   rc.setEnabled(true);
   rc.setNewSeverity(newActiveRule.getSeverity());
   if (newActiveRule.getRule().getParams() != null) {
     for (RuleParam p : newActiveRule.getRule().getParams()) {
       String newParam = newActiveRule.getParameter(p.getKey());
       if (newParam != null) {
         rc.setParameterChange(p.getKey(), null, newParam);
       }
     }
   }
   getSession().saveWithoutFlush(rc);
 }
コード例 #7
0
  @Test
  public void testUnsupportedProperty() {
    Reader reader =
        new StringReader(
            TestUtils.getResourceContent("/org/sonar/plugins/php/pmd/simple-ruleset.xml"));
    RulesProfile profile = importer.importProfile(reader, messages);

    ActiveRule check =
        profile.getActiveRuleByConfigKey(
            REPOSITORY_KEY, "rulesets/codesize.xml/CyclomaticComplexity");
    // The mock rulefinder contains only one param for the rule, but the ruleset file contains 2, so
    // we should get a warning about that.
    assertThat(check.getParameter("threshold"), nullValue());
    assertThat(messages.getWarnings().size(), is(1));
  }