Skip to content

Commit edb4ff3

Browse files
committed
Implement external JAR class loading for log parsers and log buffer selection for device logs
1 parent c899c8a commit edb4ff3

File tree

61 files changed

+988
-249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+988
-249
lines changed

app/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ dependencies {
3434
testImplementation(Mockk.mockk)
3535
}
3636

37-
tasks.test {
38-
useJUnitPlatform()
39-
}
40-
4137
// TODO 更改应用安装后的图标
4238
compose.desktop {
4339
application {

app/proguard-rules.pro

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
-keep class me.gegenbauer.catspy.view.combobox.FilterComboBox { *; }
44
-keep class me.gegenbauer.catspy.view.combobox.FilterComboBoxModel { *; }
55
-keep class me.gegenbauer.catspy.log.ui.table.SplitLogPane { *; }
6+
-keep class me.gegenbauer.catspy.log.LogParser { *; }
7+
-keep class me.gegenbauer.catspy.log.parse.* { *; }
8+
-keep class me.gegenbauer.catspy.log.LogParser$ParseMetadata { *; }
9+
-keep class me.gegenbauer.catspy.log.SequenceLogParser { *; }
610
# CatSpy End
711

812
# occupies 9.3mb
@@ -97,4 +101,9 @@
97101

98102
# jna Start
99103
-keep class com.sun.jna.** { *; }
100-
# jna End
104+
# jna End
105+
106+
# classgraph Start
107+
-keep class nonapi.io.github.classgraph.** { *; }
108+
-keep class io.github.classgraph.** { *; }
109+
# classgraph End

app/src/main/kotlin/me/gegenbauer/catspy/ui/MainFrame.kt

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
package me.gegenbauer.catspy.ui
22

33
import kotlinx.coroutines.*
4-
import me.gegenbauer.catspy.concurrency.FileSaveEvent
5-
import me.gegenbauer.catspy.concurrency.GIO
6-
import me.gegenbauer.catspy.concurrency.GlobalEventManager
7-
import me.gegenbauer.catspy.concurrency.GlobalMessageManager
8-
import me.gegenbauer.catspy.concurrency.Message
9-
import me.gegenbauer.catspy.concurrency.NormalEvent
10-
import me.gegenbauer.catspy.concurrency.OpenAdbPathSettingsEvent
4+
import me.gegenbauer.catspy.concurrency.*
115
import me.gegenbauer.catspy.conf.GlobalConfSync
126
import me.gegenbauer.catspy.configuration.SettingsManager
137
import me.gegenbauer.catspy.configuration.currentSettings
@@ -20,8 +14,8 @@ import me.gegenbauer.catspy.ddmlib.adb.AdbConf
2014
import me.gegenbauer.catspy.ddmlib.device.AdamDeviceMonitor
2115
import me.gegenbauer.catspy.glog.GLog
2216
import me.gegenbauer.catspy.iconset.appIcons
23-
import me.gegenbauer.catspy.java.ext.*
24-
import me.gegenbauer.catspy.log.metadata.LogMetadataManager
17+
import me.gegenbauer.catspy.java.ext.EMPTY_STRING
18+
import me.gegenbauer.catspy.java.ext.KotlinReflectionPreTrigger
2519
import me.gegenbauer.catspy.network.update.ReleaseEvent
2620
import me.gegenbauer.catspy.platform.currentPlatform
2721
import me.gegenbauer.catspy.strings.STRINGS
@@ -81,7 +75,7 @@ class MainFrame(
8175

8276
preTriggerKotlinReflection()
8377

84-
loadLogMetadata()
78+
loadData()
8579
}
8680

8781
private fun createUI() {
@@ -151,12 +145,8 @@ class MainFrame(
151145
}
152146
}
153147

154-
private fun loadLogMetadata() {
155-
scope.launch {
156-
withContext(Dispatchers.GIO) {
157-
ServiceManager.getContextService(LogMetadataManager::class.java).loadAllMetadata()
158-
}
159-
}
148+
private fun loadData() {
149+
mainViewModel.loadData()
160150
}
161151

162152
private fun observeEventFlow() {

app/src/main/kotlin/me/gegenbauer/catspy/ui/MainViewModel.kt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package me.gegenbauer.catspy.ui
33
import kotlinx.coroutines.CancellationException
44
import kotlinx.coroutines.Dispatchers
55
import kotlinx.coroutines.Job
6+
import kotlinx.coroutines.async
7+
import kotlinx.coroutines.awaitAll
68
import kotlinx.coroutines.channels.BufferOverflow
79
import kotlinx.coroutines.flow.MutableSharedFlow
810
import kotlinx.coroutines.flow.SharedFlow
@@ -22,6 +24,8 @@ import me.gegenbauer.catspy.context.MemoryState
2224
import me.gegenbauer.catspy.context.ServiceManager
2325
import me.gegenbauer.catspy.file.appendPath
2426
import me.gegenbauer.catspy.glog.GLog
27+
import me.gegenbauer.catspy.log.metadata.LogMetadataManager
28+
import me.gegenbauer.catspy.log.parse.ParserManager
2529
import me.gegenbauer.catspy.network.update.GithubUpdateServiceFactory
2630
import me.gegenbauer.catspy.network.update.ReleaseEvent
2731
import me.gegenbauer.catspy.network.update.data.Release
@@ -79,7 +83,10 @@ class MainViewModel(override val contexts: Contexts = Contexts.default) : Contex
7983
scope.launch {
8084
val latestReleaseResult = updateService.getLatestRelease()
8185
if (latestReleaseResult.isFailure) {
82-
GLog.w(TAG, "[checkUpdate] failed to get latest release, error=${latestReleaseResult.exceptionOrNull()}")
86+
GLog.w(
87+
TAG,
88+
"[checkUpdate] failed to get latest release, error=${latestReleaseResult.exceptionOrNull()}"
89+
)
8390
if (force) {
8491
_eventFlow.emit(ReleaseEvent.ErrorEvent(latestReleaseResult.exceptionOrNull()))
8592
}
@@ -145,7 +152,10 @@ class MainViewModel(override val contexts: Contexts = Contexts.default) : Contex
145152
return withContext(Dispatchers.GIO) {
146153
val logFile = getLastModifiedLog()
147154
logFile?.let { sourceFile ->
148-
GLog.d(TAG, "[exportLog] targetLogFile=${targetFile.absolutePath}, sourceLogFile=${sourceFile.absolutePath}")
155+
GLog.d(
156+
TAG,
157+
"[exportLog] targetLogFile=${targetFile.absolutePath}, sourceLogFile=${sourceFile.absolutePath}"
158+
)
149159

150160
val taskName = STRINGS.ui.exportFileTaskTitle.get(targetFile.absolutePath)
151161
val task = Task(taskName, object : TaskHandle {
@@ -176,6 +186,21 @@ class MainViewModel(override val contexts: Contexts = Contexts.default) : Contex
176186
}
177187
}
178188

189+
fun loadData() {
190+
scope.launch {
191+
listOf(
192+
async {
193+
val logMetadataManager = ServiceManager.getContextService(LogMetadataManager::class.java)
194+
logMetadataManager.loadAllMetadata()
195+
},
196+
async {
197+
val parserManager = ServiceManager.getContextService(ParserManager::class.java)
198+
parserManager.loadParsers()
199+
}
200+
).awaitAll()
201+
}
202+
}
203+
179204
private fun stopMemoryMonitor() {
180205
memoryMonitorJob?.cancel()
181206
}

build.gradle.kts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// build.gradle.kts 文件
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
23
plugins {
34
// this is necessary to avoid the plugins to be loaded multiple times
45
// in each subproject's classloader
@@ -15,4 +16,12 @@ allprojects {
1516
mavenCentral()
1617
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
1718
}
19+
20+
tasks.withType<KotlinCompile> {
21+
kotlinOptions {
22+
jvmTarget = "17"
23+
freeCompilerArgs += "-Xdebug"
24+
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
25+
}
26+
}
1827
}

buildSrc/src/main/kotlin/VersionManagement.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ object Oshi {
145145
val oshiCore = Dependency(GROUP_NAME, "oshi-core", VERSION)
146146
}
147147

148+
object ClassGraph {
149+
private const val GROUP_NAME = "io.github.classgraph"
150+
private const val VERSION = "4.8.179"
151+
152+
val classGraph = Dependency(GROUP_NAME, "classgraph", VERSION)
153+
}
154+
148155
data class Dependency(
149156
val group: String,
150157
val artifact: String,

cache/src/test/kotlin/me/gegenbauer/catspy/cache/PatternProviderTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class PatternProviderTest {
2121
}
2222

2323
@Test
24-
fun `should return cached pattern when requested key is alreaady in cache`() {
24+
fun `should return cached pattern when requested key is already in cache`() {
2525
// Given
2626
val patternProvider = PatternProvider()
2727
val patternKey = PatternKey("test")

catspy-log-parser.jar

4.83 KB
Binary file not shown.

concurrency/build.gradle.kts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,4 @@ dependencies {
99
implementation(projects.javaext)
1010
api(Kotlin.coroutineCore)
1111
api(Kotlin.coroutineSwing)
12-
}
13-
14-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
15-
kotlinOptions {
16-
jvmTarget = "17"
17-
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
18-
}
1912
}

concurrency/src/main/kotlin/me/gegenbauer/catspy/concurrency/IgnoreFastCallbackScheduler.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class IgnoreFastCallbackScheduler(
2424
}
2525

2626
override fun cancel() {
27+
job?.cancel()
28+
}
29+
30+
override fun destroy() {
2731
scope.cancel()
2832
}
2933
}
@@ -32,6 +36,8 @@ interface CallbackSchedule {
3236
fun schedule(callback: Callback)
3337

3438
fun cancel()
39+
40+
fun destroy()
3541
}
3642

3743
fun interface Callback {

0 commit comments

Comments
 (0)