Search in sources :

Example 71 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class CpdExecutorTest method setUp.

@Before
public void setUp() throws IOException {
    File outputDir = temp.newFolder();
    baseDir = temp.newFolder();
    settings = new MapSettings();
    publisher = mock(ReportPublisher.class);
    when(publisher.getWriter()).thenReturn(new ScannerReportWriter(outputDir));
    index = new SonarCpdBlockIndex(publisher, settings);
    componentStore = new InputComponentStore(new PathResolver());
    executor = new CpdExecutor(settings, index, publisher, componentStore);
    reader = new ScannerReportReader(outputDir);
    componentStore.put(TestInputFileBuilder.newDefaultInputModule("foo", baseDir));
    batchComponent1 = createComponent("src/Foo.php", 5);
    batchComponent2 = createComponent("src/Foo2.php", 5);
    batchComponent3 = createComponent("src/Foo3.php", 5);
}
Also used : ReportPublisher(org.sonar.scanner.report.ReportPublisher) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) SonarCpdBlockIndex(org.sonar.scanner.cpd.index.SonarCpdBlockIndex) MapSettings(org.sonar.api.config.MapSettings) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) PathResolver(org.sonar.api.scan.filesystem.PathResolver) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Before(org.junit.Before)

Example 72 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class ProjectAnalysisInfoTest method testSimpleDate.

@Test
public void testSimpleDate() {
    Settings settings = new MapSettings();
    settings.appendProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
    settings.appendProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "version");
    System2 system = mock(System2.class);
    ProjectAnalysisInfo info = new ProjectAnalysisInfo(settings, system);
    info.start();
    LocalDate date = LocalDate.of(2017, 1, 1);
    assertThat(info.analysisDate()).isEqualTo(Date.from(date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
    assertThat(info.analysisVersion()).isEqualTo("version");
}
Also used : MapSettings(org.sonar.api.config.MapSettings) System2(org.sonar.api.utils.System2) LocalDate(java.time.LocalDate) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 73 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class JavaCpdBlockIndexerTest method setUp.

@Before
public void setUp() throws IOException {
    MockitoAnnotations.initMocks(this);
    File baseDir = temp.newFolder();
    DefaultFileSystem fs = new DefaultFileSystem(baseDir);
    file = new TestInputFileBuilder("foo", "src/ManyStatements.java").setModuleBaseDir(baseDir.toPath()).setLanguage(JAVA).build();
    fs.add(file);
    File ioFile = file.file();
    FileUtils.copyURLToFile(this.getClass().getResource("ManyStatements.java"), ioFile);
    settings = new MapSettings();
    engine = new JavaCpdBlockIndexer(fs, settings, index);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) MapSettings(org.sonar.api.config.MapSettings) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 74 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class GenericCoverageSensorTest method migrateOldProperties.

@Test
public void migrateOldProperties() {
    Settings settings = new MapSettings(new PropertyDefinitions(GenericCoverageSensor.properties()));
    settings.setProperty(GenericCoverageSensor.OLD_REPORT_PATH_PROPERTY_KEY, "old.xml");
    settings.setProperty(GenericCoverageSensor.OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY, "old1.xml,old2.xml");
    settings.setProperty(GenericCoverageSensor.OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY, "old3.xml,old4.xml,old.xml");
    settings.setProperty(GenericCoverageSensor.OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY, "old5.xml,old6.xml");
    new GenericCoverageSensor(settings).execute();
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Property 'sonar.genericcoverage.reportPath' is deprecated. Please use 'sonar.coverageReportPaths' instead.", "Property 'sonar.genericcoverage.reportPaths' is deprecated. Please use 'sonar.coverageReportPaths' instead.", "Property 'sonar.genericcoverage.itReportPaths' is deprecated. Please use 'sonar.coverageReportPaths' instead.", "Property 'sonar.genericcoverage.overallReportPaths' is deprecated. Please use 'sonar.coverageReportPaths' instead.");
    assertThat(settings.getStringArray(GenericCoverageSensor.REPORT_PATHS_PROPERTY_KEY)).containsOnly("old.xml", "old1.xml", "old2.xml", "old3.xml", "old4.xml", "old5.xml", "old6.xml");
}
Also used : MapSettings(org.sonar.api.config.MapSettings) PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 75 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class GenericTestExecutionSensorTest method logWhenDeprecatedPropsAreUsed.

@Test
public void logWhenDeprecatedPropsAreUsed() throws IOException {
    File basedir = temp.newFolder();
    File report = new File(basedir, "report.xml");
    FileUtils.write(report, "<unitTest version=\"1\"><file path=\"A.java\"><testCase name=\"test1\" duration=\"500\"/></file></unitTest>");
    SensorContextTester context = SensorContextTester.create(basedir);
    Settings settings = new MapSettings(new PropertyDefinitions(GenericTestExecutionSensor.properties()));
    settings.setProperty(GenericTestExecutionSensor.OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY, "report.xml");
    context.setSettings(settings);
    new GenericTestExecutionSensor(mock(TestPlanBuilder.class)).execute(context);
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Using 'unitTest' as root element of the report is deprecated. Please change to 'testExecutions'.", "Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.");
    assertThat(logTester.logs(LoggerLevel.INFO)).contains("Imported test execution data for 0 files", "Test execution data ignored for 1 unknown files, including:\nA.java");
}
Also used : SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) MapSettings(org.sonar.api.config.MapSettings) PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) File(java.io.File) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Aggregations

MapSettings (org.sonar.api.config.MapSettings)98 Test (org.junit.Test)75 Settings (org.sonar.api.config.Settings)36 Before (org.junit.Before)20 URI (java.net.URI)13 Languages (org.sonar.api.resources.Languages)9 DefaultLanguagesRepository (org.sonar.scanner.repository.language.DefaultLanguagesRepository)9 LanguagesRepository (org.sonar.scanner.repository.language.LanguagesRepository)8 File (java.io.File)7 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)7 FileExclusions (org.sonar.api.scan.filesystem.FileExclusions)6 Properties (java.util.Properties)5 IndexedFile (org.sonar.api.batch.fs.IndexedFile)5 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)5 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)5 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)5 InputFile (org.sonar.api.batch.fs.InputFile)4 InputStream (java.io.InputStream)3 Description (org.hamcrest.Description)3 CoreProperties (org.sonar.api.CoreProperties)3