aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java
blob: 9628a3c7cef562bebe26964af3ca024bda6b9dce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * SonarQube
 * Copyright (C) 2009-2016 SonarSource SA
 * mailto:contact AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.api.config;

import com.google.common.base.MoreObjects;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;

/**
 * If batch extensions use this component, then batch must be executed with administrator rights (see properties sonar.login and sonar.password)
 *
 * @since 3.2
 */
@ScannerSide
@ServerSide
@ComputeEngineSide
public class EmailSettings {
  public static final String SMTP_HOST = "email.smtp_host.secured";
  public static final String SMTP_HOST_DEFAULT = "";
  public static final String SMTP_PORT = "email.smtp_port.secured";
  public static final String SMTP_PORT_DEFAULT = "25";
  public static final String SMTP_SECURE_CONNECTION = "email.smtp_secure_connection.secured";
  public static final String SMTP_SECURE_CONNECTION_DEFAULT = "";
  public static final String SMTP_USERNAME = "email.smtp_username.secured";
  public static final String SMTP_USERNAME_DEFAULT = "";
  public static final String SMTP_PASSWORD = "email.smtp_password.secured";
  public static final String SMTP_PASSWORD_DEFAULT = "";
  public static final String FROM = "email.from";
  public static final String FROM_DEFAULT = "noreply@nowhere";
  public static final String PREFIX = "email.prefix";
  public static final String PREFIX_DEFAULT = "[SONARQUBE]";

  private final Settings settings;

  public EmailSettings(Settings settings) {
    this.settings = settings;
  }

  public String getSmtpHost() {
    return get(SMTP_HOST, SMTP_HOST_DEFAULT);
  }

  public int getSmtpPort() {
    return Integer.parseInt(get(SMTP_PORT, SMTP_PORT_DEFAULT));
  }

  public String getSecureConnection() {
    return get(SMTP_SECURE_CONNECTION, SMTP_SECURE_CONNECTION_DEFAULT);
  }

  public String getSmtpUsername() {
    return get(SMTP_USERNAME, SMTP_USERNAME_DEFAULT);
  }

  public String getSmtpPassword() {
    return get(SMTP_PASSWORD, SMTP_PASSWORD_DEFAULT);
  }

  public String getFrom() {
    return get(FROM, FROM_DEFAULT);
  }

  public String getPrefix() {
    return get(PREFIX, PREFIX_DEFAULT);
  }

  public String getServerBaseURL() {
    return get(CoreProperties.SERVER_BASE_URL, CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE);
  }

  private String get(String key, String defaultValue) {
    return MoreObjects.firstNonNull(settings.getString(key), defaultValue);
  }
}