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 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * SonarSource :: IT :: SonarScanner CLI
  3. * Copyright (C) 2009-2022 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.Test;
  25. import org.sonarqube.ws.Components.Component;
  26. import static org.assertj.core.api.Assertions.assertThat;
  27. public class MultimoduleTest extends ScannerTestCase {
  28. /**
  29. * SONARPLUGINS-2202
  30. */
  31. @Test
  32. public void test_simplest_with_props_on_root() {
  33. SonarScanner build = newScanner(
  34. new File("projects/multi-module/simplest/simplest-with-props-on-root"));
  35. orchestrator.executeBuild(build);
  36. assertThat(getComponent("simplest-with-props-on-root").getName()).isEqualTo(
  37. "Simplest multi-module project with all properties set on the root project");
  38. if (noMoreModules()) {
  39. // Verify that we have the folders
  40. assertThat(
  41. getComponent("simplest-with-props-on-root:module1/src").getName())
  42. .isEqualTo("module1/src");
  43. assertThat(
  44. getComponent("simplest-with-props-on-root:module2/src").getName())
  45. .isEqualTo("module2/src");
  46. } else {
  47. // Verify that we have the modules
  48. assertThat(getComponent("simplest-with-props-on-root:module1").getName())
  49. .isEqualTo("module1");
  50. assertThat(getComponent("simplest-with-props-on-root:module2").getName())
  51. .isEqualTo("module2");
  52. }
  53. // And verify that the working directories are all located in the root folder
  54. File workDir = new File(
  55. "projects/multi-module/simplest/simplest-with-props-on-root/.scannerwork");
  56. assertThat(workDir).exists();
  57. assertThat(new File(workDir, "simplest-with-props-on-root_module1"))
  58. .exists();
  59. assertThat(new File(workDir, "simplest-with-props-on-root_module2"))
  60. .exists();
  61. assertThat(new File(
  62. "projects/multi-module/simplest/simplest-with-props-on-root/module1/.scannerwork"))
  63. .doesNotExist();
  64. assertThat(new File(
  65. "projects/multi-module/simplest/simplest-with-props-on-root/module2/.scannerwork"))
  66. .doesNotExist();
  67. }
  68. /**
  69. * SONARPLUGINS-2202
  70. */
  71. @Test
  72. public void test_simplest_with_props_on_each_module() {
  73. SonarScanner build = newScanner(new File(
  74. "projects/multi-module/simplest/simplest-with-props-on-each-module"));
  75. orchestrator.executeBuild(build);
  76. assertThat(getComponent("simplest-with-props-each-module").getName())
  77. .isEqualTo(
  78. "Simplest multi-module project with properties set on each module");
  79. if (noMoreModules()) {
  80. assertThat(
  81. getComponent("simplest-with-props-each-module:module1/src").getName())
  82. .isEqualTo("module1/src");
  83. assertThat(
  84. getComponent("simplest-with-props-each-module:module2/src").getName())
  85. .isEqualTo("module2/src");
  86. } else {
  87. // Verify that we have the modules
  88. assertThat(
  89. getComponent("simplest-with-props-each-module:module1").getName())
  90. .isEqualTo("module1");
  91. assertThat(getComponent(
  92. "simplest-with-props-each-module:overridden-key-for-module2").getName())
  93. .isEqualTo("Module 2");
  94. }
  95. }
  96. /**
  97. * SONARPLUGINS-2202
  98. */
  99. @Test
  100. public void test_deep_path_for_modules() {
  101. SonarScanner build = newScanner(
  102. new File("projects/multi-module/customization/deep-path-for-modules"));
  103. orchestrator.executeBuild(build);
  104. assertThat(getComponent("deep-path-for-modules").getName())
  105. .isEqualTo("Project with deep path for modules");
  106. if (noMoreModules()) {
  107. assertThat(
  108. getComponent("deep-path-for-modules:modules/module1/src").getName())
  109. .isEqualTo("module1/src");
  110. assertThat(
  111. getComponent("deep-path-for-modules:modules/module2/src").getName())
  112. .isEqualTo("module2/src");
  113. } else {
  114. // Verify that we have the modules
  115. assertThat(getComponent("deep-path-for-modules:mod1").getName())
  116. .isEqualTo("Module 1");
  117. assertThat(getComponent("deep-path-for-modules:mod2").getName())
  118. .isEqualTo("Module 2");
  119. }
  120. }
  121. /**
  122. * SONARPLUGINS-2202
  123. */
  124. @Test
  125. public void test_module_path_with_space() {
  126. SonarScanner build = newScanner(
  127. new File("projects/multi-module/customization/module-path-with-space"));
  128. orchestrator.executeBuild(build);
  129. assertThat(getComponent("module-path-with-space").getName())
  130. .isEqualTo("Project with module path that contain spaces");
  131. if (noMoreModules()) {
  132. assertThat(
  133. getComponent("module-path-with-space:my module 1/src").getName())
  134. .isEqualTo("my module 1/src");
  135. assertThat(
  136. getComponent("module-path-with-space:my module 2/src").getName())
  137. .isEqualTo("my module 2/src");
  138. } else {
  139. // Verify that we have the modules
  140. assertThat(getComponent("module-path-with-space:module1").getName())
  141. .isEqualTo("Module 1");
  142. assertThat(getComponent("module-path-with-space:module2").getName())
  143. .isEqualTo("Module 2");
  144. }
  145. }
  146. /**
  147. * SONARPLUGINS-2202
  148. */
  149. @Test
  150. public void test_overwriting_parent_properties() {
  151. SonarScanner build = newScanner(new File(
  152. "projects/multi-module/customization/overwriting-parent-properties"));
  153. orchestrator.executeBuild(build);
  154. Component rootProject = getComponent("overwriting-parent-properties");
  155. assertThat(rootProject.getName())
  156. .isEqualTo("Project with modules that overwrite properties");
  157. assertThat(rootProject.getDescription())
  158. .isEqualTo("Description of root project");
  159. if (noMoreModules()) {
  160. assertThat(
  161. getComponent("overwriting-parent-properties:module1/src1").getName())
  162. .isEqualTo("module1/src1");
  163. assertThat(
  164. getComponent("overwriting-parent-properties:module2/src2").getName())
  165. .isEqualTo("module2/src2");
  166. } else {
  167. // Verify that we have the modules
  168. Component module1 = getComponent(
  169. "overwriting-parent-properties:module1-new-key");
  170. assertThat(module1.getName()).isEqualTo("Module 1");
  171. assertThat(module1.getDescription()).isEqualTo("Description of module 1");
  172. Component module2 = getComponent(
  173. "overwriting-parent-properties:module2-new-key");
  174. assertThat(module2.getName()).isEqualTo("Module 2");
  175. assertThat(module2.getDescription()).isEqualTo("Description of module 2");
  176. }
  177. }
  178. /**
  179. * SONARPLUGINS-2202
  180. */
  181. @Test
  182. public void test_using_config_file_property() {
  183. SonarScanner build = newScanner(
  184. new File("projects/multi-module/advanced/using-config-file-prop"));
  185. orchestrator.executeBuild(build);
  186. assertThat(getComponent("using-config-file-prop").getName())
  187. .isEqualTo("Advanced use case - mostly used by the Ant task");
  188. if (noMoreModules()) {
  189. assertThat(getComponent("using-config-file-prop:module1/src").getName())
  190. .isEqualTo("module1/src");
  191. assertThat(getComponent("using-config-file-prop:module2/src").getName())
  192. .isEqualTo("module2/src");
  193. } else {
  194. // Verify that we have the modules
  195. assertThat(getComponent("using-config-file-prop:module1").getName())
  196. .isEqualTo("Module 1");
  197. assertThat(getComponent("using-config-file-prop:module2").getName())
  198. .isEqualTo("Module 2");
  199. }
  200. }
  201. private boolean noMoreModules() {
  202. return orchestrator.getServer().version().isGreaterThanOrEquals(7, 6);
  203. }
  204. /**
  205. * SONARPLUGINS-2202
  206. */
  207. @Test
  208. public void should_fail_if_unexisting_base_dir() {
  209. SonarScanner build = newScanner(
  210. new File("projects/multi-module/failures/unexisting-base-dir"));
  211. BuildResult result = orchestrator.executeBuildQuietly(build);
  212. // expect build failure
  213. assertThat(result.getStatus()).isNotEqualTo(0);
  214. // with the following message
  215. assertThat(result.getLogs())
  216. .contains("The base directory of the module 'module3' does not exist");
  217. }
  218. /**
  219. * SONARPLUGINS-2202
  220. */
  221. @Test
  222. public void should_fail_if_unexisting_config_file() {
  223. SonarScanner build = newScanner(
  224. new File("projects/multi-module/failures/unexisting-config-file"));
  225. BuildResult result = orchestrator.executeBuildQuietly(build);
  226. // expect build failure
  227. assertThat(result.getStatus()).isNotEqualTo(0);
  228. // with the following message
  229. assertThat(result.getLogs())
  230. .contains("The properties file of the module 'module1' does not exist");
  231. }
  232. }