org.sonar.api.measures.FileLinesContextFactory Java Examples
The following examples show how to use
org.sonar.api.measures.FileLinesContextFactory.
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: 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 #2
Source File: AbstractAnsibleSensorNoRuleTest.java From sonar-ansible with Apache License 2.0 | 6 votes |
@Test public void testNoActiveRule() throws IOException { SensorContextTester context = Utils.getSensorContext(); DefaultFileSystem fs = Utils.getFileSystem(); fs.setWorkDir(temporaryFolder.newFolder("temp").toPath()); context.setFileSystem(fs); FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(mock(FileLinesContext.class)); InputFile playbook1 = Utils.getInputFile("playbooks/playbook1.yml"); InputFile playbook2 = Utils.getInputFile("playbooks/playbook2.yml"); InputFile playbook3 = Utils.getInputFile("playbooks/playbook3.yml"); context.fileSystem().add(playbook1).add(playbook2).add(playbook3); MySensor sensor = new MySensor(fs); sensor.executeWithAnsibleLint(context, null); assertEquals(1, logTester.logs(LoggerLevel.INFO).size()); assertEquals("No active rules found for this plugin, skipping.", logTester.logs(LoggerLevel.INFO).get(0)); assertEquals(0, context.allIssues().size()); }
Example #3
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 #4
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 #5
Source File: EsqlSensor.java From sonar-esql-plugin with Apache License 2.0 | 6 votes |
public EsqlSensor( CheckFactory checkFactory, FileLinesContextFactory fileLinesContextFactory, FileSystem fileSystem, NoSonarFilter noSonarFilter, @Nullable CustomEsqlRulesDefinition[] customRulesDefinition ) { this.checks = EsqlChecks.createEsqlCheck(checkFactory) .addChecks(CheckList.REPOSITORY_KEY, CheckList.getChecks()) .addCustomChecks(customRulesDefinition); this.fileLinesContextFactory = fileLinesContextFactory; this.fileSystem = fileSystem; this.noSonarFilter = noSonarFilter; this.mainFilePredicate = fileSystem.predicates().and( fileSystem.predicates().hasType(InputFile.Type.MAIN), fileSystem.predicates().hasLanguage(EsqlLanguage.KEY)); this.parser = EsqlParserBuilder.createParser(); }
Example #6
Source File: MetricsSaver.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
public static void saveLineLevelMeasures(InputFile inputFile, HtmlSourceCode htmlSourceCode, FileLinesContextFactory fileLinesContextFactory) { FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(inputFile); final int lineContainsCode = 1; for (Integer line : htmlSourceCode.getDetailedLinesOfCode()) { fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, lineContainsCode); } fileLinesContext.save(); }
Example #7
Source File: HtlSensorTest.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
@Before public void setUp() { RulesDefinition rulesDefinition = new AemRulesRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); rulesDefinition.define(context); RulesDefinition.Repository htlRepository = context.repository(HtlCheckClasses.REPOSITORY_KEY); FileLinesContextFactory fileLinesContextFactory = getMockedFileLinesContextFactory(); Configuration configuration = getMockedConfiguration(); CheckFactory checkFactory = getCheckFactory(htlRepository); sensor = new HtlSensor(fileLinesContextFactory, configuration, checkFactory); tester = SensorContextTester.create(TEST_DIR); }
Example #8
Source File: MetricsVisitor.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
public MetricsVisitor(SensorContext context, Boolean ignoreHeaderComments, FileLinesContextFactory fileLinesContextFactory) { this.sensorContext = context; this.ignoreHeaderComments = ignoreHeaderComments; this.fileLinesContextFactory = fileLinesContextFactory; this.projectExecutableLines = new HashMap<>(); }
Example #9
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 #10
Source File: HtlSensor.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 4 votes |
public HtlSensor(FileLinesContextFactory fileLinesContextFactory, Configuration configuration, CheckFactory checkFactory) { super(checkFactory); this.configuration = configuration; this.fileLinesContextFactory = fileLinesContextFactory; }
Example #11
Source File: HtlSensorTest.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 4 votes |
private FileLinesContextFactory getMockedFileLinesContextFactory() { FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); when(fileLinesContextFactory.createFor(Mockito.any(InputFile.class))).thenReturn(mock(FileLinesContext.class)); return fileLinesContextFactory; }
Example #12
Source File: MetricsVisitorTest.java From sonar-esql-plugin with Apache License 2.0 | 4 votes |
private MetricsVisitor createMetricsVisitor() { FileLinesContextFactory linesContextFactory = mock(FileLinesContextFactory.class); when(linesContextFactory.createFor(INPUT_FILE)).thenReturn(linesContext); return new MetricsVisitor(context, false, linesContextFactory); }
Example #13
Source File: EsqlSensor.java From sonar-esql-plugin with Apache License 2.0 | 4 votes |
public EsqlSensor( CheckFactory checkFactory, FileLinesContextFactory fileLinesContextFactory, FileSystem fileSystem, NoSonarFilter noSonarFilter) { this(checkFactory, fileLinesContextFactory, fileSystem, noSonarFilter, null); }
Example #14
Source File: EsqlSensorTest.java From sonar-esql-plugin with Apache License 2.0 | 4 votes |
@Before public void setUp() { fileLinesContextFactory = mock(FileLinesContextFactory.class); FileLinesContext fileLinesContext = mock(FileLinesContext.class); when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext); }
Example #15
Source File: FileLinesVisitor.java From sonar-lua with GNU Lesser General Public License v3.0 | 4 votes |
public FileLinesVisitor(FileLinesContextFactory fileLinesContextFactory, FileSystem fileSystem) { this.fileLinesContextFactory = fileLinesContextFactory; this.fileSystem = fileSystem; }
Example #16
Source File: LuaSquidSensor.java From sonar-lua with GNU Lesser General Public License v3.0 | 4 votes |
public LuaSquidSensor(CheckFactory checkFactory, FileLinesContextFactory fileLinesContextFactory) { this.checks = checkFactory .<SquidCheck<LexerlessGrammar>>create(CheckList.REPOSITORY_KEY) .addAnnotatedChecks((Iterable) CheckList.getChecks()); this.fileLinesContextFactory = fileLinesContextFactory; }