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.duplication;
22 import java.util.Optional;
23 import javax.annotation.CheckForNull;
24 import org.picocontainer.Startable;
25 import org.sonar.api.utils.log.Logger;
26 import org.sonar.api.utils.log.Loggers;
27 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
28 import org.sonar.server.computation.task.projectanalysis.analysis.Branch;
30 import static com.google.common.base.Preconditions.checkState;
32 public class CrossProjectDuplicationStatusHolderImpl implements CrossProjectDuplicationStatusHolder, Startable {
34 private static final Logger LOGGER = Loggers.get(CrossProjectDuplicationStatusHolderImpl.class);
37 private Boolean enabled;
38 private final AnalysisMetadataHolder analysisMetadataHolder;
40 public CrossProjectDuplicationStatusHolderImpl(AnalysisMetadataHolder analysisMetadataHolder) {
41 this.analysisMetadataHolder = analysisMetadataHolder;
45 public boolean isEnabled() {
46 checkState(enabled != null, "Flag hasn't been initialized, the start() should have been called before.");
52 boolean enabledInReport = analysisMetadataHolder.isCrossProjectDuplicationEnabled();
53 Optional<Branch> branch = analysisMetadataHolder.getBranch();
54 boolean supportedByBranch = !branch.isPresent() || branch.get().supportsCrossProjectCpd();
55 if (enabledInReport && supportedByBranch) {
56 LOGGER.debug("Cross project duplication is enabled");
59 if (!enabledInReport) {
60 LOGGER.debug("Cross project duplication is disabled because it's disabled in the analysis report");
62 LOGGER.debug("Cross project duplication is disabled because of a branch is used");