Search in sources :

Example 16 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class JavaSquidSensorTest method createSonarComponentsMock.

private static SonarComponents createSonarComponentsMock(SensorContextTester contextTester) {
    Configuration settings = new MapSettings().asConfig();
    DefaultFileSystem fs = contextTester.fileSystem();
    JavaTestClasspath javaTestClasspath = new JavaTestClasspath(settings, fs);
    JavaClasspath javaClasspath = new JavaClasspath(settings, fs);
    FileLinesContext fileLinesContext = mock(FileLinesContext.class);
    FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
    when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext);
    SonarComponents sonarComponents = spy(new SonarComponents(fileLinesContextFactory, fs, javaClasspath, javaTestClasspath, checkFactory));
    sonarComponents.setSensorContext(contextTester);
    BadMethodNameCheck check = new BadMethodNameCheck();
    when(sonarComponents.checkClasses()).thenReturn(new JavaCheck[] { check });
    return sonarComponents;
}
Also used : SonarComponents(org.sonar.java.SonarComponents) JavaClasspath(org.sonar.java.JavaClasspath) BadMethodNameCheck(org.sonar.java.checks.naming.BadMethodNameCheck) Configuration(org.sonar.api.config.Configuration) MapSettings(org.sonar.api.config.internal.MapSettings) FileLinesContextFactory(org.sonar.api.measures.FileLinesContextFactory) JavaTestClasspath(org.sonar.java.JavaTestClasspath) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) FileLinesContext(org.sonar.api.measures.FileLinesContext) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile)

Example 17 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class JavaSquidSensorTest method executeJavaSquidSensor.

private void executeJavaSquidSensor(SensorContextTester context) {
    context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.create(6, 7), SonarQubeSide.SCANNER));
    // Mock visitor for metrics.
    FileLinesContext fileLinesContext = mock(FileLinesContext.class);
    FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
    when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext);
    DefaultFileSystem fs = context.fileSystem().setWorkDir(tmp.getRoot().toPath());
    JavaClasspath javaClasspath = mock(JavaClasspath.class);
    JavaTestClasspath javaTestClasspath = mock(JavaTestClasspath.class);
    SonarComponents sonarComponents = new SonarComponents(fileLinesContextFactory, fs, javaClasspath, javaTestClasspath, checkFactory);
    DefaultJavaResourceLocator javaResourceLocator = mock(DefaultJavaResourceLocator.class);
    NoSonarFilter noSonarFilter = mock(NoSonarFilter.class);
    PostAnalysisIssueFilter postAnalysisIssueFilter = new PostAnalysisIssueFilter(fs);
    JavaSquidSensor jss = new JavaSquidSensor(sonarComponents, fs, javaResourceLocator, new MapSettings().asConfig(), noSonarFilter, postAnalysisIssueFilter);
    jss.execute(context);
}
Also used : SonarComponents(org.sonar.java.SonarComponents) JavaClasspath(org.sonar.java.JavaClasspath) NoSonarFilter(org.sonar.api.issue.NoSonarFilter) MapSettings(org.sonar.api.config.internal.MapSettings) FileLinesContextFactory(org.sonar.api.measures.FileLinesContextFactory) PostAnalysisIssueFilter(org.sonar.java.filters.PostAnalysisIssueFilter) JavaTestClasspath(org.sonar.java.JavaTestClasspath) DefaultJavaResourceLocator(org.sonar.java.DefaultJavaResourceLocator) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) FileLinesContext(org.sonar.api.measures.FileLinesContext) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile)

Example 18 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class SurefireUtilsTest method should_get_reports_path_from_deprecated_property.

@Test
public void should_get_reports_path_from_deprecated_property() {
    MapSettings settings = new MapSettings();
    settings.setProperty("sonar.junit.reportsPath", "target/surefire");
    DefaultFileSystem fs = new DefaultFileSystem(new File("src/test/resources/org/sonar/plugins/surefire/api/SurefireUtilsTest/shouldGetReportsPathFromDeprecatedProperty"));
    PathResolver pathResolver = new PathResolver();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
    List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);
    assertThat(directories).hasSize(1);
    File directory = directories.get(0);
    assertThat(directory.exists()).isTrue();
    assertThat(directory.isDirectory()).isTrue();
    assertThat(logTester.logs(LoggerLevel.INFO)).contains("Property 'sonar.junit.reportsPath' is deprecated. Use property 'sonar.junit.reportPaths' instead.");
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) PathResolver(org.sonar.api.scan.filesystem.PathResolver) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Example 19 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class CheckVerifier method sonarComponents.

static SonarComponents sonarComponents(File file) {
    SensorContextTester context = SensorContextTester.create(new File("")).setRuntime(SonarRuntimeImpl.forSonarLint(Version.create(6, 7)));
    context.setSettings(new MapSettings().setProperty("sonar.java.failOnException", true));
    SonarComponents sonarComponents = new SonarComponents(null, context.fileSystem(), null, null, null, null) {

        @Override
        public boolean reportAnalysisError(RecognitionException re, File file) {
            return false;
        }
    };
    sonarComponents.setSensorContext(context);
    context.fileSystem().add(new TestInputFileBuilder("", file.getPath()).setCharset(StandardCharsets.UTF_8).build());
    return sonarComponents;
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) SonarComponents(org.sonar.java.SonarComponents) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) MapSettings(org.sonar.api.config.internal.MapSettings) File(java.io.File) RecognitionException(com.sonar.sslr.api.RecognitionException)

Example 20 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class SurefireSensorTest method should_execute_if_filesystem_contains_java_files.

@Test
public void should_execute_if_filesystem_contains_java_files() {
    surefireSensor = new SurefireSensor(new SurefireJavaParser(perspectives, javaResourceLocator), new MapSettings().asConfig(), fs, pathResolver);
    DefaultSensorDescriptor defaultSensorDescriptor = new DefaultSensorDescriptor();
    surefireSensor.describe(defaultSensorDescriptor);
    assertThat(defaultSensorDescriptor.languages()).containsOnly("java");
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) DefaultSensorDescriptor(org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor) Test(org.junit.Test)

Aggregations

MapSettings (org.sonar.api.config.internal.MapSettings)24 Test (org.junit.Test)11 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)11 File (java.io.File)9 InputFile (org.sonar.api.batch.fs.InputFile)5 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)5 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)5 Before (org.junit.Before)4 Test (org.junit.jupiter.api.Test)4 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)4 PathResolver (org.sonar.api.scan.filesystem.PathResolver)4 SonarComponents (org.sonar.java.SonarComponents)4 JavaClasspath (org.sonar.java.JavaClasspath)3 Path (java.nio.file.Path)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 SonarRuntime (org.sonar.api.SonarRuntime)2 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)2 FileLinesContext (org.sonar.api.measures.FileLinesContext)2 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)2 DefaultJavaResourceLocator (org.sonar.java.DefaultJavaResourceLocator)2