You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MultimoduleTest.java 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * SonarSource :: IT :: SonarQube Scanner
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package com.sonarsource.scanner.it;
  21. import com.sonar.orchestrator.build.BuildResult;
  22. import com.sonar.orchestrator.build.SonarScanner;
  23. import java.io.File;
  24. import org.junit.After;
  25. import org.junit.Test;
  26. import org.sonarqube.ws.WsComponents.Component;
  27. import static org.assertj.core.api.Assertions.assertThat;
  28. public class MultimoduleTest extends ScannerTestCase {
  29. @After
  30. public void cleanup() {
  31. orchestrator.resetData();
  32. }
  33. /**
  34. * SONARPLUGINS-2202
  35. */
  36. @Test
  37. public void test_simplest_with_props_on_root() {
  38. SonarScanner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-root"));
  39. orchestrator.executeBuild(build);
  40. assertThat(getComponent("simplest-with-props-on-root").getName()).isEqualTo("Simplest multi-module project with all properties set on the root project");
  41. if (noMoreModules()) {
  42. // Verify that we have the folders
  43. assertThat(getComponent("simplest-with-props-on-root:module1/src").getName()).isEqualTo("module1/src");
  44. assertThat(getComponent("simplest-with-props-on-root:module2/src").getName()).isEqualTo("module2/src");
  45. } else {
  46. // Verify that we have the modules
  47. assertThat(getComponent("simplest-with-props-on-root:module1").getName()).isEqualTo("module1");
  48. assertThat(getComponent("simplest-with-props-on-root:module2").getName()).isEqualTo("module2");
  49. }
  50. // And verify that the working directories are all located in the root folder
  51. File workDir = new File("projects/multi-module/simplest/simplest-with-props-on-root/.scannerwork");
  52. assertThat(workDir).exists();
  53. assertThat(new File(workDir, "simplest-with-props-on-root_module1")).exists();
  54. assertThat(new File(workDir, "simplest-with-props-on-root_module2")).exists();
  55. assertThat(new File("projects/multi-module/simplest/simplest-with-props-on-root/module1/.scannerwork")).doesNotExist();
  56. assertThat(new File("projects/multi-module/simplest/simplest-with-props-on-root/module2/.scannerwork")).doesNotExist();
  57. }
  58. /**
  59. * SONARPLUGINS-2202
  60. */
  61. @Test
  62. public void test_simplest_with_props_on_each_module() {
  63. SonarScanner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));
  64. orchestrator.executeBuild(build);
  65. assertThat(getComponent("simplest-with-props-each-module").getName()).isEqualTo("Simplest multi-module project with properties set on each module");
  66. if (noMoreModules()) {
  67. assertThat(getComponent("simplest-with-props-each-module:module1/src").getName()).isEqualTo("module1/src");
  68. assertThat(getComponent("simplest-with-props-each-module:module2/src").getName()).isEqualTo("module2/src");
  69. } else {
  70. // Verify that we have the modules
  71. assertThat(getComponent("simplest-with-props-each-module:module1").getName()).isEqualTo("module1");
  72. assertThat(getComponent("simplest-with-props-each-module:overridden-key-for-module2").getName()).isEqualTo("Module 2");
  73. }
  74. }
  75. /**
  76. * SONARPLUGINS-2202
  77. */
  78. @Test
  79. public void test_deep_path_for_modules() {
  80. SonarScanner build = newScanner(new File("projects/multi-module/customization/deep-path-for-modules"));
  81. orchestrator.executeBuild(build);
  82. assertThat(getComponent("deep-path-for-modules").getName()).isEqualTo("Project with deep path for modules");
  83. if (noMoreModules()) {
  84. assertThat(getComponent("deep-path-for-modules:modules/module1/src").getName()).isEqualTo("module1/src");
  85. assertThat(getComponent("deep-path-for-modules:modules/module2/src").getName()).isEqualTo("module2/src");
  86. } else {
  87. // Verify that we have the modules
  88. assertThat(getComponent("deep-path-for-modules:mod1").getName()).isEqualTo("Module 1");
  89. assertThat(getComponent("deep-path-for-modules:mod2").getName()).isEqualTo("Module 2");
  90. }
  91. }
  92. /**
  93. * SONARPLUGINS-2202
  94. */
  95. @Test
  96. public void test_module_path_with_space() {
  97. SonarScanner build = newScanner(new File("projects/multi-module/customization/module-path-with-space"));
  98. orchestrator.executeBuild(build);
  99. assertThat(getComponent("module-path-with-space").getName()).isEqualTo("Project with module path that contain spaces");
  100. if (noMoreModules()) {
  101. assertThat(getComponent("module-path-with-space:my module 1/src").getName()).isEqualTo("my module 1/src");
  102. assertThat(getComponent("module-path-with-space:my module 2/src").getName()).isEqualTo("my module 2/src");
  103. } else {
  104. // Verify that we have the modules
  105. assertThat(getComponent("module-path-with-space:module1").getName()).isEqualTo("Module 1");
  106. assertThat(getComponent("module-path-with-space:module2").getName()).isEqualTo("Module 2");
  107. }
  108. }
  109. /**
  110. * SONARPLUGINS-2202
  111. */
  112. @Test
  113. public void test_overwriting_parent_properties() {
  114. SonarScanner build = newScanner(new File("projects/multi-module/customization/overwriting-parent-properties"));
  115. orchestrator.executeBuild(build);
  116. Component rootProject = getComponent("overwriting-parent-properties");
  117. assertThat(rootProject.getName()).isEqualTo("Project with modules that overwrite properties");
  118. assertThat(rootProject.getDescription()).isEqualTo("Description of root project");
  119. if (noMoreModules()) {
  120. assertThat(getComponent("overwriting-parent-properties:module1/src1").getName()).isEqualTo("module1/src1");
  121. assertThat(getComponent("overwriting-parent-properties:module2/src2").getName()).isEqualTo("module2/src2");
  122. } else {
  123. // Verify that we have the modules
  124. Component module1 = getComponent("overwriting-parent-properties:module1-new-key");
  125. assertThat(module1.getName()).isEqualTo("Module 1");
  126. assertThat(module1.getDescription()).isEqualTo("Description of module 1");
  127. Component module2 = getComponent("overwriting-parent-properties:module2-new-key");
  128. assertThat(module2.getName()).isEqualTo("Module 2");
  129. assertThat(module2.getDescription()).isEqualTo("Description of module 2");
  130. }
  131. }
  132. /**
  133. * SONARPLUGINS-2202
  134. */
  135. @Test
  136. public void test_using_config_file_property() {
  137. SonarScanner build = newScanner(new File("projects/multi-module/advanced/using-config-file-prop"));
  138. orchestrator.executeBuild(build);
  139. assertThat(getComponent("using-config-file-prop").getName()).isEqualTo("Advanced use case - mostly used by the Ant task");
  140. if (noMoreModules()) {
  141. assertThat(getComponent("using-config-file-prop:module1/src").getName()).isEqualTo("module1/src");
  142. assertThat(getComponent("using-config-file-prop:module2/src").getName()).isEqualTo("module2/src");
  143. } else {
  144. // Verify that we have the modules
  145. assertThat(getComponent("using-config-file-prop:module1").getName()).isEqualTo("Module 1");
  146. assertThat(getComponent("using-config-file-prop:module2").getName()).isEqualTo("Module 2");
  147. }
  148. }
  149. private boolean noMoreModules() {
  150. return orchestrator.getServer().version().isGreaterThanOrEquals(7, 6);
  151. }
  152. /**
  153. * SONARPLUGINS-2202
  154. */
  155. @Test
  156. public void should_fail_if_unexisting_base_dir() {
  157. SonarScanner build = newScanner(new File("projects/multi-module/failures/unexisting-base-dir"));
  158. BuildResult result = orchestrator.executeBuildQuietly(build);
  159. // expect build failure
  160. assertThat(result.getStatus()).isNotEqualTo(0);
  161. // with the following message
  162. assertThat(result.getLogs()).contains("The base directory of the module 'module3' does not exist");
  163. }
  164. /**
  165. * SONARPLUGINS-2202
  166. */
  167. @Test
  168. public void should_fail_if_unexisting_config_file() {
  169. SonarScanner build = newScanner(new File("projects/multi-module/failures/unexisting-config-file"));
  170. BuildResult result = orchestrator.executeBuildQuietly(build);
  171. // expect build failure
  172. assertThat(result.getStatus()).isNotEqualTo(0);
  173. // with the following message
  174. assertThat(result.getLogs()).contains("The properties file of the module 'module1' does not exist");
  175. }
  176. }