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.

ProjectSensorsExecutor.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 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.sensor;
  21. import java.util.List;
  22. import java.util.stream.Collectors;
  23. import org.sonar.api.utils.log.Logger;
  24. import org.sonar.api.utils.log.Loggers;
  25. import org.sonar.core.util.logs.Profiler;
  26. import org.sonar.scanner.bootstrap.ScannerPluginRepository;
  27. public class ProjectSensorsExecutor {
  28. private static final Logger LOG = Loggers.get(ProjectSensorsExecutor.class);
  29. private static final Profiler profiler = Profiler.create(LOG);
  30. private final ProjectSensorExtensionDictionary selector;
  31. private final ScannerPluginRepository pluginRepo;
  32. public ProjectSensorsExecutor(ProjectSensorExtensionDictionary selector, ScannerPluginRepository pluginRepo) {
  33. this.selector = selector;
  34. this.pluginRepo = pluginRepo;
  35. }
  36. public void execute() {
  37. List<ProjectSensorWrapper> sensors = selector.selectSensors();
  38. LOG.debug("Sensors : {}", sensors.stream()
  39. .map(Object::toString)
  40. .collect(Collectors.joining(" -> ")));
  41. for (ProjectSensorWrapper sensor : sensors) {
  42. String sensorName = getSensorName(sensor);
  43. profiler.startInfo("Sensor " + sensorName);
  44. sensor.analyse();
  45. profiler.stopInfo();
  46. }
  47. }
  48. private String getSensorName(ProjectSensorWrapper sensor) {
  49. ClassLoader cl = getSensorClassLoader(sensor);
  50. String pluginKey = pluginRepo.getPluginKey(cl);
  51. if (pluginKey != null) {
  52. return sensor.toString() + " [" + pluginKey + "]";
  53. }
  54. return sensor.toString();
  55. }
  56. private static ClassLoader getSensorClassLoader(ProjectSensorWrapper sensor) {
  57. return sensor.wrappedSensor().getClass().getClassLoader();
  58. }
  59. }