Search in sources :

Example 41 with SonarScanner

use of com.sonar.orchestrator.build.SonarScanner in project sonar-web by SonarSource.

the class WebRulingTest method ruling.

@Test
public void ruling() throws Exception {
    File litsDifferencesFile = FileLocation.of("target/differences").getFile();
    String projectKey = "project";
    orchestrator.getServer().provisionProject(projectKey, projectKey);
    orchestrator.getServer().associateProjectToQualityProfile(projectKey, "web", "rules");
    SonarScanner build = SonarScanner.create().setProjectDir(FileLocation.of("../sources").getFile()).setProjectKey(projectKey).setProjectName(projectKey).setProjectVersion("1").setSourceDirs(".").setSourceEncoding("UTF-8").setProperty("sonar.web.file.suffixes", "xhtml,jspf,jsp,html,php,erb").setProperty("sonar.analysis.mode", "preview").setProperty("sonar.issuesReport.html.enable", "true").setProperty("dump.old", FileLocation.of("src/test/resources/expected").getFile().getAbsolutePath()).setProperty("dump.new", FileLocation.of("target/actual").getFile().getAbsolutePath()).setProperty("lits.differences", litsDifferencesFile.getAbsolutePath()).setProperty("sonar.cpd.skip", "true").setEnvironmentVariable("SONAR_RUNNER_OPTS", "-Xmx1024m");
    orchestrator.executeBuild(build);
    assertThat(Files.toString(litsDifferencesFile, StandardCharsets.UTF_8)).isEmpty();
}
Also used : File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 42 with SonarScanner

use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.

the class FavoriteTest method project_as_favorite_when_authenticated_and_first_analysis_and_a_project_creator_permission.

@Test
public void project_as_favorite_when_authenticated_and_first_analysis_and_a_project_creator_permission() {
    SonarScanner sampleProject = createScannerWithUserCredentials();
    addProjectCreatorPermission();
    orchestrator.executeBuild(sampleProject);
    Favorites.SearchResponse response = adminWsClient.favorites().search(new SearchRequest());
    assertThat(response.getFavoritesList()).extracting(Favorite::getKey).contains(PROJECT_KEY);
}
Also used : SearchRequest(org.sonarqube.ws.client.favorite.SearchRequest) Favorites(org.sonarqube.ws.Favorites) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 43 with SonarScanner

use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.

the class FavoriteTest method no_project_as_favorite_when_no_project_creator_permission.

@Test
public void no_project_as_favorite_when_no_project_creator_permission() {
    SonarScanner sampleProject = createScannerWithUserCredentials();
    orchestrator.executeBuild(sampleProject);
    Favorites.SearchResponse response = adminWsClient.favorites().search(new SearchRequest());
    assertThat(response.getFavoritesList()).extracting(Favorite::getKey).doesNotContain(PROJECT_KEY);
}
Also used : SearchRequest(org.sonarqube.ws.client.favorite.SearchRequest) Favorites(org.sonarqube.ws.Favorites) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 44 with SonarScanner

use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.

the class FavoriteTest method no_project_as_favorite_when_second_analysis.

@Test
public void no_project_as_favorite_when_second_analysis() {
    SonarScanner sampleProject = SonarScanner.create(projectDir("shared/xoo-sample"));
    orchestrator.executeBuild(sampleProject);
    sampleProject = createScannerWithUserCredentials();
    addProjectCreatorPermission();
    orchestrator.executeBuild(sampleProject);
    Favorites.SearchResponse response = adminWsClient.favorites().search(new SearchRequest());
    assertThat(response.getFavoritesList()).extracting(Favorite::getKey).doesNotContain(PROJECT_KEY);
}
Also used : SearchRequest(org.sonarqube.ws.client.favorite.SearchRequest) Favorites(org.sonarqube.ws.Favorites) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 45 with SonarScanner

use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.

the class IssueJsonReportTest method test_json_report_no_server_analysis.

@Test
public void test_json_report_no_server_analysis() throws Exception {
    orchestrator.getServer().restoreProfile(getResource("one-issue-per-line.xml"));
    orchestrator.getServer().provisionProject("sample", "tracking");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
    File projectDir = ItUtils.projectDir("analysis/tracking/v1");
    SonarScanner issuesModeScan = SonarScanner.create(projectDir).setProperty("sonar.analysis.mode", "issues").setProperty("sonar.userHome", temp.newFolder().getAbsolutePath()).setProperty("sonar.report.export.path", "sonar-report.json").setProperty("sonar.projectDate", "2013-05-02");
    orchestrator.executeBuild(issuesModeScan);
    File report = new File(projectDir, ".sonar/sonar-report.json");
    assertThat(report).isFile().exists();
    String json = sanitize(FileUtils.readFileToString(report));
    String expectedJson = expected("no-server-analysis.json");
    JSONAssert.assertEquals(expectedJson, json, false);
}
Also used : File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Aggregations

SonarScanner (com.sonar.orchestrator.build.SonarScanner)84 Test (org.junit.Test)65 BuildResult (com.sonar.orchestrator.build.BuildResult)38 File (java.io.File)21 QualityGate (org.sonar.wsclient.qualitygate.QualityGate)8 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 Issue (org.sonar.wsclient.issue.Issue)4 Favorites (org.sonarqube.ws.Favorites)3 SearchRequest (org.sonarqube.ws.client.favorite.SearchRequest)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 BeforeClass (org.junit.BeforeClass)2 SonarClient (org.sonar.wsclient.SonarClient)2 IssueClient (org.sonar.wsclient.issue.IssueClient)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 WebTestSuite.createSonarScanner (com.sonar.it.web.WebTestSuite.createSonarScanner)1 BuildFailureException (com.sonar.orchestrator.build.BuildFailureException)1 SonarScannerInstaller (com.sonar.orchestrator.build.SonarScannerInstaller)1 FileSystem (com.sonar.orchestrator.config.FileSystem)1