001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2014 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * SonarQube is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.batch.protocol.input; 021 022import org.sonar.batch.protocol.GsonHelper; 023 024import java.util.ArrayList; 025import java.util.Collection; 026import java.util.HashMap; 027import java.util.Map; 028 029/** 030 * Container for all global data going from server to batch. 031 * This is not an API since server and batch always share the same version. 032 */ 033public class GlobalRepositories { 034 035 private long timestamp; 036 private Collection<Metric> metrics = new ArrayList<>(); 037 private Map<String, String> globalSettings = new HashMap<>(); 038 039 public Map<String, String> globalSettings() { 040 return globalSettings; 041 } 042 043 public GlobalRepositories addGlobalSetting(String key, String value) { 044 globalSettings.put(key, value); 045 return this; 046 } 047 048 public Collection<Metric> metrics() { 049 return metrics; 050 } 051 052 public GlobalRepositories addMetric(Metric metric) { 053 metrics.add(metric); 054 return this; 055 } 056 057 public long timestamp() { 058 return timestamp; 059 } 060 061 public void setTimestamp(long timestamp) { 062 this.timestamp = timestamp; 063 } 064 065 public String toJson() { 066 return GsonHelper.create().toJson(this); 067 } 068 069 public static GlobalRepositories fromJson(String json) { 070 return GsonHelper.create().fromJson(json, GlobalRepositories.class); 071 } 072 073}