Skip to content
Merged
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
1 change: 1 addition & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
testImplementation("org.apache.commons:commons-compress:1.28.0")
testImplementation("org.apache.commons:commons-text:1.15.0")
}

gradlePlugin {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ryandens.javaagent

import org.apache.commons.text.StringEscapeUtils
import org.gradle.internal.jvm.Jvm
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
Expand Down Expand Up @@ -213,7 +214,7 @@ DEFAULT_JVM_OPTS="-javaagent:${"$"}APP_HOME/lib/simple-agent.jar -Xmx256m"
Paths.get("..", "simple-agent").toFile().copyRecursively(simpleAgentTestDir)
simpleAgentBuildScript.writeText(
simpleAgentBuildScript.readText().replace(
"id(\"com.ryandens.java-conventions\")\n",
"id(\"com.ryandens.java-conventions\")",
"",
),
)
Expand All @@ -226,6 +227,8 @@ DEFAULT_JVM_OPTS="-javaagent:${"$"}APP_HOME/lib/simple-agent.jar -Xmx256m"
""",
)

val commandLine = StringEscapeUtils.escapeJava(""".${File.separator}hello-world""")
val javaHome = StringEscapeUtils.escapeJava(Jvm.current().getJavaHome().toString())
helloWorldDir.resolve("build.gradle").writeText(
"""
plugins {
Expand All @@ -251,8 +254,8 @@ DEFAULT_JVM_OPTS="-javaagent:${"$"}APP_HOME/lib/simple-agent.jar -Xmx256m"
dependsOn('installDist')
inputs.files(layout.buildDirectory.dir('install'))
workingDir(layout.buildDirectory.dir('install').map { it.dir('hello-world').dir('bin') })
commandLine '.${File.separator}hello-world'
environment JAVA_HOME: "${Jvm.current().getJavaHome()}"
commandLine '$commandLine'
environment JAVA_HOME: "$javaHome"
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Set;
import java.util.stream.Collectors;
import org.gradle.api.provider.Provider;
import org.gradle.internal.os.OperatingSystem;
import org.gradle.process.CommandLineArgumentProvider;
import org.gradle.process.JavaForkOptions;

Expand Down Expand Up @@ -42,7 +43,12 @@ public Iterable<String> asArguments() {
.map(
file -> {
try {
return "-javaagent:" + file.getCanonicalPath();
String path = file.getCanonicalPath();
if (OperatingSystem.current().isWindows()) {
// Don't let the spaces in the Windows path break the command line
path = '"' + path + '"';
}
return "-javaagent:" + path;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Loading