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.task.projectanalysis.analysis;
22 import com.google.common.collect.ImmutableMap;
24 import javax.annotation.CheckForNull;
25 import javax.annotation.Nullable;
26 import org.sonar.server.computation.task.projectanalysis.qualityprofile.QualityProfile;
27 import org.sonar.server.computation.util.InitializedProperty;
29 import static com.google.common.base.Preconditions.checkState;
31 public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder {
33 private final InitializedProperty<String> uuid = new InitializedProperty<>();
35 private final InitializedProperty<Long> analysisDate = new InitializedProperty<>();
37 private final InitializedProperty<Analysis> baseProjectSnapshot = new InitializedProperty<>();
39 private final InitializedProperty<Boolean> crossProjectDuplicationEnabled = new InitializedProperty<>();
41 private final InitializedProperty<String> branch = new InitializedProperty<>();
43 private final InitializedProperty<Integer> rootComponentRef = new InitializedProperty<>();
45 private final InitializedProperty<Map<String, QualityProfile>> qProfilesPerLanguage = new InitializedProperty<>();
48 public MutableAnalysisMetadataHolder setUuid(String s) {
49 checkState(!uuid.isInitialized(), "Analysis uuid has already been set");
50 this.uuid.setProperty(s);
55 public MutableAnalysisMetadataHolder setAnalysisDate(long date) {
56 checkState(!analysisDate.isInitialized(), "Analysis date has already been set");
57 this.analysisDate.setProperty(date);
62 public String getUuid() {
63 checkState(uuid.isInitialized(), "Analysis uuid has not been set");
64 return this.uuid.getProperty();
68 public long getAnalysisDate() {
69 checkState(analysisDate.isInitialized(), "Analysis date has not been set");
70 return this.analysisDate.getProperty();
74 public boolean isFirstAnalysis() {
75 return getBaseProjectSnapshot() == null;
79 public MutableAnalysisMetadataHolder setBaseProjectSnapshot(@Nullable Analysis baseProjectAnalysis) {
80 checkState(!this.baseProjectSnapshot.isInitialized(), "Base project snapshot has already been set");
81 this.baseProjectSnapshot.setProperty(baseProjectAnalysis);
87 public Analysis getBaseProjectSnapshot() {
88 checkState(baseProjectSnapshot.isInitialized(), "Base project snapshot has not been set");
89 return baseProjectSnapshot.getProperty();
93 public MutableAnalysisMetadataHolder setCrossProjectDuplicationEnabled(boolean isCrossProjectDuplicationEnabled) {
94 checkState(!this.crossProjectDuplicationEnabled.isInitialized(), "Cross project duplication flag has already been set");
95 this.crossProjectDuplicationEnabled.setProperty(isCrossProjectDuplicationEnabled);
100 public boolean isCrossProjectDuplicationEnabled() {
101 checkState(crossProjectDuplicationEnabled.isInitialized(), "Cross project duplication flag has not been set");
102 return crossProjectDuplicationEnabled.getProperty();
106 public MutableAnalysisMetadataHolder setBranch(@Nullable String branch) {
107 checkState(!this.branch.isInitialized(), "Branch has already been set");
108 this.branch.setProperty(branch);
113 public String getBranch() {
114 checkState(branch.isInitialized(), "Branch has not been set");
115 return branch.getProperty();
119 public MutableAnalysisMetadataHolder setRootComponentRef(int rootComponentRef) {
120 checkState(!this.rootComponentRef.isInitialized(), "Root component ref has already been set");
121 this.rootComponentRef.setProperty(rootComponentRef);
126 public int getRootComponentRef() {
127 checkState(rootComponentRef.isInitialized(), "Root component ref has not been set");
128 return rootComponentRef.getProperty();
132 public MutableAnalysisMetadataHolder setQProfilesByLanguage(Map<String, QualityProfile> qprofilesByLanguage) {
133 checkState(!this.qProfilesPerLanguage.isInitialized(), "QProfiles by language has already been set");
134 this.qProfilesPerLanguage.setProperty(ImmutableMap.copyOf(qprofilesByLanguage));
139 public Map<String, QualityProfile> getQProfilesByLanguage() {
140 checkState(qProfilesPerLanguage.isInitialized(), "QProfiles by language has not been set");
141 return qProfilesPerLanguage.getProperty();