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