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.

SpringModuleScanContainer.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * SonarQube
  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 org.sonar.scanner.scan;
  21. import javax.annotation.Priority;
  22. import org.sonar.api.batch.fs.internal.DefaultInputModule;
  23. import org.sonar.api.scan.filesystem.FileExclusions;
  24. import org.sonar.scanner.bootstrap.ExtensionInstaller;
  25. import org.sonar.scanner.bootstrap.SpringComponentContainer;
  26. import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem;
  27. import org.sonar.scanner.scan.filesystem.ModuleInputComponentStore;
  28. import org.sonar.scanner.sensor.ModuleSensorContext;
  29. import org.sonar.scanner.sensor.ModuleSensorExtensionDictionary;
  30. import org.sonar.scanner.sensor.ModuleSensorOptimizer;
  31. import org.sonar.scanner.sensor.ModuleSensorsExecutor;
  32. import static org.sonar.api.batch.InstantiationStrategy.PER_PROJECT;
  33. import static org.sonar.scanner.bootstrap.ExtensionUtils.isDeprecatedScannerSide;
  34. import static org.sonar.scanner.bootstrap.ExtensionUtils.isInstantiationStrategy;
  35. @Priority(1)
  36. public class SpringModuleScanContainer extends SpringComponentContainer {
  37. private final DefaultInputModule module;
  38. public SpringModuleScanContainer(SpringComponentContainer parent, DefaultInputModule module) {
  39. super(parent);
  40. this.module = module;
  41. }
  42. @Override
  43. protected void doBeforeStart() {
  44. addCoreComponents();
  45. addExtensions();
  46. }
  47. private void addCoreComponents() {
  48. add(
  49. module.definition(),
  50. module,
  51. MutableModuleSettings.class,
  52. new ModuleConfigurationProvider(),
  53. ModuleSensorsExecutor.class,
  54. // file system
  55. ModuleInputComponentStore.class,
  56. FileExclusions.class,
  57. DefaultModuleFileSystem.class,
  58. ModuleSensorOptimizer.class,
  59. ModuleSensorContext.class,
  60. ModuleSensorExtensionDictionary.class
  61. );
  62. }
  63. private void addExtensions() {
  64. ExtensionInstaller pluginInstaller = parent.getComponentByType(ExtensionInstaller.class);
  65. pluginInstaller.install(this, e -> isDeprecatedScannerSide(e) && isInstantiationStrategy(e, PER_PROJECT));
  66. }
  67. @Override
  68. protected void doAfterStart() {
  69. getComponentByType(ModuleSensorsExecutor.class).execute();
  70. }
  71. }