org.sonar.api.profiles.RulesProfile Java Examples

The following examples show how to use org.sonar.api.profiles.RulesProfile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CheckstyleProfileExporter.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void exportProfile(RulesProfile profile, Writer writer) {
    try {
        final List<ActiveRule> activeRules = profile
                .getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY);
        if (activeRules != null) {
            final List<ActiveRuleWrapper> activeRuleWrappers = new ArrayList<>();
            for (ActiveRule activeRule : activeRules) {
                activeRuleWrappers.add(new ActiveRuleWrapperServerImpl(activeRule));
            }
            final Map<String, List<ActiveRuleWrapper>> activeRulesByConfigKey =
                    arrangeByConfigKey(activeRuleWrappers);
            generateXml(writer, activeRulesByConfigKey);
        }
    }
    catch (IOException ex) {
        throw new IllegalStateException("Fail to export the profile " + profile, ex);
    }
}
 
Example #2
Source File: PmdProfileImporter.java    From sonar-p3c-pmd with MIT License 6 votes vote down vote up
protected RulesProfile createRuleProfile(PmdRuleset pmdRuleset, ValidationMessages messages) {
  RulesProfile profile = RulesProfile.create();
  for (PmdRule pmdRule : pmdRuleset.getPmdRules()) {
    String ruleClassName = pmdRule.getClazz();
    if (PmdConstants.XPATH_CLASS.equals(ruleClassName)) {
      messages.addWarningText("PMD XPath rule '" + pmdRule.getName()
        + "' can't be imported automatically. The rule must be created manually through the SonarQube web interface.");
    } else {
      String ruleRef = pmdRule.getRef();
      if (ruleRef == null) {
        messages.addWarningText("A PMD rule without 'ref' attribute can't be imported. see '" + ruleClassName + "'");
      } else {
        Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PmdConstants.REPOSITORY_KEY).withConfigKey(ruleRef));
        if (rule != null) {
          ActiveRule activeRule = profile.activateRule(rule, PmdLevelUtils.fromLevel(pmdRule.getPriority()));
          setParameters(activeRule, pmdRule, rule, messages);
        } else {
          messages.addWarningText("Unable to import unknown PMD rule '" + ruleRef + "'");
        }
      }
    }
  }
  return profile;
}
 
Example #3
Source File: CheckstyleProfileExporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void addCustomCheckerFilters() {
    initSettings(CheckstyleConstants.CHECKER_FILTERS_KEY,
            "<module name=\"SuppressionCommentFilter\">"
                    + "<property name=\"offCommentFormat\" value=\"BEGIN GENERATED CODE\"/>"
                    + "<property name=\"onCommentFormat\" value=\"END GENERATED CODE\"/>"
                    + "</module>" + "<module name=\"SuppressWithNearbyCommentFilter\">"
                    + "<property name=\"commentFormat\""
                    + " value=\"CHECKSTYLE IGNORE (\\w+) FOR NEXT (\\d+) LINES\"/>"
                    + "<property name=\"checkFormat\" value=\"$1\"/>"
                    + "<property name=\"messageFormat\" value=\"$2\"/>" + "</module>");

    final RulesProfile profile = RulesProfile.create("sonar way", "java");
    final StringWriter writer = new StringWriter();
    new CheckstyleProfileExporter(settings).exportProfile(profile, writer);

    CheckstyleTestUtils.assertSimilarXmlWithResource(
            "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
                    + "addCustomFilters.xml", sanitizeForTests(writer.toString()));
}
 
Example #4
Source File: PmdProfileExporterTest.java    From sonar-p3c-pmd with MIT License 6 votes vote down vote up
@Test
public void should_export_xPath_rule() {
  Rule rule = Rule.create(PmdConstants.REPOSITORY_KEY, "MyOwnRule", "This is my own xpath rule.")
    .setConfigKey(PmdConstants.XPATH_CLASS)
    .setRepositoryKey(PmdConstants.REPOSITORY_KEY);
  rule.createParameter(PmdConstants.XPATH_EXPRESSION_PARAM);
  rule.createParameter(PmdConstants.XPATH_MESSAGE_PARAM);

  RulesProfile profile = RulesProfile.create();
  ActiveRule xpath = profile.activateRule(rule, null);
  xpath.setParameter(PmdConstants.XPATH_EXPRESSION_PARAM, "//FieldDeclaration");
  xpath.setParameter(PmdConstants.XPATH_MESSAGE_PARAM, "This is bad");

  String exportedXml = exporter.exportProfile(PmdConstants.REPOSITORY_KEY, profile);

  assertThat(exportedXml).satisfies(equalsIgnoreEOL(PmdTestUtils.getResourceContent("/org/sonar/plugins/pmd/export_xpath_rules.xml")));
}
 
Example #5
Source File: CheckstyleProfileExporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void exportParameters() {
    final RulesProfile profile = RulesProfile.create("sonar way", "java");
    final Rule rule = Rule.create("checkstyle",
            "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck", "Javadoc")
            .setConfigKey("Checker/JavadocPackage");
    rule.createParameter("format");
    // not set in the profile and no default value => not exported in
    // checkstyle
    rule.createParameter("message");
    rule.createParameter("ignore");

    profile.activateRule(rule, RulePriority.MAJOR).setParameter("format", "abcde");

    final StringWriter writer = new StringWriter();
    new CheckstyleProfileExporter(settings).exportProfile(profile, writer);

    CheckstyleTestUtils.assertSimilarXmlWithResource(
            "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
                    + "exportParameters.xml", sanitizeForTests(writer.toString()));
}
 
Example #6
Source File: CheckstyleProfileExporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void addTheIdPropertyWhenManyInstancesWithTheSameConfigKey() {
    final RulesProfile profile = RulesProfile.create("sonar way", "java");
    final Rule rule1 = Rule.create("checkstyle",
            "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck", "Javadoc")
            .setConfigKey("Checker/JavadocPackage");
    final Rule rule2 = Rule
            .create("checkstyle",
                    "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck_12345",
                    "Javadoc").setConfigKey("Checker/JavadocPackage").setParent(rule1);

    profile.activateRule(rule1, RulePriority.MAJOR);
    profile.activateRule(rule2, RulePriority.CRITICAL);

    final StringWriter writer = new StringWriter();
    new CheckstyleProfileExporter(settings).exportProfile(profile, writer);

    CheckstyleTestUtils.assertSimilarXmlWithResource(
            "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
                    + "addTheIdPropertyWhenManyInstancesWithTheSameConfigKey.xml",
            sanitizeForTests(writer.toString()));
}
 
Example #7
Source File: CheckstyleProfileExporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void singleCheckstyleRulesToExport() {
    final RulesProfile profile = RulesProfile.create("sonar way", "java");
    profile.activateRule(Rule.create("pmd", "PmdRule1", "PMD rule one"), null);
    profile.activateRule(
            Rule.create("checkstyle",
                    "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck",
                    "Javadoc").setConfigKey("Checker/JavadocPackage"), RulePriority.MAJOR);
    profile.activateRule(
            Rule.create(
                    "checkstyle",
                    "com.puppycrawl.tools.checkstyle.checks.naming.LocalFinalVariableNameCheck",
                    "Local Variable").setConfigKey(
                    "Checker/TreeWalker/Checker/TreeWalker/LocalFinalVariableName"),
            RulePriority.MINOR);

    final StringWriter writer = new StringWriter();
    new CheckstyleProfileExporter(settings).exportProfile(profile, writer);

    CheckstyleTestUtils.assertSimilarXmlWithResource(
            "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
                    + "singleCheckstyleRulesToExport.xml", sanitizeForTests(writer.toString()));
}
 
Example #8
Source File: TSQLQualityProfile.java    From sonar-tsql-plugin with GNU General Public License v3.0 5 votes vote down vote up
private void activePluginRules(final RulesProfile profile) {
	try {
		final SqlRules rules = customPluginChecks.getRules();
		for (final org.sonar.plugins.tsql.checks.custom.Rule rule : rules.getRule()) {
			profile.activateRule(Rule.create(rules.getRepoKey(), rule.getKey()), null);
		}
	}

	catch (final Throwable e) {
		LOGGER.warn("Unexpected error occured while activating custom plugin rules", e);
	}
}
 
Example #9
Source File: LuaProfile.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public RulesProfile createProfile(ValidationMessages validation) {
  AnnotationBasedProfileBuilder annotationBasedProfileBuilder = new AnnotationBasedProfileBuilder(ruleFinder);
  return annotationBasedProfileBuilder.build(
      CheckList.REPOSITORY_KEY,
      CheckList.SONAR_WAY_PROFILE,
      Lua.KEY,
      CheckList.getChecks(),
      validation);
}
 
Example #10
Source File: TypeScriptRuleProfileTest.java    From SonarTsPlugin with MIT License 5 votes vote down vote up
@Test
public void definesUnexpectedRules() {
    RulesProfile profile = this.ruleProfile.createProfile(this.validationMessages);

    for (ActiveRule rule : profile.getActiveRules()) {
        assertTrue("Unexpected rule in plugin: " + rule.getRuleKey(), this.expectedRuleNames.contains(rule.getRuleKey()));
    }
}
 
Example #11
Source File: TypeScriptRuleProfileTest.java    From SonarTsPlugin with MIT License 5 votes vote down vote up
@Test
public void definesExpectedRules() {
    RulesProfile profile = this.ruleProfile.createProfile(this.validationMessages);

    for (String ruleName : this.expectedRuleNames) {
        assertNotNull("Expected rule missing in plugin: " + ruleName, profile.getActiveRule(TsRulesDefinition.REPOSITORY_NAME, ruleName));
    }
}
 
Example #12
Source File: TypeScriptRuleProfile.java    From SonarTsPlugin with MIT License 5 votes vote down vote up
@Override
public RulesProfile createProfile(ValidationMessages validation) {
    RulesProfile profile = RulesProfile.create("TsLint", TypeScriptLanguage.LANGUAGE_KEY);

    TsRulesDefinition rules = new TsRulesDefinition();

    activateRule(profile, TsRulesDefinition.TSLINT_UNKNOWN_RULE.key);

    for (TsLintRule coreRule : rules.getCoreRules()) {
        activateRule(profile, coreRule.key);
    }

    return profile;
}
 
Example #13
Source File: CheckstyleProfileExporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void addCustomTreewalkerFilters() {
    initSettings(CheckstyleConstants.TREEWALKER_FILTERS_KEY,
            "<module name=\"SuppressWithNearbyCommentFilter\"/>");

    final RulesProfile profile = RulesProfile.create("sonar way", "java");
    final StringWriter writer = new StringWriter();
    new CheckstyleProfileExporter(settings).exportProfile(profile, writer);

    CheckstyleTestUtils.assertSimilarXmlWithResource(
            "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
                    + "addCustomTreewalkerFilters.xml", sanitizeForTests(writer.toString()));
}
 
Example #14
Source File: TSQLQualityProfile.java    From sonar-tsql-plugin with GNU General Public License v3.0 5 votes vote down vote up
private void activeRules(final RulesProfile profile, final String key, final InputStream file) {
	try {

		final JAXBContext jaxbContext = JAXBContext.newInstance(TSQLRules.class);
		final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
		final TSQLRules issues = (TSQLRules) jaxbUnmarshaller.unmarshal(file);
		for (final org.sonar.plugins.tsql.languages.TSQLRules.Rule rule : issues.rule) {
			profile.activateRule(Rule.create(key, rule.getKey()), null);
		}
	}

	catch (final Throwable e) {
		LOGGER.warn("Unexpected error occured while reading rules for " + key, e);
	}
}
 
Example #15
Source File: ApexProfileTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testCreateSonarWayProfile() {
    ValidationMessages validation = ValidationMessages.create();

    RuleFinder ruleFinder = buildRuleFinder();
    ApexProfile definition = new ApexProfile(ruleFinder);
    RulesProfile profile = definition.createProfile(validation);

    assertThat(profile.getLanguage(), equalTo(Apex.KEY));
    assertThat(profile.getName(), equalTo(CheckList.SONAR_WAY_PROFILE));
    assertThat(validation.hasErrors(), is(FALSE));
}
 
Example #16
Source File: CheckstyleProfileImporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void importParameters() {
    final Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent(
            "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/simple.xml"));
    final RulesProfile profile = importer.importProfile(reader, messages);

    final ActiveRule javadocCheck = profile.getActiveRuleByConfigKey("checkstyle",
            "Checker/JavadocPackage");
    assertThat(javadocCheck.getActiveRuleParams()).hasSize(2);
    assertThat(javadocCheck.getParameter("format")).isEqualTo("abcde");
    assertThat(javadocCheck.getParameter("ignore")).isEqualTo("true");
    // checkstyle internal parameter
    assertThat(javadocCheck.getParameter("severity")).isNull();
}
 
Example #17
Source File: CheckstyleConfigurationTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void getCheckstyleConfiguration() throws Exception {
    fileSystem.setEncoding(StandardCharsets.UTF_8);
    final MapSettings mapSettings = new MapSettings(new PropertyDefinitions(
            new CheckstylePlugin().getExtensions()));
    mapSettings.setProperty(CheckstyleConstants.CHECKER_FILTERS_KEY,
            CheckstyleConstants.CHECKER_FILTERS_DEFAULT_VALUE);
    final org.sonar.api.config.Configuration settings = new ConfigurationBridge(mapSettings);

    final RulesProfile profile = RulesProfile.create("sonar way", "java");

    final Rule rule = Rule.create("checkstyle", "CheckStyleRule1", "checkstyle rule one");
    rule.setConfigKey("checkstyle/rule1");
    profile.activateRule(rule, null);

    final CheckstyleConfiguration configuration = new CheckstyleConfiguration(settings,
            new CheckstyleProfileExporter(settings),
            new DefaultActiveRules(Collections.emptyList()), fileSystem);
    final Configuration checkstyleConfiguration = configuration.getCheckstyleConfiguration();
    assertThat(checkstyleConfiguration).isNotNull();
    assertThat(checkstyleConfiguration.getAttribute("charset")).isEqualTo("UTF-8");
    final File xmlFile = new File("checkstyle.xml");
    assertThat(xmlFile.exists()).isTrue();

    FileUtils.forceDelete(xmlFile);
}
 
Example #18
Source File: ApexProfile.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
/**
 * Returns a {@link RulesProfile} based on a list of classes annotated.
 *
 * @param validation validation message.
 * @return a rule profile.
 */
@Override
public RulesProfile createProfile(ValidationMessages validation) {
    AnnotationBasedProfileBuilder annotationBasedProfileBuilder = new AnnotationBasedProfileBuilder(ruleFinder);
    return annotationBasedProfileBuilder.build(
            CheckList.REPOSITORY_KEY,
            CheckList.SONAR_WAY_PROFILE,
            Apex.KEY,
            CheckList.getChecks(),
            validation);
}
 
Example #19
Source File: CheckstyleProfileExporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void addTabWidthProperty() {
    initSettings(CheckstyleConstants.CHECKER_TAB_WIDTH, "8");

    final RulesProfile profile = RulesProfile.create("sonar way", "java");
    final StringWriter writer = new StringWriter();
    new CheckstyleProfileExporter(settings).exportProfile(profile, writer);

    CheckstyleTestUtils.assertSimilarXmlWithResource(
            "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
                    + "addTabWidthProperty.xml", sanitizeForTests(writer.toString()));
}
 
Example #20
Source File: LuaProfileTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void should_create_sonar_way_profile() {
  ValidationMessages validation = ValidationMessages.create();

  RuleFinder ruleFinder = ruleFinder();
  LuaProfile definition = new LuaProfile(ruleFinder);
  RulesProfile profile = definition.createProfile(validation);

  assertThat(profile.getLanguage()).isEqualTo(Lua.KEY);
  assertThat(profile.getName()).isEqualTo(CheckList.SONAR_WAY_PROFILE);
  assertThat(profile.getActiveRulesByRepository(CheckList.REPOSITORY_KEY)).hasSize(15);
  assertThat(validation.hasErrors()).isFalse();
}
 
Example #21
Source File: GherkinProfileTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void should_create_sonarqube_way_profile() {
  ValidationMessages validation = ValidationMessages.create();
  GherkinProfile definition = new GherkinProfile(universalRuleFinder());
  RulesProfile profile = definition.createProfile(validation);

  assertThat(profile.getName()).isEqualTo("SonarQube Way");
  assertThat(profile.getLanguage()).isEqualTo("gherkin");
  assertThat(profile.getActiveRulesByRepository("gherkin")).hasSize(36);
  assertThat(validation.hasErrors()).isFalse();
}
 
Example #22
Source File: CheckstyleProfileExporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void ruleThrowsException() {
    final RulesProfile profile = RulesProfile.create("sonar way", "java");
    try {
        new CheckstyleProfileExporter(settings).exportProfile(profile, new IoExceptionWriter());
        Assert.fail("IOException while writing should not be ignored");
    }
    catch (IllegalStateException ex) {
        Assertions.assertThat(ex.getMessage())
                .isEqualTo("Fail to export the profile " + profile);
    }
}
 
Example #23
Source File: CheckstyleProfileExporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void noCheckstyleRulesToExport() {
    final RulesProfile profile = RulesProfile.create("sonar way", "java");

    // this is a PMD rule
    profile.activateRule(Rule.create("pmd", "PmdRule1", "PMD rule one"), null);

    final StringWriter writer = new StringWriter();
    new CheckstyleProfileExporter(settings).exportProfile(profile, writer);

    CheckstyleTestUtils.assertSimilarXmlWithResource(
            "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
                    + "noCheckstyleRulesToExport.xml", sanitizeForTests(writer.toString()));
}
 
Example #24
Source File: CheckstyleProfileExporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void alwaysSetSuppressionCommentFilter() {
    final RulesProfile profile = RulesProfile.create("sonar way", "java");

    final StringWriter writer = new StringWriter();
    new CheckstyleProfileExporter(settings).exportProfile(profile, writer);

    CheckstyleTestUtils.assertSimilarXmlWithResource(
            "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
                    + "alwaysSetSuppressionCommentFilter.xml",
            sanitizeForTests(writer.toString()));
}
 
Example #25
Source File: CheckstyleProfileImporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void importingFiltersIsNotSupported() {
    final Reader reader = new StringReader(
            CheckstyleTestUtils.getResourceContent("/org/sonar/plugins/checkstyle/"
                    + "CheckstyleProfileImporterTest/importingFiltersIsNotSupported.xml"));
    final RulesProfile profile = importer.importProfile(reader, messages);

    assertNull(profile.getActiveRuleByConfigKey("checkstyle",
            "Checker/SuppressionCommentFilter"));
    assertThat(profile.getActiveRules().size()).isEqualTo(2);
    assertThat(messages.getWarnings().size()).isEqualTo(5);
}
 
Example #26
Source File: CheckstyleProfileImporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void shouldUseTheIdPropertyToFindRule() {
    final Reader reader = new StringReader(
            CheckstyleTestUtils.getResourceContent("/org/sonar/plugins/checkstyle/"
                    + "CheckstyleProfileImporterTest/shouldUseTheIdPropertyToFindRule.xml"));
    final RulesProfile profile = importer.importProfile(reader, messages);

    assertNotNull(profile.getActiveRuleByConfigKey("checkstyle", "Checker/JavadocPackage"));
    assertThat(
            profile.getActiveRuleByConfigKey("checkstyle", "Checker/JavadocPackage").getRule()
                    .getKey()).isEqualTo(
            "com.puppycrawl.tools.checkstyle.checks.javadoc." + "JavadocPackageCheck_12345");
    assertThat(messages.getWarnings().size()).isEqualTo(0);
}
 
Example #27
Source File: CheckstyleProfileImporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void idPropertyShouldBeTheRuleKey() {
    final Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent(
            "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/"
                    + "idPropertyShouldBeTheRuleKey.xml"));
    final RulesProfile profile = importer.importProfile(reader, messages);

    assertNull(profile.getActiveRuleByConfigKey("checkstyle", "Checker/JavadocPackage"));
    assertThat(messages.getWarnings().size()).isEqualTo(1);
}
 
Example #28
Source File: CheckstyleProfileImporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void priorityIsOptional() {
    final Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent(
            "/org/sonar/plugins/checkstyle/"
                    + "CheckstyleProfileImporterTest/simple.xml"));
    final RulesProfile profile = importer.importProfile(reader, messages);

    final ActiveRule activeRule = profile.getActiveRuleByConfigKey("checkstyle",
            "Checker/TreeWalker/EqualsHashCode");
    // reuse the rule default priority
    assertThat(activeRule.getSeverity()).isEqualTo(RulePriority.BLOCKER);
}
 
Example #29
Source File: CheckstyleProfileImporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void importPriorities() {
    final Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent(
            "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/simple.xml"));
    final RulesProfile profile = importer.importProfile(reader, messages);

    final ActiveRule javadocCheck = profile.getActiveRuleByConfigKey("checkstyle",
            "Checker/JavadocPackage");
    assertThat(javadocCheck.getSeverity()).isEqualTo(RulePriority.BLOCKER);
}
 
Example #30
Source File: CheckstyleProfileImporterTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void propertiesShouldBeInherited() {
    final Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent(
            "/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/"
            + "inheritance_of_properties.xml"));
    final RulesProfile profile = importer.importProfile(reader, messages);

    final ActiveRule activeRule = profile.getActiveRuleByConfigKey("checkstyle",
            "Checker/TreeWalker/MissingOverride");
    assertThat(activeRule.getSeverity()).isEqualTo(RulePriority.BLOCKER);
    assertThat(activeRule.getParameter("javaFiveCompatibility")).isEqualTo("true");
}