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.1KB

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