Skip to content

Commit 3ca6eb4

Browse files
authored
#1567 | CCv2 | Unscramble Json Stacktrace
1 parent b4d7675 commit 3ca6eb4

File tree

7 files changed

+181
-0
lines changed

7 files changed

+181
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Display parent non-root logger below the logger entry [#1556](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1556)
1313
- Display bundled loggers templates in the Loggers toolwindow [#1538](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1538)
1414
- Preserve view position on reloading remote loggers [#1561](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1561)
15+
- Added unscrambler for JSON Stacktraces from SAP CX Cloud Logging [#1567](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1567)
1516

1617
### `Spring` enhancements
1718
- Improved simple Spring bean resolution for IntelliJ Community edition [#1563](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1563)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA.
3+
* Copyright (C) 2019-2025 EPAM Systems <[email protected]> and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13+
* See the GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package sap.commerce.toolset.ccv2.unscramble
20+
21+
import com.intellij.openapi.components.Service
22+
import com.intellij.openapi.components.service
23+
import com.intellij.util.application
24+
import kotlinx.serialization.SerializationException
25+
import kotlinx.serialization.json.*
26+
27+
@Service
28+
class CCv2UnscrambleService {
29+
30+
fun canHandle(text: String) = getThrown(text) != null
31+
32+
fun buildStackTraceString(text: String): String? = getThrown(text)
33+
?.let { buildStackTraceString(it) }
34+
35+
private fun buildStackTraceString(obj: JsonObject, indent: String = ""): String = buildString {
36+
val name = obj["name"]?.jsonPrimitive?.contentOrNull ?: "java.lang.Exception"
37+
val message = obj["message"]?.jsonPrimitive?.contentOrNull ?: ""
38+
39+
append("$indent$name: $message\n")
40+
41+
obj["extendedStackTrace"]
42+
?.jsonArray
43+
?.map { it.jsonObject }
44+
?.forEach {
45+
val className = it["class"]?.jsonPrimitive?.contentOrNull ?: "UnknownClass"
46+
val methodName = it["method"]?.jsonPrimitive?.contentOrNull ?: "unknownMethod"
47+
val fileName = it["file"]?.jsonPrimitive?.contentOrNull ?: "UnknownFile"
48+
val lineNumber = it["line"]?.jsonPrimitive?.intOrNull ?: -1
49+
val lineStr = if (lineNumber >= 0) "$fileName:$lineNumber" else fileName
50+
51+
append("$indent\tat $className.$methodName($lineStr)\n")
52+
}
53+
54+
55+
obj["cause"]
56+
?.takeUnless { it is JsonNull }
57+
?.jsonObject
58+
?.let {
59+
append("${indent}Caused by: ${buildStackTraceString(it, indent)}")
60+
}
61+
}
62+
63+
64+
private fun getThrown(text: String) = try {
65+
Json.parseToJsonElement(text)
66+
.jsonObject["thrown"]
67+
?.takeUnless { it is JsonNull }
68+
?.jsonObject
69+
?.takeIf { it.containsKey("extendedStackTrace") && it.containsKey("cause") }
70+
} catch (_: SerializationException) {
71+
null
72+
}
73+
74+
companion object {
75+
fun getInstance(): CCv2UnscrambleService = application.service()
76+
}
77+
}

modules/ccv2/ui/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,8 @@ dependencies {
4848
intellijIdeaUltimate(properties("intellij.version")) {
4949
useInstaller = false
5050
}
51+
bundledPlugins(
52+
"com.intellij.java",
53+
)
5154
}
5255
}

modules/ccv2/ui/resources/META-INF/sap.commerce.toolset-ccv2-ui.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
nonDefaultProject="true" dynamic="true"
2525
displayName="CCv2" order="first"
2626
provider="sap.commerce.toolset.ccv2.options.CCv2ExecProjectSettingsConfigurableProvider"/>
27+
28+
<unscrambleSupport implementation="sap.commerce.toolset.ccv2.unscramble.CCv2StackTraceUnscrambler"/>
29+
2730
</extensions>
2831

2932
<actions>
@@ -77,4 +80,9 @@
7780
</action>
7881
</actions>
7982

83+
<applicationListeners>
84+
<listener class="sap.commerce.toolset.ccv2.unscramble.CCv2UnscrambleListener"
85+
topic="com.intellij.openapi.application.ApplicationActivationListener"/>
86+
</applicationListeners>
87+
8088
</idea-plugin>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA.
3+
* Copyright (C) 2019-2025 EPAM Systems <[email protected]> and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13+
* See the GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package sap.commerce.toolset.ccv2.unscramble
20+
21+
import com.intellij.openapi.project.Project
22+
import com.intellij.unscramble.UnscrambleSupport
23+
import sap.commerce.toolset.i18n
24+
import javax.swing.JComponent
25+
26+
class CCv2StackTraceUnscrambler : UnscrambleSupport<JComponent> {
27+
28+
override fun unscramble(project: Project, text: String, logName: String, jComponent: JComponent?) = CCv2UnscrambleService.getInstance()
29+
.buildStackTraceString(text)
30+
31+
override fun getPresentableName() = i18n("hybris.project.ccv2.unscramble.jsonStacktrace.name")
32+
33+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA.
3+
* Copyright (C) 2019-2025 EPAM Systems <[email protected]> and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13+
* See the GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package sap.commerce.toolset.ccv2.unscramble
20+
21+
import com.intellij.openapi.application.ClipboardAnalyzeListener
22+
import com.intellij.openapi.project.DumbService
23+
import com.intellij.openapi.project.Project
24+
import com.intellij.openapi.util.registry.Registry
25+
import com.intellij.openapi.wm.IdeFrame
26+
import com.intellij.unscramble.UnscrambleDialog
27+
import java.awt.event.ActionEvent
28+
29+
class CCv2UnscrambleListener : ClipboardAnalyzeListener() {
30+
31+
override fun applicationActivated(ideFrame: IdeFrame) {
32+
if (!Registry.`is`("analyze.exceptions.on.the.fly")) return
33+
super.applicationActivated(ideFrame)
34+
}
35+
36+
override fun applicationDeactivated(ideFrame: IdeFrame) {
37+
if (!Registry.`is`("analyze.exceptions.on.the.fly")) return
38+
super.applicationDeactivated(ideFrame)
39+
}
40+
41+
override fun canHandle(value: String) = CCv2UnscrambleService.getInstance()
42+
.canHandle(value)
43+
44+
override fun handle(project: Project, value: String) {
45+
val dialog = CCv2UnscrambleDialog(project)
46+
dialog.createNormalizeTextAction().actionPerformed(null as ActionEvent?)
47+
if (!DumbService.isDumb(project)) {
48+
dialog.doOKAction()
49+
}
50+
}
51+
52+
class CCv2UnscrambleDialog(project: Project) : UnscrambleDialog(project) {
53+
public override fun doOKAction() {
54+
super.doOKAction()
55+
}
56+
}
57+
}

modules/shared/core/resources/i18n/HybrisBundle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ hybris.project.run.configuration.localserver.environment.variables.fragment.hint
5757
hybris.project.run.configuration.localserver.environment.options.group=Java Options
5858
hybris.project.run.configuration.localserver.set.custom.environment.variables.for.the.process=Set custom environment variables for the process
5959

60+
hybris.project.ccv2.unscramble.jsonStacktrace.name=SAP CCv2 Json Stacktrace Unscrambler
61+
6062
copy.and.paste.the.arguments.to.the.command.line.when.jvm.is.started=Copy and paste this to your 'tomcat.debugjavaoptions' before starting SAP CX
6163
command.line.arguments.for.remote.jvm=&Command line arguments for remote JVM:
6264

0 commit comments

Comments
 (0)