3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
20 package org.sonar.server.computation.task.projectanalysis.measure;
22 import org.sonar.api.ce.measure.MeasureComputer;
23 import org.sonar.api.utils.log.Logger;
24 import org.sonar.api.utils.log.Loggers;
25 import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
26 import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
27 import org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter;
28 import org.sonar.server.computation.task.projectanalysis.issue.ComponentIssuesRepository;
29 import org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerContextImpl;
30 import org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper;
31 import org.sonar.server.computation.task.projectanalysis.metric.MetricRepository;
33 import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.FILE;
34 import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.SUBVIEW;
35 import static org.sonar.server.computation.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
37 public class MeasureComputersVisitor extends TypeAwareVisitorAdapter {
39 private static final Logger LOGGER = Loggers.get(MeasureComputersVisitor.class);
41 private final MetricRepository metricRepository;
42 private final MeasureRepository measureRepository;
43 private final SettingsRepository settings;
45 private final MeasureComputersHolder measureComputersHolder;
46 private final ComponentIssuesRepository componentIssuesRepository;
48 public MeasureComputersVisitor(MetricRepository metricRepository, MeasureRepository measureRepository, SettingsRepository settings,
49 MeasureComputersHolder measureComputersHolder, ComponentIssuesRepository componentIssuesRepository) {
50 super(CrawlerDepthLimit.reportMaxDepth(FILE).withViewsMaxDepth(SUBVIEW), POST_ORDER);
51 this.metricRepository = metricRepository;
52 this.measureRepository = measureRepository;
53 this.settings = settings;
54 this.measureComputersHolder = measureComputersHolder;
55 this.componentIssuesRepository = componentIssuesRepository;
59 public void visitAny(org.sonar.server.computation.task.projectanalysis.component.Component component) {
60 MeasureComputerContextImpl context = new MeasureComputerContextImpl(component, settings, measureRepository, metricRepository, componentIssuesRepository);
61 for (MeasureComputerWrapper measureComputerWrapper : measureComputersHolder.getMeasureComputers()) {
62 context.setDefinition(measureComputerWrapper.getDefinition());
63 MeasureComputer measureComputer = measureComputerWrapper.getComputer();
64 LOGGER.trace("Measure computer '{}' is computing component {}", measureComputer, component);
65 measureComputer.compute(context);