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 java.util.Date;
24 import javax.annotation.CheckForNull;
25 import javax.annotation.Nullable;
26 import org.junit.rules.ExternalResource;
27 import org.sonar.server.computation.task.projectanalysis.qualityprofile.QualityProfile;
28 import org.sonar.server.computation.util.InitializedProperty;
30 import static com.google.common.base.Preconditions.checkNotNull;
31 import static com.google.common.base.Preconditions.checkState;
33 public class AnalysisMetadataHolderRule extends ExternalResource implements MutableAnalysisMetadataHolder {
35 private final InitializedProperty<String> uuid = new InitializedProperty<>();
37 private final InitializedProperty<Long> analysisDate = new InitializedProperty<>();
39 private final InitializedProperty<Analysis> baseProjectSnapshot = new InitializedProperty<>();
41 private final InitializedProperty<Boolean> crossProjectDuplicationEnabled = new InitializedProperty<>();
43 private final InitializedProperty<String> branch = new InitializedProperty<>();
45 private final InitializedProperty<Integer> rootComponentRef = new InitializedProperty<>();
47 private final InitializedProperty<Map<String, QualityProfile>> qProfilesPerLanguage = new InitializedProperty<>();
50 public String getUuid() {
51 checkState(uuid.isInitialized(), "Analysis UUID has not been set");
52 return this.uuid.getProperty();
56 public AnalysisMetadataHolderRule setUuid(String s) {
57 checkNotNull(s, "UUID must not be null");
58 this.uuid.setProperty(s);
62 public AnalysisMetadataHolderRule setAnalysisDate(Date date) {
63 checkNotNull(date, "Date must not be null");
64 this.analysisDate.setProperty(date.getTime());
69 public AnalysisMetadataHolderRule setAnalysisDate(long date) {
70 checkNotNull(date, "Date must not be null");
71 this.analysisDate.setProperty(date);
76 public long getAnalysisDate() {
77 checkState(analysisDate.isInitialized(), "Analysis date has not been set");
78 return this.analysisDate.getProperty();
82 public boolean isFirstAnalysis() {
83 return getBaseProjectSnapshot() == null;
87 public AnalysisMetadataHolderRule setBaseProjectSnapshot(@Nullable Analysis baseProjectAnalysis) {
88 this.baseProjectSnapshot.setProperty(baseProjectAnalysis);
94 public Analysis getBaseProjectSnapshot() {
95 checkState(baseProjectSnapshot.isInitialized(), "Base project snapshot has not been set");
96 return baseProjectSnapshot.getProperty();
100 public AnalysisMetadataHolderRule setCrossProjectDuplicationEnabled(boolean isCrossProjectDuplicationEnabled) {
101 this.crossProjectDuplicationEnabled.setProperty(isCrossProjectDuplicationEnabled);
106 public boolean isCrossProjectDuplicationEnabled() {
107 checkState(crossProjectDuplicationEnabled.isInitialized(), "Cross project duplication flag has not been set");
108 return crossProjectDuplicationEnabled.getProperty();
112 public AnalysisMetadataHolderRule setBranch(@Nullable String branch) {
113 this.branch.setProperty(branch);
118 public String getBranch() {
119 checkState(branch.isInitialized(), "Branch has not been set");
120 return branch.getProperty();
124 public AnalysisMetadataHolderRule setRootComponentRef(int rootComponentRef) {
125 this.rootComponentRef.setProperty(rootComponentRef);
130 public int getRootComponentRef() {
131 checkState(rootComponentRef.isInitialized(), "Root component ref has not been set");
132 return rootComponentRef.getProperty();
136 public AnalysisMetadataHolderRule setQProfilesByLanguage(Map<String, QualityProfile> qProfilesPerLanguage) {
137 this.qProfilesPerLanguage.setProperty(qProfilesPerLanguage);
142 public Map<String, QualityProfile> getQProfilesByLanguage() {
143 checkState(qProfilesPerLanguage.isInitialized(), "QProfile per language has not been set");
144 return qProfilesPerLanguage.getProperty();