org.sonar.api.config.Settings.getString()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(125)

本文整理了Java中org.sonar.api.config.Settings.getString()方法的一些代码示例,展示了Settings.getString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Settings.getString()方法的具体详情如下:
包路径:org.sonar.api.config.Settings
类名称:Settings
方法名:getString

Settings.getString介绍

[英]The effective value of the specified property. Can return null if the property is not set and has no defined default value.

If the property is encrypted with a secret key, then the returned value is decrypted.
[中]指定属性的有效值。如果未设置属性且没有定义默认值,则可以返回null。
如果属性是用密钥加密的,那么返回的值将被解密。

代码示例

代码示例来源:origin: SonarSource/sonarqube

@Override
public Optional<String> get(String key) {
 return Optional.ofNullable(settings.getString(key));
}

代码示例来源:origin: SonarSource/sonarqube

@CheckForNull
public String getString(String key) {
 return delegate.getString(key);
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public Optional<String> get(String key) {
 return Optional.ofNullable(settings.getString(key));
}

代码示例来源:origin: SonarSource/sonarqube

/**
 * Effective value as {@code long}.
 * @return the value as {@code long}. If the property does not have value nor default value, then {@code 0L} is returned.
 * @throws NumberFormatException if value is not empty and is not a parsable {@code long}
 */
public long getLong(String key) {
 String value = getString(key);
 if (StringUtils.isNotEmpty(value)) {
  return Long.parseLong(value);
 }
 return 0L;
}

代码示例来源:origin: SonarSource/sonarqube

/**
 * Effective value as boolean. It is {@code false} if {@link #getString(String)}
 * does not return {@code "true"}, even if it's not a boolean representation.
 * @return {@code true} if the effective value is {@code "true"}, else {@code false}.
 */
public boolean getBoolean(String key) {
 String value = getString(key);
 return StringUtils.isNotEmpty(value) && Boolean.parseBoolean(value);
}

代码示例来源:origin: SonarSource/sonarqube

/**
 * Effective value as {@code int}.
 * @return the value as {@code int}. If the property does not have value nor default value, then {@code 0} is returned.
 * @throws NumberFormatException if value is not empty and is not a parsable integer
 */
public int getInt(String key) {
 String value = getString(key);
 if (StringUtils.isNotEmpty(value)) {
  return Integer.parseInt(value);
 }
 return 0;
}

代码示例来源:origin: SonarSource/sonarqube

/**
 * Value is split by carriage returns.
 *
 * @return non-null array of lines. The line termination characters are excluded.
 * @since 3.2
 */
public String[] getStringLines(String key) {
 String value = getString(key);
 if (StringUtils.isEmpty(value)) {
  return new String[0];
 }
 return value.split("\r?\n|\r", -1);
}

代码示例来源:origin: SonarSource/sonarqube

private static void completeProperties(Settings settings, Properties properties, String prefix) {
 List<String> jdbcKeys = settings.getKeysStartingWith(prefix);
 for (String jdbcKey : jdbcKeys) {
  String value = settings.getString(jdbcKey);
  properties.setProperty(jdbcKey, value);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void should_fallback_deprecated_key_to_default_value_of_new_key() {
 Settings settings = new MapSettings(definitions);
 assertThat(settings.getString("newKeyWithDefaultValue")).isEqualTo("default_value");
 assertThat(settings.getString("oldKeyWithDefaultValue")).isEqualTo("default_value");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void should_fallback_deprecated_key_to_new_key() {
 Settings settings = new MapSettings(definitions);
 settings.setProperty("newKey", "value of newKey");
 assertThat(settings.getString("newKey")).isEqualTo("value of newKey");
 assertThat(settings.getString("oldKey")).isEqualTo("value of newKey");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void should_load_value_of_deprecated_key() {
 // it's used for example when deprecated settings are set through command-line
 Settings settings = new MapSettings(definitions);
 settings.setProperty("oldKey", "value of oldKey");
 assertThat(settings.getString("newKey")).isEqualTo("value of oldKey");
 assertThat(settings.getString("oldKey")).isEqualTo("value of oldKey");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void testDefaultValueOfGetString() {
 Settings settings = new MapSettings(definitions);
 assertThat(settings.getString("hello")).isEqualTo("world");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void set_property_boolean() {
 Settings settings = new MapSettings();
 settings.setProperty("foo", true);
 settings.setProperty("bar", false);
 assertThat(settings.getBoolean("foo")).isTrue();
 assertThat(settings.getBoolean("bar")).isFalse();
 assertThat(settings.getString("foo")).isEqualTo("true");
 assertThat(settings.getString("bar")).isEqualTo("false");
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public void execute(SensorContext context) {
 File f = new File(context.settings().getString(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS));
 FileSystem fs = context.fileSystem();
 FilePredicates p = fs.predicates();
 try {
  for (String path : FileUtils.readLines(f)) {
   createIssues(fs.inputFile(p.and(p.hasPath(path), p.hasType(Type.MAIN), p.hasLanguage(Xoo.KEY))), context);
  }
 } catch (IOException e) {
  throw new IllegalStateException(e);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void test_get_string() {
 Settings settings = new MapSettings(definitions);
 settings.setProperty("hello", "Russia");
 assertThat(settings.getString("hello")).isEqualTo("Russia");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void set_property_int() {
 Settings settings = new MapSettings();
 settings.setProperty("foo", 123);
 assertThat(settings.getInt("foo")).isEqualTo(123);
 assertThat(settings.getString("foo")).isEqualTo("123");
 assertThat(settings.getBoolean("foo")).isFalse();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void all_values_should_be_trimmed_set_property() {
 Settings settings = new MapSettings();
 settings.setProperty("foo", "   FOO ");
 assertThat(settings.getString("foo")).isEqualTo("FOO");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void setProperty_date() {
 Settings settings = new MapSettings();
 Date date = DateUtils.parseDateTime("2010-05-18T15:50:45+0100");
 settings.setProperty("aDate", date);
 settings.setProperty("aDateTime", date, true);
 assertThat(settings.getString("aDate")).isEqualTo("2010-05-18");
 assertThat(settings.getString("aDateTime")).startsWith("2010-05-18T");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void testSettings() {
 Settings settings = new MapSettings();
 settings.setProperty("foo", "bar");
 tester.setSettings(settings);
 assertThat(tester.settings().getString("foo")).isEqualTo("bar");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void setProperty_methods_trims_value() {
 Settings underTest = new MapSettings();
 Random random = new Random();
 String blankBefore = blank(random);
 String blankAfter = blank(random);
 String key = randomAlphanumeric(3);
 String value = randomAlphanumeric(3);
 underTest.setProperty(key, blankBefore + value + blankAfter);
 assertThat(underTest.getString(key)).isEqualTo(value);
}

相关文章