blob: c25152e4e4ba8c883263905ccecf20081097dad1 [file] [log] [blame]
// Copyright (C) 2018 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.googlesource.gerrit.plugins.renameproject;
import com.google.common.base.CharMatcher;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.server.config.PluginConfig;
import com.google.gerrit.server.config.PluginConfigFactory;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.Arrays;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@Singleton
public class Configuration {
private static final int DEFAULT_SSH_CONNECTION_TIMEOUT_MS = 2 * 60 * 1000; // 2 minutes
private static final String URL_KEY = "url";
private final int indexThreads;
private final int sshCommandTimeout;
private final int sshConnectionTimeout;
private final String renameRegex;
private final int renameReplicationRetries;
private final Set<String> urls;
@Inject
public Configuration(PluginConfigFactory pluginConfigFactory, @PluginName String pluginName) {
PluginConfig cfg = pluginConfigFactory.getFromGerritConfig(pluginName);
indexThreads = cfg.getInt("indexThreads", 4);
sshCommandTimeout = cfg.getInt("sshCommandTimeout", 0);
sshConnectionTimeout = cfg.getInt("sshConnectionTimeout", DEFAULT_SSH_CONNECTION_TIMEOUT_MS);
renameRegex = cfg.getString("renameRegex", ".+");
renameReplicationRetries = cfg.getInt("renameReplicationRetries", 3);
urls =
Arrays.stream(cfg.getStringList(URL_KEY))
.filter(Objects::nonNull)
.filter(s -> !s.isEmpty())
.map(s -> CharMatcher.is('/').trimTrailingFrom(s))
.collect(Collectors.toSet());
}
public int getIndexThreads() {
return indexThreads;
}
public Set<String> getUrls() {
return urls;
}
public int getSshCommandTimeout() {
return sshCommandTimeout;
}
public int getSshConnectionTimeout() {
return sshConnectionTimeout;
}
public String getRenameRegex() {
return renameRegex;
}
public int getRenameReplicationRetries() {
return renameReplicationRetries;
}
}