Skip to content

Commit 84eb612

Browse files
committed
Remove java agent from test run classpath
1 parent 9fd4a6b commit 84eb612

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

src/main/scala/com/lightbend/sbt/javaagent/JavaAgent.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ object JavaAgent extends AutoPlugin {
6464
fork in run := enableFork(fork in run, _.scope.run).value,
6565
fork in Test := enableFork(fork in Test, _.scope.test).value,
6666
javaOptions in run ++= agentOptions(_.agent.scope.run).value,
67-
javaOptions in Test ++= agentOptions(_.agent.scope.test).value
67+
javaOptions in Test ++= agentOptions(_.agent.scope.test).value,
68+
fullClasspath in Test := filterAgents((fullClasspath in Test).value, resolvedJavaAgents.value)
6869
)
6970

7071
private def resolveAgents = Def.task[Seq[ResolvedAgent]] {
@@ -93,4 +94,8 @@ object JavaAgent extends AutoPlugin {
9394
}
9495
}
9596

97+
def filterAgents(classpath: Classpath, resolvedAgents: Seq[ResolvedAgent]): Classpath = {
98+
val agents = resolvedAgents.map(resolved => resolved.artifact.absolutePath)
99+
classpath.filter(aFile => !agents.contains(aFile.data.getAbsolutePath))
100+
}
96101
}

src/sbt-test/agent/compile/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
> check-log
55
> stage
66
> check-dist
7+
> check-test-and-run-paths

src/sbt-test/agent/compile/test.sbt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,18 @@ TaskKey[Unit]("check-dist") := {
1919
expect("dist run", output, "Agent 86")
2020
expect("dist run", output, "class maxwell.Maxwell")
2121
}
22+
23+
TaskKey[Unit]("check-test-and-run-paths") := {
24+
assert(
25+
!((dependencyClasspath in Runtime).value exists (f => f.data.name.contains("maxwell"))),
26+
"maxwell test agent is available on the runtime class path"
27+
)
28+
assert(
29+
(dependencyClasspath in Test).value exists (f => f.data.name.contains("maxwell")),
30+
"maxwell test agent is not available on the test compile class path"
31+
)
32+
assert(
33+
!((fullClasspath in Test).value exists (f => f.data.name.contains("maxwell"))),
34+
"maxwell test agent is available on the test run class path"
35+
)
36+
}

src/sbt-test/agent/test/test.sbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ TaskKey[Unit]("check") := {
99
"javaOptions in Test do not contain 'maxwell' agent"
1010
)
1111

12+
assert(
13+
!((fullClasspath in Test).value exists (f => f.data.name.contains("maxwell"))),
14+
"maxwell test agent is available on the test run class path"
15+
)
16+
1217
val testLog = IO.read(BuiltinCommands.lastLogFile(state.value).get)
1318

1419
assert(

0 commit comments

Comments
 (0)