use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class CommonsCollectionsTest method initAndScan.
private void initAndScan() {
File prjDir = new File("target/test-projects/commons-collections-3.2.1");
File srcDir = new File(prjDir, "src");
context = SensorContextTester.create(srcDir);
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 = new JavaResourceLocator() {
public Map<String, String> sourceFileCache = Maps.newHashMap();
@Override
public InputFile findResourceByClassName(String className) {
return null;
}
@Override
public String findSourceFileKeyByClassName(String className) {
String name = className.replace('.', '/');
return sourceFileCache.get(name);
}
@Override
public Collection<File> classFilesToAnalyze() {
return Collections.emptyList();
}
@Override
public Collection<File> classpath() {
return null;
}
@Override
public void scanFile(JavaFileScannerContext context) {
JavaFilesCache javaFilesCache = new JavaFilesCache();
javaFilesCache.scanFile(context);
for (String key : javaFilesCache.resourcesCache.keySet()) {
sourceFileCache.put(key, context.getFileKey());
}
}
};
squid = new JavaSquid(new JavaVersionImpl(), null, measurer, javaResourceLocator, null, new JavaCheck[0]);
squid.scan(files, Collections.<File>emptyList());
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class JavaClasspathTest method validate_libraries_only_if_not_filtered_out.
@Test
public void validate_libraries_only_if_not_filtered_out() throws Exception {
settings.setProperty(JavaClasspathProperties.SONAR_JAVA_LIBRARIES, new File("src/test/files/classpath/lib/lib.so").getAbsolutePath());
fs = new DefaultFileSystem(new File("src/test/files/classpath/"));
TestInputFileBuilder inputFile = new TestInputFileBuilder("", "plop.java");
inputFile.setType(InputFile.Type.MAIN);
inputFile.setLanguage("java");
fs.add(inputFile.build());
javaClasspath = createJavaClasspath();
assertThat(javaClasspath.getElements()).isEmpty();
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class JavaClasspathTest method setUp.
@Before
public void setUp() throws Exception {
fs = new DefaultFileSystem(new File("src/test/files/classpath/"));
TestInputFileBuilder inputFile = new TestInputFileBuilder("", "foo.java");
inputFile.setLanguage("java");
inputFile.setType(InputFile.Type.MAIN);
fs.add(inputFile.build());
settings = new MapSettings();
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class JavaClasspathTest method createTwoFilesInFileSystem.
private void createTwoFilesInFileSystem() {
fs = new DefaultFileSystem(new File("src/test/files/classpath/"));
TestInputFileBuilder inputFile = new TestInputFileBuilder("", "plop.java");
inputFile.setType(InputFile.Type.MAIN);
inputFile.setLanguage("java");
fs.add(inputFile.build());
inputFile = new TestInputFileBuilder("", "bar.java");
inputFile.setType(InputFile.Type.MAIN);
inputFile.setLanguage("java");
fs.add(inputFile.build());
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class JavaClasspathTest method sonar_binaries_should_not_check_for_existence_of_files_when_no_sources.
@Test
public void sonar_binaries_should_not_check_for_existence_of_files_when_no_sources() throws Exception {
settings.setProperty(JavaClasspathProperties.SONAR_JAVA_BINARIES, "toto/**/hello.jar");
fs = new DefaultFileSystem(new File("src/test/files/classpath/"));
TestInputFileBuilder inputFile = new TestInputFileBuilder("", "plop.java");
inputFile.setType(InputFile.Type.TEST);
inputFile.setLanguage("java");
fs.add(inputFile.build());
javaClasspath = createJavaClasspath();
assertThat(javaClasspath.getElements()).isEmpty();
}
Aggregations