You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2020/07/04 19:10:27 UTC
[netbeans] 01/02: Make configureproxy idenpotent when invoked
multiple times
This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch release120
in repository https://gitbox.apache.org/repos/asf/netbeans.git
commit 27220bbd767eba456bb20045072b2f9a45608785
Author: Jaroslav Tulach <ja...@oracle.com>
AuthorDate: Mon Jun 22 10:04:12 2020 +0200
Make configureproxy idenpotent when invoked multiple times
---
.../netbeans/nbbuild/extlibs/ConfigureProxy.java | 73 +++++++++++-----------
1 file changed, 38 insertions(+), 35 deletions(-)
diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/ConfigureProxy.java b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/ConfigureProxy.java
index 3b4960b..4d96452 100644
--- a/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/ConfigureProxy.java
+++ b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/ConfigureProxy.java
@@ -84,51 +84,21 @@ public final class ConfigureProxy extends Task {
static URLConnection openConnection(Task task, final URL url, URI[] connectedVia) throws IOException {
final URLConnection[] conn = { null };
final List<Exception> errs = new CopyOnWriteArrayList<>();
+ final StringBuilder msgs = new StringBuilder();
final CountDownLatch connected = new CountDownLatch(1);
ExecutorService connectors = Executors.newFixedThreadPool(3);
connectors.submit(() -> {
- String httpProxy = System.getenv("http_proxy");
- if (httpProxy != null) {
- try {
- URI uri = new URI(httpProxy);
- InetSocketAddress address = InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort());
- Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
- URLConnection test = url.openConnection(proxy);
- test.connect();
- conn[0] = test;
- connected.countDown();
- if (connectedVia != null) {
- connectedVia[0] = uri;
- }
- } catch (IOException | URISyntaxException ex) {
- errs.add(ex);
- }
- }
+ checkProxyProperty("http_proxy", url, conn, connectedVia, connected, errs, msgs);
});
connectors.submit(() -> {
- String httpProxy = System.getenv("https_proxy");
- if (httpProxy != null) {
- try {
- URI uri = new URI(httpProxy);
- InetSocketAddress address = InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort());
- Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
- URLConnection test = url.openConnection(proxy);
- test.connect();
- conn[0] = test;
- connected.countDown();
- if (connectedVia != null) {
- connectedVia[0] = uri;
- }
- } catch (IOException | URISyntaxException ex) {
- errs.add(ex);
- }
- }
+ checkProxyProperty("https_proxy", url, conn, connectedVia, connected, errs, msgs);
});
connectors.submit(() -> {
try {
- URLConnection test = url.openConnection();
+ URLConnection test = url.openConnection(Proxy.NO_PROXY);
test.connect();
conn[0] = test;
+ msgs.append("\nNo proxy connected");
connected.countDown();
} catch (IOException ex) {
errs.add(ex);
@@ -142,9 +112,42 @@ public final class ConfigureProxy extends Task {
for (Exception ex : errs) {
task.log(ex, Project.MSG_ERR);
}
+ task.log(msgs.toString(), Project.MSG_ERR);
throw new IOException("Cannot connect to " + url);
+ } else {
+ task.log(msgs.toString(), Project.MSG_DEBUG);
}
return conn[0];
}
+ private static void checkProxyProperty(
+ String propertyName, final URL url,
+ final URLConnection[] conn, URI[] connectedVia,
+ final CountDownLatch connected,
+ final List<Exception> errs,
+ StringBuilder msgs
+ ) {
+ String httpProxy = System.getenv(propertyName);
+ msgs.append("\n[" + propertyName + "] set to " + httpProxy);
+ if (httpProxy != null) {
+ try {
+ URI uri = new URI(httpProxy);
+ InetSocketAddress address = InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort());
+ Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
+ URLConnection test = url.openConnection(proxy);
+ test.connect();
+ msgs.append("\n[" + propertyName + "] connected");
+ conn[0] = test;
+ if (connectedVia != null) {
+ connectedVia[0] = uri;
+ }
+ connected.countDown();
+ msgs.append("\n[" + propertyName + "] countDown");
+ } catch (IOException | URISyntaxException ex) {
+ errs.add(ex);
+ msgs.append("\n[" + propertyName + "] exception " + ex.getMessage());
+ }
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists