@Test public void non_associated_mode() throws IOException { restoreProfile("one-issue-per-line.xml"); setDefaultQualityProfile("xoo", "one-issue-per-line"); SonarRunner runner = configureRunnerIssues("shared/xoo-sample-non-associated"); BuildResult result = orchestrator.executeBuild(runner); assertThat(result.getLogs()).contains("Local analysis"); assertThat(result.getLogs()).contains("Cache not found, synchronizing data"); assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17); result = orchestrator.executeBuild(runner); assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17); assertThat(result.getLogs()).contains("Found cache"); }
@Test // SONARJS-301 public void print_log_for_not_found_resource() throws InterruptedException { SonarRunner build = Tests.createSonarRunnerBuild() .setProjectDir(TestUtils.projectDir("lcov")) .setProjectKey("project") .setProjectName("project") .setProjectVersion("1.0") .setSourceDirs(".") .setProperty( "sonar.javascript.lcov.reportPath", TestUtils.file("projects/lcov/coverage-wrong-file-name.lcov").getAbsolutePath()) .setDebugLogs(true); BuildResult result = orchestrator.executeBuild(build); // Check that a log is printed String logs = result.getLogs(); assertThat(Pattern.compile("Analysing .*coverage-wrong-file-name\\.lcov").matcher(logs).find()) .isTrue(); assertThat( Pattern.compile("Default value of zero will be saved for file: .*file\\.js") .matcher(logs) .find()) .isTrue(); assertThat( Pattern.compile( "INFO.*Could not resolve 1 file paths in coverage-wrong-file-name\\.lcov, " + "first unresolved path: \\./wrong/fileName\\.js") .matcher(logs) .find()) .isTrue(); }
@Test public void invalid_test_report() throws Exception { BuildResult result = orchestrator.executeBuildQuietly(createBuild("invalid_report.xml")); assertThat(result.isSuccess()).isFalse(); assertThat(result.getLogs()).contains("Cannot feed the data into sonar"); assertProjectMeasures(PROJECT, nullMeasures()); }
@Test public void invalid_binaries_dir_should_fail_analysis() { SonarScanner scanner = ditProjectSonarScanner(); scanner.setProperty("sonar.java.binaries", "target/dummy__Dir"); BuildResult buildResult = ORCHESTRATOR.executeBuildQuietly(scanner); assertThat(buildResult.getStatus()).isNotEqualTo(0); assertThat(buildResult.getLogs()) .contains("No files nor directories matching 'target/dummy__Dir'"); }
@Test public void should_fail_if_plugin_access_secured_properties() throws IOException { // Test access from task (ie BatchSettings) SonarRunner runner = configureRunnerIssues("shared/xoo-sample", "accessSecuredFromTask", "true"); BuildResult result = orchestrator.executeBuildQuietly(runner); assertThat(result.getLogs()) .contains( "Access to the secured property 'foo.bar.secured' is not possible in issues mode. " + "The SonarQube plugin which requires this property must be deactivated in issues mode."); // Test access from sensor (ie ModuleSettings) runner = configureRunnerIssues("shared/xoo-sample", "accessSecuredFromSensor", "true"); result = orchestrator.executeBuildQuietly(runner); assertThat(result.getLogs()) .contains( "Access to the secured property 'foo.bar.secured' is not possible in issues mode. " + "The SonarQube plugin which requires this property must be deactivated in issues mode."); }
/** SONAR-926 SONAR-5069 */ @Test public void test_sonar_runner_inspection() { orchestrator .getServer() .restoreProfile( FileLocation.ofClasspath("/analysis/MultiLanguageTest/one-issue-per-line.xml")); orchestrator .getServer() .restoreProfile( FileLocation.ofClasspath("/analysis/MultiLanguageTest/one-issue-per-line-xoo2.xml")); orchestrator.getServer().provisionProject("multi-language-sample", "multi-language-sample"); orchestrator .getServer() .associateProjectToQualityProfile("multi-language-sample", "xoo", "one-issue-per-line"); orchestrator .getServer() .associateProjectToQualityProfile( "multi-language-sample", "xoo2", "one-issue-per-line-xoo2"); SonarRunner build = SonarRunner.create().setProjectDir(ItUtils.projectDir("analysis/xoo-multi-languages")); BuildResult result = orchestrator.executeBuild(build); assertThat(result.getLogs()).contains("2 files indexed"); assertThat(result.getLogs()).contains("Quality profile for xoo: one-issue-per-line"); assertThat(result.getLogs()).contains("Quality profile for xoo2: one-issue-per-line-xoo2"); // modules Resource project = getResource("multi-language-sample", "files", "violations"); assertThat(project.getMeasureIntValue("files")).isEqualTo(2); assertThat(project.getMeasureIntValue("violations")).isEqualTo(26); Resource xooFile = getResource("multi-language-sample:src/sample/Sample.xoo", "violations"); assertThat(xooFile.getMeasureIntValue("violations")).isEqualTo(13); Resource xoo2File = getResource("multi-language-sample:src/sample/Sample.xoo2", "violations"); assertThat(xoo2File.getMeasureIntValue("violations")).isEqualTo(13); }
@Test public void should_support_the_old_binaries_and_libraries_properties() { SonarScanner scanner = ditProjectSonarScanner(); scanner.setProperty("sonar.binaries", "target/classes"); scanner.setProperty("sonar.libraries", guavaJarPath); BuildResult buildResult = ORCHESTRATOR.executeBuildQuietly(scanner); assertThat(buildResult.getLogs()) .contains( "sonar.binaries and sonar.libraries are not supported since version 4.0 of sonar-java-plugin," + " please use sonar.java.binaries and sonar.java.libraries instead"); assertThat(buildResult.isSuccess()).isFalse(); }
@Test public void invalid_incremental_mode() throws IOException { restoreProfile("one-issue-per-line.xml"); orchestrator.getServer().provisionProject("sample", "xoo-sample"); orchestrator .getServer() .associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line"); SonarRunner runner = configureRunner("shared/xoo-sample"); runner.setProperty("sonar.analysis.mode", "incremental"); thrown.expect(BuildFailureException.class); BuildResult res = orchestrator.executeBuild(runner); assertThat(res.getLogs()) .contains("Invalid analysis mode: incremental. This mode was removed in SonarQube 5.2"); }
// SONAR-5715 @Test public void test_issues_mode_on_project_with_space_in_filename() throws IOException { restoreProfile("with-many-rules.xml"); orchestrator.getServer().provisionProject("sample", "xoo-sample-with-spaces"); orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "with-many-rules"); SonarRunner runner = configureRunner("batch/xoo-sample-with-spaces/v2"); BuildResult result = orchestrator.executeBuild(runner); assertThat(getResource("sample:my sources/main/xoo/sample/My Sample.xoo")).isNotNull(); runner = configureRunnerIssues("batch/xoo-sample-with-spaces/v2"); result = orchestrator.executeBuild(runner); // Analysis is not persisted in database Resource project = getResource("com.sonarsource.it.samples:simple-sample"); assertThat(project).isNull(); assertThat(result.getLogs()).contains("Issues"); assertThat(result.getLogs()).contains("ANALYSIS SUCCESSFUL"); }
@Test public void should_not_fail_on_resources_that_have_existed_before() throws IOException { restoreProfile("with-many-rules.xml"); orchestrator.getServer().provisionProject("sample", "xoo-history"); orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "with-many-rules"); // First real scan with source SonarRunner runner = configureRunner("shared/xoo-history-v2"); BuildResult result = orchestrator.executeBuild(runner); assertThat(getResource("sample:src/main/xoo/sample/ClassAdded.xoo")).isNotNull(); // Second scan should remove ClassAdded.xoo runner = configureRunner("shared/xoo-history-v1"); result = orchestrator.executeBuild(runner); assertThat(getResource("sample:src/main/xoo/sample/ClassAdded.xoo")).isNull(); // Re-add ClassAdded.xoo in local workspace runner = configureRunnerIssues("shared/xoo-history-v2"); result = orchestrator.executeBuild(runner); assertThat(getResource("sample:src/main/xoo/sample/ClassAdded.xoo")).isNull(); assertThat(result.getLogs()).contains("Issues"); assertThat(result.getLogs()).contains("ANALYSIS SUCCESSFUL"); }