List of usage examples for org.eclipse.jgit.lib Config getBoolean
public boolean getBoolean(final String section, final String name, final boolean defaultValue)
From source file:com.google.gerrit.httpd.raw.HostPageServlet.java
License:Apache License
@Inject
HostPageServlet(Provider<CurrentUser> cu, DynamicItem<WebSession> w, SitePaths sp, ThemeFactory themeFactory,
ServletContext servletContext, DynamicSet<WebUiPlugin> webUiPlugins, DynamicSet<MessageOfTheDay> motd,
@GerritServerConfig Config cfg, StaticServlet ss, NotesMigration migration)
throws IOException, ServletException {
currentUser = cu;/*ww w . j a va2s . co m*/
session = w;
plugins = webUiPlugins;
messages = motd;
signedOutTheme = themeFactory.getSignedOutTheme();
signedInTheme = themeFactory.getSignedInTheme();
site = sp;
refreshHeaderFooter = cfg.getBoolean("site", "refreshHeaderFooter", true);
staticServlet = ss;
isNoteDbEnabled = migration.enabled();
pluginsLoadTimeout = getPluginsLoadTimeout(cfg);
final String pageName = "HostPage.html";
template = HtmlDomUtil.parseFile(getClass(), pageName);
if (template == null) {
throw new FileNotFoundException("No " + pageName + " in webapp");
}
if (HtmlDomUtil.find(template, "gerrit_module") == null) {
throw new ServletException("No gerrit_module in " + pageName);
}
if (HtmlDomUtil.find(template, HPD_ID) == null) {
throw new ServletException("No " + HPD_ID + " in " + pageName);
}
String src = "gerrit_ui/gerrit_ui.nocache.js";
try (InputStream in = servletContext.getResourceAsStream("/" + src)) {
if (in != null) {
Hasher md = Hashing.md5().newHasher();
final byte[] buf = new byte[1024];
int n;
while ((n = in.read(buf)) > 0) {
md.putBytes(buf, 0, n);
}
src += "?content=" + md.hash().toString();
} else {
log.debug("No " + src + " in webapp root; keeping noncache.js URL");
}
} catch (IOException e) {
throw new IOException("Failed reading " + src, e);
}
noCacheName = src;
page = new Page();
}
From source file:com.google.gerrit.httpd.raw.SiteStaticDirectoryServlet.java
License:Apache License
@Inject SiteStaticDirectoryServlet(SitePaths site, @GerritServerConfig Config cfg, @Named(StaticModule.CACHE) Cache<Path, Resource> cache) { super(cache, cfg.getBoolean("site", "refreshHeaderFooter", true)); Path p;/*from w ww . j a va 2 s . c om*/ try { p = site.static_dir.toRealPath().normalize(); } catch (IOException e) { p = site.static_dir.toAbsolutePath().normalize(); } staticBase = p; }
From source file:com.google.gerrit.httpd.raw.StaticServlet.java
License:Apache License
@Inject StaticServlet(@GerritServerConfig Config cfg, SitePaths site) { Path p;/*from w w w . jav a 2s. com*/ try { p = site.static_dir.toRealPath().normalize(); } catch (IOException e) { p = site.static_dir.toAbsolutePath().normalize(); } staticBase = p; refresh = cfg.getBoolean("site", "refreshHeaderFooter", true); cache = CacheBuilder.newBuilder().maximumWeight(1 << 20).weigher(new Weigher<String, Resource>() { @Override public int weigh(String name, Resource r) { return 2 * name.length() + r.raw.length; } }).build(new CacheLoader<String, Resource>() { @Override public Resource load(String name) throws Exception { return loadResource(name); } }); }
From source file:com.google.gerrit.httpd.rpc.changedetail.ChangeDetailFactory.java
License:Apache License
@Inject ChangeDetailFactory(final PatchSetDetailFactory.Factory patchSetDetail, final ReviewDb db, final GitRepositoryManager repoManager, final ChangeControl.Factory changeControlFactory, final AccountInfoCacheFactory.Factory accountInfoCacheFactory, final AnonymousUser anonymousUser, final Mergeable mergeable, @GerritServerConfig final Config cfg, @Assisted final Change.Id id) { this.patchSetDetail = patchSetDetail; this.db = db; this.repoManager = repoManager; this.changeControlFactory = changeControlFactory; this.anonymousUser = anonymousUser; this.aic = accountInfoCacheFactory.create(); this.mergeable = mergeable; this.testMerge = cfg.getBoolean("changeMerge", "test", false); this.changeId = id; }
From source file:com.google.gerrit.httpd.template.SiteHeaderFooter.java
License:Apache License
@Inject SiteHeaderFooter(@GerritServerConfig Config cfg, SitePaths sitePaths) { this.refreshHeaderFooter = cfg.getBoolean("site", "refreshHeaderFooter", true); this.sitePaths = sitePaths; try {// w ww . ja v a 2s .c om Template t = new Template(sitePaths); t.load(); template = t; } catch (IOException e) { log.warn("Cannot load site header or footer", e); } }
From source file:com.google.gerrit.pgm.http.jetty.JettyServer.java
License:Apache License
@Inject JettyServer(@GerritServerConfig final Config cfg, final SitePaths site, final JettyEnv env, final HttpLogFactory httpLogFactory) throws MalformedURLException, IOException { this.site = site; httpd = new Server(threadPool(cfg)); httpd.setConnectors(listen(httpd, cfg)); Handler app = makeContext(env, cfg); if (cfg.getBoolean("httpd", "requestLog", !reverseProxy)) { RequestLogHandler handler = new RequestLogHandler(); handler.setRequestLog(httpLogFactory.get()); handler.setHandler(app);/*from w w w . ja v a 2 s .co m*/ app = handler; } if (cfg.getBoolean("httpd", "registerMBeans", false)) { MBeanContainer mbean = new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); httpd.addEventListener(mbean); httpd.addBean(Log.getRootLogger()); httpd.addBean(mbean); } httpd.setHandler(app); httpd.setStopAtShutdown(false); }
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 w w w. j a v a 2 s. c o m*/ 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.ErrorLogFile.java
License:Apache License
private static void initLogSystem(Path logdir, Config config) { final Logger root = LogManager.getRootLogger(); root.removeAllAppenders();/* w w w. j a v a 2 s. co m*/ boolean json = config.getBoolean("log", "jsonLogging", false); boolean text = config.getBoolean("log", "textLogging", true) || !json; if (text) { root.addAppender( SystemLog.createAppender(logdir, LOG_NAME, new PatternLayout("[%d] %-5p %c %x: %m%n"))); } if (json) { root.addAppender(SystemLog.createAppender(logdir, LOG_NAME + JSON_SUFFIX, new JSONEventLayoutV1())); } }
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; }//from w w w. j a v a2s .c o m return threads; }
From source file:com.google.gerrit.server.account.GetAgreements.java
License:Apache License
@Inject GetAgreements(Provider<CurrentUser> self, ProjectCache projectCache, AgreementJson agreementJson, @GerritServerConfig Config config) { this.self = self; this.projectCache = projectCache; this.agreementJson = agreementJson; this.agreementsEnabled = config.getBoolean("auth", "contributorAgreements", false); }