use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class IssuesModeTest method runConcurrentIssues.
private void runConcurrentIssues(final String workDirPath) throws Exception {
// Install sonar-runner in advance to avoid concurrent unzip issues
FileSystem fileSystem = orchestrator.getConfiguration().fileSystem();
new SonarScannerInstaller(fileSystem).install(Version.create(SonarScanner.DEFAULT_SCANNER_VERSION), fileSystem.workspace(), true);
final int nThreads = 3;
ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
List<Callable<BuildResult>> tasks = new ArrayList<>();
final File homeDir = temp.newFolder();
for (int i = 0; i < nThreads; i++) {
tasks.add(new Callable<BuildResult>() {
public BuildResult call() throws Exception {
SonarScanner runner = configureRunnerIssues("shared/xoo-sample", homeDir, "sonar.it.enableWaitingSensor", "true", "sonar.working.directory", workDirPath);
return orchestrator.executeBuild(runner);
}
});
}
boolean expectedError = false;
for (Future<BuildResult> result : executorService.invokeAll(tasks)) {
try {
result.get();
} catch (ExecutionException e) {
if (e.getCause() instanceof BuildFailureException) {
BuildFailureException bfe = (BuildFailureException) e.getCause();
assertThat(bfe.getResult().getLogs()).contains("Another SonarQube analysis is already in progress for this project");
expectedError = true;
} else {
throw e;
}
}
}
if (!expectedError) {
fail("At least one of the threads should have failed");
}
}
use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class IssuesModeTest method only_scan_changed_files_transitions.
// SONAR-6931
@Test
public void only_scan_changed_files_transitions() throws IOException {
restoreProfile("one-issue-per-line.xml");
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
SonarScanner runner = configureRunner("shared/xoo-sample", "sonar.verbose", "true");
BuildResult result = orchestrator.executeBuild(runner);
List<Issue> serverIssues = ItUtils.getAllServerIssues(orchestrator);
for (Issue i : serverIssues) {
assertThat(i.status()).isEqualTo("OPEN");
}
assertThat(serverIssues).hasSize(17);
// resolve 2 issues
IssueClient issueClient = orchestrator.getServer().wsClient("admin", "admin").issueClient();
issueClient.doTransition(serverIssues.get(0).key(), "wontfix");
issueClient.doTransition(serverIssues.get(1).key(), "wontfix");
// do it again, scanning nothing (all files should be unchanged)
runner = configureRunnerIssues("shared/xoo-sample", null, "sonar.verbose", "true");
result = orchestrator.executeBuild(runner);
assertThat(result.getLogs()).contains("Scanning only changed files");
assertThat(result.getLogs()).contains("'One Issue Per Line' skipped because there is no related file in current project");
ItUtils.assertIssuesInJsonReport(result, 0, 0, 15);
}
use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class IssuesModeTest method only_scan_changed_files_qps.
// SONAR-6931
@Test
public void only_scan_changed_files_qps() throws IOException {
restoreProfile("one-issue-per-line.xml");
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
SonarScanner runner = configureRunner("shared/xoo-sample", "sonar.verbose", "true");
BuildResult result = orchestrator.executeBuild(runner);
List<Issue> serverIssues = ItUtils.getAllServerIssues(orchestrator);
for (Issue i : serverIssues) {
assertThat(i.status()).isEqualTo("OPEN");
}
assertThat(serverIssues).hasSize(17);
// change quality profile
restoreProfile("with-many-rules.xml");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "with-many-rules");
// do it again, scanning nothing (all files should be unchanged)
runner = configureRunnerIssues("shared/xoo-sample", null, "sonar.verbose", "true");
result = orchestrator.executeBuild(runner);
assertThat(result.getLogs()).contains("Scanning only changed files");
assertThat(result.getLogs()).contains("'One Issue Per Line' skipped because there is no related file in current project");
ItUtils.assertIssuesInJsonReport(result, 0, 0, 17);
}
use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class IssuesModeTest method only_scan_changed_files_on_change.
// SONAR-6931
@Test
public void only_scan_changed_files_on_change() throws IOException {
restoreProfile("one-issue-per-line.xml");
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
SonarScanner runner = configureRunner("shared/xoo-sample", "sonar.verbose", "true");
BuildResult result = orchestrator.executeBuild(runner);
// change QP
restoreProfile("with-many-rules.xml");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "with-many-rules");
// now change file hash in a temporary location
File tmpProjectDir = temp.newFolder();
FileUtils.copyDirectory(ItUtils.projectDir("shared/xoo-sample"), tmpProjectDir);
File srcFile = new File(tmpProjectDir, "src/main/xoo/sample/Sample.xoo");
FileUtils.write(srcFile, "\n", StandardCharsets.UTF_8, true);
// scan again, with different QP
runner = SonarScanner.create(tmpProjectDir, "sonar.working.directory", temp.newFolder().getAbsolutePath(), "sonar.analysis.mode", "issues", "sonar.report.export.path", "sonar-report.json", "sonar.userHome", temp.newFolder().getAbsolutePath(), "sonar.verbose", "true", "sonar.scanChangedFilesOnly", "true");
result = orchestrator.executeBuild(runner);
assertThat(result.getLogs()).contains("Scanning only changed files");
assertThat(result.getLogs()).doesNotContain("'One Issue Per Line' skipped because there is no related file in current project");
ItUtils.assertIssuesInJsonReport(result, 3, 0, 17);
}
use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class IssuesModeTest method should_not_fail_on_resources_that_have_existed_before.
@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
SonarScanner runner = configureRunner("shared/xoo-history-v2");
orchestrator.executeBuild(runner);
assertThat(getComponent(orchestrator, "sample:src/main/xoo/sample/ClassAdded.xoo")).isNotNull();
// Second scan should remove ClassAdded.xoo
runner = configureRunner("shared/xoo-history-v1");
orchestrator.executeBuild(runner);
assertThat(getMeasureAsDouble(orchestrator, "sample:src/main/xoo/sample/ClassAdded.xoo", "ncloc")).isNull();
// Re-add ClassAdded.xoo in local workspace
runner = configureRunnerIssues("shared/xoo-history-v2", null);
BuildResult result = orchestrator.executeBuild(runner);
assertThat(getMeasureAsDouble(orchestrator, "sample:src/main/xoo/sample/ClassAdded.xoo", "ncloc")).isNull();
assertThat(result.getLogs()).contains("Issues");
assertThat(result.getLogs()).contains("ANALYSIS SUCCESSFUL");
}
Aggregations