Repository navigation
Expand file tree
/
Copy pathDownloadOpenTelemetryAgentTask.java
More file actions
56 lines (42 loc) · 1.73 KB
/
Copy pathDownloadOpenTelemetryAgentTask.java
File metadata and controls
56 lines (42 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.github.stickerifier.stickerify;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.jetbrains.annotations.NotNull;
import javax.inject.Inject;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
public abstract class DownloadOpenTelemetryAgentTask extends DefaultTask {
public static final String DEFAULT_TASK_NAME = "downloadOpenTelemetryAgent";
@Input
public abstract Property<@NotNull String> getVersion();
@Input
public abstract Property<@NotNull Integer> getDownloadTimeoutMillis();
@OutputFile
public abstract RegularFileProperty getDestinationFile();
@Inject
public DownloadOpenTelemetryAgentTask() {
setGroup("distribution");
setDescription("Downloads OpenTelemetry agent jar.");
getDownloadTimeoutMillis().convention(12000);
}
@TaskAction
public void downloadJar() throws IOException {
var version = getVersion().get();
var urlString = "https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v%s/opentelemetry-javaagent.jar".formatted(version);
var targetFile = getDestinationFile().get().getAsFile();
var _ = targetFile.getParentFile().mkdirs();
var connection = URI.create(urlString).toURL().openConnection();
int timeoutMillis = getDownloadTimeoutMillis().get();
connection.setConnectTimeout(timeoutMillis);
connection.setReadTimeout(timeoutMillis);
try (var inputStream = connection.getInputStream()) {
Files.copy(inputStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
}