Exemplo n.º 1
0
  @Test
  public void exclude_source_files() {
    scan(
        "sonar.global.exclusions", "**/*Ignore*.xoo",
        "sonar.exclusions", "**/*Exclude*.xoo,src/main/xoo/org/sonar/tests/packageToExclude/**",
        "sonar.test.exclusions", "**/ClassTwoTest.xoo");

    Resource project = projectWithMetrics("ncloc", "files", "directories");

    assertThat(project.getMeasureIntValue("files")).isEqualTo(4);
    assertThat(project.getMeasureIntValue("ncloc")).isEqualTo(60);
    assertThat(project.getMeasureIntValue("directories")).isEqualTo(3);
  }
Exemplo n.º 2
0
  @Test
  public void should_exclude_source_files() {
    assumeTrue(AndroidTestSuite.isAtLeastPlugin1_1());
    SonarRunner analysis =
        SonarRunner.create()
            .setProfile("it-profile")
            .setProjectName("SonarAndroidSample")
            .setProjectKey("SonarAndroidSample")
            .setProjectVersion("1.0")
            .setSourceDirs("app/src/main")
            .setProjectDir(new File("projects/SonarAndroidSample"))
            .setProperty("skipTests", "true")
            .setProperty("sonar.global.exclusions", "**/TestViolations.java")
            .setProperty("sonar.android.lint.report", "lint-results.xml")
            .setProperty("sonar.import_unknown_files", "true");

    orchestrator.executeBuild(analysis);
    Resource project =
        sonar.find(ResourceQuery.createForMetrics("SonarAndroidSample", "violations"));

    int expectedViolations = 0;
    if (AndroidTestSuite.sonarqube_version_is_after_5_1()) {
      // After version 5.1 xml files will be indexed thanks to sonar.import_unknown_files parameter
      // and so issues can be reported on them.
      expectedViolations = 4;
    }
    assertThat(project.getMeasureIntValue("violations")).isEqualTo(expectedViolations);
  }
Exemplo n.º 3
0
  @Test
  @Ignore("Deactivated awaiting resolution of http://jira.sonarsource.com/browse/JC-145")
  public void should_run_lint_after_export_and_import_results() throws Exception {
    assumeTrue(AndroidTestSuite.isAtLeastPlugin1_1());
    String response = exportProfile("it-profile");
    File baseDir = new File("projects/SonarAndroidSample/app");
    FileUtils.write(new File(baseDir, "lint.xml"), response, Charsets.UTF_8);
    ProcessBuilder pb = new ProcessBuilder("CMD", "/C", "gradle lint");
    pb.directory(baseDir);
    pb.inheritIO();
    Process gradleProcess = pb.start();
    int exitStatus = gradleProcess.waitFor();
    if (exitStatus != 0) {
      fail("Failed to execute gradle lint.");
    }
    SonarRunner analysis =
        SonarRunner.create()
            .setProfile("it-profile")
            .setProjectName("SonarAndroidSample2")
            .setProjectKey("SonarAndroidSample2")
            .setProjectVersion("1.0")
            .setSourceDirs("src/main")
            .setProjectDir(baseDir)
            .setProperty("sonar.android.lint.report", "lint-report-build.xml")
            .setProperty("sonar.import_unknown_files", "true");
    orchestrator.executeBuild(analysis);
    Resource project =
        sonar.find(ResourceQuery.createForMetrics("SonarAndroidSample2", "violations"));

    assertThat(project.getMeasureIntValue("violations")).isEqualTo(2);
  }
Exemplo n.º 4
0
  /** 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);
  }
Exemplo n.º 5
0
  /** SONAR-1896 */
  @Test
  public void include_test_files() {
    scan("sonar.test.inclusions", "src/test/xoo/**/*One*.xoo,src/test/xoo/**/*Two*.xoo");

    Resource project = projectWithMetrics("tests");
    assertThat(project.getMeasureIntValue("tests")).isEqualTo(2);

    List<Resource> testFiles =
        orchestrator
            .getServer()
            .getWsClient()
            .findAll(new ResourceQuery(PROJECT).setQualifiers("UTS").setDepth(-1));

    assertThat(testFiles).hasSize(2);
    assertThat(testFiles).extracting("name").containsOnly("ClassOneTest.xoo", "ClassTwoTest.xoo");
  }
Exemplo n.º 6
0
  /** SONAR-1896 */
  @Test
  public void include_source_files() {
    scan(
        "sonar.dynamicAnalysis", "false",
        "sonar.inclusions", "**/*One.xoo,**/*Two.xoo");

    Resource project = projectWithMetrics("files");
    assertThat(project.getMeasureIntValue("files")).isEqualTo(2);

    List<Resource> sourceFiles =
        orchestrator
            .getServer()
            .getWsClient()
            .findAll(new ResourceQuery(PROJECT).setQualifiers("FIL").setDepth(-1));

    assertThat(sourceFiles).hasSize(2);
    assertThat(sourceFiles).extracting("name").containsOnly("ClassOne.xoo", "ClassTwo.xoo");
  }