org.sonar.api.config.Settings类的使用及代码示例

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

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

Settings介绍

暂无

代码示例

代码示例来源: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 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

@Test
public void should_load_values_of_deprecated_key() {
 Settings settings = new MapSettings(definitions);
 settings.setProperty("oldKey", "a,b");
 assertThat(settings.getStringArray("newKey")).containsOnly("a", "b");
 assertThat(settings.getStringArray("oldKey")).containsOnly("a", "b");
}

代码示例来源: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

public Settings appendProperty(String key, @Nullable String value) {
 Optional<String> existingValue = getRawString(definitions.validKey(key));
 String newValue;
 if (!existingValue.isPresent()) {
  newValue = trim(value);
 } else {
  newValue = existingValue.get() + "," + trim(value);
 }
 return setProperty(key, newValue);
}

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

/**
 * @see #setProperty(String, String)
 */
public Settings setProperty(String key, @Nullable Date date, boolean includeTime) {
 if (date == null) {
  return removeProperty(key);
 }
 return setProperty(key, includeTime ? DateUtils.formatDateTime(date) : DateUtils.formatDate(date));
}

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

/**
 * @see #setProperty(String, String)
 */
public Settings setProperty(String key, @Nullable Date date) {
 return setProperty(key, date, false);
}

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

CoreTestDb init(@Nullable String schemaPath, BiConsumer<Database, Boolean> extendedStart) {
 if (db == null) {
  Settings settings = new MapSettings().addProperties(System.getProperties());
  if (isNotEmpty(settings.getString("orchestrator.configUrl"))) {
   loadOrchestratorSettings(settings);
  String login = settings.getString(JDBC_USERNAME.getKey());
  for (String key : settings.getKeysStartingWith("sonar.jdbc")) {
   LOG.info(key + ": " + settings.getString(key));
  String dialect = settings.getString("sonar.jdbc.dialect");
  if (dialect != null && !"h2".equals(dialect)) {
   db = new DefaultDatabase(new LogbackHelper(), settings);
  } else {
   db = new H2Database("h2Tests" + DigestUtils.md5Hex(StringUtils.defaultString(schemaPath)), schemaPath == null);

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

public Settings setProperty(String key, @Nullable String[] values) {
 requireNonNull(key, "key can't be null");
 String effectiveKey = key.trim();
 Optional<PropertyDefinition> def = getDefinition(effectiveKey);
 if (!def.isPresent() || (!def.get().multiValues())) {
  throw new IllegalStateException("Fail to set multiple values on a single value property " + key);
 }
 String text = null;
 if (values != null) {
  List<String> escaped = new ArrayList<>();
  for (String value : values) {
   if (null != value) {
    escaped.add(value.replace(",", "%2C"));
   } else {
    escaped.add("");
   }
  }
  String escapedValue = escaped.stream().collect(Collectors.joining(","));
  text = trim(escapedValue);
 }
 return setProperty(key, text);
}

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

/**
 * Effective value as {@code Double}.
 * @return the value as {@code Double}. If the property does not have value nor default value, then {@code null} is returned.
 * @throws NumberFormatException if value is not empty and is not a parsable number
 */
@CheckForNull
public Double getDouble(String key) {
 String value = getString(key);
 if (StringUtils.isNotEmpty(value)) {
  try {
   return Double.valueOf(value);
  } catch (NumberFormatException e) {
   throw new IllegalStateException(String.format("The property '%s' is not a double value", key));
  }
 }
 return null;
}

代码示例来源: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

/**
 * 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

@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 getStringArray() {
 Settings settings = new MapSettings(definitions);
 String[] array = settings.getStringArray("array");
 assertThat(array).isEqualTo(new String[] {"one", "two", "three"});
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

public static boolean isCrossProjectDuplicationEnabled(Settings settings) {
 return settings.getBoolean(CoreProperties.CPD_CROSS_PROJECT)
  // No cross project duplication for branches
  && StringUtils.isBlank(settings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY));
}

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

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

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

@Test
public void ignore_case_of_boolean_values() {
 Settings settings = new MapSettings();
 settings.setProperty("foo", "true");
 settings.setProperty("bar", "TRUE");
 // labels in UI
 settings.setProperty("baz", "True");
 assertThat(settings.getBoolean("foo")).isTrue();
 assertThat(settings.getBoolean("bar")).isTrue();
 assertThat(settings.getBoolean("baz")).isTrue();
}

代码示例来源:origin: SonarSource/sonar-github

public String repository() {
 if (settings.hasKey(GitHubPlugin.GITHUB_REPO)) {
  return repoFromProp();
 }
 if (isNotBlank(settings.getString(CoreProperties.LINKS_SOURCES_DEV)) || isNotBlank(settings.getString(CoreProperties.LINKS_SOURCES))) {
  return repoFromScmProps();
 }
 throw MessageException.of("Unable to determine GitHub repository name for this project. Please provide it using property '" + GitHubPlugin.GITHUB_REPO
  + "' or configure property '" + CoreProperties.LINKS_SOURCES + "'.");
}

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

@Test
public void get_boolean() {
 Settings settings = new MapSettings(definitions);
 assertThat(settings.getBoolean("boolean")).isTrue();
 assertThat(settings.getBoolean("falseboolean")).isFalse();
 assertThat(settings.getBoolean("unknown")).isFalse();
 assertThat(settings.getBoolean("hello")).isFalse();
}

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

@Test
public void default_number_values_are_zero() {
 Settings settings = new MapSettings();
 assertThat(settings.getInt("foo")).isEqualTo(0);
 assertThat(settings.getLong("foo")).isEqualTo(0L);
}

相关文章