org.sonar.api.rules.RuleFinder Java Examples
The following examples show how to use
org.sonar.api.rules.RuleFinder.
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: PmdProfileImporterTest.java From sonar-p3c-pmd with MIT License | 6 votes |
static RuleFinder createRuleFinder() { RuleFinder ruleFinder = mock(RuleFinder.class); when(ruleFinder.find(any(RuleQuery.class))).then(new Answer<Rule>() { @Override public Rule answer(InvocationOnMock invocation) { RuleQuery query = (RuleQuery) invocation.getArguments()[0]; String configKey = query.getConfigKey(); String key = configKey.substring(configKey.lastIndexOf('/') + 1, configKey.length()); Rule rule = Rule.create(query.getRepositoryKey(), key, "").setConfigKey(configKey).setSeverity(RulePriority.BLOCKER); if (rule.getConfigKey().equals("rulesets/java/coupling.xml/ExcessiveImports")) { rule.createParameter("minimum"); } return rule; } }); return ruleFinder; }
Example #2
Source File: PmdProfileExporterTest.java From sonar-p3c-pmd with MIT License | 6 votes |
static RuleFinder createRuleFinder(final List<RulesDefinition.Rule> rules) { RuleFinder ruleFinder = mock(RuleFinder.class); final List<Rule> convertedRules = convert(rules); when(ruleFinder.find(any(RuleQuery.class))).then(new Answer<Rule>() { @Override public Rule answer(InvocationOnMock invocation) { RuleQuery query = (RuleQuery) invocation.getArguments()[0]; for (Rule rule : convertedRules) { if (query.getConfigKey().equals(rule.getConfigKey())) { return rule; } } return null; } }); return ruleFinder; }
Example #3
Source File: ScssProfileTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private RuleFinder universalRuleFinder() { RuleFinder ruleFinder = mock(RuleFinder.class); when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer( iom -> Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1])); return ruleFinder; }
Example #4
Source File: LuaProfileTest.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
static RuleFinder ruleFinder() { return when(mock(RuleFinder.class).findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() { @Override public Rule answer(InvocationOnMock invocation) { Object[] arguments = invocation.getArguments(); return Rule.create((String) arguments[0], (String) arguments[1], (String) arguments[1]); } }).getMock(); }
Example #5
Source File: LuaProfileTest.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
@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 #6
Source File: GherkinProfileTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private RuleFinder universalRuleFinder() { RuleFinder ruleFinder = mock(RuleFinder.class); when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() { @Override public Rule answer(InvocationOnMock iom) throws Throwable { return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]); } }); return ruleFinder; }
Example #7
Source File: ApexProfileTest.java From enforce-sonarqube-plugin with MIT License | 5 votes |
static RuleFinder buildRuleFinder() { Rule rule = mock(RuleFinder.class).findByKey(anyString(), anyString()); return when(rule).thenAnswer((InvocationOnMock invocation) -> { Object[] arguments = invocation.getArguments(); return Rule.create(String.valueOf(arguments[0]), String.valueOf(arguments[1]), String.valueOf(arguments[1])); }).getMock(); }
Example #8
Source File: ApexProfileTest.java From enforce-sonarqube-plugin with MIT License | 5 votes |
@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 #9
Source File: LessProfileTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private RuleFinder universalRuleFinder() { RuleFinder ruleFinder = mock(RuleFinder.class); when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer( iom -> Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1])); return ruleFinder; }
Example #10
Source File: CssProfileTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private RuleFinder universalRuleFinder() { RuleFinder ruleFinder = mock(RuleFinder.class); when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer( iom -> Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1])); return ruleFinder; }
Example #11
Source File: PmdProfileExporterTest.java From sonar-p3c-pmd with MIT License | 5 votes |
static RulesProfile importProfile(String configuration) { PmdRulesDefinition definition = new PmdRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(PmdConstants.REPOSITORY_KEY); RuleFinder ruleFinder = createRuleFinder(repository.rules()); PmdProfileImporter importer = new PmdProfileImporter(ruleFinder); return importer.importProfile(new StringReader(configuration), ValidationMessages.create()); }
Example #12
Source File: PmdProfileImporterTest.java From sonar-p3c-pmd with MIT License | 5 votes |
@Test public void should_warn_on_unknown_rule() { Reader reader = read("/org/sonar/plugins/pmd/simple.xml"); importer = new PmdProfileImporter(mock(RuleFinder.class)); RulesProfile profile = importer.importProfile(reader, messages); assertThat(profile.getActiveRules()).isEmpty(); assertThat(messages.getWarnings()).hasSize(4); }
Example #13
Source File: ScssProfile.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 4 votes |
public ScssProfile(RuleFinder ruleFinder) { this.ruleFinder = ruleFinder; }
Example #14
Source File: PmdProfileImporter.java From sonar-p3c-pmd with MIT License | 4 votes |
public PmdProfileImporter(RuleFinder ruleFinder) { super(PmdConstants.REPOSITORY_KEY, PmdConstants.PLUGIN_NAME); setSupportedLanguages(Java.KEY); this.ruleFinder = ruleFinder; }
Example #15
Source File: CheckstyleProfileImporter.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 4 votes |
public CheckstyleProfileImporter(RuleFinder ruleFinder) { super(CheckstyleConstants.REPOSITORY_KEY, CheckstyleConstants.PLUGIN_NAME); setSupportedLanguages(CheckstyleConstants.JAVA_KEY); this.ruleFinder = ruleFinder; }
Example #16
Source File: CheckstyleProfileImporterTest.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 4 votes |
private static RuleFinder newRuleFinder() { final RuleFinder ruleFinder = mock(RuleFinder.class); when(ruleFinder.find(any(RuleQuery.class))).thenAnswer(new RuleAnswer()); return ruleFinder; }
Example #17
Source File: LessProfile.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 4 votes |
public LessProfile(RuleFinder ruleFinder) { this.ruleFinder = ruleFinder; }
Example #18
Source File: CssProfile.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 4 votes |
public CssProfile(RuleFinder ruleFinder) { this.ruleFinder = ruleFinder; }
Example #19
Source File: GherkinProfile.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 4 votes |
public GherkinProfile(RuleFinder ruleFinder) { this.ruleFinder = ruleFinder; }
Example #20
Source File: LuaProfile.java From sonar-lua with GNU Lesser General Public License v3.0 | 4 votes |
public LuaProfile(RuleFinder ruleFinder) { this.ruleFinder = ruleFinder; }
Example #21
Source File: PmdViolationRecorder.java From sonar-p3c-pmd with MIT License | 4 votes |
public PmdViolationRecorder(FileSystem fs, RuleFinder ruleFinder, ResourcePerspectives perspectives) { this.fs = fs; this.ruleFinder = ruleFinder; this.perspectives = perspectives; }
Example #22
Source File: ApexProfile.java From enforce-sonarqube-plugin with MIT License | 2 votes |
/** * Default constructor to store a rule. * * @param ruleFinder rules. */ public ApexProfile(RuleFinder ruleFinder) { this.ruleFinder = ruleFinder; }