Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added proxy support for tests #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
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;
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
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;

Expand Down Expand Up @@ -105,14 +108,38 @@ private DefaultRepositorySystemSession newRepositorySystemSession(RepositorySyst
private List<org.eclipse.aether.repository.RemoteRepository> repositories(RepositorySystem system, RepositorySystemSession session) {
List<org.eclipse.aether.repository.RemoteRepository> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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);
Expand Down Expand Up @@ -100,9 +132,9 @@ public void stop() {
Log.info("Jenkins stopped");
}

private ProcessBuilder process(Path executable, String... arguments) {
private ProcessBuilder process(Path executable, List<String> arguments) {
List<String> args = new ArrayList<>(windowsOrUnix(executable));
args.addAll(asList(arguments));
args.addAll(arguments);

return new ProcessBuilder(args);
}
Expand Down