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


Java RulesProfile类代码示例

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


RulesProfile类属于org.sonar.api.profiles包,在下文中一共展示了RulesProfile类的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: exportProfile

import org.sonar.api.profiles.RulesProfile; //导入依赖的package包/类
@Override
public void exportProfile(RulesProfile profile, Writer writer) {
    try {
        final List<ActiveRule> activeRules = profile
                .getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY);
        if (activeRules != null) {
            final Map<String, List<ActiveRule>> activeRulesByConfigKey =
                    arrangeByConfigKey(activeRules);
            generateXml(writer, activeRulesByConfigKey);
        }
    }
    catch (IOException ex) {
        throw new IllegalStateException("Fail to export the profile " + profile, ex);
    }

}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:17,代码来源:CheckstyleProfileExporter.java

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

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

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

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

示例8: getExtensions

import org.sonar.api.profiles.RulesProfile; //导入依赖的package包/类
@Override
public List getExtensions() {
  List extensions = new ArrayList<Object>();

  extensions.add(new AbstractLanguage("vbnet") {

    @Override
    public String[] getFileSuffixes() {
      return new String[] {".vb"};
    }

  });

  extensions.add(new ProfileDefinition() {

    @Override
    public RulesProfile createProfile(ValidationMessages validation) {
      RulesProfile profile = RulesProfile.create("Sonar Way", "vbnet");
      profile.setDefaultProfile(true);
      return profile;
    }

  });

  return extensions;
}
 
开发者ID:GregBartlett,项目名称:sonar-resharper,代码行数:27,代码来源:FakeVbNetPlugin.java

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

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

示例11: test_profile_importer

import org.sonar.api.profiles.RulesProfile; //导入依赖的package包/类
@Test
public void test_profile_importer() throws Exception {
  String content = "<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\">ERROR</s:String>" +
    "<s:String x:Key=\"/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedVariable_002ECompiler/@EntryIndexedValue\">HINT</s:String>" +
    "<s:String x:Key=\"/Default/CodeInspection/Highlighting/InspectionSeverities/=key2/@EntryIndexedValue\">DO_NOT_SHOW</s:String>" +
    "<s:String x:Key=\"/Default/CodeInspection/Highlighting/InspectionSeverities/=key2\">DO_NOT_SHOW</s:String>" +
    "<s:String x:Key=\"/Default/CodeInspection/Highlighting/InspectionSeverities/=key2/@EntryIndexedValue\">INVALID_SEVERITY</s:String>" +
    "<s:String x:Key=\"/other/entry\">value</s:String>" +
    "<s:String>value</s:String>" +
    "<s:other>value</s:other>" +
    "</wpf:ResourceDictionary>";
  ReSharperProfileImporter importer = new ReSharperProfileImporter(new ReSharperConfiguration("key", "key", "key"));
  ValidationMessages messages = ValidationMessages.create();
  RulesProfile profile = importer.importProfile(new StringReader(content), messages);
  List<ActiveRule> rules = profile.getActiveRules();
  assertThat(rules).hasSize(3);
  Map<String, String> ruleKeys = getKeysWithSeverities(rules);
  assertThat(ruleKeys.keySet()).containsOnly("key1", "key2", "UnusedVariable.Compiler");
  assertThat(ruleKeys.get("key1")).isEqualTo("MAJOR");
  assertThat(ruleKeys.get("key2")).isEqualTo("CRITICAL");
  assertThat(ruleKeys.get("UnusedVariable.Compiler")).isEqualTo("INFO");
  assertThat(messages.getErrors()).containsExactly("Skipping rule key2 because has an unexpected severity: INVALID_SEVERITY");
}
 
开发者ID:GregBartlett,项目名称:sonar-resharper,代码行数:26,代码来源:ReSharperProfileImporterTest.java

示例12: shouldExecuteOnProject

import org.sonar.api.profiles.RulesProfile; //导入依赖的package包/类
@Test
public void shouldExecuteOnProject() {
  Settings settings = mock(Settings.class);
  RulesProfile profile = mock(RulesProfile.class);
  DefaultFileSystem fileSystem = new DefaultFileSystem();
  ResourcePerspectives perspectives = mock(ResourcePerspectives.class);

  Project project = mock(Project.class);

  ReSharperSensor sensor = new ReSharperSensor(
    new ReSharperConfiguration("lang", "foo-resharper", "fooReportkey"),
    settings, profile, fileSystem, perspectives);

  assertThat(sensor.shouldExecuteOnProject(project)).isFalse();

  fileSystem.add(new DefaultInputFile("").setAbsolutePath("").setLanguage("foo"));
  when(profile.getActiveRulesByRepository("foo-resharper")).thenReturn(ImmutableList.<ActiveRule>of());
  assertThat(sensor.shouldExecuteOnProject(project)).isFalse();

  fileSystem.add(new DefaultInputFile("").setAbsolutePath("").setLanguage("lang"));
  when(profile.getActiveRulesByRepository("foo-resharper")).thenReturn(ImmutableList.of(mock(ActiveRule.class)));
  assertThat(sensor.shouldExecuteOnProject(project)).isTrue();

  when(profile.getActiveRulesByRepository("foo-resharper")).thenReturn(ImmutableList.<ActiveRule>of());
  assertThat(sensor.shouldExecuteOnProject(project)).isFalse();
}
 
开发者ID:GregBartlett,项目名称:sonar-resharper,代码行数:27,代码来源:ReSharperSensorTest.java

示例13: createChecks

import org.sonar.api.profiles.RulesProfile; //导入依赖的package包/类
/**
 * Instantiate checks as defined in the RulesProfile.
 * 
 * @param profile
 */
public static List<BeanCheck> createChecks(final RulesProfile profile) {
    LOGGER.debug("Loading checks for profile " + profile.getName());

    List<BeanCheck> checks = new ArrayList<BeanCheck>();
    LOGGER.debug("SpringSensor analyse profile.getActiveRules().size(): " + profile.getActiveRules().size());

    for (ActiveRule activeRule : profile.getActiveRules()) {
    	LOGGER.debug("SpringRulesRepository createChecks activeRule: " + activeRule.toString());
        if (REPOSITORY_KEY.equals(activeRule.getRepositoryKey())) {
            Class<BeanCheck> checkClass = getCheckClass(activeRule);
        	LOGGER.debug("SpringRulesRepository createChecks checkClass.getName(): " + checkClass.getName());
            if (checkClass != null) {
                checks.add(createCheck(checkClass, activeRule));
            }
        }
    }

    return checks;
}
 
开发者ID:shmc,项目名称:sonar-spring-rules-plugin,代码行数:25,代码来源:SpringRulesRepository.java

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

示例15: createProfile

import org.sonar.api.profiles.RulesProfile; //导入依赖的package包/类
@Override
public RulesProfile createProfile(ValidationMessages validation) {
    AnnotationBasedProfileBuilder annotationBasedProfileBuilder = new AnnotationBasedProfileBuilder(ruleFinder);
    return annotationBasedProfileBuilder.build(
            CheckList.REPOSITORY_KEY,
            CheckList.MAIN_PROFILE,
            OneC.KEY,
            CheckList.getChecks(),
            validation);
}
 
开发者ID:antowski,项目名称:sonar-onec,代码行数:11,代码来源:OneCQualityProfile.java


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