org.sonar.api.batch.rule.ActiveRules Java Examples
The following examples show how to use
org.sonar.api.batch.rule.ActiveRules.
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: LessAnalyzerSensorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() { inputFile("parsingError.less"); ActiveRules activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(CheckList.LESS_REPOSITORY_KEY, "S2260")) .activate() .build(); checkFactory = new CheckFactory(activeRules); context.setActiveRules(activeRules); createLessSquidSensor().execute(context); Collection<Issue> issues = context.allIssues(); assertThat(issues).hasSize(1); Issue issue = issues.iterator().next(); assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1); }
Example #2
Source File: GherkinSquidSensorTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void should_execute_and_save_issues_on_UTF8_with_BOM_file() { inputFile("my-feature-bom.feature", Charsets.UTF_8); ActiveRules activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, CommentConventionCheck.class.getAnnotation(Rule.class).key())) .activate() .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, MissingNewlineAtEndOfFileCheck.class.getAnnotation(Rule.class).key())) .activate() .build(); checkFactory = new CheckFactory(activeRules); createGherkinSquidSensor().execute(context); assertThat(context.allIssues()).hasSize(3); }
Example #3
Source File: GherkinSquidSensorTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void should_execute_and_save_issues_on_UTF8_file() { inputFile("my-feature.feature", Charsets.UTF_8); ActiveRules activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, CommentConventionCheck.class.getAnnotation(Rule.class).key())) .activate() .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, MissingNewlineAtEndOfFileCheck.class.getAnnotation(Rule.class).key())) .activate() .build(); checkFactory = new CheckFactory(activeRules); createGherkinSquidSensor().execute(context); assertThat(context.allIssues()).hasSize(3); }
Example #4
Source File: GherkinSquidSensorTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void should_execute_and_save_issues_on_UTF8_with_BOM_file_french() { inputFile("my-feature-bom-fr.feature", Charsets.UTF_8); ActiveRules activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, CommentConventionCheck.class.getAnnotation(Rule.class).key())) .activate() .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, MissingNewlineAtEndOfFileCheck.class.getAnnotation(Rule.class).key())) .activate() .build(); checkFactory = new CheckFactory(activeRules); createGherkinSquidSensor().execute(context); assertThat(context.allIssues()).hasSize(3); }
Example #5
Source File: CheckstyleProfileExporter.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 6 votes |
public void exportProfile(ActiveRules activeRules, Writer writer) { try { final List<ActiveRuleWrapper> activeRuleWrappers = new ArrayList<>(); for (org.sonar.api.batch.rule.ActiveRule activeRule : activeRules .findByRepository(CheckstyleConstants.REPOSITORY_KEY)) { activeRuleWrappers.add(new ActiveRuleWrapperScannerImpl(activeRule)); } final Map<String, List<ActiveRuleWrapper>> activeRulesByConfigKey = arrangeByConfigKey(activeRuleWrappers); generateXml(writer, activeRulesByConfigKey); } catch (IOException ex) { throw new IllegalStateException("Fail to export active rules.", ex); } }
Example #6
Source File: GherkinSquidSensorTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void should_execute_and_save_issues_on_UTF8_file_french() { inputFile("my-feature-fr.feature", Charsets.UTF_8); ActiveRules activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, CommentConventionCheck.class.getAnnotation(Rule.class).key())) .activate() .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, MissingNewlineAtEndOfFileCheck.class.getAnnotation(Rule.class).key())) .activate() .build(); checkFactory = new CheckFactory(activeRules); createGherkinSquidSensor().execute(context); assertThat(context.allIssues()).hasSize(3); }
Example #7
Source File: ScssAnalyzerSensorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() { inputFile("parsingError.scss"); ActiveRules activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(CheckList.SCSS_REPOSITORY_KEY, "S2260")) .activate() .build(); checkFactory = new CheckFactory(activeRules); context.setActiveRules(activeRules); createScssSquidSensor().execute(context); Collection<Issue> issues = context.allIssues(); assertThat(issues).hasSize(1); Issue issue = issues.iterator().next(); assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1); }
Example #8
Source File: GherkinSquidSensorTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() { String relativePath = "parsing-error.feature"; inputFile(relativePath, Charsets.UTF_8); ActiveRules activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, "S2260")) .activate() .build(); checkFactory = new CheckFactory(activeRules); context.setActiveRules(activeRules); createGherkinSquidSensor().execute(context); Collection<Issue> issues = context.allIssues(); assertThat(issues).hasSize(1); Issue issue = issues.iterator().next(); assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1); }
Example #9
Source File: EsqlSensorTest.java From sonar-esql-plugin with Apache License 2.0 | 6 votes |
@Test public void parsing_error() { String relativePath = "cpd/parsingError.esql"; inputFile(relativePath); String parsingErrorCheckKey = "ParsingError"; ActiveRules activeRules = (new ActiveRulesBuilder()) .addRule(new NewActiveRule.Builder().setName("ParsingError").setRuleKey(RuleKey.of(CheckList.REPOSITORY_KEY, parsingErrorCheckKey)).build()) .build(); checkFactory = new CheckFactory(activeRules); context.setActiveRules(activeRules); createSensor().execute(context); Collection<Issue> issues = context.allIssues(); assertThat(issues).hasSize(1); Issue issue = issues.iterator().next(); assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(3); assertThat(issue.primaryLocation().message()).isEqualTo("Parse error"); assertThat(context.allAnalysisErrors()).hasSize(1); }
Example #10
Source File: EsqlSensorTest.java From sonar-esql-plugin with Apache License 2.0 | 6 votes |
@Test public void analysis_with_issues_should_not_add_error_to_context() { inputFile("file.esql"); ActiveRules activeRules = (new ActiveRulesBuilder()) .addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of(CheckList.REPOSITORY_KEY, "MissingNewlineAtEndOfFile")).build()) .build(); checkFactory = new CheckFactory(activeRules); createSensor().execute(context); Collection<Issue> issues = context.allIssues(); assertThat(issues).hasSize(1); assertThat(context.allAnalysisErrors()).isEmpty(); }
Example #11
Source File: EsqlSensorTest.java From sonar-esql-plugin with Apache License 2.0 | 6 votes |
@Test public void custom_rule() throws Exception { inputFile("file.esql"); ActiveRules activeRules = (new ActiveRulesBuilder()) .addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of("customKey", "key")).build()).build(); checkFactory = new CheckFactory(activeRules); createSensorWithCustomRules().execute(context); Collection<Issue> issues = context.allIssues(); assertThat(issues).hasSize(1); Issue issue = issues.iterator().next(); assertThat(issue.gap()).isEqualTo(42); assertThat(issue.primaryLocation().message()).isEqualTo("Message of custom rule"); assertThat(issue.primaryLocation().textRange()) .isEqualTo(new DefaultTextRange(new DefaultTextPointer(1, 0), new DefaultTextPointer(1, 24))); }
Example #12
Source File: CssAnalyzerSensorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() { inputFile("parsingError.css"); ActiveRules activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(CheckList.CSS_REPOSITORY_KEY, "S2260")) .activate() .build(); checkFactory = new CheckFactory(activeRules); context.setActiveRules(activeRules); createCssSquidSensor().execute(context); Collection<Issue> issues = context.allIssues(); assertThat(issues).hasSize(1); Issue issue = issues.iterator().next(); assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1); }
Example #13
Source File: AbstractAnsibleSensorTest.java From sonar-ansible with Apache License 2.0 | 6 votes |
@Before public void init() throws Exception { context = Utils.getSensorContext(); DefaultFileSystem fs = Utils.getFileSystem(); fs.setWorkDir(temporaryFolder.newFolder("temp").toPath()); context.setFileSystem(fs); ActiveRules activeRules = new ActiveRulesBuilder() .create(ruleKey1) .activate() .create(ruleKey2) .activate() .create(ruleKey3) .activate() .build(); context.setActiveRules(activeRules); FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(mock(FileLinesContext.class)); sensor = new MySensor(fs); }
Example #14
Source File: AnsibleSensorTest.java From sonar-ansible with Apache License 2.0 | 6 votes |
@Before public void init() throws Exception { Path baseDir = Paths.get("src/test/resources"); context = SensorContextTester.create(baseDir); DefaultFileSystem fs = new DefaultFileSystem(baseDir); fs.setWorkDir(temporaryFolder.newFolder("temp").toPath()); context.setFileSystem(fs); ActiveRules activeRules = new ActiveRulesBuilder() .create(ruleKey1) .activate() .create(ruleKey2) .activate() .create(ruleKey3) .activate() .build(); context.setActiveRules(activeRules); FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(mock(FileLinesContext.class)); sensor = new AnsibleSensor(fs); }
Example #15
Source File: AnsibleExtraSensorTest.java From sonar-ansible with Apache License 2.0 | 6 votes |
@Before public void init() throws Exception { context = Utils.getSensorContext(); DefaultFileSystem fs = Utils.getFileSystem(); fs.setWorkDir(temporaryFolder.newFolder("temp").toPath()); context.setFileSystem(fs); ActiveRules activeRules = new ActiveRulesBuilder() .create(ruleKey1) .activate() .create(ruleKey2) .activate() .build(); context.setActiveRules(activeRules); FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(mock(FileLinesContext.class)); sensor = new AnsibleExtraSensor(context.fileSystem()); }
Example #16
Source File: ColdFusionSensor.java From sonar-coldfusion with Apache License 2.0 | 5 votes |
public ColdFusionSensor(FileSystem fs, ActiveRules ruleProfile) { Preconditions.checkNotNull(fs); Preconditions.checkNotNull(ruleProfile); this.fs = fs; this.ruleProfile = ruleProfile; }
Example #17
Source File: ColdFusionProfileExporter.java From sonar-coldfusion with Apache License 2.0 | 5 votes |
public void exportProfile(ActiveRules activeRules, Writer writer) { try { new CFLintConfigExporter(activeRules.findByRepository(ColdFusionPlugin.REPOSITORY_KEY)).save(writer); } catch (IOException | XMLStreamException e) { Throwables.propagate(e); } }
Example #18
Source File: LuaSquidSensorTest.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void setUp() throws Exception { NewActiveRule ar = new ActiveRulesBuilder().create(RuleKey.of("lua", "S1125")).setSeverity("BLOCKER"); ActiveRules activeRules = new DefaultActiveRules(Collections.singletonList(ar)); CheckFactory checkFactory = new CheckFactory(activeRules); FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); when(fileLinesContextFactory.createFor(Mockito.any(InputFile.class))).thenReturn(mock(FileLinesContext.class)); sensor = new LuaSquidSensor(checkFactory, fileLinesContextFactory); tester = SensorContextTester.create(TEST_DIR); }
Example #19
Source File: GherkinSquidSensorTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void should_not_raise_any_issue_because_the_parsing_error_rule_is_not_activated() { String relativePath = "parsing-error.feature"; inputFile(relativePath, Charsets.UTF_8); ActiveRules activeRules = new ActiveRulesBuilder().build(); checkFactory = new CheckFactory(activeRules); context.setActiveRules(activeRules); createGherkinSquidSensor().execute(context); Collection<Issue> issues = context.allIssues(); assertThat(issues).hasSize(0); }
Example #20
Source File: EsqlSensorTest.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
@Test public void save_issue() throws Exception { inputFile("file.esql"); ActiveRules activeRules = (new ActiveRulesBuilder()) .addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of(CheckList.REPOSITORY_KEY, "MissingNewlineAtEndOfFile")).build()) .addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of(CheckList.REPOSITORY_KEY, "InitializeVariables")).build()) .build(); checkFactory = new CheckFactory(activeRules); createSensor().execute(context); Collection<Issue> issues = context.allIssues(); assertThat(issues).hasSize(2); }
Example #21
Source File: ApexSquidSensorTest.java From enforce-sonarqube-plugin with MIT License | 5 votes |
@Before public void setUp() { ActiveRules activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(CheckList.REPOSITORY_KEY, "PrintStatementUsage")) .setName("Print Statement Usage") .activate() .build(); CheckFactory checkFactory = new CheckFactory(activeRules); perspectives = mock(ResourcePerspectives.class); fileSystem = new DefaultFileSystem(new File(".")); squidSensor = new ApexSquidSensor(fileSystem, perspectives, checkFactory); }
Example #22
Source File: CheckstyleConfigurationTest.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void exportProfile(ActiveRules activeRules, Writer writer) { try { writer.write("<conf/>"); } catch (IOException ex) { throw new IllegalStateException(ex); } }
Example #23
Source File: CheckstyleProfileExporterTest.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void singleCheckstyleActiveRulesToExport() { final ActiveRules activeRules = Mockito.mock(ActiveRules.class); Mockito.when(activeRules.findByRepository(CheckstyleConstants.REPOSITORY_KEY)) .thenReturn(Collections.singletonList(new TestActiveRule())); final StringWriter writer = new StringWriter(); new CheckstyleProfileExporter(settings).exportProfile(activeRules, writer); CheckstyleTestUtils.assertSimilarXmlWithResource( "/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/" + "singleCheckstyleActiveRulesToExport.xml", sanitizeForTests(writer.toString())); }
Example #24
Source File: CheckstyleAuditListenerTest.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void before() { fileSystem = mock(FileSystem.class); context = mock(SensorContext.class); inputFile = mock(InputFile.class); ruleFinder = mock(ActiveRules.class); final FilePredicates predicates = mock(FilePredicates.class); final FilePredicate filePredicate = mock(FilePredicate.class); when(fileSystem.inputFile(any(FilePredicate.class))).thenReturn(inputFile); when(fileSystem.predicates()).thenReturn(predicates); when(predicates.hasAbsolutePath(anyString())).thenReturn(filePredicate); }
Example #25
Source File: CheckstyleConfiguration.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 5 votes |
public CheckstyleConfiguration( org.sonar.api.config.Configuration conf, CheckstyleProfileExporter confExporter, ActiveRules activeRules, FileSystem fileSystem) { this.conf = conf; this.confExporter = confExporter; this.activeRules = activeRules; this.fileSystem = fileSystem; }
Example #26
Source File: ScssAnalyzerSensorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void should_not_raise_any_issue_because_the_parsing_error_rule_is_not_activated() { inputFile("parsingError.scss"); ActiveRules activeRules = new ActiveRulesBuilder().build(); checkFactory = new CheckFactory(activeRules); context.setActiveRules(activeRules); createScssSquidSensor().execute(context); Collection<Issue> issues = context.allIssues(); assertThat(issues).isEmpty(); }
Example #27
Source File: ScssAnalyzerSensorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void should_execute_and_save_issues(String fileName) { inputFile(fileName); ActiveRules activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(CheckList.SCSS_REPOSITORY_KEY, "scss-variable-naming-convention")) .activate() .create(RuleKey.of(CheckList.SCSS_REPOSITORY_KEY, "important")) .activate() .build(); checkFactory = new CheckFactory(activeRules); createScssSquidSensor().execute(context); assertThat(context.allIssues()).hasSize(3); }
Example #28
Source File: LessAnalyzerSensorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void should_not_raise_any_issue_because_the_parsing_error_rule_is_not_activated() { inputFile("parsingError.less"); ActiveRules activeRules = new ActiveRulesBuilder().build(); checkFactory = new CheckFactory(activeRules); context.setActiveRules(activeRules); createLessSquidSensor().execute(context); Collection<Issue> issues = context.allIssues(); assertThat(issues).isEmpty(); }
Example #29
Source File: LessAnalyzerSensorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void should_execute_and_save_issues(String fileName) { inputFile(fileName); ActiveRules activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(CheckList.LESS_REPOSITORY_KEY, "less-variable-naming-convention")) .activate() .create(RuleKey.of(CheckList.LESS_REPOSITORY_KEY, "important")) .activate() .build(); checkFactory = new CheckFactory(activeRules); createLessSquidSensor().execute(context); assertThat(context.allIssues()).hasSize(3); }
Example #30
Source File: EmbeddedCssAnalyzerSensorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void should_not_execute_and_save_issues(String fileName) { inputFile(fileName); ActiveRules activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(CheckList.CSS_REPOSITORY_KEY, "S1135")) .activate() .create(RuleKey.of(CheckList.CSS_REPOSITORY_KEY, "important")) .activate() .build(); checkFactory = new CheckFactory(activeRules); createEmbeddedCssSquidSensor().execute(context); assertThat(context.allIssues()).isEmpty(); }