Пример #1
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);
  }
Пример #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);
  }
Пример #3
0
  @Test
  public void should_export_profile() throws Exception {
    assumeTrue(AndroidTestSuite.isAtLeastPlugin1_1());
    // url : profiles/export?format=android-lint&language=java&name=Android%2520Lint
    String response = exportProfile("Android Lint");

    String expectedExport =
        FileUtils.readFileToString(new File("src/test/resources/lint-export.xml"));
    assertThat(response).isEqualTo(expectedExport);
  }