You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Settings.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2020 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. import java.util.Date;
  22. import java.util.List;
  23. import javax.annotation.CheckForNull;
  24. import org.sonar.api.ce.ComputeEngineSide;
  25. import org.sonar.api.scanner.ScannerSide;
  26. import org.sonar.api.server.ServerSide;
  27. import org.sonar.api.utils.DateUtils;
  28. import org.sonarsource.api.sonarlint.SonarLintSide;
  29. /**
  30. * @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.
  31. */
  32. @ServerSide
  33. @ComputeEngineSide
  34. @ScannerSide
  35. @SonarLintSide
  36. @Deprecated
  37. public abstract class Settings {
  38. /**
  39. * @return {@code true} if the property has a non-default value, else {@code false}.
  40. */
  41. public abstract boolean hasKey(String key);
  42. /**
  43. * The effective value of the specified property. Can return
  44. * {@code null} if the property is not set and has no
  45. * defined default value.
  46. * <p>
  47. * If the property is encrypted with a secret key,
  48. * then the returned value is decrypted.
  49. * </p>
  50. *
  51. * @throws IllegalStateException if value is encrypted but fails to be decrypted.
  52. */
  53. @CheckForNull
  54. public abstract String getString(String key);
  55. /**
  56. * Effective value as boolean. It is {@code false} if {@link #getString(String)}
  57. * does not return {@code "true"}, even if it's not a boolean representation.
  58. *
  59. * @return {@code true} if the effective value is {@code "true"}, else {@code false}.
  60. */
  61. public abstract boolean getBoolean(String key);
  62. /**
  63. * Effective value as {@code int}.
  64. *
  65. * @return the value as {@code int}. If the property does not have value nor default value, then {@code 0} is returned.
  66. * @throws NumberFormatException if value is not empty and is not a parsable integer
  67. */
  68. public abstract int getInt(String key);
  69. /**
  70. * Effective value as {@code long}.
  71. *
  72. * @return the value as {@code long}. If the property does not have value nor default value, then {@code 0L} is returned.
  73. * @throws NumberFormatException if value is not empty and is not a parsable {@code long}
  74. */
  75. public abstract long getLong(String key);
  76. /**
  77. * Effective value as {@link Date}, without time fields. Format is {@link DateUtils#DATE_FORMAT}.
  78. *
  79. * @return the value as a {@link Date}. If the property does not have value nor default value, then {@code null} is returned.
  80. * @throws RuntimeException if value is not empty and is not in accordance with {@link DateUtils#DATE_FORMAT}.
  81. */
  82. @CheckForNull
  83. public abstract Date getDate(String key);
  84. /**
  85. * Effective value as {@link Date}, with time fields. Format is {@link DateUtils#DATETIME_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#DATETIME_FORMAT}.
  89. */
  90. @CheckForNull
  91. public abstract Date getDateTime(String key);
  92. /**
  93. * Effective value as {@code Float}.
  94. *
  95. * @return the value as {@code Float}. If the property does not have value nor default value, then {@code null} is returned.
  96. * @throws NumberFormatException if value is not empty and is not a parsable number
  97. */
  98. @CheckForNull
  99. public abstract Float getFloat(String key);
  100. /**
  101. * Effective value as {@code Double}.
  102. *
  103. * @return the value as {@code Double}. If the property does not have value nor default value, then {@code null} is returned.
  104. * @throws NumberFormatException if value is not empty and is not a parsable number
  105. */
  106. @CheckForNull
  107. public abstract Double getDouble(String key);
  108. /**
  109. * Value is split by comma and trimmed. Never returns null.
  110. * <br>
  111. * Examples :
  112. * <ul>
  113. * <li>"one,two,three " -&gt; ["one", "two", "three"]</li>
  114. * <li>" one, two, three " -&gt; ["one", "two", "three"]</li>
  115. * <li>"one, , three" -&gt; ["one", "", "three"]</li>
  116. * </ul>
  117. */
  118. public abstract String[] getStringArray(String key);
  119. /**
  120. * Value is split by carriage returns.
  121. *
  122. * @return non-null array of lines. The line termination characters are excluded.
  123. * @since 3.2
  124. */
  125. public abstract String[] getStringLines(String key);
  126. /**
  127. * Value is split and trimmed.
  128. */
  129. public abstract String[] getStringArrayBySeparator(String key, String separator);
  130. public abstract List<String> getKeysStartingWith(String prefix);
  131. }