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

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