Skip to content
Open
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
45 changes: 23 additions & 22 deletions core/src/main/java/hudson/tools/ZipExtractionInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ public String getSubdir() {
}

@Override
public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log)
throws IOException, InterruptedException {
FilePath dir = preferredLocation(tool, node);
if (dir.installIfNecessaryFrom(new URL(url), log, "Unpacking " + url + " to " + dir + " on " + node.getDisplayName())) {
if (dir.installIfNecessaryFrom(
new URL(url),
log,
"Unpacking " + url + " to " + dir + " on " + node.getDisplayName())) {
dir.act(new ChmodRecAPlusX());
}
if (subdir == null) {
return dir;
} else {
return dir.child(subdir);
}
return (subdir == null) ? dir : dir.child(subdir);
}

@Extension @Symbol("zip")
Expand All @@ -119,6 +119,7 @@ public FormValidation doCheckUrl(@QueryParameter String value) throws Interrupte
} catch (URISyntaxException e) {
return FormValidation.error(e, Messages.ZipExtractionInstaller_malformed_url());
}

if (uri.getScheme() != null && !uri.getScheme().startsWith("http")) {
try {
Path.of(uri);
Expand All @@ -127,17 +128,19 @@ public FormValidation doCheckUrl(@QueryParameter String value) throws Interrupte
return FormValidation.error(e, Messages.ZipExtractionInstaller_malformed_url());
}
}
HttpClient httpClient = ProxyConfiguration.newHttpClient();
HttpRequest httpRequest;
try {
httpRequest = ProxyConfiguration.newHttpRequestBuilder(uri)
.method("HEAD", HttpRequest.BodyPublishers.noBody())
.build();
} catch (IllegalArgumentException e) {
return FormValidation.error(e, Messages.ZipExtractionInstaller_malformed_url());
}
try {
HttpResponse<Void> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.discarding());

try (HttpClient httpClient = ProxyConfiguration.newHttpClient()) {
HttpRequest httpRequest;
try {
httpRequest = ProxyConfiguration.newHttpRequestBuilder(uri)
.method("HEAD", HttpRequest.BodyPublishers.noBody())
.build();
} catch (IllegalArgumentException e) {
return FormValidation.error(e, Messages.ZipExtractionInstaller_malformed_url());
}

HttpResponse<Void> httpResponse =
httpClient.send(httpRequest, HttpResponse.BodyHandlers.discarding());
if (httpResponse.statusCode() == HttpURLConnection.HTTP_OK) {
return FormValidation.ok();
}
Expand All @@ -146,20 +149,19 @@ public FormValidation doCheckUrl(@QueryParameter String value) throws Interrupte
return FormValidation.error(e, Messages.ZipExtractionInstaller_could_not_connect());
}
}

}

/**
* Sets execute permission on all files, since unzip etc. might not do this.
* Hackish, is there a better way?
*/
static class ChmodRecAPlusX extends MasterToSlaveFileCallable<Void> {
private static final long serialVersionUID = 1L;

@Override
public Void invoke(File d, VirtualChannel channel) throws IOException {
if (!Functions.isWindows())
if (!Functions.isWindows()) {
process(d);
}
return null;
}

Expand All @@ -176,5 +178,4 @@ private void process(File f) {
}
}
}

}