aboutsummaryrefslogtreecommitdiffstats
path: root/it/src/test/java/com/sonarsource/scanner
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-07-28 12:36:45 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-07-31 08:55:41 +0200
commitb0583c0fbddafdd013bd9289d0385beb1c299a17 (patch)
tree987ff3a01e709ccdd634618b1f33d7df80485333 /it/src/test/java/com/sonarsource/scanner
parent265b9abd6d508d5ae83495958c27363fdd7d6740 (diff)
downloadsonar-scanner-cli-b0583c0fbddafdd013bd9289d0385beb1c299a17.tar.gz
sonar-scanner-cli-b0583c0fbddafdd013bd9289d0385beb1c299a17.zip
SQSCANNER-43 Remove deprecated sonar-runner bat/sh scripts
Diffstat (limited to 'it/src/test/java/com/sonarsource/scanner')
-rw-r--r--it/src/test/java/com/sonarsource/scanner/it/DistributionTest.java72
-rw-r--r--it/src/test/java/com/sonarsource/scanner/it/JavaTest.java296
-rw-r--r--it/src/test/java/com/sonarsource/scanner/it/MultimoduleTest.java200
-rw-r--r--it/src/test/java/com/sonarsource/scanner/it/ScannerTestCase.java133
-rw-r--r--it/src/test/java/com/sonarsource/scanner/it/SonarScannerTestSuite.java40
5 files changed, 741 insertions, 0 deletions
diff --git a/it/src/test/java/com/sonarsource/scanner/it/DistributionTest.java b/it/src/test/java/com/sonarsource/scanner/it/DistributionTest.java
new file mode 100644
index 0000000..310ffba
--- /dev/null
+++ b/it/src/test/java/com/sonarsource/scanner/it/DistributionTest.java
@@ -0,0 +1,72 @@
+/*
+ * SonarSource :: IT :: SonarQube Scanner
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package com.sonarsource.scanner.it;
+
+import com.sonar.orchestrator.build.BuildFailureException;
+import com.sonar.orchestrator.build.SonarScanner;
+import com.sonar.orchestrator.locator.ResourceLocation;
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+import org.junit.After;
+import org.junit.Test;
+import org.sonarqube.ws.WsMeasures.Measure;
+
+import static java.lang.Integer.parseInt;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DistributionTest extends ScannerTestCase {
+
+ @After
+ public void cleanup() {
+ orchestrator.resetData();
+ }
+
+ @Test
+ public void should_succeed_with_self_contained_jre_despite_rubbish_java_home() throws IOException, InterruptedException {
+ String projectKey = "java:basedir-with-source";
+ orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml"));
+ orchestrator.getServer().provisionProject(projectKey, "Basedir with source");
+ orchestrator.getServer().associateProjectToQualityProfile(projectKey, "java", "sonar-way");
+
+ File projectDir = new File("projects/basedir-with-source");
+ SonarScanner build = newScanner(projectDir, "sonar.projectKey", projectKey)
+ .setEnvironmentVariable("JAVA_HOME", "nonexistent")
+ .useNative();
+ orchestrator.executeBuild(build, true);
+
+ Map<String, Measure> projectMeasures = getMeasures(projectKey, "files", "ncloc");
+ assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(1);
+ assertThat(parseInt(projectMeasures.get("ncloc").getValue())).isGreaterThan(1);
+ }
+
+ @Test(expected = BuildFailureException.class)
+ public void should_fail_without_self_contained_jre_when_rubbish_java_home() throws IOException, InterruptedException {
+ String projectKey = "java:basedir-with-source";
+ orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml"));
+ orchestrator.getServer().provisionProject(projectKey, "Basedir with source");
+ orchestrator.getServer().associateProjectToQualityProfile(projectKey, "java", "sonar-way");
+
+ File projectDir = new File("projects/basedir-with-source");
+ SonarScanner build = newScanner(projectDir, "sonar.projectKey", projectKey)
+ .setEnvironmentVariable("JAVA_HOME", "nonexistent");
+ orchestrator.executeBuild(build, true);
+ }
+}
diff --git a/it/src/test/java/com/sonarsource/scanner/it/JavaTest.java b/it/src/test/java/com/sonarsource/scanner/it/JavaTest.java
new file mode 100644
index 0000000..1f53a88
--- /dev/null
+++ b/it/src/test/java/com/sonarsource/scanner/it/JavaTest.java
@@ -0,0 +1,296 @@
+/*
+ * SonarSource :: IT :: SonarQube Scanner
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package com.sonarsource.scanner.it;
+
+import com.sonar.orchestrator.build.BuildResult;
+import com.sonar.orchestrator.build.SonarScanner;
+import com.sonar.orchestrator.locator.ResourceLocation;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.junit.After;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.wsclient.issue.Issue;
+import org.sonar.wsclient.issue.IssueQuery;
+import org.sonarqube.ws.WsComponents.Component;
+import org.sonarqube.ws.WsMeasures.Measure;
+
+import static java.lang.Integer.parseInt;
+import static org.fest.assertions.Assertions.assertThat;
+
+public class JavaTest extends ScannerTestCase {
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ @After
+ public void cleanup() {
+ orchestrator.resetData();
+ }
+
+ /**
+ * No bytecode, only sources
+ */
+ @Test
+ public void scan_java_sources() {
+ orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml"));
+ orchestrator.getServer().provisionProject("java:sample", "Java Sample, with comma");
+ orchestrator.getServer().associateProjectToQualityProfile("java:sample", "java", "sonar-way");
+
+ SonarScanner build = newScanner(new File("projects/java-sample"))
+ .setProperty("sonar.verbose", "true");
+ // SONARPLUGINS-3061
+ // Add a trailing slash
+ build.setProperty("sonar.host.url", orchestrator.getServer().getUrl() + "/");
+ orchestrator.executeBuild(build);
+
+ Component project = getComponent("java:sample");
+ assertThat(project.getName()).isEqualTo("Java Sample, with comma");
+ assertThat(project.getDescription()).isEqualTo("This is a Java sample");
+
+ Map<String, Measure> projectMeasures = getMeasures("java:sample", "files", "ncloc", "classes", "violations");
+ // SONARPLUGINS-2399
+ assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(2);
+ assertThat(parseInt(projectMeasures.get("classes").getValue())).isEqualTo(2);
+ assertThat(parseInt(projectMeasures.get("ncloc").getValue())).isGreaterThan(10);
+ assertThat(parseInt(projectMeasures.get("violations").getValue())).isGreaterThan(0);
+
+ Component file = getComponent("java:sample:src/basic/Hello.java");
+ assertThat(file.getName()).isEqualTo("Hello.java");
+
+ Map<String, Measure> fileMeasures = getMeasures("java:sample:src/basic/Hello.java", "files", "ncloc", "classes", "violations");
+ assertThat(parseInt(fileMeasures.get("ncloc").getValue())).isEqualTo(7);
+ assertThat(parseInt(fileMeasures.get("violations").getValue())).isGreaterThan(0);
+ }
+
+ /**
+ * Only tests, no sources
+ */
+ @Test
+ public void scan_java_tests() {
+ orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml"));
+ orchestrator.getServer().provisionProject("java:sampletest", "Java Sample");
+ orchestrator.getServer().associateProjectToQualityProfile("java:sampletest", "java", "sonar-way");
+
+ SonarScanner build = newScanner(new File("projects/java-sample"))
+ .setProperty("sonar.projectKey", "java:sampletest")
+ .setProperty("sonar.tests", "src")
+ .setProperty("sonar.sources", "");
+ orchestrator.executeBuild(build);
+
+ Component file = getComponent("java:sampletest:src/basic/Hello.java");
+ assertThat(file.getName()).isEqualTo("Hello.java");
+ assertThat(file.getQualifier()).isEqualTo("UTS");
+ }
+
+ @Test
+ public void scan_java_sources_and_bytecode() {
+ orchestrator.getServer().restoreProfile(ResourceLocation.create("/requires-bytecode-profile.xml"));
+ orchestrator.getServer().provisionProject("java:bytecode", "Java Bytecode Sample");
+ orchestrator.getServer().associateProjectToQualityProfile("java:bytecode", "java", "requires-bytecode");
+
+ SonarScanner build = newScanner(new File("projects/java-bytecode"));
+ orchestrator.executeBuild(build);
+
+ Component project = getComponent("java:bytecode");
+ assertThat(project.getName()).isEqualTo("Java Bytecode Sample");
+
+ Map<String, Measure> projectMeasures = getMeasures("java:bytecode", "violations");
+ // the squid rules enabled in sonar-way-profile do not exist in SQ 3.0
+ assertThat(parseInt(projectMeasures.get("violations").getValue())).isGreaterThan(0);
+
+ assertThat(getMeasureAsInteger("java:bytecode:src/HasFindbugsViolation.java", "violations")).isGreaterThan(0);
+
+ // findbugs is executed on bytecode
+ List<Issue> issues = orchestrator.getServer().wsClient().issueClient().find(IssueQuery.create().componentRoots("java:bytecode").rules("squid:S1147")).list();
+ assertThat(issues).hasSize(1);
+ assertThat(issues.get(0).ruleKey()).isEqualTo("squid:S1147");
+
+ // Squid performs analysis of dependencies
+ issues = orchestrator.getServer().wsClient().issueClient().find(IssueQuery.create().componentRoots("java:bytecode").rules("squid:CallToDeprecatedMethod")).list();
+ assertThat(issues).hasSize(1);
+ assertThat(issues.get(0).ruleKey()).isEqualTo("squid:CallToDeprecatedMethod");
+ }
+
+ @Test
+ public void basedir_contains_java_sources() {
+ orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml"));
+ orchestrator.getServer().provisionProject("java:basedir-with-source", "Basedir with source");
+ orchestrator.getServer().associateProjectToQualityProfile("java:basedir-with-source", "java", "sonar-way");
+
+ SonarScanner build = newScanner(new File("projects/basedir-with-source"));
+ orchestrator.executeBuild(build);
+
+ Map<String, Measure> projectMeasures = getMeasures("java:basedir-with-source", "files", "ncloc");
+ assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(1);
+ assertThat(parseInt(projectMeasures.get("ncloc").getValue())).isGreaterThan(1);
+ }
+
+ /**
+ * Replace the maven format groupId:artifactId by a single key
+ */
+ @Test
+ public void should_support_simple_project_keys() {
+ orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml"));
+ orchestrator.getServer().provisionProject("SAMPLE", "Java Sample, with comma");
+ orchestrator.getServer().associateProjectToQualityProfile("SAMPLE", "java", "sonar-way");
+
+ SonarScanner build = newScanner(new File("projects/java-sample"))
+ .setProjectKey("SAMPLE");
+ orchestrator.executeBuild(build);
+
+ Map<String, Measure> projectMeasures = getMeasures("SAMPLE", "files", "ncloc");
+ assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(2);
+ assertThat(parseInt(projectMeasures.get("ncloc").getValue())).isGreaterThan(1);
+ }
+
+ /**
+ * SONARPLUGINS-1230
+ */
+ @Test
+ public void should_override_working_dir_with_relative_path() {
+ SonarScanner build = newScanner(new File("projects/override-working-dir"))
+ .setProperty("sonar.working.directory", ".overridden-relative-sonar");
+ orchestrator.executeBuild(build);
+
+ assertThat(new File("projects/override-working-dir/.sonar")).doesNotExist();
+ assertThat(new File("projects/override-working-dir/.overridden-relative-sonar")).exists().isDirectory();
+ }
+
+ /**
+ * SONARPLUGINS-1230
+ */
+ @Test
+ public void should_override_working_dir_with_absolute_path() {
+ File projectHome = new File("projects/override-working-dir");
+ SonarScanner build = newScanner(projectHome)
+ .setProperty("sonar.working.directory", new File(projectHome, ".overridden-absolute-sonar").getAbsolutePath());
+ orchestrator.executeBuild(build);
+
+ assertThat(new File("projects/override-working-dir/.sonar")).doesNotExist();
+ assertThat(new File("projects/override-working-dir/.overridden-absolute-sonar")).exists().isDirectory();
+ }
+
+ /**
+ * SONARPLUGINS-1856
+ */
+ @Test
+ public void should_fail_if_source_dir_does_not_exist() {
+ SonarScanner build = newScanner(new File("projects/bad-source-dirs"));
+
+ BuildResult result = orchestrator.executeBuildQuietly(build);
+ assertThat(result.getStatus()).isNotEqualTo(0);
+ // with the following message
+ assertThat(result.getLogs()).contains("Invalid value of sonar.sources for bad-source-dirs");
+ }
+
+ /**
+ * SONARPLUGINS-2256
+ */
+ @Test
+ public void should_warn_when_analysis_is_platform_dependent() {
+ SonarScanner build = newScanner(new File("projects/java-sample"))
+ // ORCH-243
+ .setSourceEncoding("");
+ String log = orchestrator.executeBuild(build).getLogs();
+
+ // Note: we can't really check the locale value and the charset because the ones used during the Sonar analysis may not be the ones
+ // used to launch the tests. But we can check that the analysis is platform dependent (i.e. "sonar.sourceEncoding" hasn't been set).
+ assertThat(log).contains("Default locale:");
+ assertThat(log).contains(", source code encoding:");
+ assertThat(log).contains("(analysis is platform dependent)");
+ }
+
+ /**
+ * SONARUNNER-153
+ */
+ @Test
+ public void should_enable_verbose() {
+ // this line should appear in all versions (LTS-DEV) in debug only
+ String expectedLog = "Available languages:";
+ SonarScanner build = newScanner(new File("projects/java-sample"))
+ .setProperty("sonar.verbose", "true");
+ String logs = orchestrator.executeBuild(build).getLogs();
+ assertThat(logs).contains(expectedLog);
+ }
+
+ @Test
+ public void should_use_environment_props() {
+ SonarScanner build = newScanner(new File("projects/java-sample-no-properties"))
+ .setEnvironmentVariable("SONARQUBE_SCANNER_PARAMS", "{"
+ + "\"sonar.projectKey\" : \"java:sample\"," +
+ "\"sonar.projectName\" : \"Java Sample, with comma\"," +
+ "\"sonar.projectDescription\" : \"This is a Java sample\"," +
+ "\"sonar.projectVersion\" : \"1.2.3\"," +
+ "\"sonar.sources\" : \"src\" }");
+ orchestrator.executeBuild(build);
+ }
+
+ @Test
+ public void should_skip_analysis() {
+ SonarScanner build = newScanner(new File("projects/java-sample"))
+ .setProperty("sonar.host.url", "http://foo")
+ .setEnvironmentVariable("SONARQUBE_SCANNER_PARAMS", "{ \"sonar.scanner.skip\":\"true\" }");
+
+ BuildResult result = orchestrator.executeBuild(build);
+ assertThat(result.getLogs()).contains("SonarQube Scanner analysis skipped");
+ }
+
+ @Test
+ public void should_fail_if_unable_to_connect() {
+ SonarScanner build = newScanner(new File("projects/java-sample"))
+ .setProperty("sonar.host.url", "http://foo");
+
+ BuildResult result = orchestrator.executeBuildQuietly(build);
+ // expect build failure
+ assertThat(result.getStatus()).isNotEqualTo(0);
+ // with the following message
+ assertThat(result.getLogs()).contains("SonarQube server [http://foo] can not be reached");
+ }
+
+ // SONARPLUGINS-3574
+ @Test
+ public void run_from_external_location() throws IOException {
+ File tempDir = temp.newFolder();
+ SonarScanner build = newScanner(tempDir)
+ .setProperty("sonar.projectBaseDir", new File("projects/java-sample").getAbsolutePath())
+ .addArguments("-e");
+ orchestrator.executeBuild(build);
+
+ assertThat(getComponent("java:sample").getDescription()).isEqualTo("This is a Java sample");
+ Map<String, Measure> projectMeasures = getMeasures("java:sample", "files", "ncloc", "classes", "violations");
+ assertThat(projectMeasures.values().stream().filter(measure -> measure.getValue() != null).collect(Collectors.toList())).hasSize(4);
+ }
+
+ @Test
+ public void verify_env_variable() {
+ SonarScanner build = newScanner(new File("projects/java-sample"))
+ .setEnvironmentVariable("SONAR_SCANNER_OPTS", "-Xmx2m");
+ BuildResult executeBuild = orchestrator.executeBuildQuietly(build);
+ assertThat(executeBuild.getStatus()).isNotEqualTo(0);
+ String logs = executeBuild.getLogs();
+ assertThat(logs).contains("java.lang.OutOfMemoryError");
+ }
+
+}
diff --git a/it/src/test/java/com/sonarsource/scanner/it/MultimoduleTest.java b/it/src/test/java/com/sonarsource/scanner/it/MultimoduleTest.java
new file mode 100644
index 0000000..52931ee
--- /dev/null
+++ b/it/src/test/java/com/sonarsource/scanner/it/MultimoduleTest.java
@@ -0,0 +1,200 @@
+/*
+ * SonarSource :: IT :: SonarQube Scanner
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package com.sonarsource.scanner.it;
+
+import com.sonar.orchestrator.build.BuildResult;
+import com.sonar.orchestrator.build.SonarScanner;
+import java.io.File;
+import org.junit.After;
+import org.junit.Test;
+import org.sonarqube.ws.WsComponents.Component;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class MultimoduleTest extends ScannerTestCase {
+
+ @After
+ public void cleanup() {
+ orchestrator.resetData();
+ }
+
+ /**
+ * SONARPLUGINS-2202
+ */
+ @Test
+ public void test_simplest_with_props_on_root() {
+ SonarScanner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-root"));
+
+ orchestrator.executeBuild(build);
+
+ assertThat(getComponent("simplest-with-props-on-root").getName()).isEqualTo("Simplest multi-module project with all properties set on the root project");
+
+ // Verify that we have the modules
+ assertThat(getComponent("simplest-with-props-on-root:module1").getName()).isEqualTo("module1");
+
+ assertThat(getComponent("simplest-with-props-on-root:module2").getName()).isEqualTo("module2");
+
+ // And verify that the working directories are all located in the root folder
+ File workDir = new File("projects/multi-module/simplest/simplest-with-props-on-root/.scannerwork");
+ assertThat(workDir).exists();
+ assertThat(new File(workDir, "simplest-with-props-on-root_module1")).exists();
+ assertThat(new File(workDir, "simplest-with-props-on-root_module2")).exists();
+ assertThat(new File("projects/multi-module/simplest/simplest-with-props-on-root/module1/.scannerwork")).doesNotExist();
+ assertThat(new File("projects/multi-module/simplest/simplest-with-props-on-root/module2/.scannerwork")).doesNotExist();
+ }
+
+ /**
+ * SONARPLUGINS-2421
+ */
+ @Test
+ public void test_multi_language_with_same_projectdir() {
+ SonarScanner build = newScanner(new File("projects/multi-module/multi-language"));
+
+ orchestrator.executeBuild(build);
+
+ assertThat(getComponent("multi-language").getName()).isEqualTo("Simplest multi-language project");
+
+ // Verify that we have the modules
+ assertThat(getComponent("multi-language:java-module").getName()).isEqualTo("java-module");
+
+ assertThat(getComponent("multi-language:js-module").getName()).isEqualTo("js-module");
+ }
+
+ /**
+ * SONARPLUGINS-2202
+ */
+ @Test
+ public void test_simplest_with_props_on_each_module() {
+ SonarScanner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));
+
+ orchestrator.executeBuild(build);
+
+ assertThat(getComponent("simplest-with-props-each-module").getName()).isEqualTo("Simplest multi-module project with properties set on each module");
+
+ // Verify that we have the modules
+ assertThat(getComponent("simplest-with-props-each-module:module1").getName()).isEqualTo("module1");
+
+ assertThat(getComponent("simplest-with-props-each-module:overridden-key-for-module2").getName()).isEqualTo("Module 2");
+ }
+
+ /**
+ * SONARPLUGINS-2202
+ */
+ @Test
+ public void test_deep_path_for_modules() {
+ SonarScanner build = newScanner(new File("projects/multi-module/customization/deep-path-for-modules"));
+
+ orchestrator.executeBuild(build);
+
+ assertThat(getComponent("deep-path-for-modules").getName()).isEqualTo("Project with deep path for modules");
+
+ // Verify that we have the modules
+ assertThat(getComponent("deep-path-for-modules:mod1").getName()).isEqualTo("Module 1");
+
+ assertThat(getComponent("deep-path-for-modules:mod2").getName()).isEqualTo("Module 2");
+ }
+
+ /**
+ * SONARPLUGINS-2202
+ */
+ @Test
+ public void test_module_path_with_space() {
+ SonarScanner build = newScanner(new File("projects/multi-module/customization/module-path-with-space"));
+
+ orchestrator.executeBuild(build);
+
+ assertThat(getComponent("module-path-with-space").getName()).isEqualTo("Project with module path that contain spaces");
+
+ // Verify that we have the modules
+ assertThat(getComponent("module-path-with-space:module1").getName()).isEqualTo("Module 1");
+
+ assertThat(getComponent("module-path-with-space:module2").getName()).isEqualTo("Module 2");
+ }
+
+ /**
+ * SONARPLUGINS-2202
+ */
+ @Test
+ public void test_overwriting_parent_properties() {
+ SonarScanner build = newScanner(new File("projects/multi-module/customization/overwriting-parent-properties"));
+
+ orchestrator.executeBuild(build);
+
+ Component rootProject = getComponent("overwriting-parent-properties");
+ assertThat(rootProject.getName()).isEqualTo("Project with modules that overwrite properties");
+ assertThat(rootProject.getDescription()).isEqualTo("Description of root project");
+
+ // Verify that we have the modules
+ Component module1 = getComponent("overwriting-parent-properties:module1-new-key");
+ assertThat(module1.getName()).isEqualTo("Module 1");
+ assertThat(module1.getDescription()).isEqualTo("Description of module 1");
+
+ Component module2 = getComponent("overwriting-parent-properties:module2-new-key");
+ assertThat(module2.getName()).isEqualTo("Module 2");
+ assertThat(module2.getDescription()).isEqualTo("Description of module 2");
+ }
+
+ /**
+ * SONARPLUGINS-2202
+ */
+ @Test
+ public void test_using_config_file_property() {
+ SonarScanner build = newScanner(new File("projects/multi-module/advanced/using-config-file-prop"));
+
+ orchestrator.executeBuild(build);
+
+ assertThat(getComponent("using-config-file-prop").getName()).isEqualTo("Advanced use case - mostly used by the Ant task");
+
+ // Verify that we have the modules
+ assertThat(getComponent("using-config-file-prop:module1").getName()).isEqualTo("Module 1");
+
+ assertThat(getComponent("using-config-file-prop:module2").getName()).isEqualTo("Module 2");
+ }
+
+ /**
+ * SONARPLUGINS-2202
+ */
+ @Test
+ public void should_fail_if_unexisting_base_dir() {
+ SonarScanner build = newScanner(new File("projects/multi-module/failures/unexisting-base-dir"));
+
+ BuildResult result = orchestrator.executeBuildQuietly(build);
+ // expect build failure
+ assertThat(result.getStatus()).isNotEqualTo(0);
+ // with the following message
+ assertThat(result.getLogs()).contains("The base directory of the module 'module3' does not exist");
+
+ }
+
+ /**
+ * SONARPLUGINS-2202
+ */
+ @Test
+ public void should_fail_if_unexisting_config_file() {
+ SonarScanner build = newScanner(new File("projects/multi-module/failures/unexisting-config-file"));
+
+ BuildResult result = orchestrator.executeBuildQuietly(build);
+ // expect build failure
+ assertThat(result.getStatus()).isNotEqualTo(0);
+ // with the following message
+ assertThat(result.getLogs()).contains("The properties file of the module 'module1' does not exist");
+ }
+
+}
diff --git a/it/src/test/java/com/sonarsource/scanner/it/ScannerTestCase.java b/it/src/test/java/com/sonarsource/scanner/it/ScannerTestCase.java
new file mode 100644
index 0000000..be19ea9
--- /dev/null
+++ b/it/src/test/java/com/sonarsource/scanner/it/ScannerTestCase.java
@@ -0,0 +1,133 @@
+/*
+ * SonarSource :: IT :: SonarQube Scanner
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package com.sonarsource.scanner.it;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarScanner;
+import com.sonar.orchestrator.version.Version;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import javax.annotation.CheckForNull;
+import org.apache.commons.lang.StringUtils;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.rules.ExpectedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonarqube.ws.WsComponents;
+import org.sonarqube.ws.WsComponents.Component;
+import org.sonarqube.ws.WsMeasures;
+import org.sonarqube.ws.WsMeasures.Measure;
+import org.sonarqube.ws.client.HttpConnector;
+import org.sonarqube.ws.client.WsClient;
+import org.sonarqube.ws.client.WsClientFactories;
+import org.sonarqube.ws.client.component.ShowWsRequest;
+import org.sonarqube.ws.client.measure.ComponentWsRequest;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.singletonList;
+
+public abstract class ScannerTestCase {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ScannerTestCase.class);
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @ClassRule
+ public static Orchestrator orchestrator = SonarScannerTestSuite.ORCHESTRATOR;
+
+ private static Version artifactVersion;
+
+ private static Version artifactVersion() {
+ if (artifactVersion == null) {
+ String scannerVersion = System.getProperty("scanner.version");
+ if (StringUtils.isNotBlank(scannerVersion)) {
+ LOG.info("Use provided Scanner version: " + scannerVersion);
+ artifactVersion = Version.create(scannerVersion);
+ } else {
+ try (FileInputStream fis = new FileInputStream(new File("../target/maven-archiver/pom.properties"))) {
+ Properties props = new Properties();
+ props.load(fis);
+ artifactVersion = Version.create(props.getProperty("version"));
+ return artifactVersion;
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+ return artifactVersion;
+ }
+
+ SonarScanner newScanner(File baseDir, String... keyValueProperties) {
+ SonarScanner scannerCli = SonarScanner.create(baseDir, keyValueProperties);
+ scannerCli.setScannerVersion(artifactVersion().toString());
+ return scannerCli;
+ }
+
+ @CheckForNull
+ static Map<String, Measure> getMeasures(String componentKey, String... metricKeys) {
+ return newWsClient().measures().component(new ComponentWsRequest()
+ .setComponentKey(componentKey)
+ .setMetricKeys(asList(metricKeys)))
+ .getComponent().getMeasuresList()
+ .stream()
+ .collect(Collectors.toMap(Measure::getMetric, Function.identity()));
+ }
+
+ @CheckForNull
+ static Measure getMeasure(String componentKey, String metricKey) {
+ WsMeasures.ComponentWsResponse response = newWsClient().measures().component(new ComponentWsRequest()
+ .setComponentKey(componentKey)
+ .setMetricKeys(singletonList(metricKey)));
+ List<Measure> measures = response.getComponent().getMeasuresList();
+ return measures.size() == 1 ? measures.get(0) : null;
+ }
+
+ @CheckForNull
+ static Integer getMeasureAsInteger(String componentKey, String metricKey) {
+ Measure measure = getMeasure(componentKey, metricKey);
+ return (measure == null) ? null : Integer.parseInt(measure.getValue());
+ }
+
+ @CheckForNull
+ static Double getMeasureAsDouble(String componentKey, String metricKey) {
+ Measure measure = getMeasure(componentKey, metricKey);
+ return (measure == null) ? null : Double.parseDouble(measure.getValue());
+ }
+
+ @CheckForNull
+ static Component getComponent(String componentKey) {
+ return newWsClient().components().show(new ShowWsRequest().setKey(componentKey)).getComponent();
+ }
+
+ static WsClient newWsClient() {
+ return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder()
+ .url(orchestrator.getServer().getUrl())
+ .build());
+ }
+
+}
diff --git a/it/src/test/java/com/sonarsource/scanner/it/SonarScannerTestSuite.java b/it/src/test/java/com/sonarsource/scanner/it/SonarScannerTestSuite.java
new file mode 100644
index 0000000..6b157b2
--- /dev/null
+++ b/it/src/test/java/com/sonarsource/scanner/it/SonarScannerTestSuite.java
@@ -0,0 +1,40 @@
+/*
+ * SonarSource :: IT :: SonarQube Scanner
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package com.sonarsource.scanner.it;
+
+import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({JavaTest.class, MultimoduleTest.class, DistributionTest.class})
+public class SonarScannerTestSuite {
+
+ @ClassRule
+ public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
+ .setOrchestratorProperty("javaVersion", "LATEST_RELEASE")
+ .addPlugin("java")
+ .setOrchestratorProperty("javascriptVersion", "LATEST_RELEASE")
+ .addPlugin("javascript")
+ .build();
+
+}