Java Code Examples for com.sonar.orchestrator.build.SonarScanner

The following examples show how to use com.sonar.orchestrator.build.SonarScanner. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@BeforeClass
public static void init() {
  orchestrator.resetData();

  SonarScanner build = Tests.createSonarScannerBuild()
    .setProjectDir(new File("../projects/custom-rules/"))
    .setProjectKey(PROJECT_KEY)
    .setProjectName(PROJECT_KEY);

  orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
  Tests.setCssProfile("css-custom-rules-profile", PROJECT_KEY);
  Tests.setLessProfile("less-custom-rules-profile", PROJECT_KEY);
  Tests.setScssProfile("scss-custom-rules-profile", PROJECT_KEY);
  orchestrator.executeBuild(build);

  issueClient = orchestrator.getServer().wsClient().issueClient();
}
 
Example 2
@Test
public void test() throws Exception {
  File litsDifferencesFile = FileLocation.of("target/differences").getFile();
  orchestrator.getServer().provisionProject("project", "project");
  orchestrator.getServer().associateProjectToQualityProfile("project", "css", "rules");
  orchestrator.getServer().associateProjectToQualityProfile("project", "less", "rules");
  orchestrator.getServer().associateProjectToQualityProfile("project", "scss", "rules");
  SonarScanner build = SonarScanner.create(FileLocation.of("../projects").getFile())
    .setProjectKey("project")
    .setSourceDirs("./")
    .setSourceEncoding("UTF-8")
    .setProperty("sonar.import_unknown_files", "true")
    .setProperty("sonar.analysis.mode", "preview")
    .setProperty("sonar.issuesReport.html.enable", "true")
    .setProperty("dump.old", FileLocation.of("src/test/expected").getFile().getAbsolutePath())
    .setProperty("dump.new", FileLocation.of("target/actual").getFile().getAbsolutePath())
    .setProperty("lits.differences", litsDifferencesFile.getAbsolutePath())
    .setProperty("sonar.cpd.skip", "true");
  orchestrator.executeBuild(build);

  assertThat(Files.asCharSource(litsDifferencesFile, StandardCharsets.UTF_8).read()).isEmpty();
}
 
Example 3
@Test
public void test() throws Exception {
  File litsDifferencesFile = FileLocation.of("target/differences").getFile();
  orchestrator.getServer().provisionProject("project", "project");
  orchestrator.getServer().associateProjectToQualityProfile("project", "gherkin", "rules");
  SonarScanner build = SonarScanner.create(FileLocation.of("../projects").getFile())
    .setProjectKey("project")
    .setLanguage("gherkin")
    .setSourceDirs("./")
    .setSourceEncoding("UTF-8")
    .setProperty("sonar.analysis.mode", "preview")
    .setProperty("sonar.issuesReport.html.enable", "true")
    .setProperty("dump.old", FileLocation.of("src/test/expected").getFile().getAbsolutePath())
    .setProperty("dump.new", FileLocation.of("target/actual").getFile().getAbsolutePath())
    .setProperty("lits.differences", litsDifferencesFile.getAbsolutePath())
    .setProperty("sonar.cpd.skip", "true")
    .setProperty("sonar.exclusions",
      "custom/spelling/spelling-fr.feature,"
        + "custom/indentation/indentation-custom-ok.feature,"
        + "custom/indentation/indentation-custom-ko.feature"
    );
  orchestrator.executeBuild(build);

  assertThat(Files.asCharSource(litsDifferencesFile, StandardCharsets.UTF_8).read()).isEmpty();
}
 
Example 4
Source Project: sonar-clover   Source File: CloverTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void reuse_report_project_java() {
  String project = "reuseReport";
  String file = keyFor(project, "HelloWorld.java", ":src/main/java/");
  SonarScanner analysis = SonarScanner.create()
    .setProjectName(project)
    .setProjectKey(project)
    .setProjectVersion("1.0")
    .setSourceDirs("src/main/java")
    .setProjectDir(new File("projects/reuseReport"))
    .setProperty("sonar.clover.reportPath", "clover.xml")
    .setProperty("sonar.java.binaries", "target/classes");
  if (!orchestrator.getConfiguration().getPluginVersion("clover").isGreaterThan("2.9")) {
    analysis.setProperty("sonar.java.coveragePlugin", "clover");
  }

  orchestrator.executeBuild(analysis);

  assertThat(getMeasure(project, "lines_to_cover")).isEqualTo(8);
  assertThat(getMeasure(project, "uncovered_lines")).isEqualTo(4);

  assertThat(getMeasure(file, "files")).isEqualTo(1);
  assertThat(getMeasure(file, "lines_to_cover")).isEqualTo(4);
  assertThat(getMeasure(file, "uncovered_lines")).isEqualTo(2);
}
 
Example 5
Source Project: sonar-clover   Source File: CloverTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void reuse_report_project_groovy() {
  String project = "groovy-clover-sample";
  String groovyFile = keyFor(project, "org/sonar/Example.groovy", ":src/main/groovy/");
  orchestrator.getServer().provisionProject("groovy-clover-sample", "groovy-clover-sample");
  orchestrator.getServer().associateProjectToQualityProfile("groovy-clover-sample", "grvy", "rules");
  SonarScanner analysis = SonarScanner.create()
    .setProjectName(project)
    .setProjectKey(project)
    .setProjectVersion("1.0")
    .setSourceDirs("src/main/groovy")
    .setLanguage("grvy")
    .setProjectDir(new File("projects/groovy-clover-sample"))
    .setProperty("sonar.clover.reportPath", "clover.xml");

  orchestrator.executeBuild(analysis);

  assertThat(getMeasure(project, "lines_to_cover")).isEqualTo(2);
  assertThat(getMeasure(project, "uncovered_lines")).isEqualTo(0);

  assertThat(getMeasure(groovyFile, "files")).isEqualTo(1);
  assertThat(getMeasure(groovyFile, "lines_to_cover")).isEqualTo(2);
  assertThat(getMeasure(groovyFile, "uncovered_lines")).isEqualTo(0);
}
 
Example 6
@BeforeClass
public static void init() {
  orchestrator.resetData();

  SonarScanner build = Tests.createSonarScannerBuild()
    .setProjectDir(new File("../projects/issues/"))
    .setProjectKey(PROJECT_KEY)
    .setProjectName(PROJECT_KEY);

  orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
  Tests.setCssProfile("css-zero-units-only-profile", PROJECT_KEY);
  Tests.setLessProfile("less-zero-units-only-profile", PROJECT_KEY);
  Tests.setScssProfile("scss-zero-units-only-profile", PROJECT_KEY);
  orchestrator.executeBuild(build);
}
 
Example 7
@BeforeClass
public static void init() {
  orchestrator.resetData();

  SonarScanner build = Tests.createSonarScannerBuild()
    .setProjectDir(new File("../projects/less-metrics/"))
    .setProjectKey(PROJECT_KEY)
    .setProjectName(PROJECT_KEY);

  orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
  Tests.setLessProfile("less-empty-profile", PROJECT_KEY);
  orchestrator.executeBuild(build);
}
 
Example 8
@BeforeClass
public static void init() {
  orchestrator.resetData();

  SonarScanner build = Tests.createSonarScannerBuild()
    .setProjectDir(new File("../projects/scss-duplications/"))
    .setProjectKey(PROJECT_KEY)
    .setProjectName(PROJECT_KEY);

  orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
  Tests.setScssProfile("scss-empty-profile", PROJECT_KEY);
  orchestrator.executeBuild(build);
}
 
Example 9
@BeforeClass
public static void init() {
  orchestrator.resetData();

  SonarScanner build = Tests.createSonarScannerBuild()
    .setProjectDir(new File("../projects/less-duplications/"))
    .setProjectKey(PROJECT_KEY)
    .setProjectName(PROJECT_KEY);

  orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
  Tests.setLessProfile("less-empty-profile", PROJECT_KEY);
  orchestrator.executeBuild(build);
}
 
Example 10
public static SonarScanner createSonarScannerBuild() {
  SonarScanner build = SonarScanner.create();
  build.setProjectVersion("1.0");
  build.setSourceEncoding("UTF-8");
  build.setSourceDirs("src");
  return build;
}
 
Example 11
@BeforeClass
public static void init() {
  orchestrator.resetData();

  SonarScanner build = Tests.createSonarScannerBuild()
    .setProjectDir(new File("../projects/scss-metrics/"))
    .setProjectKey(PROJECT_KEY)
    .setProjectName(PROJECT_KEY);

  orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
  Tests.setScssProfile("scss-empty-profile", PROJECT_KEY);
  orchestrator.executeBuild(build);
}
 
Example 12
@BeforeClass
public static void init() {
  orchestrator.resetData();

  SonarScanner build = Tests.createSonarScannerBuild()
    .setProjectDir(new File("../projects/css-duplications/"))
    .setProjectKey(PROJECT_KEY)
    .setProjectName(PROJECT_KEY);

  orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
  Tests.setCssProfile("css-empty-profile", PROJECT_KEY);
  orchestrator.executeBuild(build);
}
 
Example 13
@BeforeClass
public static void init() {
  orchestrator.resetData();

  SonarScanner build = Tests.createSonarScannerBuild()
    .setProjectDir(new File("../projects/css-metrics/"))
    .setProjectKey(PROJECT_KEY)
    .setProjectName(PROJECT_KEY);

  orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
  Tests.setCssProfile("css-empty-profile", PROJECT_KEY);
  orchestrator.executeBuild(build);
}
 
Example 14
@BeforeClass
public static void init() {
  orchestrator.resetData();

  SonarScanner build = Tests.createSonarScannerBuild()
    .setProjectDir(new File("../projects/minified/"))
    .setProjectKey(PROJECT_KEY)
    .setProjectName(PROJECT_KEY);

  orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
  Tests.setCssProfile("css-zero-units-only-profile", PROJECT_KEY);
  orchestrator.executeBuild(build);
}
 
Example 15
@org.junit.BeforeClass
public static void init() {
  orchestrator.resetData();

  SonarScanner build = Tests.createSonarScannerBuild()
    .setProjectDir(new File("../projects/issues/"))
    .setProjectKey(PROJECT_KEY)
    .setProjectName(PROJECT_KEY);

  orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
  Tests.setProfile("allowed-tags-only-profile", PROJECT_KEY);
  orchestrator.executeBuild(build);
}
 
Example 16
@BeforeClass
public static void init() {
  orchestrator.resetData();

  SonarScanner build = Tests.createSonarScannerBuild()
    .setProjectDir(new File("../projects/custom-rules/"))
    .setProjectKey(PROJECT_KEY)
    .setProjectName(PROJECT_KEY);

  orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
  Tests.setProfile("gherkin-custom-rules-profile", PROJECT_KEY);
  orchestrator.executeBuild(build);

  issueClient = orchestrator.getServer().wsClient().issueClient();
}
 
Example 17
@BeforeClass
public static void init() {
  orchestrator.resetData();

  SonarScanner build = Tests.createSonarScannerBuild()
    .setProjectDir(new File("../projects/metrics/"))
    .setProjectKey(PROJECT_KEY)
    .setProjectName(PROJECT_KEY);

  orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
  Tests.setProfile("empty-profile", PROJECT_KEY);
  orchestrator.executeBuild(build);
}
 
Example 18
public static SonarScanner createSonarScannerBuild() {
  SonarScanner build = SonarScanner.create();
  build.setProjectVersion("1.0");
  build.setSourceEncoding("UTF-8");
  build.setSourceDirs("src");
  return build;
}