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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * SonarSource :: IT :: SonarQube Scanner
  3. * Copyright (C) 2009 SonarSource
  4. * sonarqube@googlegroups.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
  17. * License along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
  19. */
  20. package com.sonar.runner.it;
  21. import com.sonar.orchestrator.build.BuildResult;
  22. import com.sonar.orchestrator.build.SonarRunner;
  23. import java.io.File;
  24. import org.junit.After;
  25. import org.junit.Test;
  26. import org.sonar.wsclient.services.Resource;
  27. import org.sonar.wsclient.services.ResourceQuery;
  28. import static org.fest.assertions.Assertions.assertThat;
  29. public class MultimoduleTest extends ScannerTestCase {
  30. @After
  31. public void cleanup() {
  32. orchestrator.resetData();
  33. }
  34. /**
  35. * SONARPLUGINS-2202
  36. */
  37. @Test
  38. public void test_simplest_with_props_on_root() {
  39. SonarRunner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-root"));
  40. orchestrator.executeBuild(build);
  41. Resource rootProject = findResource("simplest-with-props-on-root");
  42. assertThat(rootProject.getName()).isEqualTo("Simplest multi-module project with all properties set on the root project");
  43. assertThat(rootProject.getVersion()).isEqualTo("1.2.3");
  44. // Verify that we have the modules
  45. Resource module1 = findResource("simplest-with-props-on-root:module1");
  46. assertThat(module1.getName()).isEqualTo("module1");
  47. assertThat(module1.getVersion()).isEqualTo("1.2.3");
  48. Resource module2 = findResource("simplest-with-props-on-root:module2");
  49. assertThat(module2.getName()).isEqualTo("module2");
  50. assertThat(module2.getVersion()).isEqualTo("1.2.3");
  51. // And verify that the working directories are all located in the root folder
  52. File workDir = new File("projects/multi-module/simplest/simplest-with-props-on-root/.sonar");
  53. assertThat(workDir).exists();
  54. assertThat(new File(workDir, "simplest-with-props-on-root_module1")).exists();
  55. assertThat(new File(workDir, "simplest-with-props-on-root_module2")).exists();
  56. assertThat(new File("projects/multi-module/simplest/simplest-with-props-on-root/module1/.sonar")).doesNotExist();
  57. assertThat(new File("projects/multi-module/simplest/simplest-with-props-on-root/module2/.sonar")).doesNotExist();
  58. }
  59. /**
  60. * SONARPLUGINS-2421
  61. */
  62. @Test
  63. public void test_multi_language_with_same_projectdir() {
  64. SonarRunner build = newScanner(new File("projects/multi-module/multi-language"));
  65. orchestrator.executeBuild(build);
  66. Resource rootProject = findResource("multi-language");
  67. assertThat(rootProject.getName()).isEqualTo("Simplest multi-language project");
  68. assertThat(rootProject.getVersion()).isEqualTo("1.2.3");
  69. // Verify that we have the modules
  70. Resource module1 = findResource("multi-language:java-module");
  71. assertThat(module1.getName()).isEqualTo("java-module");
  72. assertThat(module1.getVersion()).isEqualTo("1.2.3");
  73. Resource module2 = findResource("multi-language:js-module");
  74. assertThat(module2.getName()).isEqualTo("js-module");
  75. assertThat(module2.getVersion()).isEqualTo("1.2.3");
  76. }
  77. /**
  78. * SONARPLUGINS-2202
  79. */
  80. @Test
  81. public void test_simplest_with_props_on_each_module() {
  82. SonarRunner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));
  83. orchestrator.executeBuild(build);
  84. Resource rootProject = findResource("simplest-with-props-each-module");
  85. assertThat(rootProject.getName()).isEqualTo("Simplest multi-module project with properties set on each module");
  86. assertThat(rootProject.getVersion()).isEqualTo("1.2.3");
  87. // Verify that we have the modules
  88. Resource module1 = findResource("simplest-with-props-each-module:module1");
  89. assertThat(module1.getName()).isEqualTo("module1");
  90. assertThat(module1.getVersion()).isEqualTo("1.2.3");
  91. Resource module2 = findResource("simplest-with-props-each-module:overridden-key-for-module2");
  92. assertThat(module2.getName()).isEqualTo("Module 2");
  93. assertThat(module2.getVersion()).isEqualTo("1.2.3");
  94. }
  95. /**
  96. * SONARPLUGINS-2295
  97. */
  98. @Test
  99. public void test_warning_when_source_folder_on_root_module() {
  100. SonarRunner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));
  101. assertThat(orchestrator.executeBuild(build).getLogs()).contains("/!\\ A multi-module project can't have source folders");
  102. }
  103. /**
  104. * SONARPLUGINS-2202
  105. */
  106. @Test
  107. public void test_deep_path_for_modules() {
  108. SonarRunner build = newScanner(new File("projects/multi-module/customization/deep-path-for-modules"));
  109. orchestrator.executeBuild(build);
  110. Resource rootProject = findResource("deep-path-for-modules");
  111. assertThat(rootProject.getName()).isEqualTo("Project with deep path for modules");
  112. assertThat(rootProject.getVersion()).isEqualTo("1.2.3");
  113. // Verify that we have the modules
  114. Resource module1 = findResource("deep-path-for-modules:mod1");
  115. assertThat(module1.getName()).isEqualTo("Module 1");
  116. assertThat(module1.getVersion()).isEqualTo("1.2.3");
  117. Resource module2 = findResource("deep-path-for-modules:mod2");
  118. assertThat(module2.getName()).isEqualTo("Module 2");
  119. assertThat(module2.getVersion()).isEqualTo("1.2.3");
  120. }
  121. /**
  122. * SONARPLUGINS-2202
  123. */
  124. @Test
  125. public void test_module_path_with_space() {
  126. SonarRunner build = newScanner(new File("projects/multi-module/customization/module-path-with-space"));
  127. orchestrator.executeBuild(build);
  128. Resource rootProject = findResource("module-path-with-space");
  129. assertThat(rootProject.getName()).isEqualTo("Project with module path that contain spaces");
  130. assertThat(rootProject.getVersion()).isEqualTo("1.2.3");
  131. // Verify that we have the modules
  132. Resource module1 = findResource("module-path-with-space:module1");
  133. assertThat(module1.getName()).isEqualTo("Module 1");
  134. assertThat(module1.getVersion()).isEqualTo("1.2.3");
  135. Resource module2 = findResource("module-path-with-space:module2");
  136. assertThat(module2.getName()).isEqualTo("Module 2");
  137. assertThat(module2.getVersion()).isEqualTo("1.2.3");
  138. }
  139. /**
  140. * SONARPLUGINS-2202
  141. */
  142. @Test
  143. public void test_overwriting_parent_properties() {
  144. SonarRunner build = newScanner(new File("projects/multi-module/customization/overwriting-parent-properties"));
  145. orchestrator.executeBuild(build);
  146. Resource rootProject = findResource("overwriting-parent-properties");
  147. assertThat(rootProject.getName()).isEqualTo("Project with modules that overwrite properties");
  148. assertThat(rootProject.getVersion()).isEqualTo("1.2.3");
  149. assertThat(rootProject.getDescription()).isEqualTo("Description of root project");
  150. // Verify that we have the modules
  151. Resource module1 = findResource("overwriting-parent-properties:module1-new-key");
  152. assertThat(module1.getName()).isEqualTo("Module 1");
  153. assertThat(module1.getVersion()).isEqualTo("1.2.3");
  154. assertThat(module1.getDescription()).isEqualTo("Description of module 1");
  155. Resource module2 = findResource("overwriting-parent-properties:module2-new-key");
  156. assertThat(module2.getName()).isEqualTo("Module 2");
  157. assertThat(module2.getVersion()).isEqualTo("1.2.3");
  158. assertThat(module2.getDescription()).isEqualTo("Description of module 2");
  159. }
  160. /**
  161. * SONARPLUGINS-2202
  162. */
  163. @Test
  164. public void test_using_config_file_property() {
  165. SonarRunner build = newScanner(new File("projects/multi-module/advanced/using-config-file-prop"));
  166. orchestrator.executeBuild(build);
  167. Resource rootProject = findResource("using-config-file-prop");
  168. assertThat(rootProject.getName()).isEqualTo("Advanced use case - mostly used by the Ant task");
  169. assertThat(rootProject.getVersion()).isEqualTo("1.2.3");
  170. // Verify that we have the modules
  171. Resource module1 = findResource("using-config-file-prop:module1");
  172. assertThat(module1.getName()).isEqualTo("Module 1");
  173. assertThat(module1.getVersion()).isEqualTo("1.2.3");
  174. Resource module2 = findResource("using-config-file-prop:module2");
  175. assertThat(module2.getName()).isEqualTo("Module 2");
  176. assertThat(module2.getVersion()).isEqualTo("1.2.3");
  177. }
  178. /**
  179. * SONARPLUGINS-2202
  180. */
  181. @Test
  182. public void should_fail_if_unexisting_base_dir() {
  183. SonarRunner build = newScanner(new File("projects/multi-module/failures/unexisting-base-dir"));
  184. BuildResult result = orchestrator.executeBuildQuietly(build);
  185. // expect build failure
  186. assertThat(result.getStatus()).isNotEqualTo(0);
  187. // with the following message
  188. assertThat(result.getLogs()).contains("The base directory of the module 'module3' does not exist");
  189. }
  190. /**
  191. * SONARPLUGINS-2202
  192. */
  193. @Test
  194. public void should_fail_if_unexisting_config_file() {
  195. SonarRunner build = newScanner(new File("projects/multi-module/failures/unexisting-config-file"));
  196. BuildResult result = orchestrator.executeBuildQuietly(build);
  197. // expect build failure
  198. assertThat(result.getStatus()).isNotEqualTo(0);
  199. // with the following message
  200. assertThat(result.getLogs()).contains("The properties file of the module 'module1' does not exist");
  201. }
  202. private Resource findResource(String resourceKey) {
  203. return orchestrator.getServer().getWsClient().find(new ResourceQuery(resourceKey));
  204. }
  205. }