Search in sources :

Example 6 with ClasspathForMain

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);
}
Also used : SonarComponents(org.sonar.java.SonarComponents) Configuration(org.sonar.api.config.Configuration) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) NoSonarFilter(org.sonar.api.issue.NoSonarFilter) DefaultJavaResourceLocator(org.sonar.java.DefaultJavaResourceLocator) ClasspathForMain(org.sonar.java.classpath.ClasspathForMain) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem)

Example 7 with ClasspathForMain

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());
}
Also used : SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) ClasspathForTest(org.sonar.java.classpath.ClasspathForTest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) ClasspathForMain(org.sonar.java.classpath.ClasspathForMain) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.jupiter.api.Test) ClasspathForTest(org.sonar.java.classpath.ClasspathForTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with ClasspathForMain

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);
}
Also used : SonarComponents(org.sonar.java.SonarComponents) MapSettings(org.sonar.api.config.internal.MapSettings) JavaVersionImpl(org.sonar.java.model.JavaVersionImpl) ClasspathForTest(org.sonar.java.classpath.ClasspathForTest) VisitorsBridge(org.sonar.java.model.VisitorsBridge) ClasspathForMain(org.sonar.java.classpath.ClasspathForMain) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem)

Example 9 with ClasspathForMain

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;
}
Also used : VisitorsBridge(org.sonar.java.model.VisitorsBridge) ClasspathForMain(org.sonar.java.classpath.ClasspathForMain) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

ClasspathForMain (org.sonar.java.classpath.ClasspathForMain)9 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)7 InputFile (org.sonar.api.batch.fs.InputFile)6 SonarComponents (org.sonar.java.SonarComponents)6 ClasspathForTest (org.sonar.java.classpath.ClasspathForTest)6 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)5 File (java.io.File)4 Test (org.junit.jupiter.api.Test)3 Configuration (org.sonar.api.config.Configuration)3 MapSettings (org.sonar.api.config.internal.MapSettings)3 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)3 FileLinesContext (org.sonar.api.measures.FileLinesContext)3 DefaultJavaResourceLocator (org.sonar.java.DefaultJavaResourceLocator)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)2 BadMethodNameCheck (org.sonar.java.checks.naming.BadMethodNameCheck)2 VisitorsBridge (org.sonar.java.model.VisitorsBridge)2 AnalyzerMessage (org.sonar.java.reporting.AnalyzerMessage)2