Skip to content
Permalink
Browse files

41: Bot launcher should detect ev. http proxy in environment

Reviewed-by: rwestberg
  • Loading branch information
Erik Helin
Erik Helin committed Jul 4, 2019
1 parent 7c68b3b commit 965be9c69ee88074dc888ec93167d8de02fa5940
@@ -50,6 +50,7 @@ dependencies {
implementation project(':ini')
implementation project(':process')
implementation project(':args')
implementation project(':proxy')

testImplementation project(':test')
}
@@ -29,6 +29,7 @@
requires org.openjdk.skara.json;
requires org.openjdk.skara.args;
requires org.openjdk.skara.process;
requires org.openjdk.skara.proxy;

requires java.sql;

@@ -26,6 +26,7 @@
import org.openjdk.skara.bot.*;
import org.openjdk.skara.host.network.URIBuilder;
import org.openjdk.skara.json.*;
import org.openjdk.skara.proxy.HttpProxy;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -109,6 +110,7 @@ private static JSONObject readConfiguration(Path jsonFile) {
}

public static void main(String... args) {
HttpProxy.setup();

var flags = List.of(
Option.shortcut("t")
@@ -27,6 +27,7 @@
import org.gradle.api.Project;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -38,10 +39,14 @@ public void apply(Project project) {
value = value == null ? System.getenv(key.toUpperCase()) : value;
if (value != null) {
var protocol = key.split("_")[0];
var uri = URI.create(value);
if (System.getProperty(protocol + ".proxyHost") == null) {
System.setProperty(protocol + ".proxyHost", uri.getHost());
System.setProperty(protocol + ".proxyPort", String.valueOf(uri.getPort()));
try {
var uri = new URI(value);
if (System.getProperty(protocol + ".proxyHost") == null && uri.getHost() != null) {
System.setProperty(protocol + ".proxyHost", uri.getHost());
System.setProperty(protocol + ".proxyPort", String.valueOf(uri.getPort()));
}
} catch (URISyntaxException e) {
// pass
}
}
}
@@ -38,6 +38,7 @@ dependencies {
implementation project(':webrev')
implementation project(':json')
implementation project(':host')
implementation project(':proxy')
}


@@ -28,6 +28,7 @@
requires org.openjdk.skara.args;
requires org.openjdk.skara.json;
requires org.openjdk.skara.host;
requires org.openjdk.skara.proxy;

requires java.net.http;
requires java.logging;
@@ -25,6 +25,7 @@
import org.openjdk.skara.args.*;
import org.openjdk.skara.host.*;
import org.openjdk.skara.vcs.Repository;
import org.openjdk.skara.proxy.HttpProxy;

import java.io.IOException;
import java.net.URI;
@@ -26,6 +26,7 @@
import org.openjdk.skara.host.*;
import org.openjdk.skara.vcs.*;
import org.openjdk.skara.vcs.openjdk.*;
import org.openjdk.skara.proxy.HttpProxy;

import java.io.IOException;
import java.net.URI;
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

module {
name = 'org.openjdk.skara.proxy'
test {
requires 'org.junit.jupiter.api'
opens 'org.openjdk.skara.args' to 'org.junit.platform.commons'
}
}

publishing {
publications {
proxy(MavenPublication) {
from components.java
}
}
}
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module org.openjdk.skara.proxy {
exports org.openjdk.skara.proxy;
}
@@ -20,30 +20,39 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.openjdk.skara.cli;
package org.openjdk.skara.proxy;

import java.util.List;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

class HttpProxy {
static void setup() {
public class HttpProxy {
public static void setup() {
for (var key : List.of("http_proxy", "https_proxy")) {
var value = System.getenv(key);
value = value == null ? System.getenv(key.toUpperCase()) : value;
if (value != null) {
var protocol = key.split("_")[0];
var uri = URI.create(value);
System.setProperty(protocol + ".proxyHost", uri.getHost());
System.setProperty(protocol + ".proxyPort", String.valueOf(uri.getPort()));
try {
var uri = new URI(value);
if (System.getProperty(protocol + ".proxyHost") == null && uri.getHost() != null) {
System.setProperty(protocol + ".proxyHost", uri.getHost());
System.setProperty(protocol + ".proxyPort", String.valueOf(uri.getPort()));
}
} catch (URISyntaxException e) {
// pass
}
}
}
var no_proxy = System.getenv("no_proxy");
no_proxy = no_proxy == null ? System.getenv("NO_PROXY") : no_proxy;
if (no_proxy != null) {
var hosts = no_proxy.replace(",", "|")
.replaceAll("^\\.", "*.")
.replaceAll("\\|\\.", "|*.");
System.setProperty("http.nonProxyHosts", hosts);
if (no_proxy != null && System.getProperty("http.nonProxyHosts") == null) {
var hosts = Arrays.stream(no_proxy.split(","))
.map(s -> s.startsWith(".") ? "*" + s : s)
.collect(Collectors.toList());
System.setProperty("http.nonProxyHosts", String.join("|", hosts));
}
}
}
@@ -34,6 +34,7 @@ include 'jcheck'
include 'json'
include 'mailinglist'
include 'process'
include 'proxy'
include 'storage'
include 'test'
include 'vcs'

0 comments on commit 965be9c

Please sign in to comment.
You can’t perform that action at this time.