use of org.sonar.java.classpath.ClasspathForMain in project sonar-java by SonarSource.
the class JavaSensorTest method executeJavaSensorForPerformanceMeasure.
private void executeJavaSensorForPerformanceMeasure(MapSettings settings, Path workDir) throws IOException {
Configuration configuration = settings.asConfig();
SensorContextTester context = createContext(InputFile.Type.MAIN).setRuntime(SonarRuntimeImpl.forSonarQube(Version.create(8, 7), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY));
context.setSettings(settings);
DefaultFileSystem fs = context.fileSystem();
fs.setWorkDir(workDir);
SonarComponents components = createSonarComponentsMock(context);
DefaultJavaResourceLocator resourceLocator = new DefaultJavaResourceLocator(new ClasspathForMain(configuration, fs));
JavaSensor jss = new JavaSensor(components, fs, resourceLocator, configuration, mock(NoSonarFilter.class), null);
jss.execute(context);
}
use of org.sonar.java.classpath.ClasspathForMain in project sonar-java by SonarSource.
the class SonarComponentsTest method jsp_classpath_should_include_plugin.
@Test
void jsp_classpath_should_include_plugin() throws Exception {
SensorContextTester sensorContextTester = SensorContextTester.create(new File(""));
DefaultFileSystem fs = sensorContextTester.fileSystem();
ClasspathForMain javaClasspath = mock(ClasspathForMain.class);
File someJar = new File("some.jar");
when(javaClasspath.getElements()).thenReturn(Collections.singletonList(someJar));
File plugin = new File("target/classes");
SonarComponents sonarComponents = new SonarComponents(fileLinesContextFactory, fs, javaClasspath, mock(ClasspathForTest.class), checkFactory);
List<String> jspClassPath = sonarComponents.getJspClasspath().stream().map(File::getAbsolutePath).collect(Collectors.toList());
assertThat(jspClassPath).containsExactly(plugin.getAbsolutePath(), someJar.getAbsolutePath());
}
use of org.sonar.java.classpath.ClasspathForMain in project sonar-java by SonarSource.
the class JavaAstScannerTest method scanFilesWithVisitors.
private void scanFilesWithVisitors(List<InputFile> inputFiles, List<JavaFileScanner> visitors, int javaVersion, boolean failOnException, boolean autoscanMode) {
context.setSettings(new MapSettings().setProperty(SonarComponents.FAIL_ON_EXCEPTION_KEY, failOnException).setProperty(SonarComponents.SONAR_AUTOSCAN, autoscanMode));
DefaultFileSystem fileSystem = context.fileSystem();
ClasspathForMain classpathForMain = new ClasspathForMain(context.config(), fileSystem);
ClasspathForTest classpathForTest = new ClasspathForTest(context.config(), fileSystem);
SonarComponents sonarComponents = new SonarComponents(null, fileSystem, classpathForMain, classpathForTest, null);
sonarComponents.setSensorContext(context);
JavaAstScanner scanner = new JavaAstScanner(sonarComponents);
VisitorsBridge visitorBridge = new VisitorsBridge(visitors, new ArrayList<>(), sonarComponents, new JavaVersionImpl(javaVersion));
scanner.setVisitorBridge(visitorBridge);
scanner.scan(inputFiles);
}
use of org.sonar.java.classpath.ClasspathForMain in project sonar-java by SonarSource.
the class DefaultJavaResourceLocatorTest method setup.
@BeforeAll
public static void setup() {
ClasspathForMain javaClasspath = mock(ClasspathForMain.class);
when(javaClasspath.getBinaryDirs()).thenReturn(Collections.singletonList(new File("target/test-classes")));
when(javaClasspath.getElements()).thenReturn(Collections.singletonList(new File("target/test-classes")));
InputFile inputFile = TestUtils.inputFile("src/test/java/org/sonar/java/DefaultJavaResourceLocatorTest.java");
DefaultJavaResourceLocator jrl = new DefaultJavaResourceLocator(javaClasspath);
JavaAstScanner.scanSingleFileForTests(inputFile, new VisitorsBridge(jrl));
javaResourceLocator = jrl;
}
Aggregations