Skip to content

Commit 45e671f

Browse files
More code review fixes
1 parent 5c9eba0 commit 45e671f

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

‎build.gradle.kts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ val jlink = tasks.register<JlinkTask>(JlinkTask.DEFAULT_TASK_NAME) {
5353

5454
options = listOf("--strip-debug", "--no-header-files", "--no-man-pages", "--ignore-modified-runtime", "--generate-cds-archive")
5555
modules = listOf(
56-
"java.instrument", // for JUnit
57-
"java.management", // for OpenTelemetry
58-
"java.naming", // for Logback
59-
"java.sql", // for Tika
60-
"jdk.unsupported" // for Gson
56+
"java.instrument", // for JUnit
57+
"java.management", // for OpenTelemetry
58+
"java.naming", // for Logback
59+
"java.sql", // for Tika
60+
"jdk.unsupported" // for Gson
6161
)
6262
includeModulePath = false
6363
javaCompiler = javaToolchains.compilerFor(java.toolchain)
@@ -98,16 +98,24 @@ tasks.test {
9898
}
9999
}
100100

101+
application {
102+
mainClass = "com.github.stickerifier.stickerify.runner.Main"
103+
applicationDefaultJvmArgs = listOf("--enable-final-field-mutation=ALL-UNNAMED")
104+
}
105+
101106
val openTelemetryAgent = tasks.register<DownloadOpenTelemetryAgentTask>(DownloadOpenTelemetryAgentTask.DEFAULT_TASK_NAME) {
102107
description = "Downloads the OpenTelemetry agent for the distribution package."
103108

104109
version = libs.versions.opentelemetry.get()
105110
destinationFile = layout.buildDirectory.file("openTelemetryAgent/opentelemetry-javaagent.jar")
106111
}
107112

108-
application {
109-
mainClass = "com.github.stickerifier.stickerify.runner.Main"
110-
applicationDefaultJvmArgs = listOf("--enable-final-field-mutation=ALL-UNNAMED", "-javaagent:" + openTelemetryAgent.get().destinationFile.get().asFile.name)
113+
tasks.named<CreateStartScripts>(ApplicationPlugin.TASK_START_SCRIPTS_NAME) {
114+
val agentJarName = openTelemetryAgent.get().destinationFile.get().asFile.name
115+
defaultJvmOpts = (defaultJvmOpts ?: emptyList()) + "-javaagent:$agentJarName"
116+
117+
(unixStartScriptGenerator as TemplateBasedScriptGenerator).template = resources.text.fromFile("src/main/resources/customUnixStartScript.txt")
118+
(windowsStartScriptGenerator as TemplateBasedScriptGenerator).template = resources.text.fromFile("src/main/resources/customWindowsStartScript.txt")
111119
}
112120

113121
distributions {
@@ -118,8 +126,3 @@ distributions {
118126
}
119127
}
120128
}
121-
122-
tasks.named<CreateStartScripts>(ApplicationPlugin.TASK_START_SCRIPTS_NAME) {
123-
(unixStartScriptGenerator as TemplateBasedScriptGenerator).template = resources.text.fromFile("src/main/resources/customUnixStartScript.txt")
124-
(windowsStartScriptGenerator as TemplateBasedScriptGenerator).template = resources.text.fromFile("src/main/resources/customWindowsStartScript.txt")
125-
}

‎buildSrc/src/main/java/com/github/stickerifier/stickerify/DownloadOpenTelemetryAgentTask.java‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ public abstract class DownloadOpenTelemetryAgentTask extends DefaultTask {
2121
@Input
2222
public abstract Property<@NotNull String> getVersion();
2323

24+
@Input
25+
public abstract Property<@NotNull Integer> getDownloadTimeoutMillis();
26+
2427
@OutputFile
2528
public abstract RegularFileProperty getDestinationFile();
2629

2730
@Inject
2831
public DownloadOpenTelemetryAgentTask() {
2932
setGroup("distribution");
3033
setDescription("Downloads OpenTelemetry agent jar.");
34+
35+
getDownloadTimeoutMillis().convention(12000);
3136
}
3237

3338
@TaskAction
@@ -37,7 +42,13 @@ public void downloadJar() throws IOException {
3742
var targetFile = getDestinationFile().get().getAsFile();
3843

3944
var _ = targetFile.getParentFile().mkdirs();
40-
try (var inputStream = URI.create(urlString).toURL().openStream()) {
45+
46+
var connection = URI.create(urlString).toURL().openConnection();
47+
int timeoutMillis = getDownloadTimeoutMillis().get();
48+
connection.setConnectTimeout(timeoutMillis);
49+
connection.setReadTimeout(timeoutMillis);
50+
51+
try (var inputStream = connection.getInputStream()) {
4152
Files.copy(inputStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
4253
}
4354
}

0 commit comments

Comments
 (0)