Skip to content

Commit adaad47

Browse files
committed
chore: ignore internal groovy variables
ref: sourceplusplus/sourceplusplus#905
1 parent 5ee29bd commit adaad47

File tree

4 files changed

+121
-1
lines changed

4 files changed

+121
-1
lines changed

boot/build.gradle.kts

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
id("java")
66
id("org.jetbrains.kotlin.jvm")
77
id("maven-publish")
8+
id("groovy")
89
}
910

1011
val probeGroup: String by project
@@ -75,6 +76,7 @@ dependencies {
7576
testImplementation("io.vertx:vertx-service-proxy:$vertxVersion")
7677
testImplementation("io.vertx:vertx-service-discovery:$vertxVersion")
7778
testImplementation("io.vertx:vertx-lang-kotlin-coroutines:$vertxVersion")
79+
testImplementation("org.codehaus.groovy:groovy-all:3.0.13")
7880
}
7981

8082
tasks.test {
@@ -206,3 +208,7 @@ fun projectDependency(name: String): ProjectDependency {
206208
DependencyHandlerScope.of(rootProject.dependencies).project(":probes:jvm$name")
207209
}
208210
}
211+
212+
tasks.named<GroovyCompile>("compileTestGroovy") {
213+
classpath += files(tasks.compileTestKotlin)
214+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Source++, the continuous feedback platform for developers.
3+
* Copyright (C) 2022-2023 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package integration.breakpoint
18+
19+
import integration.ProbeIntegrationTest
20+
import io.vertx.junit5.VertxTestContext
21+
import org.junit.jupiter.api.Test
22+
import spp.protocol.instrument.LiveBreakpoint
23+
import spp.protocol.instrument.event.LiveBreakpointHit
24+
import spp.protocol.instrument.event.LiveInstrumentEvent
25+
import spp.protocol.instrument.event.LiveInstrumentEventType
26+
import spp.protocol.instrument.location.LiveSourceLocation
27+
import spp.protocol.instrument.throttle.InstrumentThrottle
28+
29+
import static org.junit.jupiter.api.Assertions.assertEquals
30+
import static org.junit.jupiter.api.Assertions.assertNotNull
31+
32+
class GroovyBreakpointTest extends ProbeIntegrationTest {
33+
34+
private void doTest() {
35+
def a = null
36+
def b = 1
37+
def c = 'a'
38+
def d = "a"
39+
def e = true
40+
def f = 1.0
41+
def g = 1.0f
42+
def h = 1L
43+
}
44+
45+
@Test
46+
void testGroovy() {
47+
def breakpointId = "groovy-breakpoint-test"
48+
def testContext = new VertxTestContext()
49+
getLiveInstrumentSubscription(breakpointId).handler {
50+
def body = it.body()
51+
testContext.verify {
52+
def event = LiveInstrumentEvent.fromJson(body)
53+
if (event.eventType == LiveInstrumentEventType.BREAKPOINT_HIT) {
54+
def item = event as LiveBreakpointHit
55+
def vars = item.stackTrace.first().variables
56+
assertEquals(8, vars.size())
57+
58+
assertNotNull(vars.stream().find { it.name == "a" })
59+
assertNotNull(vars.stream().find { it.name == "b" })
60+
assertNotNull(vars.stream().find { it.name == "c" })
61+
assertNotNull(vars.stream().find { it.name == "d" })
62+
assertNotNull(vars.stream().find { it.name == "e" })
63+
assertNotNull(vars.stream().find { it.name == "f" })
64+
assertNotNull(vars.stream().find { it.name == "g" })
65+
66+
testContext.completeNow()
67+
}
68+
}
69+
}
70+
71+
instrumentService.addLiveInstrument(
72+
new LiveBreakpoint(
73+
null,
74+
new LiveSourceLocation(
75+
GroovyBreakpointTest.class.name,
76+
42, //todo: breaks if bp on return
77+
"spp-test-probe"
78+
),
79+
null,
80+
null,
81+
1,
82+
breakpointId,
83+
true,
84+
false,
85+
false,
86+
InstrumentThrottle.DEFAULT,
87+
new HashMap<String, Object>()
88+
)
89+
).onComplete {
90+
if (it.succeeded()) {
91+
log.info("Triggering breakpoint")
92+
doTest()
93+
} else {
94+
testContext.failNow(it.cause())
95+
}
96+
}
97+
98+
errorOnTimeout(testContext, 2000)
99+
}
100+
}

boot/src/test/kotlin/integration/ProbeIntegrationTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ abstract class ProbeIntegrationTest {
149149
return vertx.eventBus().localConsumer(listenAddress)
150150
}
151151

152+
@JvmStatic
152153
fun getLiveInstrumentSubscription(instrumentId: String): MessageConsumer<JsonObject> {
153154
val listenAddress = toLiveInstrumentSubscription(instrumentId)
154155

services/src/main/kotlin/spp/probe/services/common/model/ClassMetadata.kt

+14-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class ClassMetadata(val outerClass: Boolean) : Serializable {
2727
private val ignoredVariables = Pattern.compile(
2828
"(_\\\$EnhancedClassField_ws)|((delegate|cachedValue)\\$[a-zA-Z0-9\$]+)"
2929
)
30+
private val ignoredTypes = setOf(
31+
"Lgroovy/lang/MetaClass;"
32+
)
3033
}
3134

3235
val innerClasses = mutableListOf<Class<*>>()
@@ -39,7 +42,11 @@ class ClassMetadata(val outerClass: Boolean) : Serializable {
3942
}
4043

4144
fun addField(field: ClassField) {
42-
if (ignoredVariables.matcher(field.name).matches()) {
45+
if (field.name.contains("$")) {
46+
return //ignore synthetic variables
47+
} else if (ignoredTypes.contains(field.desc)) {
48+
return
49+
} else if (ignoredVariables.matcher(field.name).matches()) {
4350
return
4451
}
4552

@@ -51,6 +58,12 @@ class ClassMetadata(val outerClass: Boolean) : Serializable {
5158
}
5259

5360
fun addVariable(methodId: String, variable: LocalVariable) {
61+
if (variable.name.contains("$")) {
62+
return //ignore synthetic variables
63+
} else if (ignoredTypes.contains(variable.desc)) {
64+
return
65+
}
66+
5467
variables.computeIfAbsent(methodId) { ArrayList() }
5568
variables[methodId]!!.add(variable)
5669
}

0 commit comments

Comments
 (0)