Search in sources :

Example 46 with SonarScanner

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

the class PermissionSearchTest method analyzeProject.

@BeforeClass
public static void analyzeProject() {
    orchestrator.resetData();
    orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/authorisation/one-issue-per-line-profile.xml"));
    orchestrator.getServer().provisionProject(PROJECT_KEY, "Sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
    SonarScanner sampleProject = SonarScanner.create(projectDir("shared/xoo-sample"));
    orchestrator.executeBuild(sampleProject);
    adminWsClient = newAdminWsClient(orchestrator);
    permissionsWsClient = adminWsClient.permissions();
    createUser(LOGIN, "George Orwell");
    createGroup(GROUP_NAME);
}
Also used : SonarScanner(com.sonar.orchestrator.build.SonarScanner) BeforeClass(org.junit.BeforeClass)

Example 47 with SonarScanner

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

the class ProjectsWsTest method projects_web_service.

/**
   * SONAR-3105
   */
@Test
public void projects_web_service() throws IOException {
    SonarScanner build = SonarScanner.create(projectDir("shared/xoo-sample"));
    orchestrator.executeBuild(build);
    String url = orchestrator.getServer().getUrl() + "/api/projects/index?key=sample&versions=true";
    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet get = new HttpGet(url);
        HttpResponse response = httpclient.execute(get);
        assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
        String content = IOUtils.toString(response.getEntity().getContent());
        assertThat(content).doesNotContain("error");
        assertThat(content).contains("sample");
        EntityUtils.consume(response.getEntity());
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}
Also used : DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 48 with SonarScanner

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

the class SSLTest method simple_analysis_with_server_certificate.

@Test
public void simple_analysis_with_server_certificate() throws Exception {
    startSSLTransparentReverseProxy(false);
    SonarScanner sonarScanner = SonarScanner.create(ItUtils.projectDir("shared/xoo-sample")).setScannerVersion("2.7").setProperty("sonar.host.url", "https://localhost:" + httpsPort);
    BuildResult buildResult = orchestrator.executeBuildQuietly(sonarScanner);
    assertThat(buildResult.getLastStatus()).isNotEqualTo(0);
    assertThat(buildResult.getLogs()).contains("javax.net.ssl.SSLHandshakeException");
    Path clientTruststore = Paths.get(SSLTest.class.getResource(CLIENT_TRUSTSTORE).toURI()).toAbsolutePath();
    String truststorePassword = CLIENT_TRUSTSTORE_PWD;
    buildResult = orchestrator.executeBuild(sonarScanner.setEnvironmentVariable("SONAR_SCANNER_OPTS", "-Djavax.net.ssl.trustStore=" + clientTruststore.toString() + " -Djavax.net.ssl.trustStorePassword=" + truststorePassword));
}
Also used : Path(java.nio.file.Path) BuildResult(com.sonar.orchestrator.build.BuildResult) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 49 with SonarScanner

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

the class ScannerTest method should_honor_sonarUserHome.

@Test
public void should_honor_sonarUserHome() {
    File userHome = temp.getRoot();
    orchestrator.getServer().provisionProject("sample", "xoo-sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
    SonarScanner scanner = configureScanner("shared/xoo-sample", "sonar.verbose", "true");
    scanner.setEnvironmentVariable("SONAR_USER_HOME", "/dev/null");
    BuildResult buildResult = orchestrator.executeBuildQuietly(scanner);
    assertThat(buildResult.getLastStatus()).isEqualTo(1);
    buildResult = scan("shared/xoo-sample", "sonar.verbose", "true", "sonar.userHome", userHome.getAbsolutePath());
    assertThat(buildResult.isSuccess()).isTrue();
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 50 with SonarScanner

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

the class IssueJsonReportTest method test_json_report_on_sub_module.

/**
   * Multi-modules project but Eclipse scans only a single module
   */
@Test
public void test_json_report_on_sub_module() throws Exception {
    orchestrator.getServer().restoreProfile(getResource("one-issue-per-line.xml"));
    orchestrator.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "Multi-module sample");
    orchestrator.getServer().associateProjectToQualityProfile("com.sonarsource.it.samples:multi-modules-sample", "xoo", "one-issue-per-line");
    File rootDir = ItUtils.projectDir("shared/xoo-multi-modules-sample");
    SonarScanner scan = SonarScanner.create(rootDir).setProperty("sonar.projectDate", "2013-05-01");
    orchestrator.executeBuild(scan);
    // Issues mode scan on a module -> no new issues
    File moduleDir = ItUtils.projectDir("shared/xoo-multi-modules-sample/module_a/module_a1");
    SonarScanner issuesModeScan = SonarScanner.create(moduleDir).setProperty("sonar.projectKey", "com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1").setProperty("sonar.projectVersion", "1.0-SNAPSHOT").setProperty("sonar.projectName", "ModuleA1").setProperty("sonar.sources", "src/main/xoo").setProperty("sonar.language", "xoo").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(moduleDir, ".sonar/sonar-report.json");
    assertThat(report).isFile().exists();
    String json = sanitize(FileUtils.readFileToString(report));
    // SONAR-5218 All issues are updated as their root project id has changed (it's now the sub module)
    String expectedJson = expected("report-on-sub-module.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