|
| 1 | +/* |
| 2 | + * Sonar Plugin API |
| 3 | + * Copyright (C) 2009-2023 SonarSource SA |
| 4 | + * mailto:info AT sonarsource DOT com |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU Lesser General Public |
| 8 | + * License as published by the Free Software Foundation; either |
| 9 | + * version 3 of the License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + * Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public License |
| 17 | + * along with this program; if not, write to the Free Software Foundation, |
| 18 | + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | + */ |
| 20 | +package org.sonar.api.config; |
| 21 | + |
| 22 | +import java.util.Date; |
| 23 | +import java.util.List; |
| 24 | +import javax.annotation.CheckForNull; |
| 25 | +import org.sonar.api.ce.ComputeEngineSide; |
| 26 | +import org.sonar.api.scanner.ScannerSide; |
| 27 | +import org.sonar.api.server.ServerSide; |
| 28 | +import org.sonar.api.utils.DateUtils; |
| 29 | +import org.sonarsource.api.sonarlint.SonarLintSide; |
| 30 | + |
| 31 | +/** |
| 32 | + * @deprecated since 6.5 use {@link Configuration}. Implementation moved out of the API in 8.3. Only remains minimal interface to make some outdated plugins happy. |
| 33 | + */ |
| 34 | +@ServerSide |
| 35 | +@ComputeEngineSide |
| 36 | +@ScannerSide |
| 37 | +@SonarLintSide |
| 38 | +@Deprecated(since = "6.5") |
| 39 | +public abstract class Settings { |
| 40 | + |
| 41 | + /** |
| 42 | + * @return {@code true} if the property has a non-default value, else {@code false}. |
| 43 | + */ |
| 44 | + public abstract boolean hasKey(String key); |
| 45 | + |
| 46 | + /** |
| 47 | + * The effective value of the specified property. Can return |
| 48 | + * {@code null} if the property is not set and has no |
| 49 | + * defined default value. |
| 50 | + * <p> |
| 51 | + * If the property is encrypted with a secret key, |
| 52 | + * then the returned value is decrypted. |
| 53 | + * </p> |
| 54 | + * |
| 55 | + * @throws IllegalStateException if value is encrypted but fails to be decrypted. |
| 56 | + */ |
| 57 | + @CheckForNull |
| 58 | + public abstract String getString(String key); |
| 59 | + |
| 60 | + /** |
| 61 | + * Effective value as boolean. It is {@code false} if {@link #getString(String)} |
| 62 | + * does not return {@code "true"}, even if it's not a boolean representation. |
| 63 | + * |
| 64 | + * @return {@code true} if the effective value is {@code "true"}, else {@code false}. |
| 65 | + */ |
| 66 | + public abstract boolean getBoolean(String key); |
| 67 | + |
| 68 | + /** |
| 69 | + * Effective value as {@code int}. |
| 70 | + * |
| 71 | + * @return the value as {@code int}. If the property does not have value nor default value, then {@code 0} is returned. |
| 72 | + * @throws NumberFormatException if value is not empty and is not a parsable integer |
| 73 | + */ |
| 74 | + public abstract int getInt(String key); |
| 75 | + |
| 76 | + /** |
| 77 | + * Effective value as {@code long}. |
| 78 | + * |
| 79 | + * @return the value as {@code long}. If the property does not have value nor default value, then {@code 0L} is returned. |
| 80 | + * @throws NumberFormatException if value is not empty and is not a parsable {@code long} |
| 81 | + */ |
| 82 | + public abstract long getLong(String key); |
| 83 | + |
| 84 | + /** |
| 85 | + * Effective value as {@link Date}, without time fields. Format is {@link DateUtils#DATE_FORMAT}. |
| 86 | + * |
| 87 | + * @return the value as a {@link Date}. If the property does not have value nor default value, then {@code null} is returned. |
| 88 | + * @throws RuntimeException if value is not empty and is not in accordance with {@link DateUtils#DATE_FORMAT}. |
| 89 | + */ |
| 90 | + @CheckForNull |
| 91 | + public abstract Date getDate(String key); |
| 92 | + |
| 93 | + /** |
| 94 | + * Effective value as {@link Date}, with time fields. Format is {@link DateUtils#DATETIME_FORMAT}. |
| 95 | + * |
| 96 | + * @return the value as a {@link Date}. If the property does not have value nor default value, then {@code null} is returned. |
| 97 | + * @throws RuntimeException if value is not empty and is not in accordance with {@link DateUtils#DATETIME_FORMAT}. |
| 98 | + */ |
| 99 | + @CheckForNull |
| 100 | + public abstract Date getDateTime(String key); |
| 101 | + |
| 102 | + /** |
| 103 | + * Effective value as {@code Float}. |
| 104 | + * |
| 105 | + * @return the value as {@code Float}. If the property does not have value nor default value, then {@code null} is returned. |
| 106 | + * @throws NumberFormatException if value is not empty and is not a parsable number |
| 107 | + */ |
| 108 | + @CheckForNull |
| 109 | + public abstract Float getFloat(String key); |
| 110 | + |
| 111 | + /** |
| 112 | + * Effective value as {@code Double}. |
| 113 | + * |
| 114 | + * @return the value as {@code Double}. If the property does not have value nor default value, then {@code null} is returned. |
| 115 | + * @throws NumberFormatException if value is not empty and is not a parsable number |
| 116 | + */ |
| 117 | + @CheckForNull |
| 118 | + public abstract Double getDouble(String key); |
| 119 | + |
| 120 | + /** |
| 121 | + * Value is split by comma and trimmed. Never returns null. |
| 122 | + * <br> |
| 123 | + * Examples : |
| 124 | + * <ul> |
| 125 | + * <li>"one,two,three " -> ["one", "two", "three"]</li> |
| 126 | + * <li>" one, two, three " -> ["one", "two", "three"]</li> |
| 127 | + * <li>"one, , three" -> ["one", "", "three"]</li> |
| 128 | + * </ul> |
| 129 | + */ |
| 130 | + public abstract String[] getStringArray(String key); |
| 131 | + |
| 132 | + /** |
| 133 | + * Value is split by carriage returns. |
| 134 | + * |
| 135 | + * @return non-null array of lines. The line termination characters are excluded. |
| 136 | + * @since 3.2 |
| 137 | + */ |
| 138 | + public abstract String[] getStringLines(String key); |
| 139 | + |
| 140 | + /** |
| 141 | + * Value is split and trimmed. |
| 142 | + */ |
| 143 | + public abstract String[] getStringArrayBySeparator(String key, String separator); |
| 144 | + |
| 145 | + public abstract List<String> getKeysStartingWith(String prefix); |
| 146 | + |
| 147 | +} |
0 commit comments