当前位置: 首页>>代码示例>>Java>>正文


Java RulesProfile.activateRule方法代码示例

本文整理汇总了Java中org.sonar.api.profiles.RulesProfile.activateRule方法的典型用法代码示例。如果您正苦于以下问题:Java RulesProfile.activateRule方法的具体用法?Java RulesProfile.activateRule怎么用?Java RulesProfile.activateRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.sonar.api.profiles.RulesProfile的用法示例。


在下文中一共展示了RulesProfile.activateRule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addTheIdPropertyWhenManyInstancesWithTheSameConfigKey

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@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()));
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:23,代码来源:CheckstyleProfileExporterTest.java

示例2: getCheckstyleConfiguration

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void getCheckstyleConfiguration() throws Exception {
    fileSystem.setEncoding(StandardCharsets.UTF_8);
    final Settings settings = new Settings(new PropertyDefinitions(
            new CheckstylePlugin().getExtensions()));
    settings.setProperty(CheckstyleConstants.CHECKER_FILTERS_KEY,
            CheckstyleConstants.CHECKER_FILTERS_DEFAULT_VALUE);

    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), profile, 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);
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:26,代码来源:CheckstyleConfigurationTest.java

示例3: testProfileExporter

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@Test
public void testProfileExporter() throws Exception {
  RulesProfile profile = RulesProfile.create();
  profile.activateRule(Rule.create(CSharpReSharperProvider.RESHARPER_CONF.repositoryKey(), "key1", "key1 name"), null);
  profile.activateRule(Rule.create(CSharpReSharperProvider.RESHARPER_CONF.repositoryKey(), "key2", "key2 name"), null);
  profile.activateRule(Rule.create(CSharpReSharperProvider.RESHARPER_CONF.repositoryKey(), "key3", "key3 name"), null);
  profile.activateRule(Rule.create(VBNetReSharperProvider.RESHARPER_CONF.repositoryKey(), "key4", "key4 name"), null);

  CSharpReSharperProvider.CSharpReSharperProfileExporter profileExporter = new CSharpReSharperProvider.CSharpReSharperProfileExporter();
  StringWriter writer = new StringWriter();
  profileExporter.exportProfile(profile, writer);
  assertThat(writer.toString().replace("\r", "").replace("\n", "")).isEqualTo("<wpf:ResourceDictionary xml:space=\"preserve\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:s=\"clr-namespace:System;assembly=mscorlib\" xmlns:ss=\"urn:shemas-jetbrains-com:settings-storage-xaml\" xmlns:wpf=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" +
    "  <s:String x:Key=\"/Default/CodeInspection/Highlighting/InspectionSeverities/=key1/@EntryIndexedValue\">WARNING</s:String>" +
    "  <s:String x:Key=\"/Default/CodeInspection/Highlighting/InspectionSeverities/=key2/@EntryIndexedValue\">WARNING</s:String>" +
    "  <s:String x:Key=\"/Default/CodeInspection/Highlighting/InspectionSeverities/=key3/@EntryIndexedValue\">WARNING</s:String>" +
    "</wpf:ResourceDictionary>");
}
 
开发者ID:GregBartlett,项目名称:sonar-resharper,代码行数:18,代码来源:CSharpReSharperProviderTest.java

示例4: activateRules

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
public void activateRules(RulesProfile profile, String repositoryKey, String profilePath) {
  Set<String> activeKeys = loadActiveKeysFromJsonProfile(profilePath);
  for (String activeKey : activeKeys) {
    Rule rule = ruleFinder.findByKey(repositoryKey, activeKey);
    if (rule == null) {
      String errorMessage = "Failed to activate rule with key '%s'. No corresponding rule found in repository with key '%s'.";
      throw new IllegalStateException(String.format(errorMessage, activeKey, repositoryKey));
    }

    profile.activateRule(rule, null);
  }
}
 
开发者ID:SonarSource,项目名称:sonar-analyzer-commons,代码行数:13,代码来源:ProfileDefinitionReader.java

示例5: processRule

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
private void processRule(RulesProfile profile, String path, String moduleName,
        Map<String, String> properties, ValidationMessages messages) {
    final Rule rule;
    final String id = properties.get("id");
    final String warning;
    if (StringUtils.isNotBlank(id)) {
        rule = ruleFinder.find(RuleQuery.create()
                .withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withKey(id));
        warning = "Checkstyle rule with key '" + id + "' not found";

    }
    else {
        final String configKey = path + moduleName;
        rule = ruleFinder
                .find(RuleQuery.create().withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY)
                        .withConfigKey(configKey));
        warning = "Checkstyle rule with config key '" + configKey + "' not found";
    }

    if (rule == null) {
        messages.addWarningText(warning);

    }
    else {
        final ActiveRule activeRule = profile.activateRule(rule, null);
        activateProperties(activeRule, properties);
    }
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:29,代码来源:CheckstyleProfileImporter.java

示例6: noCheckstyleRulesToExport

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@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()));
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:15,代码来源:CheckstyleProfileExporterTest.java

示例7: singleCheckstyleRulesToExport

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@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.sizes.LineLengthCheck",
                    "Line Length").setConfigKey("Checker/TreeWalker/LineLength"),
            RulePriority.CRITICAL);
    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()));
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:29,代码来源:CheckstyleProfileExporterTest.java

示例8: createProfile

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@Override
public final RulesProfile createProfile(ValidationMessages validation) {
  RulesProfile profile = RulesProfile.create(getProfileName(), getLanguageKey());
  for (Class ruleClass : TanaguruCheckClasses.getCheckClasses()) {
    String ruleKey = RuleAnnotationUtils.getRuleKey(ruleClass);
    if (isActive(ruleClass)) {
      Rule rule = ruleFinder.findByKey(getRepositoryKey(), ruleKey);
      profile.activateRule(rule, null);
    }
  }
  return profile;
}
 
开发者ID:Asqatasun,项目名称:Asqatasun-Sonar-Plugin,代码行数:13,代码来源:BaseProfileDefinition.java

示例9: activeRules

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
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);
	}
}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:16,代码来源:TSQLQualityProfile.java

示例10: activePluginRules

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
private void activePluginRules(final RulesProfile profile) {
	try {
		final SqlRules rules = new CustomPluginChecksProvider().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);
	}
}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:13,代码来源:TSQLQualityProfile.java

示例11: testWriterException

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@Test
public void testWriterException() throws Exception {
  Writer writer = mock(Writer.class);
  doThrow(IOException.class).when(writer).write(anyString());

  RulesProfile profile = RulesProfile.create("name", "key");
  profile.activateRule(Rule.create("key", "ruleKey", "ruleName"), null);

  ReSharperProfileExporter exporter = new ReSharperProfileExporter(new ReSharperConfiguration("key", "key", "key"));

  thrown.expectMessage("Failed to export profile [name=name,language=key]");
  thrown.expect(IllegalStateException.class);

  exporter.exportProfile(profile, writer);
}
 
开发者ID:GregBartlett,项目名称:sonar-resharper,代码行数:16,代码来源:ReSharperProfileExporterTest.java

示例12: testProfileExporter

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@Test
public void testProfileExporter() throws Exception {
  RulesProfile profile = RulesProfile.create();
  profile.activateRule(Rule.create(VBNetReSharperProvider.RESHARPER_CONF.repositoryKey(), "key1", "key1 name"), null);
  profile.activateRule(Rule.create(VBNetReSharperProvider.RESHARPER_CONF.repositoryKey(), "key2", "key2 name"), null);
  profile.activateRule(Rule.create(CSharpReSharperProvider.RESHARPER_CONF.repositoryKey(), "key3", "key3 name"), null);

  VBNetReSharperProvider.VBNetReSharperProfileExporter profileExporter = new VBNetReSharperProvider.VBNetReSharperProfileExporter();
  StringWriter writer = new StringWriter();
  profileExporter.exportProfile(profile, writer);
  assertThat(writer.toString().replace("\r", "").replace("\n", "")).isEqualTo("<wpf:ResourceDictionary xml:space=\"preserve\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:s=\"clr-namespace:System;assembly=mscorlib\" xmlns:ss=\"urn:shemas-jetbrains-com:settings-storage-xaml\" xmlns:wpf=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" +
    "  <s:String x:Key=\"/Default/CodeInspection/Highlighting/InspectionSeverities/=key1/@EntryIndexedValue\">WARNING</s:String>" +
    "  <s:String x:Key=\"/Default/CodeInspection/Highlighting/InspectionSeverities/=key2/@EntryIndexedValue\">WARNING</s:String>" +
    "</wpf:ResourceDictionary>");
}
 
开发者ID:GregBartlett,项目名称:sonar-resharper,代码行数:16,代码来源:VBNetReSharperProviderTest.java

示例13: createProfile

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@Override
public RulesProfile createProfile(final ValidationMessages validation) {
    LOGGER.debug("DefaultSpringProfile createProfile start");
    List<Rule> rules = this.springRulesRepository.createRules();
    RulesProfile rulesProfile = RulesProfile.create("Default Spring Profile", Spring.KEY);
    for (Rule rule : rules) {
        LOGGER.debug("DefaultSpringProfile createProfile activating rule: " + rule.toString());
        rulesProfile.activateRule(rule, null);
    }
    rulesProfile.setDefaultProfile(true);
    LOGGER.debug("DefaultSpringProfile createProfile end");
    return rulesProfile;
}
 
开发者ID:shmc,项目名称:sonar-spring-rules-plugin,代码行数:14,代码来源:DefaultSpringProfile.java

示例14: createProfile

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@Override
public RulesProfile createProfile(ValidationMessages messages) {
  RulesProfile profile = RulesProfile.create(NAME, WebConstants.LANGUAGE_KEY);
  Set<String> activeKeys = loadActiveKeysFromJsonProfile();
  for (Class ruleClass : CheckClasses.getCheckClasses()) {
    String ruleKey = RuleAnnotationUtils.getRuleKey(ruleClass);
    if (activeKeys.contains(ruleKey)) {
      Rule rule = ruleFinder.findByKey(WebRulesDefinition.REPOSITORY_KEY, ruleKey);
      profile.activateRule(rule, null);
    }
  }
  return profile;
}
 
开发者ID:SonarSource,项目名称:sonar-web,代码行数:14,代码来源:SonarWayProfile.java

示例15: activateRule

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
private static void activateRule(RulesProfile profile, String ruleKey) {
    profile.activateRule(Rule.create(TsRulesDefinition.REPOSITORY_NAME, ruleKey), null);
}
 
开发者ID:Pablissimo,项目名称:SonarTsPlugin,代码行数:4,代码来源:TypeScriptRuleProfile.java


注:本文中的org.sonar.api.profiles.RulesProfile.activateRule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。