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


Java RulesProfile.create方法代码示例

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


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

示例1: load_profile_keys

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@Test
public void load_profile_keys() throws Exception {
  ruleFinder = mock(RuleFinder.class);
  when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
    @Override
    public Rule answer(InvocationOnMock iom) throws Throwable {
      String repositoryKey = (String) iom.getArguments()[0];
      String ruleKey = (String) iom.getArguments()[1];
      return Rule.create(repositoryKey, ruleKey, ruleKey);
    }
  });

  RulesProfile profile = RulesProfile.create("profile-name", "lang-key");
  ProfileDefinitionReader definitionReader = new ProfileDefinitionReader(ruleFinder);
  definitionReader.activateRules(profile, "repo-key", "org/sonarsource/analyzer/commons/Sonar_way_profile.json");
  assertThat(profile.getActiveRules()).hasSize(2);
  assertThat(profile.getActiveRule("repo-key", "S100")).isNotNull();
  assertThat(profile.getActiveRule("repo-key", "S110")).isNotNull();
  assertThat(profile.getActiveRule("repo-key", "S123")).isNull();
  assertThat(profile.getActiveRule("repo-key", "S666")).isNull();
}
 
开发者ID:SonarSource,项目名称:sonar-analyzer-commons,代码行数:22,代码来源:ProfileDefinitionReaderTest.java

示例2: fails_with_non_existing_rule_key

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@Test
public void fails_with_non_existing_rule_key() throws Exception {
  ruleFinder = mock(RuleFinder.class);
  when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
    @Override
    public Rule answer(InvocationOnMock iom) throws Throwable {
      String repositoryKey = (String) iom.getArguments()[0];
      String ruleKey = (String) iom.getArguments()[1];
      if (ruleKey.equals("S666")) {
        return null;
      }
      return Rule.create(repositoryKey, ruleKey, ruleKey);
    }
  });

  RulesProfile profile = RulesProfile.create("profile-name", "lang-key");
  ProfileDefinitionReader definitionReader = new ProfileDefinitionReader(ruleFinder);

  thrown.expect(IllegalStateException.class);
  thrown.expectMessage("Failed to activate rule with key 'S666'. No corresponding rule found in repository with key 'repo-key'.");

  definitionReader.activateRules(profile, "repo-key", "org/sonarsource/analyzer/commons/Sonar_way_profile_invalid.json");
}
 
开发者ID:SonarSource,项目名称:sonar-analyzer-commons,代码行数:24,代码来源:ProfileDefinitionReaderTest.java

示例3: 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

示例4: exportParameters

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

示例5: addCustomCheckerFilters

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

示例6: 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

示例7: importProfile

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@Override
public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
  this.messages = messages;
  profile = RulesProfile.create();
  StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
    @Override
    public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
      rootCursor.advance();
      parseRootNode(rootCursor);
    }
  });
  try {
    parser.parse(new ReaderInputStream(reader));
  } catch (XMLStreamException e) {
    String errorMessage = "Error parsing content";
    messages.addErrorText(errorMessage + ": " + e);
    LOG.error(errorMessage, e);
  }
  return profile;
}
 
开发者ID:GregBartlett,项目名称:sonar-resharper,代码行数:21,代码来源:ReSharperProfileImporter.java

示例8: 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

示例9: importProfile

import org.sonar.api.profiles.RulesProfile; //导入方法依赖的package包/类
@Override
public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
    final SMInputFactory inputFactory = initStax();
    final RulesProfile profile = RulesProfile.create();
    try {
        final Module checkerModule = loadModule(inputFactory.rootElementCursor(reader)
                .advance());

        for (Module rootModule : checkerModule.modules) {
            final Map<String, String> rootModuleProperties = new HashMap<>(
                    checkerModule.properties);
            rootModuleProperties.putAll(rootModule.properties);

            if (StringUtils.equals(TREEWALKER_MODULE, rootModule.name)) {
                processTreewalker(profile, rootModule, rootModuleProperties, messages);
            }
            else {
                processModule(profile, CHECKER_MODULE + "/", rootModule.name,
                        rootModuleProperties, messages);
            }
        }

    }
    catch (XMLStreamException ex) {
        final String message = "XML is not valid: " + ex.getMessage();
        LOG.error(message, ex);
        messages.addErrorText(message);
    }
    return profile;
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:31,代码来源:CheckstyleProfileImporter.java

示例10: alwaysSetSuppressionCommentFilter

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

示例11: 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

示例12: 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

示例13: addCustomTreewalkerFilters

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

示例14: 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

示例15: createProfile

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


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