Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ExecuteVisitorsStep.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2020 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.ce.task.projectanalysis.step;
  21. import java.util.List;
  22. import java.util.Map;
  23. import org.sonar.api.utils.log.Logger;
  24. import org.sonar.api.utils.log.Loggers;
  25. import org.sonar.ce.task.projectanalysis.component.ComponentVisitor;
  26. import org.sonar.ce.task.projectanalysis.component.TreeRootHolder;
  27. import org.sonar.ce.task.projectanalysis.component.VisitorsCrawler;
  28. import org.sonar.ce.task.step.ComputationStep;
  29. public class ExecuteVisitorsStep implements ComputationStep {
  30. private static final Logger LOGGER = Loggers.get(ExecuteVisitorsStep.class);
  31. private final TreeRootHolder treeRootHolder;
  32. private final List<ComponentVisitor> visitors;
  33. public ExecuteVisitorsStep(TreeRootHolder treeRootHolder, List<ComponentVisitor> visitors) {
  34. this.treeRootHolder = treeRootHolder;
  35. this.visitors = visitors;
  36. }
  37. @Override
  38. public String getDescription() {
  39. return "Execute component visitors";
  40. }
  41. @Override
  42. public void execute(ComputationStep.Context context) {
  43. VisitorsCrawler visitorsCrawler = new VisitorsCrawler(visitors, LOGGER.isDebugEnabled());
  44. visitorsCrawler.visit(treeRootHolder.getRoot());
  45. logVisitorExecutionDurations(visitors, visitorsCrawler);
  46. }
  47. private static void logVisitorExecutionDurations(List<ComponentVisitor> visitors, VisitorsCrawler visitorsCrawler) {
  48. if (LOGGER.isDebugEnabled()) {
  49. LOGGER.debug(" Execution time for each component visitor:");
  50. Map<ComponentVisitor, Long> cumulativeDurations = visitorsCrawler.getCumulativeDurations();
  51. for (ComponentVisitor visitor : visitors) {
  52. LOGGER.debug(" - {} | time={}ms", visitor.getClass().getSimpleName(), cumulativeDurations.get(visitor));
  53. }
  54. }
  55. }
  56. }