Java Code Examples for org.sonar.api.batch.fs.internal.DefaultFileSystem#setWorkDir()
The following examples show how to use
org.sonar.api.batch.fs.internal.DefaultFileSystem#setWorkDir() .
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: CheckstyleConfigurationTest.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void beforeClass() { fileSystem = new DefaultFileSystem(new File("")); fileSystem.setWorkDir(new File(".").toPath()); final File file = new File("mainFile"); final DefaultInputFile inputFile = new DefaultInputFile( new DefaultIndexedFile("", new File("").toPath(), file.getName(), "java"), DefaultInputFile::checkMetadata); fileSystem.add(inputFile); final File testFile = new File("testFile"); final DefaultInputFile testInputFile = new DefaultInputFile( new DefaultIndexedFile(testFile.toPath(), "", "testFile", "testFile", InputFile.Type.TEST, "java", TestInputFileBuilder.nextBatchId(), new SensorStrategy()), DefaultInputFile::checkMetadata); fileSystem.add(testInputFile); }
Example 6
Source File: ColdfusionSensorTest.java From sonar-coldfusion with Apache License 2.0 | 5 votes |
@Test public void testBasicCFMAnalysis() { DefaultFileSystem fileSystem = new DefaultFileSystem(tmpFolder.getRoot()); fileSystem.setEncoding(Charsets.UTF_8); fileSystem.setWorkDir(tmpFolder.getRoot().toPath()); context.setFileSystem(fileSystem); context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.create(7, 6), SonarQubeSide.SCANNER)); context.settings().appendProperty("sonar.projectBaseDir", baseDir.getPath()); addFilesToFs(); CommandExecutor commandExecutor = CommandExecutor.create(); String javaHome = System.getProperty("java.home"); Assert.assertTrue(javaHome!=null && !javaHome.equals("")); if(OSValidator.isWindows()) { context.settings().appendProperty(ColdFusionPlugin.CFLINT_JAVA, javaHome + "/bin/java.exe"); } else { context.settings().appendProperty(ColdFusionPlugin.CFLINT_JAVA, javaHome + "/bin/java"); } ColdFusionSensor sensor = new ColdFusionSensor(context.fileSystem(), rulesProfile); sensor.execute(context); Integer nloc = 0; Integer comments = 0; Integer complexity = 0; for (InputFile o : context.fileSystem().inputFiles()) { Measure<Integer> measureNloc = context.measure(o.key(),CoreMetrics.NCLOC.key()); Measure<Integer> measureComment = context.measure(o.key(),CoreMetrics.COMMENT_LINES.key()); Measure<Integer> measureComplexity = context.measure(o.key(),CoreMetrics.COMPLEXITY.key()); nloc+=measureNloc.value(); comments+=measureComment.value(); complexity+=measureComplexity.value(); } assertThat(nloc).isEqualTo(56); assertThat(comments).isEqualTo(9); assertThat(complexity).isEqualTo(10); }