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

x33g5p2x  于2022-01-18 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(136)

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

Configuration.getInt介绍

[英]Effective value as int.
[中]有效值为int。

代码示例

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

/**
  * Not applicable to Java, as the {@link BlockChunker} that it uses does not record start and end units of each block. 
  * Also, it uses statements instead of tokens. 
  */
 int getMinimumTokens(String languageKey) {
  return settings.getInt("sonar.cpd." + languageKey + ".minimumTokens").orElse(100);
 }
}

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

private int getMinimumTokens(String languageKey) {
 // The java language is an exception : it doesn't compute tokens but statement, so the settings could not be used.
 if (languageKey.equalsIgnoreCase(JAVA_KEY)) {
  return 0;
 }
 return config.getInt("sonar.cpd." + languageKey + ".minimumTokens").orElse(100);
}

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

private static int getSessionTimeoutInSeconds(Configuration config) {
 int minutes = config.getInt(SESSION_TIMEOUT_IN_MINUTES_PROPERTY).orElse(SESSION_TIMEOUT_DEFAULT_VALUE_IN_MINUTES);
 checkArgument(minutes > 0, "Property %s must be strictly positive. Got %s", SESSION_TIMEOUT_IN_MINUTES_PROPERTY, minutes);
 checkArgument(minutes <= MAX_SESSION_TIMEOUT_IN_MINUTES, "Property %s must not be greater than 3 months (%s minutes). Got %s minutes",
  SESSION_TIMEOUT_IN_MINUTES_PROPERTY, MAX_SESSION_TIMEOUT_IN_MINUTES, minutes);
 return minutes * 60;
}

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

public static PurgeConfiguration newDefaultPurgeConfiguration(Configuration config, IdUuidPair rootId, Collection<String> disabledComponentUuids) {
 return new PurgeConfiguration(rootId, Arrays.asList(Scopes.DIRECTORY, Scopes.FILE), config.getInt(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES).get(),
  config.getInt(PurgeConstants.DAYS_BEFORE_DELETING_INACTIVE_SHORT_LIVING_BRANCHES), System2.INSTANCE, disabledComponentUuids);
}

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

private int nonNullAsInt(String key) {
 return config.getInt(key).orElseThrow(() -> new IllegalArgumentException(String.format("Property %s is not set", key)));
}

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

private int getCpdBlockSize(@Nullable String languageKey) {
 if (languageKey == null) {
  return DEFAULT_CPD_MIN_LINES;
 }
 return settings.getInt("sonar.cpd." + languageKey + ".minimumLines")
  .orElseGet(() -> {
   if ("cobol".equals(languageKey)) {
    return 30;
   }
   if ("abap".equals(languageKey)) {
    return 20;
   }
   return DEFAULT_CPD_MIN_LINES;
  });
}

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

public CeConfigurationImpl(Configuration configuration, @Nullable WorkerCountProvider workerCountProvider) {
 this.workerCountProvider = workerCountProvider;
 this.gracefultStopTimeoutInMs = configuration.getInt(SONAR_CE_GRACEFUL_STOP_TIME_OUT_IN_MS).orElse(GRACEFUL_STOP_TIMEOUT);
 if (workerCountProvider == null) {
  this.workerCount = DEFAULT_WORKER_COUNT;
  this.workerThreadCount = DEFAULT_WORKER_THREAD_COUNT;
 } else {
  this.workerCount = readWorkerCount(workerCountProvider);
  this.workerThreadCount = MAX_WORKER_THREAD_COUNT;
 }
}

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

private int frequency() {
  return config.getInt(SONAR_TELEMETRY_FREQUENCY_IN_SECONDS.getKey())
   .orElseThrow(() -> new IllegalStateException(String.format("Setting '%s' must be provided.", SONAR_TELEMETRY_FREQUENCY_IN_SECONDS)));
 }
}

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

static Date getDateFromWeeks(Configuration config, String propertyKey) {
 int weeks = config.getInt(propertyKey).get();
 return DateUtils.addWeeks(new Date(), -weeks);
}

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

static Date getDateFromHours(Configuration config, String propertyKey) {
 int hours = config.getInt(propertyKey).get();
 return DateUtils.addHours(new Date(), -hours);
}

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

private void applySettingsConfiguration(SettingsConfiguration settingsConfiguration) {
 settings.put("index.mapper.dynamic", valueOf(false));
 settings.put("index.refresh_interval", refreshInterval(settingsConfiguration));
 Configuration config = settingsConfiguration.getConfiguration();
 boolean clusterMode = config.getBoolean(CLUSTER_ENABLED.getKey()).orElse(false);
 int shards = config.getInt(format("sonar.search.%s.shards", indexName))
  .orElse(settingsConfiguration.getDefaultNbOfShards());
 int replicas = clusterMode ? config.getInt(SEARCH_REPLICAS.getKey()).orElse(1) : 0;
 settings.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, shards);
 settings.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, replicas);
}

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

private String computeBaseUrl() {
 String host = config.get("sonar.web.host").orElse("");
 int port = config.getInt("sonar.web.port").orElse(0);
 String context = config.get("sonar.web.context").orElse("");
 StringBuilder res = new StringBuilder();
 res.append("http://");
 appendHost(host, res);
 appendPort(port, res);
 appendContext(context, res);
 return res.toString();
}

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

private static int computePort(Configuration configuration) {
 return configuration.getInt(CLUSTER_NODE_HZ_PORT.getKey())
  .orElseThrow(missingPropertyISE(CLUSTER_NODE_HZ_PORT.getKey()));
}

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

@Test
 public void minimumTokensByLanguage() {
  when(configuration.getInt("sonar.cpd.java.minimumTokens")).thenReturn(Optional.of(42));
  when(configuration.getInt("sonar.cpd.php.minimumTokens")).thenReturn(Optional.of(33));

  assertThat(cpdSettings.getMinimumTokens("java")).isEqualTo(42);
  assertThat(cpdSettings.getMinimumTokens("php")).isEqualTo(33);
 }
}

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

@Test
public void defaultMinimumTokens() {
 when(configuration.getInt(anyString())).thenReturn(Optional.empty());
 assertThat(cpdSettings.getMinimumTokens("java")).isEqualTo(100);
}

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

public EsClient provide(Configuration config) {
 if (cache == null) {
  Settings.Builder esSettings = Settings.builder();
  // mandatory property defined by bootstrap process
  esSettings.put("cluster.name", config.get(CLUSTER_NAME.getKey()).get());
  boolean clusterEnabled = config.getBoolean(CLUSTER_ENABLED.getKey()).orElse(false);
  boolean searchNode = !clusterEnabled || SEARCH.equals(NodeType.parse(config.get(CLUSTER_NODE_TYPE.getKey()).orElse(null)));
  final TransportClient nativeClient = new MinimalTransportClient(esSettings.build());
  if (clusterEnabled && !searchNode) {
   esSettings.put("client.transport.sniff", true);
   Arrays.stream(config.getStringArray(CLUSTER_SEARCH_HOSTS.getKey()))
    .map(HostAndPort::fromString)
    .forEach(h -> addHostToClient(h, nativeClient));
   LOGGER.info("Connected to remote Elasticsearch: [{}]", displayedAddresses(nativeClient));
  } else {
   HostAndPort host = HostAndPort.fromParts(config.get(SEARCH_HOST.getKey()).get(), config.getInt(SEARCH_PORT.getKey()).get());
   addHostToClient(host, nativeClient);
   LOGGER.info("Connected to local Elasticsearch: [{}]", displayedAddresses(nativeClient));
  }
  cache = new EsClient(nativeClient);
 }
 return cache;
}

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

/**
  * Not applicable to Java, as the {@link BlockChunker} that it uses does not record start and end units of each block. 
  * Also, it uses statements instead of tokens. 
  */
 int getMinimumTokens(String languageKey) {
  return settings.getInt("sonar.cpd." + languageKey + ".minimumTokens").orElse(100);
 }
}

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

private static int getSessionTimeoutInSeconds(Configuration config) {
 int minutes = config.getInt(SESSION_TIMEOUT_IN_MINUTES_PROPERTY).orElse(SESSION_TIMEOUT_DEFAULT_VALUE_IN_MINUTES);
 checkArgument(minutes > 0, "Property %s must be strictly positive. Got %s", SESSION_TIMEOUT_IN_MINUTES_PROPERTY, minutes);
 checkArgument(minutes <= MAX_SESSION_TIMEOUT_IN_MINUTES, "Property %s must not be greater than 3 months (%s minutes). Got %s minutes",
  SESSION_TIMEOUT_IN_MINUTES_PROPERTY, MAX_SESSION_TIMEOUT_IN_MINUTES, minutes);
 return minutes * 60;
}

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

public CeConfigurationImpl(Configuration configuration, WorkerCountProvider workerCountProvider) {
 this.workerCountProvider = workerCountProvider;
 this.workerThreadCount = MAX_WORKER_THREAD_COUNT;
 this.workerCount = readWorkerCount(workerCountProvider);
 this.gracefultStopTimeoutInMs = configuration.getInt(SONAR_CE_GRACEFUL_STOP_TIME_OUT_IN_MS).orElse(GRACEFUL_STOP_TIMEOUT);
}

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

private void applySettingsConfiguration(SettingsConfiguration settingsConfiguration) {
 settings.put("index.mapper.dynamic", valueOf(false));
 settings.put("index.refresh_interval", refreshInterval(settingsConfiguration));
 Configuration config = settingsConfiguration.getConfiguration();
 boolean clusterMode = config.getBoolean(CLUSTER_ENABLED.getKey()).orElse(false);
 int shards = config.getInt(format("sonar.search.%s.shards", indexName))
  .orElse(settingsConfiguration.getDefaultNbOfShards());
 int replicas = clusterMode ? config.getInt(SEARCH_REPLICAS.getKey()).orElse(1) : 0;
 settings.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, shards);
 settings.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, replicas);
}

相关文章