本文整理汇总了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()));
}
示例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);
}
示例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>");
}
示例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);
}
}
示例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);
}
}
示例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()));
}
示例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()));
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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>");
}
示例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;
}
示例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;
}
示例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);
}