Skip to content

Commit 10cb6f5

Browse files
committed
fix-paths-with-spaces-in-java-tool-options
1 parent df40dff commit 10cb6f5

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

jvm-common/src/main/kotlin/org/digma/intellij/plugin/idea/execution/JavaToolOptionsBuilder.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ open class JavaToolOptionsBuilder(
5454

5555
//digma agent must be before otel agent in the command line
5656
javaToolOptions
57-
.append("-javaagent:${otelAgentPathProvider.digmaAgentPath}")
57+
.append("-javaagent:${quote(otelAgentPathProvider.digmaAgentPath)}")
5858
.append(" ")
5959

6060

6161
javaToolOptions
62-
.append("-javaagent:${otelAgentPathProvider.otelAgentPath}")
62+
.append("-javaagent:${quote(otelAgentPathProvider.otelAgentPath)}")
6363
.append(" ")
6464

6565
val useExtension: String? = System.getProperty("org.digma.plugin.useOtelExtension")
6666
if (useExtension == null || useExtension == "true") {
6767
if (otelAgentPathProvider.digmaExtensionPath != null) {
6868
javaToolOptions
69-
.append("-Dotel.javaagent.extensions=${otelAgentPathProvider.digmaExtensionPath}")
69+
.append("-Dotel.javaagent.extensions=${quote(otelAgentPathProvider.digmaExtensionPath)}")
7070
.append(" ")
7171
}
7272
}
@@ -272,7 +272,7 @@ open class JavaToolOptionsBuilder(
272272
): JavaToolOptionsBuilder {
273273
if (!parametersExtractor.isOtelServiceNameAlreadyDefined()) {
274274
javaToolOptions
275-
.append("-Dotel.service.name=${serviceNameProvider.provideServiceName(moduleResolver)}")
275+
.append("-Dotel.service.name=${quote(serviceNameProvider.provideServiceName(moduleResolver))}")
276276
.append(" ")
277277
}
278278
return this
@@ -284,7 +284,7 @@ open class JavaToolOptionsBuilder(
284284
if (isTest) {
285285
val envPart = "$DIGMA_ENVIRONMENT_NAME_RESOURCE_ATTRIBUTE=$LOCAL_TESTS_ENV"
286286
javaToolOptions
287-
.append("-Dquarkus.otel.resource.attributes=\"$envPart\"")
287+
.append("-Dquarkus.otel.resource.attributes=${quote(envPart)}")
288288
.append(" ")
289289
.append("-Dquarkus.otel.bsp.schedule.delay=1") // set delay to 1 millisecond
290290
.append(" ")
@@ -331,6 +331,13 @@ open class JavaToolOptionsBuilder(
331331
return SettingsState.getInstance().extendedObservability.isNullOrBlank().not()
332332
}
333333

334+
335+
//use quote() to quote string in system properties that may contain spaces and other special characters
336+
private fun quote(str:String?): String? {
337+
return str?.let {
338+
"\"".plus(it).plus("\"")
339+
}
340+
}
334341
}
335342

336343

jvm-common/src/main/kotlin/org/digma/intellij/plugin/idea/execution/OtelAgentPathProvider.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import org.digma.intellij.plugin.common.FileUtils
1111

1212
class OtelAgentPathProvider(configuration: RunConfiguration) {
1313

14+
//Note that these paths may contain spaces. consider that when using these paths.
15+
//for example when used in java tool options as system properties they need to be quoted.
1416
val otelAgentPath: String?
1517
val digmaExtensionPath: String?
1618
val digmaAgentPath: String?

0 commit comments

Comments
 (0)