List of usage examples for org.eclipse.jgit.lib Config getInt
public int getInt(final String section, final String name, final int defaultValue)
From source file:com.ericsson.gerrit.plugins.highavailability.Configuration.java
License:Apache License
private static int getInt(Config cfg, String section, String name, int defaultValue) { try {//from w w w.ja v a2 s . c o m return cfg.getInt(section, name, defaultValue); } catch (IllegalArgumentException e) { log.error("invalid value for {}; using default value {}", name, defaultValue); log.debug("Failed to retrieve integer value: {}", e.getMessage(), e); return defaultValue; } }
From source file:com.google.gerrit.common.ChangeHookRunner.java
License:Apache License
/** * Create a new ChangeHookRunner.//w w w .jav a 2s . c o m * * @param queue Queue to use when processing hooks. * @param repoManager The repository manager. * @param config Config file to use. * @param sitePath The sitepath of this gerrit install. * @param projectCache the project cache instance for the server. */ @Inject public ChangeHookRunner(WorkQueue queue, GitRepositoryManager repoManager, @GerritServerConfig Config config, @AnonymousCowardName String anonymousCowardName, SitePaths sitePath, ProjectCache projectCache, AccountCache accountCache, EventFactory eventFactory, DynamicSet<EventListener> unrestrictedListeners) { this.anonymousCowardName = anonymousCowardName; this.repoManager = repoManager; this.hookQueue = queue.createQueue(1, "hook"); this.projectCache = projectCache; this.accountCache = accountCache; this.eventFactory = eventFactory; this.sitePaths = sitePath; this.unrestrictedListeners = unrestrictedListeners; Path hooksPath; String hooksPathConfig = config.getString("hooks", null, "path"); if (hooksPathConfig != null) { hooksPath = Paths.get(hooksPathConfig); } else { hooksPath = sitePath.hooks_dir; } // When adding a new hook, make sure to check that the setting name // canonicalizes correctly in hook() below. patchsetCreatedHook = hook(config, hooksPath, "patchset-created"); draftPublishedHook = hook(config, hooksPath, "draft-published"); commentAddedHook = hook(config, hooksPath, "comment-added"); changeMergedHook = hook(config, hooksPath, "change-merged"); mergeFailedHook = hook(config, hooksPath, "merge-failed"); changeAbandonedHook = hook(config, hooksPath, "change-abandoned"); changeRestoredHook = hook(config, hooksPath, "change-restored"); refUpdatedHook = hook(config, hooksPath, "ref-updated"); reviewerAddedHook = hook(config, hooksPath, "reviewer-added"); topicChangedHook = hook(config, hooksPath, "topic-changed"); claSignedHook = hook(config, hooksPath, "cla-signed"); refUpdateHook = hook(config, hooksPath, "ref-update"); hashtagsChangedHook = hook(config, hooksPath, "hashtags-changed"); projectCreatedHook = hook(config, hooksPath, "project-created"); syncHookTimeout = config.getInt("hooks", "syncHookTimeout", 30); syncHookThreadPool = Executors .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("SyncHook-%d").build()); }
From source file:com.google.gerrit.httpd.auth.openid.LoginForm.java
License:Apache License
@Inject LoginForm(@CanonicalWebUrl @Nullable Provider<String> urlProvider, @GerritServerConfig Config config, AuthConfig authConfig, OpenIdServiceImpl impl, SiteHeaderFooter header, Provider<OAuthSessionOverOpenID> oauthSessionProvider, Provider<CurrentUser> currentUserProvider, DynamicMap<OAuthServiceProvider> oauthServiceProviders) { this.urlProvider = urlProvider; this.impl = impl; this.header = header; this.maxRedirectUrlLength = config.getInt("openid", "maxRedirectUrlLength", 10); this.oauthSessionProvider = oauthSessionProvider; this.currentUserProvider = currentUserProvider; this.oauthServiceProviders = oauthServiceProviders; if (urlProvider == null || Strings.isNullOrEmpty(urlProvider.get())) { log.error("gerrit.canonicalWebUrl must be set in gerrit.config"); }// w ww . ja v a 2 s .c o m if (authConfig.getAuthType() == AuthType.OPENID_SSO) { suggestProviders = ImmutableSet.of(); ssoUrl = authConfig.getOpenIdSsoUrl(); } else { Set<String> providers = Sets.newHashSet(); for (Map.Entry<String, String> e : ALL_PROVIDERS.entrySet()) { if (impl.isAllowedOpenID(e.getValue())) { providers.add(e.getKey()); } } suggestProviders = ImmutableSet.copyOf(providers); ssoUrl = null; } }
From source file:com.google.gerrit.lucene.LuceneChangeIndex.java
License:Apache License
@AssistedInject LuceneChangeIndex(@GerritServerConfig Config cfg, SitePaths sitePaths, @IndexExecutor(INTERACTIVE) ListeningExecutorService executor, Provider<ReviewDb> db, ChangeData.Factory changeDataFactory, FillArgs fillArgs, @Assisted Schema<ChangeData> schema, @Assisted @Nullable String base) throws IOException { this.sitePaths = sitePaths; this.fillArgs = fillArgs; this.executor = executor; this.db = db; this.changeDataFactory = changeDataFactory; this.schema = schema; this.useDocValuesForSorting = schema.getVersion() >= 15; this.idSortField = sortFieldName(LegacyChangeIdPredicate.idField(schema)); CustomMappingAnalyzer analyzer = new CustomMappingAnalyzer(new StandardAnalyzer(CharArraySet.EMPTY_SET), CUSTOM_CHAR_MAPPING);/*from w w w . j a v a 2 s . co m*/ queryBuilder = new QueryBuilder(analyzer); BooleanQuery .setMaxClauseCount(cfg.getInt("index", "defaultMaxClauseCount", BooleanQuery.getMaxClauseCount())); GerritIndexWriterConfig openConfig = new GerritIndexWriterConfig(cfg, "changes_open"); GerritIndexWriterConfig closedConfig = new GerritIndexWriterConfig(cfg, "changes_closed"); SearcherFactory searcherFactory = newSearcherFactory(); if (cfg.getBoolean("index", "lucene", "testInmemory", false)) { openIndex = new SubIndex(new RAMDirectory(), "ramOpen", openConfig, searcherFactory); closedIndex = new SubIndex(new RAMDirectory(), "ramClosed", closedConfig, searcherFactory); } else { Path dir = base != null ? Paths.get(base) : LuceneVersionManager.getDir(sitePaths, schema); openIndex = new SubIndex(dir.resolve(CHANGES_OPEN), openConfig, searcherFactory); closedIndex = new SubIndex(dir.resolve(CHANGES_CLOSED), closedConfig, searcherFactory); } }
From source file:com.google.gerrit.pgm.http.jetty.HttpLog.java
License:Apache License
HttpLog(final SitePaths site, final Config config) { final DailyRollingFileAppender dst = new DailyRollingFileAppender(); dst.setName(LOG_NAME);/*ww w . j a va 2s .c o m*/ dst.setLayout(new MyLayout()); dst.setEncoding("UTF-8"); dst.setFile(new File(resolve(site.logs_dir), LOG_NAME).getPath()); dst.setImmediateFlush(true); dst.setAppend(true); dst.setThreshold(Level.INFO); dst.setErrorHandler(new DieErrorHandler()); dst.activateOptions(); dst.setErrorHandler(new LogLogHandler()); async = new AsyncAppender(); async.setBlocking(true); async.setBufferSize(config.getInt("core", "asyncLoggingBufferSize", 64)); async.setLocationInfo(false); async.addAppender(dst); async.activateOptions(); }
From source file:com.google.gerrit.pgm.http.jetty.JettyServer.java
License:Apache License
private Connector[] listen(Server server, Config cfg) { // OpenID and certain web-based single-sign-on products can cause // some very long headers, especially in the Referer header. We // need to use a larger default header size to ensure we have // the space required. ///*from www .jav a 2 s. com*/ final int requestHeaderSize = cfg.getInt("httpd", "requestheadersize", 16386); final URI[] listenUrls = listenURLs(cfg); final boolean reuseAddress = cfg.getBoolean("httpd", "reuseaddress", true); final int acceptors = cfg.getInt("httpd", "acceptorThreads", 2); final AuthType authType = cfg.getEnum("auth", null, "type", AuthType.OPENID); reverseProxy = isReverseProxied(listenUrls); final Connector[] connectors = new Connector[listenUrls.length]; for (int idx = 0; idx < listenUrls.length; idx++) { final URI u = listenUrls[idx]; final int defaultPort; final ServerConnector c; HttpConfiguration config = defaultConfig(requestHeaderSize); if (AuthType.CLIENT_SSL_CERT_LDAP.equals(authType) && !"https".equals(u.getScheme())) { throw new IllegalArgumentException("Protocol '" + u.getScheme() + "' " + " not supported in httpd.listenurl '" + u + "' when auth.type = '" + AuthType.CLIENT_SSL_CERT_LDAP.name() + "'; only 'https' is supported"); } if ("http".equals(u.getScheme())) { defaultPort = 80; c = newServerConnector(server, acceptors, config); } else if ("https".equals(u.getScheme())) { SslContextFactory ssl = new SslContextFactory(); final Path keystore = getFile(cfg, "sslkeystore", "etc/keystore"); String password = cfg.getString("httpd", null, "sslkeypassword"); if (password == null) { password = "gerrit"; } ssl.setKeyStorePath(keystore.toAbsolutePath().toString()); ssl.setTrustStorePath(keystore.toAbsolutePath().toString()); ssl.setKeyStorePassword(password); ssl.setTrustStorePassword(password); if (AuthType.CLIENT_SSL_CERT_LDAP.equals(authType)) { ssl.setNeedClientAuth(true); Path crl = getFile(cfg, "sslcrl", "etc/crl.pem"); if (Files.exists(crl)) { ssl.setCrlPath(crl.toAbsolutePath().toString()); ssl.setValidatePeerCerts(true); } } defaultPort = 443; config.addCustomizer(new SecureRequestCustomizer()); c = new ServerConnector(server, null, null, null, 0, acceptors, new SslConnectionFactory(ssl, "http/1.1"), new HttpConnectionFactory(config)); } else if ("proxy-http".equals(u.getScheme())) { defaultPort = 8080; config.addCustomizer(new ForwardedRequestCustomizer()); c = newServerConnector(server, acceptors, config); } else if ("proxy-https".equals(u.getScheme())) { defaultPort = 8080; config.addCustomizer(new ForwardedRequestCustomizer()); config.addCustomizer(new HttpConfiguration.Customizer() { @Override public void customize(Connector connector, HttpConfiguration channelConfig, Request request) { request.setScheme(HttpScheme.HTTPS.asString()); request.setSecure(true); } }); c = newServerConnector(server, acceptors, config); } else { throw new IllegalArgumentException( "Protocol '" + u.getScheme() + "' " + " not supported in httpd.listenurl '" + u + "';" + " only 'http', 'https', 'proxy-http, 'proxy-https'" + " are supported"); } try { if (u.getHost() == null && (u.getAuthority().equals("*") // || u.getAuthority().startsWith("*:"))) { // Bind to all local addresses. Port wasn't parsed right by URI // due to the illegal host of "*" so replace with a legal name // and parse the URI. // final URI r = new URI(u.toString().replace('*', 'A')).parseServerAuthority(); c.setHost(null); c.setPort(0 < r.getPort() ? r.getPort() : defaultPort); } else { final URI r = u.parseServerAuthority(); c.setHost(r.getHost()); c.setPort(0 <= r.getPort() ? r.getPort() : defaultPort); } } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid httpd.listenurl " + u, e); } c.setReuseAddress(reuseAddress); connectors[idx] = c; } return connectors; }
From source file:com.google.gerrit.pgm.util.ThreadLimiter.java
License:Apache License
private static int limitThreads(Config cfg, DataSourceType dst, int threads) { boolean usePool = cfg.getBoolean("database", "connectionpool", dst.usePool()); int poolLimit = cfg.getInt("database", "poollimit", DataSourceProvider.DEFAULT_POOL_LIMIT); if (usePool && threads > poolLimit) { log.warn("Limiting program to " + poolLimit + " threads due to database.poolLimit"); return poolLimit; }// ww w. j av a2 s .c o m return threads; }
From source file:com.google.gerrit.server.auth.ldap.LdapRealm.java
License:Apache License
static int optional(Config config, String name, int defaultValue) { return config.getInt("ldap", name, defaultValue); }
From source file:com.google.gerrit.server.change.PreviewSubmit.java
License:Apache License
@Inject PreviewSubmit(Provider<ReviewDb> dbProvider, Provider<MergeOp> mergeOpProvider, AllowedFormats allowedFormats, @GerritServerConfig Config cfg) { this.dbProvider = dbProvider; this.mergeOpProvider = mergeOpProvider; this.allowedFormats = allowedFormats; this.maxBundleSize = cfg.getInt("download", "maxBundleSize", MAX_DEFAULT_BUNDLE_SIZE); }
From source file:com.google.gerrit.server.change.SuggestReviewers.java
License:Apache License
@Inject
SuggestReviewers(AccountVisibility av, AccountLoader.Factory accountLoaderFactory,
AccountControl.Factory accountControlFactory, AccountCache accountCache,
GroupMembers.Factory groupMembersFactory, IdentifiedUser.GenericFactory identifiedUserFactory,
Provider<CurrentUser> currentUser, Provider<ReviewDb> dbProvider, @GerritServerConfig Config cfg,
GroupBackend groupBackend, ReviewerSuggestionCache reviewerSuggestionCache) {
this.accountLoader = accountLoaderFactory.create(true);
this.accountControl = accountControlFactory.get();
this.accountCache = accountCache;
this.groupMembersFactory = groupMembersFactory;
this.dbProvider = dbProvider;
this.identifiedUserFactory = identifiedUserFactory;
this.currentUser = currentUser;
this.groupBackend = groupBackend;
this.reviewerSuggestionCache = reviewerSuggestionCache;
this.maxSuggestedReviewers = cfg.getInt("suggest", "maxSuggestedReviewers", DEFAULT_MAX_SUGGESTED);
this.limit = this.maxSuggestedReviewers;
this.fullTextMaxMatches = cfg.getInt("suggest", "fullTextSearchMaxMatches", DEFAULT_MAX_MATCHES);
String suggest = cfg.getString("suggest", null, "accounts");
if ("OFF".equalsIgnoreCase(suggest) || "false".equalsIgnoreCase(suggest)) {
this.suggestAccounts = false;
} else {//from w w w .ja v a 2 s . c o m
this.useFullTextSearch = cfg.getBoolean("suggest", "fullTextSearch", false);
this.suggestAccounts = (av != AccountVisibility.NONE);
}
this.suggestFrom = cfg.getInt("suggest", null, "from", 0);
this.maxAllowed = cfg.getInt("addreviewer", "maxAllowed", PostReviewers.DEFAULT_MAX_REVIEWERS);
}