3 * Copyright (C) 2009-2022 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.filemove;
22 import java.util.HashSet;
24 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
25 import org.sonar.ce.task.projectanalysis.component.Component;
27 import static com.google.common.base.Preconditions.checkArgument;
28 import static com.google.common.base.Preconditions.checkNotNull;
29 import static com.google.common.base.Preconditions.checkState;
31 public class AddedFileRepositoryImpl implements MutableAddedFileRepository {
32 private final Set<Component> addedComponents = new HashSet<>();
33 private final AnalysisMetadataHolder analysisMetadataHolder;
35 public AddedFileRepositoryImpl(AnalysisMetadataHolder analysisMetadataHolder) {
36 this.analysisMetadataHolder = analysisMetadataHolder;
40 public boolean isAdded(Component component) {
41 checkComponent(component);
42 if (analysisMetadataHolder.isFirstAnalysis()) {
45 return addedComponents.contains(component);
49 public void register(Component component) {
50 checkComponent(component);
51 checkArgument(component.getType() == Component.Type.FILE, "component must be a file");
52 checkState(!analysisMetadataHolder.isFirstAnalysis(), "No file can be registered on first analysis");
54 addedComponents.add(component);
57 private static void checkComponent(Component component) {
58 checkNotNull(component, "component can't be null");