Skip to content

Commit 3ea86f1

Browse files
committed
Merge branch 'master' into live-insight
2 parents 6912cc4 + f5b5b89 commit 3ea86f1

File tree

20 files changed

+174
-103
lines changed

20 files changed

+174
-103
lines changed

src/main/kotlin/spp/protocol/artifact/ArtifactQualifiedName.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ data class ArtifactQualifiedName(
3030
val identifier: String,
3131
val commitId: String? = null,
3232
val type: ArtifactType,
33-
val lineNumber: Int? = null,
34-
val operationName: String? = null //todo: only method artifacts need
33+
val lineNumber: Int? = null
3534
) {
3635

3736
constructor(json: JsonObject) : this(
3837
json.getString("identifier"),
3938
json.getString("commitId"),
4039
ArtifactType.valueOf(json.getString("type")),
41-
json.getInteger("lineNumber"),
42-
json.getString("operationName")
40+
json.getInteger("lineNumber")
4341
)
4442

4543
fun toJson(): JsonObject {
@@ -48,7 +46,6 @@ data class ArtifactQualifiedName(
4846
json.put("commitId", commitId)
4947
json.put("type", type.name)
5048
json.put("lineNumber", lineNumber)
51-
json.put("operationName", operationName)
5249
return json
5350
}
5451

src/main/kotlin/spp/protocol/artifact/OrderType.kt

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/main/kotlin/spp/protocol/artifact/log/LogOrderType.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,13 @@
1616
*/
1717
package spp.protocol.artifact.log
1818

19-
import spp.protocol.artifact.OrderType
20-
2119
/**
22-
* todo: description.
20+
* Represents a known order type for sorting logs.
2321
*
2422
* @since 0.2.0
2523
* @author [Brandon Fergerson](mailto:[email protected])
2624
*/
27-
enum class LogOrderType : OrderType {
25+
enum class LogOrderType {
2826
NEWEST_LOGS,
29-
OLDEST_LOGS;
30-
31-
//todo: not need to replace _LOGS?
32-
val id = name.replace("_LOGS", "").toLowerCase()
33-
override val description = id.toLowerCase().capitalize()
27+
OLDEST_LOGS
3428
}

src/main/kotlin/spp/protocol/artifact/trace/TraceOrderType.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,14 @@
1616
*/
1717
package spp.protocol.artifact.trace
1818

19-
import spp.protocol.artifact.OrderType
20-
2119
/**
22-
* todo: description.
20+
* Represents a known order type for sorting traces.
2321
*
2422
* @since 0.1.0
2523
* @author [Brandon Fergerson](mailto:[email protected])
2624
*/
27-
enum class TraceOrderType : OrderType {
25+
enum class TraceOrderType {
2826
LATEST_TRACES,
2927
SLOWEST_TRACES,
30-
FAILED_TRACES;
31-
32-
//todo: not need to replace _TRACES?
33-
val id = name.replace("_TRACES", "").toLowerCase()
34-
override val description = id.toLowerCase().capitalize()
35-
val fullDescription = name.toLowerCase().split("_").joinToString(" ") { it.capitalize() }
28+
FAILED_TRACES
3629
}

src/main/kotlin/spp/protocol/instrument/LiveBreakpoint.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,17 @@ data class LiveBreakpoint(
117117
/**
118118
* Specify explicitly so Kotlin doesn't override.
119119
*/
120+
@Suppress("RedundantOverride")
120121
override fun equals(other: Any?): Boolean = super.equals(other)
121122

122123
/**
123124
* Specify explicitly so Kotlin doesn't override.
124125
*/
126+
@Suppress("RedundantOverride")
125127
override fun hashCode(): Int = super.hashCode()
126128

127129
fun addHitListener(vertx: Vertx, listener: (LiveBreakpointHit) -> Unit) {
128-
val instrumentId = id
129-
if (instrumentId == null) {
130-
error("Instrument must be applied before adding a hit listener")
131-
}
132-
130+
val instrumentId = id ?: error("Instrument must be applied before adding a hit listener")
133131
vertx.eventBus().consumer<JsonObject>(toLiveInstrumentSubscription(instrumentId)).handler {
134132
val event = LiveInstrumentEvent.fromJson(it.body())
135133
if (event.eventType == LiveInstrumentEventType.BREAKPOINT_HIT) {

src/main/kotlin/spp/protocol/instrument/location/LiveLocation.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package spp.protocol.instrument.location
1818

19+
import io.vertx.core.json.JsonObject
1920
import spp.protocol.platform.general.Service
2021

2122
/**
@@ -24,4 +25,17 @@ import spp.protocol.platform.general.Service
2425
interface LiveLocation {
2526
val service: Service?
2627
val probeId: String?
28+
29+
fun isSameLocation(location: LiveLocation): Boolean
30+
fun toJson(): JsonObject
31+
32+
companion object {
33+
fun fromJson(json: JsonObject): LiveLocation {
34+
return if (json.containsKey("source")) {
35+
LiveSourceLocation(json)
36+
} else {
37+
Service(json)
38+
}
39+
}
40+
}
2741
}

src/main/kotlin/spp/protocol/instrument/location/LiveSourceLocation.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ data class LiveSourceLocation @JvmOverloads constructor(
3636
val scope: LocationScope = LocationScope.LINE
3737
) : LiveLocation, Comparable<LiveSourceLocation> {
3838

39+
init {
40+
require(source.isNotBlank()) { "source is required" }
41+
}
42+
3943
constructor(json: JsonObject) : this(
4044
source = json.getString("source"),
4145
line = json.getInteger("line") ?: -1,
@@ -51,7 +55,16 @@ data class LiveSourceLocation @JvmOverloads constructor(
5155
scope = json.getString("scope")?.let { LocationScope.valueOf(it) } ?: LocationScope.LINE
5256
)
5357

54-
fun toJson(): JsonObject {
58+
override fun isSameLocation(location: LiveLocation): Boolean {
59+
if (location !is LiveSourceLocation) return false
60+
if (source != location.source) return false
61+
if (line != location.line && line != -1 && location.line != -1) return false //-1 is wildcard
62+
if (service != null && (location.service == null || !service.isSameLocation(location.service!!))) return false
63+
if (probeId != null && probeId != location.probeId) return false
64+
return true
65+
}
66+
67+
override fun toJson(): JsonObject {
5568
val json = JsonObject()
5669
json.put("source", source)
5770
json.put("line", line)
@@ -70,7 +83,7 @@ data class LiveSourceLocation @JvmOverloads constructor(
7083
fun isSameLocation(other: LiveSourceLocation): Boolean {
7184
if (source != other.source) return false
7285
if (line != other.line && line != -1 && other.line != -1) return false //-1 is wildcard
73-
if (service != null && (other.service == null || !service.isSameService(other.service))) return false
86+
if (service != null && (other.service == null || !service.isSameLocation(other.service))) return false
7487
if (probeId != null && probeId != other.probeId) return false
7588
return true
7689
}

src/main/kotlin/spp/protocol/platform/auth/RolePermission.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ enum class RolePermission(val manager: Boolean, val commandType: CommandType) {
8484
BREAKPOINT_VARIABLE_CONTROL(false, LIVE_INSTRUMENT),
8585

8686
//views
87-
ADD_LIVE_VIEW_SUBSCRIPTION(false, LIVE_VIEW),
88-
REMOVE_LIVE_VIEW_SUBSCRIPTION(false, LIVE_VIEW),
89-
GET_LIVE_VIEW_SUBSCRIPTIONS(false, LIVE_VIEW),
87+
ADD_LIVE_VIEW(false, LIVE_VIEW),
88+
REMOVE_LIVE_VIEW(false, LIVE_VIEW),
89+
GET_LIVE_VIEWS(false, LIVE_VIEW),
9090

9191
// VIEW_OVERVIEW(false, LIVE_VIEW),
9292
VIEW_ACTIVITY(false, LIVE_VIEW),
@@ -95,7 +95,20 @@ enum class RolePermission(val manager: Boolean, val commandType: CommandType) {
9595
SHOW_QUICK_STATS(false, LIVE_VIEW);
9696

9797
companion object {
98-
fun fromString(s: String): RolePermission? {
98+
fun fromString(s: String): RolePermission {
99+
return fromStringOrNull(s) ?: RolePermission.valueOf(s)
100+
}
101+
102+
fun fromStringOrNull(s: String): RolePermission? {
103+
//todo: remove v0.8.0+
104+
if (s == "ADD_LIVE_VIEW_SUBSCRIPTION") {
105+
return ADD_LIVE_VIEW
106+
} else if (s == "REMOVE_LIVE_VIEW_SUBSCRIPTION") {
107+
return REMOVE_LIVE_VIEW
108+
} else if (s == "GET_LIVE_VIEW_SUBSCRIPTIONS") {
109+
return GET_LIVE_VIEWS
110+
}
111+
99112
val exactMatch = values().firstOrNull { it.name.equals(s, true) }
100113
if (exactMatch != null) {
101114
return exactMatch

src/main/kotlin/spp/protocol/platform/developer/SelfInfo.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ data class SelfInfo(
3333
constructor(json: JsonObject) : this(
3434
developer = Developer(json.getJsonObject("developer")),
3535
roles = json.getJsonArray("roles").map { DeveloperRole.fromString(it.toString()) },
36-
permissions = json.getJsonArray("permissions")
37-
.map { RolePermission.fromString(it.toString()) ?: error("Invalid permission: $it") },
36+
permissions = json.getJsonArray("permissions").map { RolePermission.fromString(it.toString()) },
3837
access = json.getJsonArray("access").map { AccessPermission(JsonObject.mapFrom(it)) }
3938
)
4039

src/main/kotlin/spp/protocol/platform/general/Service.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
*/
1717
package spp.protocol.platform.general
1818

19+
import com.fasterxml.jackson.annotation.JsonIgnore
1920
import io.vertx.codegen.annotations.DataObject
21+
import io.vertx.codegen.annotations.GenIgnore
2022
import io.vertx.core.json.JsonObject
23+
import spp.protocol.instrument.location.LiveLocation
2124
import spp.protocol.platform.general.util.IDManager
2225

2326
/**
@@ -34,7 +37,16 @@ data class Service(
3437
val normal: Boolean = true,
3538
val environment: String? = null,
3639
val version: String? = null
37-
) {
40+
) : LiveLocation {
41+
42+
@GenIgnore
43+
@get:JsonIgnore
44+
@delegate:JsonIgnore
45+
override val service: Service by lazy { this }
46+
47+
@GenIgnore
48+
@get:JsonIgnore
49+
override val probeId: String? = null
3850

3951
val id by lazy {
4052
if (version != null) {
@@ -54,7 +66,7 @@ data class Service(
5466
json.getString("version")
5567
)
5668

57-
fun toJson(): JsonObject {
69+
override fun toJson(): JsonObject {
5870
val json = JsonObject()
5971
json.put("name", name)
6072
json.put("group", group)
@@ -77,7 +89,8 @@ data class Service(
7789
/**
7890
* Ensures all non-null fields are equal.
7991
*/
80-
fun isSameService(other: Service): Boolean {
92+
override fun isSameLocation(location: LiveLocation): Boolean {
93+
val other = location.service ?: return false
8194
if (name != other.name) return false
8295
if (group != null && group != other.group) return false
8396
if (shortName != null && shortName != other.shortName) return false

0 commit comments

Comments
 (0)