|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- /*
- * SonarSource :: IT :: SonarScanner CLI
- * Copyright (C) 2009-2024 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.Test;
- import org.sonarqube.ws.Components.Component;
-
- import static org.assertj.core.api.Assertions.assertThat;
-
- public class MultimoduleTest extends ScannerTestCase {
-
- /**
- * 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");
-
- if (noMoreModules()) {
- // Verify that we have the folders
- assertThat(
- getComponent("simplest-with-props-on-root:module1/src").getName())
- .isEqualTo("module1/src");
- assertThat(
- getComponent("simplest-with-props-on-root:module2/src").getName())
- .isEqualTo("module2/src");
- } else {
- // 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-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");
-
- if (noMoreModules()) {
- assertThat(
- getComponent("simplest-with-props-each-module:module1/src").getName())
- .isEqualTo("module1/src");
- assertThat(
- getComponent("simplest-with-props-each-module:module2/src").getName())
- .isEqualTo("module2/src");
- } else {
- // 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");
-
- if (noMoreModules()) {
- assertThat(
- getComponent("deep-path-for-modules:modules/module1/src").getName())
- .isEqualTo("module1/src");
- assertThat(
- getComponent("deep-path-for-modules:modules/module2/src").getName())
- .isEqualTo("module2/src");
- } else {
- // 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");
-
- if (noMoreModules()) {
- assertThat(
- getComponent("module-path-with-space:my module 1/src").getName())
- .isEqualTo("my module 1/src");
- assertThat(
- getComponent("module-path-with-space:my module 2/src").getName())
- .isEqualTo("my module 2/src");
- } else {
- // 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");
-
- if (noMoreModules()) {
- assertThat(
- getComponent("overwriting-parent-properties:module1/src1").getName())
- .isEqualTo("module1/src1");
- assertThat(
- getComponent("overwriting-parent-properties:module2/src2").getName())
- .isEqualTo("module2/src2");
- } else {
- // 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");
-
- if (noMoreModules()) {
- assertThat(getComponent("using-config-file-prop:module1/src").getName())
- .isEqualTo("module1/src");
- assertThat(getComponent("using-config-file-prop:module2/src").getName())
- .isEqualTo("module2/src");
- } else {
- // 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");
- }
- }
-
- private boolean noMoreModules() {
- return orchestrator.getServer().version().isGreaterThanOrEquals(7, 6);
- }
-
- /**
- * 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");
- }
-
- }
|