/** * 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); } }
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); }
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; }
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); }
private int nonNullAsInt(String key) { return config.getInt(key).orElseThrow(() -> new IllegalArgumentException(String.format("Property %s is not set", key))); }
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; }); }
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; } }
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))); } }
static Date getDateFromWeeks(Configuration config, String propertyKey) { int weeks = config.getInt(propertyKey).get(); return DateUtils.addWeeks(new Date(), -weeks); }
static Date getDateFromHours(Configuration config, String propertyKey) { int hours = config.getInt(propertyKey).get(); return DateUtils.addHours(new Date(), -hours); }
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); }
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(); }
private static int computePort(Configuration configuration) { return configuration.getInt(CLUSTER_NODE_HZ_PORT.getKey()) .orElseThrow(missingPropertyISE(CLUSTER_NODE_HZ_PORT.getKey())); }
@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); } }
@Test public void defaultMinimumTokens() { when(configuration.getInt(anyString())).thenReturn(Optional.empty()); assertThat(cpdSettings.getMinimumTokens("java")).isEqualTo(100); }
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; }
/** * 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); } }
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; }
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); }
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); }