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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * SonarSource :: IT :: SonarQube Scanner
  3. * Copyright (C) 2009-2018 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.fest.assertions.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. // Verify that we have the modules
  42. assertThat(getComponent("simplest-with-props-on-root:module1").getName()).isEqualTo("module1");
  43. assertThat(getComponent("simplest-with-props-on-root:module2").getName()).isEqualTo("module2");
  44. // And verify that the working directories are all located in the root folder
  45. File workDir = new File("projects/multi-module/simplest/simplest-with-props-on-root/.scannerwork");
  46. assertThat(workDir).exists();
  47. assertThat(new File(workDir, "simplest-with-props-on-root_module1")).exists();
  48. assertThat(new File(workDir, "simplest-with-props-on-root_module2")).exists();
  49. assertThat(new File("projects/multi-module/simplest/simplest-with-props-on-root/module1/.scannerwork")).doesNotExist();
  50. assertThat(new File("projects/multi-module/simplest/simplest-with-props-on-root/module2/.scannerwork")).doesNotExist();
  51. }
  52. /**
  53. * SONARPLUGINS-2202
  54. */
  55. @Test
  56. public void test_simplest_with_props_on_each_module() {
  57. SonarScanner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));
  58. orchestrator.executeBuild(build);
  59. assertThat(getComponent("simplest-with-props-each-module").getName()).isEqualTo("Simplest multi-module project with properties set on each module");
  60. // Verify that we have the modules
  61. assertThat(getComponent("simplest-with-props-each-module:module1").getName()).isEqualTo("module1");
  62. assertThat(getComponent("simplest-with-props-each-module:overridden-key-for-module2").getName()).isEqualTo("Module 2");
  63. }
  64. /**
  65. * SONARPLUGINS-2202
  66. */
  67. @Test
  68. public void test_deep_path_for_modules() {
  69. SonarScanner build = newScanner(new File("projects/multi-module/customization/deep-path-for-modules"));
  70. orchestrator.executeBuild(build);
  71. assertThat(getComponent("deep-path-for-modules").getName()).isEqualTo("Project with deep path for modules");
  72. // Verify that we have the modules
  73. assertThat(getComponent("deep-path-for-modules:mod1").getName()).isEqualTo("Module 1");
  74. assertThat(getComponent("deep-path-for-modules:mod2").getName()).isEqualTo("Module 2");
  75. }
  76. /**
  77. * SONARPLUGINS-2202
  78. */
  79. @Test
  80. public void test_module_path_with_space() {
  81. SonarScanner build = newScanner(new File("projects/multi-module/customization/module-path-with-space"));
  82. orchestrator.executeBuild(build);
  83. assertThat(getComponent("module-path-with-space").getName()).isEqualTo("Project with module path that contain spaces");
  84. // Verify that we have the modules
  85. assertThat(getComponent("module-path-with-space:module1").getName()).isEqualTo("Module 1");
  86. assertThat(getComponent("module-path-with-space:module2").getName()).isEqualTo("Module 2");
  87. }
  88. /**
  89. * SONARPLUGINS-2202
  90. */
  91. @Test
  92. public void test_overwriting_parent_properties() {
  93. SonarScanner build = newScanner(new File("projects/multi-module/customization/overwriting-parent-properties"));
  94. orchestrator.executeBuild(build);
  95. Component rootProject = getComponent("overwriting-parent-properties");
  96. assertThat(rootProject.getName()).isEqualTo("Project with modules that overwrite properties");
  97. assertThat(rootProject.getDescription()).isEqualTo("Description of root project");
  98. // Verify that we have the modules
  99. Component module1 = getComponent("overwriting-parent-properties:module1-new-key");
  100. assertThat(module1.getName()).isEqualTo("Module 1");
  101. assertThat(module1.getDescription()).isEqualTo("Description of module 1");
  102. Component module2 = getComponent("overwriting-parent-properties:module2-new-key");
  103. assertThat(module2.getName()).isEqualTo("Module 2");
  104. assertThat(module2.getDescription()).isEqualTo("Description of module 2");
  105. }
  106. /**
  107. * SONARPLUGINS-2202
  108. */
  109. @Test
  110. public void test_using_config_file_property() {
  111. SonarScanner build = newScanner(new File("projects/multi-module/advanced/using-config-file-prop"));
  112. orchestrator.executeBuild(build);
  113. assertThat(getComponent("using-config-file-prop").getName()).isEqualTo("Advanced use case - mostly used by the Ant task");
  114. // Verify that we have the modules
  115. assertThat(getComponent("using-config-file-prop:module1").getName()).isEqualTo("Module 1");
  116. assertThat(getComponent("using-config-file-prop:module2").getName()).isEqualTo("Module 2");
  117. }
  118. /**
  119. * SONARPLUGINS-2202
  120. */
  121. @Test
  122. public void should_fail_if_unexisting_base_dir() {
  123. SonarScanner build = newScanner(new File("projects/multi-module/failures/unexisting-base-dir"));
  124. BuildResult result = orchestrator.executeBuildQuietly(build);
  125. // expect build failure
  126. assertThat(result.getStatus()).isNotEqualTo(0);
  127. // with the following message
  128. assertThat(result.getLogs()).contains("The base directory of the module 'module3' does not exist");
  129. }
  130. /**
  131. * SONARPLUGINS-2202
  132. */
  133. @Test
  134. public void should_fail_if_unexisting_config_file() {
  135. SonarScanner build = newScanner(new File("projects/multi-module/failures/unexisting-config-file"));
  136. BuildResult result = orchestrator.executeBuildQuietly(build);
  137. // expect build failure
  138. assertThat(result.getStatus()).isNotEqualTo(0);
  139. // with the following message
  140. assertThat(result.getLogs()).contains("The properties file of the module 'module1' does not exist");
  141. }
  142. }