001 /* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2013 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 */ 020 package org.sonar.api.config; 021 022 import com.google.common.base.Objects; 023 import org.sonar.api.BatchComponent; 024 import org.sonar.api.CoreProperties; 025 import org.sonar.api.ServerComponent; 026 import org.sonar.api.config.Settings; 027 028 /** 029 * If batch extensions use this component, then batch must be executed with administrator rights (see properties sonar.login and sonar.password) 030 * 031 * @since 3.2 032 */ 033 public class EmailSettings implements BatchComponent, ServerComponent { 034 public static final String SMTP_HOST = "email.smtp_host.secured"; 035 public static final String SMTP_HOST_DEFAULT = ""; 036 public static final String SMTP_PORT = "email.smtp_port.secured"; 037 public static final String SMTP_PORT_DEFAULT = "25"; 038 public static final String SMTP_SECURE_CONNECTION = "email.smtp_secure_connection.secured"; 039 public static final String SMTP_SECURE_CONNECTION_DEFAULT = ""; 040 public static final String SMTP_USERNAME = "email.smtp_username.secured"; 041 public static final String SMTP_USERNAME_DEFAULT = ""; 042 public static final String SMTP_PASSWORD = "email.smtp_password.secured"; 043 public static final String SMTP_PASSWORD_DEFAULT = ""; 044 public static final String FROM = "email.from"; 045 public static final String FROM_DEFAULT = "noreply@nowhere"; 046 public static final String PREFIX = "email.prefix"; 047 public static final String PREFIX_DEFAULT = "[SONARQUBE]"; 048 049 private final Settings settings; 050 051 public EmailSettings(Settings settings) { 052 this.settings = settings; 053 } 054 055 public String getSmtpHost() { 056 return get(SMTP_HOST, SMTP_HOST_DEFAULT); 057 } 058 059 public int getSmtpPort() { 060 return Integer.parseInt(get(SMTP_PORT, SMTP_PORT_DEFAULT)); 061 } 062 063 public String getSecureConnection() { 064 return get(SMTP_SECURE_CONNECTION, SMTP_SECURE_CONNECTION_DEFAULT); 065 } 066 067 public String getSmtpUsername() { 068 return get(SMTP_USERNAME, SMTP_USERNAME_DEFAULT); 069 } 070 071 public String getSmtpPassword() { 072 return get(SMTP_PASSWORD, SMTP_PASSWORD_DEFAULT); 073 } 074 075 public String getFrom() { 076 return get(FROM, FROM_DEFAULT); 077 } 078 079 public String getPrefix() { 080 return get(PREFIX, PREFIX_DEFAULT); 081 } 082 083 public String getServerBaseURL() { 084 return get(CoreProperties.SERVER_BASE_URL, CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE); 085 } 086 087 private String get(String key, String defaultValue) { 088 return Objects.firstNonNull(settings.getString(key), defaultValue); 089 } 090 }