diff --git a/build-monitor-acceptance/src/main/java/com/smartcodeltd/aether/ArtifactTransporter.java b/build-monitor-acceptance/src/main/java/com/smartcodeltd/aether/ArtifactTransporter.java index fb62f73c0..909f42cad 100644 --- a/build-monitor-acceptance/src/main/java/com/smartcodeltd/aether/ArtifactTransporter.java +++ b/build-monitor-acceptance/src/main/java/com/smartcodeltd/aether/ArtifactTransporter.java @@ -8,7 +8,9 @@ import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory; import org.eclipse.aether.impl.DefaultServiceLocator; +import org.eclipse.aether.repository.Authentication; import org.eclipse.aether.repository.LocalRepository; +import org.eclipse.aether.repository.Proxy; import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.ArtifactResult; @@ -16,6 +18,7 @@ import org.eclipse.aether.spi.connector.transport.TransporterFactory; import org.eclipse.aether.transport.file.FileTransporterFactory; import org.eclipse.aether.transport.http.HttpTransporterFactory; +import org.eclipse.aether.util.repository.AuthenticationBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -105,14 +108,38 @@ private DefaultRepositorySystemSession newRepositorySystemSession(RepositorySyst private List repositories(RepositorySystem system, RepositorySystemSession session) { List repositories = new ArrayList<>(); + Proxy httpProxy = getProxy("http"); + Proxy httpsProxy = getProxy("https"); for (RemoteRepository location : remoteLocations) { - repositories.add(new org.eclipse.aether.repository.RemoteRepository.Builder( + org.eclipse.aether.repository.RemoteRepository.Builder builder = new org.eclipse.aether.repository.RemoteRepository.Builder( location.id(), location.type(), - location.url() - ).build()); + location.url()); + if (location.url().startsWith("http") && httpProxy != null) { + builder.setProxy(httpProxy); + } else if (location.url().startsWith("https") && httpsProxy != null) { + builder.setProxy(httpsProxy); + } + repositories.add(builder.build()); } return repositories; } + + private Proxy getProxy(String protocol) { + String proxyHost = System.getProperty(protocol + ".proxyHost"); + String proxyPort = System.getProperty(protocol + ".proxyPort"); + if (proxyHost != null && proxyPort != null) { + String proxyUser = System.getProperty(protocol + ".proxyUser"); + String proxyPassword = System.getProperty(protocol + ".proxyPassword"); + Authentication authentication = null; + if (proxyUser != null) { + String password = proxyPassword != null ? proxyPassword : ""; + authentication = new AuthenticationBuilder().addUsername(proxyUser).addPassword(password).build(); + } + return new Proxy("http", proxyHost, Integer.parseInt(proxyPort), authentication); + } else { + return null; + } + } } diff --git a/build-monitor-acceptance/src/main/java/net/serenitybdd/integration/jenkins/process/JenkinsProcess.java b/build-monitor-acceptance/src/main/java/net/serenitybdd/integration/jenkins/process/JenkinsProcess.java index 253c99b2c..548d865a3 100644 --- a/build-monitor-acceptance/src/main/java/net/serenitybdd/integration/jenkins/process/JenkinsProcess.java +++ b/build-monitor-acceptance/src/main/java/net/serenitybdd/integration/jenkins/process/JenkinsProcess.java @@ -41,13 +41,45 @@ public JenkinsProcess(@NotNull Path java, @NotNull Path jenkinsWar, @NotNull int env.put("JENKINS_HOME", jenkinsHome.toAbsolutePath().toString()); env.put("JAVA_HOME", java.getParent().getParent().toAbsolutePath().toString()); - process = process(java, - "-Duser.language=en", + List arguments = new ArrayList<>(); + String httpProxy = System.getProperty("http.proxyHost"); + String httpProxyPort = System.getProperty("http.proxyPort"); + String httpProxyUser = System.getProperty("http.proxyUser"); + String httpProxyPassword = System.getProperty("http.proxyPassword"); + String httpsProxy = System.getProperty("https.proxyHost"); + String httpsProxyPort = System.getProperty("https.proxyPort"); + String httpsProxyUser = System.getProperty("https.proxyUser"); + String httpsProxyPassword = System.getProperty("https.proxyPassword"); + if (httpProxy != null) { + arguments.add("-Dhttp.proxyHost=" + httpProxy); + } + if (httpProxyPort != null) { + arguments.add("-Dhttp.proxyPort=" + httpProxyPort); + } + if (httpProxyUser != null) { + arguments.add("-Dhttp.proxyUser=" + httpProxyUser); + } + if (httpProxyPassword != null) { + arguments.add("-Dhttp.proxyPassword=" + httpProxyPassword); + } + if (httpsProxy != null) { + arguments.add("-Dhttps.proxyHost=" + httpsProxy); + } + if (httpsProxyPort != null) { + arguments.add("-Dhttps.proxyPort=" + httpsProxyPort); + } + if (httpsProxyUser != null) { + arguments.add("-Dhttps.proxyUser=" + httpsProxyUser); + } + if (httpsProxyPassword != null) { + arguments.add("-Dhttps.proxyPassword=" + httpsProxyPassword); + } + arguments.addAll(Arrays.asList("-Duser.language=en", "-Dhudson.Main.development=true", "-jar", jenkinsWar.toString(), "--ajp13Port=-1", - "--httpPort=" + port - ).directory(jenkinsHome.toFile()); + "--httpPort=" + port)); + process = process(java, arguments).directory(jenkinsHome.toFile()); process.environment().putAll(Collections.unmodifiableMap(env)); process.redirectErrorStream(true); @@ -100,9 +132,9 @@ public void stop() { Log.info("Jenkins stopped"); } - private ProcessBuilder process(Path executable, String... arguments) { + private ProcessBuilder process(Path executable, List arguments) { List args = new ArrayList<>(windowsOrUnix(executable)); - args.addAll(asList(arguments)); + args.addAll(arguments); return new ProcessBuilder(args); }