Search in sources :

Example 36 with Settings

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

the class FileExclusionsTest method load_inclusions.

@Test
public void load_inclusions() {
    Settings settings = new MapSettings();
    settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Foo.java");
    settings.setProperty(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY, "**/*FooTest.java");
    FileExclusions moduleExclusions = new FileExclusions(settings);
    assertThat(moduleExclusions.sourceInclusions()).containsOnly("**/*Foo.java");
    assertThat(moduleExclusions.testInclusions()).containsOnly("**/*FooTest.java");
}
Also used : MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 37 with Settings

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

the class ProjectScanContainer method doBeforeStart.

@Override
protected void doBeforeStart() {
    addBatchComponents();
    ProjectLock lock = getComponentByType(ProjectLock.class);
    lock.tryLock();
    getComponentByType(WorkDirectoryCleaner.class).execute();
    addBatchExtensions();
    Settings settings = getComponentByType(Settings.class);
    if (settings != null && settings.getBoolean(CoreProperties.PROFILING_LOG_PROPERTY)) {
        add(PhasesSumUpTimeProfiler.class);
    }
    if (isTherePreviousAnalysis()) {
        addIssueTrackingComponents();
    }
}
Also used : Settings(org.sonar.api.config.Settings)

Example 38 with Settings

use of org.sonar.api.config.Settings 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 39 with Settings

use of org.sonar.api.config.Settings 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 40 with Settings

use of org.sonar.api.config.Settings 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

Settings (org.sonar.api.config.Settings)52 MapSettings (org.sonar.api.config.MapSettings)43 Test (org.junit.Test)41 Before (org.junit.Before)5 Languages (org.sonar.api.resources.Languages)5 FileExclusions (org.sonar.api.scan.filesystem.FileExclusions)5 DefaultLanguagesRepository (org.sonar.scanner.repository.language.DefaultLanguagesRepository)5 LanguagesRepository (org.sonar.scanner.repository.language.LanguagesRepository)5 IndexedFile (org.sonar.api.batch.fs.IndexedFile)4 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)4 File (java.io.File)3 String.format (java.lang.String.format)3 TransportClient (org.elasticsearch.client.transport.TransportClient)3 PropertyDto (org.sonar.db.property.PropertyDto)3 InetAddress (java.net.InetAddress)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Condition (org.assertj.core.api.Condition)2 TransportAddress (org.elasticsearch.common.transport.TransportAddress)2 Rule (org.junit.Rule)2 ExpectedException (org.junit.rules.ExpectedException)2