3 * Copyright (C) 2009-2020 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.ce.task.projectanalysis.issue;
22 import java.util.Collections;
23 import java.util.List;
24 import javax.annotation.Nullable;
25 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
26 import org.sonar.ce.task.projectanalysis.component.Component;
27 import org.sonar.ce.task.projectanalysis.component.ReportModulesPath;
28 import org.sonar.ce.task.projectanalysis.filemove.MovedFilesRepository;
29 import org.sonar.ce.task.projectanalysis.filemove.MovedFilesRepository.OriginalFile;
30 import org.sonar.core.issue.DefaultIssue;
31 import org.sonar.core.issue.tracking.Input;
32 import org.sonar.db.DbClient;
33 import org.sonar.server.issue.IssueFieldsSetter;
36 * Factory of {@link Input} of base data for issue tracking. Data are lazy-loaded.
38 public class TrackerBaseInputFactory extends BaseInputFactory {
40 private final ComponentIssuesLoader issuesLoader;
41 private final DbClient dbClient;
42 private final MovedFilesRepository movedFilesRepository;
43 private final ReportModulesPath reportModulesPath;
44 private final AnalysisMetadataHolder analysisMetadataHolder;
45 private final IssueFieldsSetter issueUpdater;
46 private final ComponentsWithUnprocessedIssues componentsWithUnprocessedIssues;
48 public TrackerBaseInputFactory(ComponentIssuesLoader issuesLoader, DbClient dbClient, MovedFilesRepository movedFilesRepository, ReportModulesPath reportModulesPath,
49 AnalysisMetadataHolder analysisMetadataHolder, IssueFieldsSetter issueUpdater, ComponentsWithUnprocessedIssues componentsWithUnprocessedIssues) {
50 this.issuesLoader = issuesLoader;
51 this.dbClient = dbClient;
52 this.movedFilesRepository = movedFilesRepository;
53 this.reportModulesPath = reportModulesPath;
54 this.analysisMetadataHolder = analysisMetadataHolder;
55 this.issueUpdater = issueUpdater;
56 this.componentsWithUnprocessedIssues = componentsWithUnprocessedIssues;
59 public Input<DefaultIssue> create(Component component) {
60 if (component.getType() == Component.Type.PROJECT) {
61 return new ProjectTrackerBaseLazyInput(analysisMetadataHolder, componentsWithUnprocessedIssues, dbClient, issueUpdater, issuesLoader, reportModulesPath, component);
62 } else if (component.getType() == Component.Type.DIRECTORY) {
63 // Folders have no issues
64 return new EmptyTrackerBaseLazyInput(dbClient, component);
66 return new FileTrackerBaseLazyInput(dbClient, component, movedFilesRepository.getOriginalFile(component).orNull());
69 private class FileTrackerBaseLazyInput extends BaseLazyInput {
71 private FileTrackerBaseLazyInput(DbClient dbClient, Component component, @Nullable OriginalFile originalFile) {
72 super(dbClient, component, originalFile);
76 protected List<DefaultIssue> loadIssues() {
77 return issuesLoader.loadOpenIssues(effectiveUuid);
82 private static class EmptyTrackerBaseLazyInput extends BaseLazyInput {
84 private EmptyTrackerBaseLazyInput(DbClient dbClient, Component component) {
85 super(dbClient, component, null);
89 protected List<DefaultIssue> loadIssues() {
90 return Collections.emptyList();