Dissolve gerrit-httpd top-level directory

Change-Id: I287b29b893c6f561dbbf6fa04dc714b4b7f48d54
This commit is contained in:
David Ostrovsky
2017-08-23 08:20:28 +02:00
committed by Dave Borowitz
parent 3675f601fa
commit a84dbc81bf
134 changed files with 49 additions and 52 deletions

View File

@@ -0,0 +1,72 @@
// Copyright (C) 2014 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.google.gerrit.httpd;
import com.google.common.base.Strings;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.jgit.lib.Config;
@Singleton
class ProxyPropertiesProvider implements Provider<ProxyProperties> {
private URL proxyUrl;
private String proxyUser;
private String proxyPassword;
@Inject
ProxyPropertiesProvider(@GerritServerConfig Config config) throws MalformedURLException {
String proxyUrlStr = config.getString("http", null, "proxy");
if (!Strings.isNullOrEmpty(proxyUrlStr)) {
proxyUrl = new URL(proxyUrlStr);
proxyUser = config.getString("http", null, "proxyUsername");
proxyPassword = config.getString("http", null, "proxyPassword");
String userInfo = proxyUrl.getUserInfo();
if (userInfo != null) {
int c = userInfo.indexOf(':');
if (0 < c) {
proxyUser = userInfo.substring(0, c);
proxyPassword = userInfo.substring(c + 1);
} else {
proxyUser = userInfo;
}
}
}
}
@Override
public ProxyProperties get() {
return new ProxyProperties() {
@Override
public URL getProxyUrl() {
return proxyUrl;
}
@Override
public String getUsername() {
return proxyUser;
}
@Override
public String getPassword() {
return proxyPassword;
}
};
}
}