use of org.sonar.plugins.java.api.JavaResourceLocator 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());
}
use of org.sonar.plugins.java.api.JavaResourceLocator 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.plugins.java.api.JavaResourceLocator in project sonar-java by SonarSource.
the class JacocoSensorJava9Test method test_jacoco_java9_coverage.
@Test
public void test_jacoco_java9_coverage() throws Exception {
Path baseDir = Paths.get(getClass().getResource("/org/sonar/plugins/jacoco/JaCoCoJava9Test/").toURI());
Files.copy(baseDir.resolve("Hello9.class.toCopy"), baseDir.resolve("Hello9.class"), StandardCopyOption.REPLACE_EXISTING);
DefaultInputFile resource = new TestInputFileBuilder("", "").setLines(10).build();
JavaResourceLocator javaResourceLocator = mock(JavaResourceLocator.class);
when(javaResourceLocator.findResourceByClassName(anyString())).thenReturn(resource);
JavaClasspath javaClasspath = mock(JavaClasspath.class);
when(javaClasspath.getBinaryDirs()).thenReturn(Collections.singletonList(baseDir.toFile()));
SensorContextTester context = SensorContextTester.create(baseDir);
context.settings().setProperty(REPORT_PATHS_PROPERTY, "jacoco.exec");
JaCoCoSensor sensor = new JaCoCoSensor(null, javaResourceLocator, javaClasspath);
sensor.execute(context);
assertThat(context.lineHits(resource.key(), 5)).isEqualTo(1);
}
use of org.sonar.plugins.java.api.JavaResourceLocator in project sonar-java by SonarSource.
the class SurefireSensorTest method before.
@Before
public void before() {
fs = new DefaultFileSystem(new File("src/test/resources"));
DefaultInputFile javaFile = new TestInputFileBuilder("", "src/org/foo/java").setLanguage("java").build();
fs.add(javaFile);
perspectives = mock(ResourcePerspectives.class);
javaResourceLocator = mock(JavaResourceLocator.class);
when(javaResourceLocator.findResourceByClassName(anyString())).thenAnswer(invocation -> resource((String) invocation.getArguments()[0]));
surefireSensor = new SurefireSensor(new SurefireJavaParser(perspectives, javaResourceLocator), new MapSettings().asConfig(), fs, pathResolver);
}
Aggregations