3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact 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.analysis;
22 import com.google.common.collect.ImmutableMap;
24 import javax.annotation.CheckForNull;
25 import javax.annotation.Nullable;
26 import org.sonar.server.computation.qualityprofile.QualityProfile;
27 import org.sonar.server.computation.snapshot.Snapshot;
28 import org.sonar.server.computation.util.InitializedProperty;
30 import static com.google.common.base.Preconditions.checkState;
32 public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder {
34 private InitializedProperty<Long> analysisDate = new InitializedProperty<>();
36 private InitializedProperty<Snapshot> baseProjectSnapshot = new InitializedProperty<>();
38 private InitializedProperty<Boolean> crossProjectDuplicationEnabled = new InitializedProperty<>();
40 private InitializedProperty<String> branch = new InitializedProperty<>();
42 private InitializedProperty<Integer> rootComponentRef = new InitializedProperty<>();
44 private InitializedProperty<Map<String, QualityProfile>> qProfilesPerLanguage = new InitializedProperty<>();
47 public MutableAnalysisMetadataHolder setAnalysisDate(long date) {
48 checkState(!analysisDate.isInitialized(), "Analysis date has already been set");
49 this.analysisDate.setProperty(date);
54 public long getAnalysisDate() {
55 checkState(analysisDate.isInitialized(), "Analysis date has not been set");
56 return this.analysisDate.getProperty();
60 public boolean isFirstAnalysis() {
61 return getBaseProjectSnapshot() == null;
65 public MutableAnalysisMetadataHolder setBaseProjectSnapshot(@Nullable Snapshot baseProjectSnapshot) {
66 checkState(!this.baseProjectSnapshot.isInitialized(), "Base project snapshot has already been set");
67 this.baseProjectSnapshot.setProperty(baseProjectSnapshot);
73 public Snapshot getBaseProjectSnapshot() {
74 checkState(baseProjectSnapshot.isInitialized(), "Base project snapshot has not been set");
75 return baseProjectSnapshot.getProperty();
79 public MutableAnalysisMetadataHolder setCrossProjectDuplicationEnabled(boolean isCrossProjectDuplicationEnabled) {
80 checkState(!this.crossProjectDuplicationEnabled.isInitialized(), "Cross project duplication flag has already been set");
81 this.crossProjectDuplicationEnabled.setProperty(isCrossProjectDuplicationEnabled);
86 public boolean isCrossProjectDuplicationEnabled() {
87 checkState(crossProjectDuplicationEnabled.isInitialized(), "Cross project duplication flag has not been set");
88 return crossProjectDuplicationEnabled.getProperty();
92 public MutableAnalysisMetadataHolder setBranch(@Nullable String branch) {
93 checkState(!this.branch.isInitialized(), "Branch has already been set");
94 this.branch.setProperty(branch);
99 public String getBranch() {
100 checkState(branch.isInitialized(), "Branch has not been set");
101 return branch.getProperty();
105 public MutableAnalysisMetadataHolder setRootComponentRef(int rootComponentRef) {
106 checkState(!this.rootComponentRef.isInitialized(), "Root component ref has already been set");
107 this.rootComponentRef.setProperty(rootComponentRef);
112 public int getRootComponentRef() {
113 checkState(rootComponentRef.isInitialized(), "Root component ref has not been set");
114 return rootComponentRef.getProperty();
118 public MutableAnalysisMetadataHolder setQProfilesByLanguage(Map<String, QualityProfile> qprofilesByLanguage) {
119 checkState(!this.qProfilesPerLanguage.isInitialized(), "QProfiles by language has already been set");
120 this.qProfilesPerLanguage.setProperty(ImmutableMap.copyOf(qprofilesByLanguage));
125 public Map<String, QualityProfile> getQProfilesByLanguage() {
126 checkState(qProfilesPerLanguage.isInitialized(), "QProfiles by language has not been set");
127 return qProfilesPerLanguage.getProperty();