use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class JavaSquidSensorTest method createContext.
private static SensorContextTester createContext(InputFile.Type onType) throws IOException {
SensorContextTester context = SensorContextTester.create(new File("src/test/java/").getAbsoluteFile());
DefaultFileSystem fs = context.fileSystem();
String effectiveKey = "org/sonar/plugins/java/JavaSquidSensorTest.java";
File file = new File(fs.baseDir(), effectiveKey);
DefaultInputFile inputFile = new TestInputFileBuilder("", effectiveKey).setLanguage("java").setModuleBaseDir(fs.baseDirPath()).setType(onType).initMetadata(new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8)).setCharset(StandardCharsets.UTF_8).build();
fs.add(inputFile);
return context;
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class JavaSquidSensorTest method testIssueCreation.
private void testIssueCreation(InputFile.Type onType, int expectedIssues) throws IOException {
MapSettings settings = new MapSettings();
NoSonarFilter noSonarFilter = mock(NoSonarFilter.class);
SensorContextTester context = createContext(onType).setRuntime(SonarRuntimeImpl.forSonarLint(Version.create(6, 7)));
DefaultFileSystem fs = context.fileSystem();
SonarComponents sonarComponents = createSonarComponentsMock(context);
DefaultJavaResourceLocator javaResourceLocator = new DefaultJavaResourceLocator(fs, new JavaClasspath(settings.asConfig(), fs));
PostAnalysisIssueFilter postAnalysisIssueFilter = new PostAnalysisIssueFilter(fs);
JavaSquidSensor jss = new JavaSquidSensor(sonarComponents, fs, javaResourceLocator, settings.asConfig(), noSonarFilter, postAnalysisIssueFilter);
jss.execute(context);
verify(noSonarFilter, times(1)).noSonarInFile(fs.inputFiles().iterator().next(), Sets.newHashSet(96));
verify(sonarComponents, times(expectedIssues)).reportIssue(any(AnalyzerMessage.class));
settings.setProperty(Java.SOURCE_VERSION, "wrongFormat");
jss.execute(context);
settings.setProperty(Java.SOURCE_VERSION, "1.7");
jss.execute(context);
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class XmlFileSensorTest method test_no_issues_but_xml_file_still_published.
@Test
public void test_no_issues_but_xml_file_still_published() throws Exception {
SensorContextTester context = SensorContextTester.create(new File("src/test/files/maven2/").getAbsoluteFile());
DefaultFileSystem fs = context.fileSystem();
final File file = new File("src/test/files/maven2/pom.xml");
DefaultInputFile inputFile = new TestInputFileBuilder("", "pom.xml").setModuleBaseDir(fs.baseDirPath()).setPublish(false).build();
fs.add(inputFile);
SonarComponents sonarComponents = createSonarComponentsMock(fs, file);
XmlFileSensor sensor = new XmlFileSensor(sonarComponents, fs);
assertThat(inputFile.isPublished()).isFalse();
sensor.execute(context);
assertThat(inputFile.isPublished()).isTrue();
verify(sonarComponents, never()).reportIssue(Mockito.argThat(argument -> file.getAbsolutePath().equals(argument.getFile().getAbsolutePath())));
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class SurefireUtilsTest method should_only_use_new_property_if_both_set.
@Test
public void should_only_use_new_property_if_both_set() {
MapSettings settings = new MapSettings();
settings.setProperty("sonar.junit.reportsPath", "../shouldGetReportsPathFromDeprecatedProperty/target/surefire");
settings.setProperty("sonar.junit.reportPaths", "target/surefire,submodule/target/surefire");
DefaultFileSystem fs = new DefaultFileSystem(new File("src/test/resources/org/sonar/plugins/surefire/api/SurefireUtilsTest/shouldGetReportsPathFromProperty"));
PathResolver pathResolver = new PathResolver();
assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);
assertThat(directories).hasSize(2);
File directory1 = directories.get(0);
assertThat(directory1.exists()).isTrue();
assertThat(directory1.isDirectory()).isTrue();
File directory2 = directories.get(1);
assertThat(directory2.exists()).isTrue();
assertThat(directory2.isDirectory()).isTrue();
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Property 'sonar.junit.reportsPath' is deprecated and will be ignored, as property 'sonar.junit.reportPaths' is also set.");
assertThat(logTester.logs(LoggerLevel.INFO)).doesNotContain("Property 'sonar.junit.reportsPath' is deprecated. Use property 'sonar.junit.reportPaths' instead.");
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class StrutsTest method initAndScan.
private static void initAndScan() {
File prjDir = new File("target/test-projects/struts-core-1.3.9");
File srcDir = new File(prjDir, "src");
context = SensorContextTester.create(prjDir);
DefaultFileSystem fs = context.fileSystem();
Collection<File> files = FileUtils.listFiles(srcDir, new String[] { "java" }, true);
for (File file : files) {
fs.add(new TestInputFileBuilder("", file.getPath()).build());
}
Measurer measurer = new Measurer(fs, context, mock(NoSonarFilter.class));
JavaResourceLocator javaResourceLocator = mock(JavaResourceLocator.class);
JavaSquid squid = new JavaSquid(new JavaVersionImpl(), null, measurer, javaResourceLocator, null, new JavaCheck[0]);
squid.scan(files, Collections.<File>emptyList());
}
Aggregations