001/* 002 * SonarQube 003 * Copyright (C) 2009-2016 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * This program 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 * This program 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.api.config; 021 022import org.sonar.api.ExtensionPoint; 023import org.sonar.api.server.ServerSide; 024 025import javax.annotation.Nullable; 026 027/** 028 * Observe changes of global properties done from web application. It does not support : 029 * <ul> 030 * <li>changes done by end-users from the page "Project Settings"</li> 031 * <li>changes done programmatically on the component org.sonar.api.config.Settings</li> 032 * <li>changes done when restoring settings from XML using backup/restore feature</li> 033 * </ul> 034 * 035 * @since 3.0 036 */ 037@ServerSide 038@ExtensionPoint 039public abstract class GlobalPropertyChangeHandler { 040 041 public static final class PropertyChange { 042 private String key; 043 private String newValue; 044 045 private PropertyChange(String key, @Nullable String newValue) { 046 this.key = key; 047 this.newValue = newValue; 048 } 049 050 public static PropertyChange create(String key, @Nullable String newValue) { 051 return new PropertyChange(key, newValue); 052 } 053 054 public String getKey() { 055 return key; 056 } 057 058 public String getNewValue() { 059 return newValue; 060 } 061 062 @Override 063 public String toString() { 064 return String.format("[key=%s, newValue=%s]", key, newValue); 065 } 066 } 067 068 /** 069 * This method gets called when a property is changed. 070 */ 071 public abstract void onChange(PropertyChange change); 072 073}