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.List;
24 import org.sonar.ce.task.projectanalysis.component.Component;
25 import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
26 import org.sonar.ce.task.projectanalysis.component.TypeAwareVisitorAdapter;
27 import org.sonar.ce.task.projectanalysis.util.cache.DiskCache;
28 import org.sonar.core.issue.DefaultIssue;
30 import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
33 * Close issues on removed components
35 public class CloseIssuesOnRemovedComponentsVisitor extends TypeAwareVisitorAdapter {
37 private final ComponentIssuesLoader issuesLoader;
38 private final ComponentsWithUnprocessedIssues componentsWithUnprocessedIssues;
39 private final IssueCache issueCache;
40 private final IssueLifecycle issueLifecycle;
42 public CloseIssuesOnRemovedComponentsVisitor(ComponentIssuesLoader issuesLoader, ComponentsWithUnprocessedIssues componentsWithUnprocessedIssues, IssueCache issueCache,
43 IssueLifecycle issueLifecycle) {
44 super(CrawlerDepthLimit.PROJECT, POST_ORDER);
45 this.issuesLoader = issuesLoader;
46 this.componentsWithUnprocessedIssues = componentsWithUnprocessedIssues;
47 this.issueCache = issueCache;
48 this.issueLifecycle = issueLifecycle;
52 public void visitProject(Component project) {
53 closeIssuesForDeletedComponentUuids(componentsWithUnprocessedIssues.getUuids());
56 private void closeIssuesForDeletedComponentUuids(Set<String> deletedComponentUuids) {
57 try (DiskCache<DefaultIssue>.DiskAppender cacheAppender = issueCache.newAppender()) {
58 for (String deletedComponentUuid : deletedComponentUuids) {
59 List<DefaultIssue> issues = issuesLoader.loadOpenIssues(deletedComponentUuid);
60 for (DefaultIssue issue : issues) {
61 issue.setBeingClosed(true);
62 // TODO should be renamed
63 issue.setOnDisabledRule(false);
64 issueLifecycle.doAutomaticTransition(issue);
65 cacheAppender.append(issue);