Move HttpSupport's configureHttpProxy to jgit-pgm
This is the last chunk of code in jgit-core which references the awtui package. Moving it to the only consumer in jgit-pgm allows us to move the awtui package over to the jgit-awtui module. Change-Id: I2fd81be2076117b2f2c5f8ed45de7f29272af6cf Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
8d5510d51c
commit
41e4b2fed4
|
@ -1,6 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2008-2009, Google Inc.
|
|
||||||
* Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
|
|
||||||
* Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.com>
|
* Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.com>
|
||||||
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
|
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
|
||||||
* and other copyright owners as documented in the project's IP log.
|
* and other copyright owners as documented in the project's IP log.
|
||||||
|
@ -47,19 +45,20 @@
|
||||||
package org.eclipse.jgit.pgm;
|
package org.eclipse.jgit.pgm;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kohsuke.args4j.Argument;
|
|
||||||
import org.kohsuke.args4j.CmdLineException;
|
|
||||||
import org.kohsuke.args4j.ExampleMode;
|
|
||||||
import org.kohsuke.args4j.Option;
|
|
||||||
import org.eclipse.jgit.awtui.AwtAuthenticator;
|
import org.eclipse.jgit.awtui.AwtAuthenticator;
|
||||||
import org.eclipse.jgit.errors.TransportException;
|
import org.eclipse.jgit.errors.TransportException;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
import org.eclipse.jgit.pgm.opt.CmdLineParser;
|
import org.eclipse.jgit.pgm.opt.CmdLineParser;
|
||||||
import org.eclipse.jgit.pgm.opt.SubcommandHandler;
|
import org.eclipse.jgit.pgm.opt.SubcommandHandler;
|
||||||
import org.eclipse.jgit.util.HttpSupport;
|
import org.kohsuke.args4j.Argument;
|
||||||
|
import org.kohsuke.args4j.CmdLineException;
|
||||||
|
import org.kohsuke.args4j.ExampleMode;
|
||||||
|
import org.kohsuke.args4j.Option;
|
||||||
|
|
||||||
/** Command line entry point. */
|
/** Command line entry point. */
|
||||||
public class Main {
|
public class Main {
|
||||||
|
@ -88,7 +87,7 @@ public static void main(final String[] argv) {
|
||||||
final Main me = new Main();
|
final Main me = new Main();
|
||||||
try {
|
try {
|
||||||
AwtAuthenticator.install();
|
AwtAuthenticator.install();
|
||||||
HttpSupport.configureHttpProxy();
|
configureHttpProxy();
|
||||||
me.execute(argv);
|
me.execute(argv);
|
||||||
} catch (Die err) {
|
} catch (Die err) {
|
||||||
System.err.println("fatal: " + err.getMessage());
|
System.err.println("fatal: " + err.getMessage());
|
||||||
|
@ -181,4 +180,43 @@ private static File findGitDir() {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the JRE's standard HTTP based on <code>http_proxy</code>.
|
||||||
|
* <p>
|
||||||
|
* The popular libcurl library honors the <code>http_proxy</code>
|
||||||
|
* environment variable as a means of specifying an HTTP proxy for requests
|
||||||
|
* made behind a firewall. This is not natively recognized by the JRE, so
|
||||||
|
* this method can be used by command line utilities to configure the JRE
|
||||||
|
* before the first request is sent.
|
||||||
|
*
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* the value in <code>http_proxy</code> is unsupportable.
|
||||||
|
*/
|
||||||
|
private static void configureHttpProxy() throws MalformedURLException {
|
||||||
|
final String s = System.getenv("http_proxy");
|
||||||
|
if (s == null || s.equals(""))
|
||||||
|
return;
|
||||||
|
|
||||||
|
final URL u = new URL((s.indexOf("://") == -1) ? "http://" + s : s);
|
||||||
|
if (!"http".equals(u.getProtocol()))
|
||||||
|
throw new MalformedURLException("Invalid http_proxy: " + s
|
||||||
|
+ ": Only http supported.");
|
||||||
|
|
||||||
|
final String proxyHost = u.getHost();
|
||||||
|
final int proxyPort = u.getPort();
|
||||||
|
|
||||||
|
System.setProperty("http.proxyHost", proxyHost);
|
||||||
|
if (proxyPort > 0)
|
||||||
|
System.setProperty("http.proxyPort", String.valueOf(proxyPort));
|
||||||
|
|
||||||
|
final String userpass = u.getUserInfo();
|
||||||
|
if (userpass != null && userpass.contains(":")) {
|
||||||
|
final int c = userpass.indexOf(':');
|
||||||
|
final String user = userpass.substring(0, c);
|
||||||
|
final String pass = userpass.substring(c + 1);
|
||||||
|
AwtAuthenticator.add(new AwtAuthenticator.CachedAuthentication(
|
||||||
|
proxyHost, proxyPort, user, pass));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,56 +47,14 @@
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.ProxySelector;
|
import java.net.ProxySelector;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
import org.eclipse.jgit.awtui.AwtAuthenticator;
|
|
||||||
|
|
||||||
/** Extra utilities to support usage of HTTP. */
|
/** Extra utilities to support usage of HTTP. */
|
||||||
public class HttpSupport {
|
public class HttpSupport {
|
||||||
/**
|
|
||||||
* Configure the JRE's standard HTTP based on <code>http_proxy</code>.
|
|
||||||
* <p>
|
|
||||||
* The popular libcurl library honors the <code>http_proxy</code>
|
|
||||||
* environment variable as a means of specifying an HTTP proxy for requests
|
|
||||||
* made behind a firewall. This is not natively recognized by the JRE, so
|
|
||||||
* this method can be used by command line utilities to configure the JRE
|
|
||||||
* before the first request is sent.
|
|
||||||
*
|
|
||||||
* @throws MalformedURLException
|
|
||||||
* the value in <code>http_proxy</code> is unsupportable.
|
|
||||||
*/
|
|
||||||
public static void configureHttpProxy() throws MalformedURLException {
|
|
||||||
final String s = System.getenv("http_proxy");
|
|
||||||
if (s == null || s.equals(""))
|
|
||||||
return;
|
|
||||||
|
|
||||||
final URL u = new URL((s.indexOf("://") == -1) ? "http://" + s : s);
|
|
||||||
if (!"http".equals(u.getProtocol()))
|
|
||||||
throw new MalformedURLException("Invalid http_proxy: " + s
|
|
||||||
+ ": Only http supported.");
|
|
||||||
|
|
||||||
final String proxyHost = u.getHost();
|
|
||||||
final int proxyPort = u.getPort();
|
|
||||||
|
|
||||||
System.setProperty("http.proxyHost", proxyHost);
|
|
||||||
if (proxyPort > 0)
|
|
||||||
System.setProperty("http.proxyPort", String.valueOf(proxyPort));
|
|
||||||
|
|
||||||
final String userpass = u.getUserInfo();
|
|
||||||
if (userpass != null && userpass.contains(":")) {
|
|
||||||
final int c = userpass.indexOf(':');
|
|
||||||
final String user = userpass.substring(0, c);
|
|
||||||
final String pass = userpass.substring(c + 1);
|
|
||||||
AwtAuthenticator.add(new AwtAuthenticator.CachedAuthentication(
|
|
||||||
proxyHost, proxyPort, user, pass));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL encode a value string into an output buffer.
|
* URL encode a value string into an output buffer.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue