Wiki source code of Debugging

Last modified by Thomas Mortagne on 2025/01/16 16:28

Hide last authors
VincentMassol 1.1 1 There are several possibilities for debugging XWiki:
ShawnLauzon 1.11 2
Marius Dumitru Florea 8.1 3 {{toc/}}
VincentMassol 1.2 4
Thomas Mortagne 20.1 5 = Debug mode =
6
Thomas Mortagne 23.1 7 It's possible to enable debug log by adding ##debug=true## (as in [[http://127.0.0.1:8080/xwiki/bin/Main/WebHome?debug=true]]) to the URL. This provide various details on what exactly happens during the request.
Thomas Mortagne 20.1 8
Thomas Mortagne 24.1 9 == Elapsed time tree ==
Thomas Mortagne 23.1 10
11 A detailed tree of how long has been spent in each step. You can add you own step to the tree by using [[progress API>>extensions:Extension.Job Module||anchor="HNotifyaboutprogress"]].
12
Thomas Mortagne 35.1 13 {{image reference="elapsedtimetree.png"/}}
Thomas Mortagne 26.1 14
Marius Dumitru Florea 8.1 15 = Debugging XWiki from your IDE =
ShawnLauzon 1.10 16
Marius Dumitru Florea 8.1 17 == Debugging with Eclipse ==
Marius Dumitru Florea 7.1 18
ShawnLauzon 1.10 19 Once you've gotten the debugger working, you'll wonder how you ever survived without it.
20
Thomas Mortagne 42.1 21 === Complete tutorial based on M2E and WTP ===
Thomas Mortagne 3.1 22
Manuel Smeria 14.2 23 [[Debug XWiki with Eclipse>>DebugXEWithEclipse]]
Thomas Mortagne 3.1 24
Marius Dumitru Florea 8.1 25 === Debug a XWiki released version ===
Thomas Mortagne 3.1 26
Manuel Smeria 14.2 27 * Follow the steps from [[Building In Eclipse>>BuildingInEclipse]] including the optional "Import the WAR as a web project".
Marius Dumitru Florea 7.1 28 * Select from the Eclipse menu **Run > Debug...**
ShawnLauzon 1.10 29 * Create a new configuration for your server
Manuel Smeria 14.2 30 * Hit the **Debug** button
31 * Set breakpoints, step through code, have fun!
rewbs 1.12 32
Marius Dumitru Florea 7.1 33 WTP will deploy XWiki into ##{workspace_location}/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/webapps/xwiki##. If you suspect a change has not been deployed correctly (e.g. a change to a config file), check there to confirm.
rewbs 1.12 34
Marius Dumitru Florea 7.1 35 If you are working on an XWiki plugin in a separate project in your workspace, you can ensure it is automatically deployed to XWiki's ##WEB-INF/lib## directory when debugging. Open the project properties of the XWiki project resulting from the WAR import above, go to the ##J2EE Module Dependencies## section, and add your plugin project.
rewbs 1.13 36
Marius Dumitru Florea 8.1 37 === Using Firebug when debugging a selenium test ===
Thomas Mortagne 3.1 38
Manuel Smeria 14.2 39 For that you will need to install Firebug [[as a global extension>>http://kb.mozillazine.org/Installing_extensions#Global_installation]]
Thomas Mortagne 4.1 40
Marius Dumitru Florea 8.1 41 = Remote Debugging =
VincentMassol 1.2 42
Vincent Massol 45.1 43 To perform remote debugging, start your wiki in debug mode. To do this you can:
Manuel Leduc 49.1 44
Vincent Massol 45.1 45 * use the ##start_xwiki_debug.sh## executable if you're using the Standalone packaging
46 * modify the way you start your container and ensure that the following JVM parameters are passed:(((
Marius Dumitru Florea 7.1 47 {{code}}
Antoine Mottier 50.1 48 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
Marius Dumitru Florea 7.1 49 {{/code}}
VincentMassol 1.3 50
51 For example, for Jetty you could use the following start script:
52
Marius Dumitru Florea 7.1 53 {{code}}
VincentMassol 1.3 54 #!/bin/sh
55
56 JETTY_HOME=.
57 JETTY_PORT=8080
Antoine Mottier 50.1 58 JAVA_OPTS="-Xmx300m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
VincentMassol 1.3 59
60 java $JAVA_OPTS -Dfile.encoding=iso-8859-1 -Djetty.port=$JETTY_PORT -Djetty.home=$JETTY_HOME -jar $JETTY_HOME/start.jar
Marius Dumitru Florea 7.1 61 {{/code}}
VincentMassol 1.3 62
Marius Dumitru Florea 7.1 63 If you are using the Tomcat service on Windows, you should modify the JVM args with the Tomcat Service Configuration Panel. Select the Java tab and add each of the options **on a separate line**. For example:
ShawnLauzon 1.8 64
Marius Dumitru Florea 7.1 65 {{code}}
66 -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 5.5
67 -Dcatalina.base=C:\Program Files\Apache Software Foundation\Tomcat 5.5
68 -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\endorsed
69 -Djava.io.tmpdir=C:\Program Files\Apache Software Foundation\Tomcat 5.5\temp
ShawnLauzon 1.9 70 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
Marius Dumitru Florea 7.1 71 -Djava.util.logging.config.file=C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\logging.properties
Antoine Mottier 50.1 72 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
Marius Dumitru Florea 7.1 73 {{/code}}
Vincent Massol 45.1 74 )))
ShawnLauzon 1.9 75
Vincent Massol 45.1 76 Then, in your favorite IDE, open the XWiki project and run a remote debugging session, attached to the socket on port 5005. For example, if you're using IntelliJ IDEA, go to ##Run|Edit Configurations...## and create a new ##Remote## configuration (default parameters should be fine). Then execute it and IDEA will connect to the executing JVM.
Silvia Macovei 8.2 77
VincentMassol 1.3 78 You can then place breakpoints in your source code.
79
Vincent Massol 46.1 80 Debugging options for ##start_xwiki_debug.sh##:
Manuel Leduc 49.1 81
82 * Use the ##~-~-suspend## parameter to tell the JVM to wait until someone connect to the debugging port before progressing.
Vincent Massol 46.1 83 * Use the ##JETTY_DEBUG_PORT## environment variable to control the JVM debug port to use (default is ##5005##).
Manuel Leduc 49.1 84 * {{version since="12.8RC1"}}Use the ##-dp <number>## (or ##-~-debugPort <number>##) parameter to control the JVM debug port to use (default is ##5005##).{{/version}}
Vincent Massol 45.1 85
Marius Dumitru Florea 8.1 86 = Logging =
amelentyev 1.18 87
Marius Dumitru Florea 8.1 88 == Turning on logging inside XWiki ==
VincentMassol 1.2 89
Simon Urli 49.2 90 See the [[Logging page in the Admin guide>>xwiki:Documentation.AdminGuide.Logging]].
VincentMassol 1.1 91
Vincent Massol 19.1 92 == Logging shutdown operations ==
93
Thomas Mortagne 55.1 94 To log debug information of what happens when there are shutdown operations, simply set the log level to ##DEBUG## for the ##org.xwiki.shutdown## logger:
Vincent Massol 19.1 95
96 {{code language="xml"}}
97 <logger name="org.xwiki.shutdown" level="info"/>
98 {{/code}}
99
Marius Dumitru Florea 8.1 100 == Logging calls at the database level ==
VincentMassol 1.1 101
Vincent Massol 16.1 102 You have several options:
Thomas Mortagne 26.1 103
Simon Urli 49.2 104 * Configure Hibernate to log SQL calls. To do this edit XWiki's log configuration file (see the [[Logging page>>xwiki:Documentation.AdminGuide.Logging]]) and change the log level from ##warn## to ##trace## for the following:(((
Vincent Massol 16.1 105 {{code language="none"}}
106 <!-- Log HQL query parser activity -->
107 <logger name="org.hibernate.hql.ast.AST" level="warn"/>
108 <!-- Log just the SQL -->
109 <logger name="org.hibernate.SQL" level="warn"/>
110 <!-- Log JDBC bind parameters -->
111 <logger name="org.hibernate.type" level="warn"/>
112 <!-- Log schema export/update -->
113 <logger name="org.hibernate.tool.hbm2ddl" level="warn"/>
114 <!-- Log HQL parse trees -->
115 <logger name="org.hibernate.hql" level="warn"/>
116 <!-- Log cache activity -->
117 <logger name="org.hibernate.cache" level="warn"/>
118 <!-- Log transaction activity -->
119 <logger name="org.hibernate.transaction" level="warn"/>
120 <!-- Log JDBC resource acquisition -->
121 <logger name="org.hibernate.jdbc" level="warn"/>
122 <!-- Enable the following line if you want to track down connection leakages when using
123 DriverManagerConnectionProvider -->
124 <logger name="org.hibernate.connection.DriverManagerConnectionProvider" level="warn"/>
125 <!-- Log prepared statement cache activity -->
126 <logger name="org.hibernate.ps.PreparedStatementCache" level="warn"/>
127 {{/code}}
128 )))
129 * Use a wrapping JDBC driver such as [[log4jdbc>>http://code.google.com/p/log4jdbc/]] or [[p6spy>>http://sourceforge.net/projects/p6spy/]].
Thomas Mortagne 42.1 130 * (((
Manuel Leduc 49.1 131 Turn on logging in your database. The configuration is database-dependent*
132
133 (((
134 For **HSQLDB**. Two solutions:* Solution 1: Edit ##WEB-INF/hibernate.cfg.xml## and modify the URL connection property to add ##hsqldb.sqllog=3##, as in:
135
136 (((
Vincent Massol 17.1 137 {{code language="none"}}
138 <property name="connection.url">jdbc:hsqldb:file:${environment.permanentDirectory}/database/xwiki_db;shutdown=true;hsqldb.sqllog=3</property>
139 {{/code}}
140 )))
Manuel Leduc 49.1 141
Thomas Mortagne 42.1 142 * Solution 2: Using Byteman (See the section below for more information). For example the following rule (tested on HSQLDB 2.3.1) will log SQL statements with parameters and schema when there's more than 1 parameter:(((
Vincent Massol 18.1 143 {{code language="none"}}
144 RULE Log SQL Statement
145 CLASS org.hsqldb.Session
146 METHOD executeCompiledStatement(org.hsqldb.Statement, Object[], int)
147 AT ENTRY
148 IF $2.length > 0
149 DO traceln("SQL Statement = [" + $1.getSQL() + "], parameter 1 = [" + $2[0] + "], schema = [" + $1.getSchemaName().name + "]")
150 ENDRULE
151 {{/code}}
VincentMassol 1.4 152
Vincent Massol 18.1 153 Will give for example:
154
155 {{code language="none"}}
156 SQL Statement = [select xwikidocum0_.XWD_ID as XWD1_0_0_, xwikidocum0_.XWD_FULLNAME as XWD2_0_0_, xwikidocum0_.XWD_NAME as XWD3_0_0_, xwikidocum0_.XWD_TITLE as XWD4_0_0_, xwikidocum0_.XWD_LANGUAGE as XWD5_0_0_, xwikidocum0_.XWD_DEFAULT_LANGUAGE as XWD6_0_0_, xwikidocum0_.XWD_TRANSLATION as XWD7_0_0_, xwikidocum0_.XWD_DATE as XWD8_0_0_, xwikidocum0_.XWD_CONTENT_UPDATE_DATE as XWD9_0_0_, xwikidocum0_.XWD_CREATION_DATE as XWD10_0_0_, xwikidocum0_.XWD_AUTHOR as XWD11_0_0_, xwikidocum0_.XWD_CONTENT_AUTHOR as XWD12_0_0_, xwikidocum0_.XWD_CREATOR as XWD13_0_0_, xwikidocum0_.XWD_WEB as XWD14_0_0_, xwikidocum0_.XWD_CONTENT as XWD15_0_0_, xwikidocum0_.XWD_VERSION as XWD16_0_0_, xwikidocum0_.XWD_CUSTOM_CLASS as XWD17_0_0_, xwikidocum0_.XWD_PARENT as XWD18_0_0_, xwikidocum0_.XWD_CLASS_XML as XWD19_0_0_, xwikidocum0_.XWD_ELEMENTS as XWD20_0_0_, xwikidocum0_.XWD_DEFAULT_TEMPLATE as XWD21_0_0_, xwikidocum0_.XWD_VALIDATION_SCRIPT as XWD22_0_0_, xwikidocum0_.XWD_COMMENT as XWD23_0_0_, xwikidocum0_.XWD_MINOREDIT as XWD24_0_0_, xwikidocum0_.XWD_SYNTAX_ID as XWD25_0_0_, xwikidocum0_.XWD_HIDDEN as XWD26_0_0_ from xwikidoc xwikidocum0_ where xwikidocum0_.XWD_ID=?], parameter 1 = [-4526159677276379501], schema = [TEST91]
157 {{/code}}
158 )))
Thomas Mortagne 42.1 159 )))
160 )))
Vincent Massol 18.1 161
Vincent Massol 37.1 162 == Logging HTTP calls ==
163
Vincent Massol 37.2 164 XWiki uses [[HTTP Client>>https://hc.apache.org/httpcomponents-client-ga/]] in most places and logging what it does is easy. You'll need to add the following to XWiki's ##logback.xml## file:
Vincent Massol 37.1 165
166 {{code language="xml"}}
167 <logger name="org.apache.http" level="debug"/>
168 <logger name="org.apache.http.headers" level="debug"/>
169 <logger name="org.apache.http.wire" level="debug"/>
170 {{/code}}
171
Vincent Massol 10.1 172 == Using Byteman ==
173
174 [[Byteman>>https://www.jboss.org/byteman]] is a great framework that allows to modify bytecode in a running JVM. It can easily be used to add logging (for ex) to find out what's happening in a running XWiki instance. Here's a quick tutorial:
Thomas Mortagne 26.1 175
Manuel Smeria 14.2 176 * Download Byteman and unzip it in a directory. Set the ##$BYTEMAN_HOME## environment property to point to the directory where you've unzipped it. For example:
Thomas Mortagne 26.1 177 {{code}}export BYTEMAN_HOME=/Users/vmassol/dev/byteman/byteman-download-2.1.0{{/code}}
Vincent Massol 10.1 178 * Start an XWiki instance somewhere on the same machine
Manuel Smeria 14.2 179 * Go to ##$BYTEMAN_HOME/bin## and connect Byteman to XWiki. For example:
Thomas Mortagne 26.1 180 {{code}}sh bminstall.sh -b -Dorg.jboss.byteman.transform.all jetty/start.jar{{/code}}
181 * Now create a Byteman rule by creating a file, for example ##my.btm## with the following:(((
Vincent Massol 10.1 182 {{code}}
183 RULE XWiki Docs loaded
184 CLASS XWikiHibernateStore
185 METHOD loadXWikiDoc
186 AT ENTRY
187 IF TRUE
188 DO traceln("Load document = " + $1.getDocumentReference())
189 ENDRULE
190 {{/code}}
191 )))
192 * Load this rule with: {{code}}sh bmsubmit.sh -l my.btm{{/code}}
Thomas Mortagne 26.1 193 * Call a URL in your wiki and check that the console prints the document references that get loaded! For example:(((
Vincent Massol 10.1 194 {{code}}
195 Load document = xwiki:Main.WebPreferences
196 Load document = xwiki:ColorThemes.DefaultColorTheme
197 Load document = xwiki:XWiki.SearchSuggestConfig
198 Load document = xwiki:XWiki.SearchSuggestConfig
199 Load document = xwiki:Dashboard.WebHome
200 Load document = xwiki:XWiki.GadgetClass
201 Load document = xwiki:Dashboard.WebHome
202 Load document = xwiki:Dashboard.WebPreferences
203 Load document = xwiki:Dashboard.colibri
204 Load document = xwiki:Main.Welcome
205 ...
206 {{/code}}
207 )))
Vincent Massol 11.1 208 * Modify your rule or add new rules to the same file and apply the changes with {{code}}sh bmsubmit.sh -l my.btm{{/code}}
209 * Remove your rules with {{code}}sh bmsubmit.sh -u{{/code}}
Vincent Massol 10.1 210
Manuel Smeria 14.2 211 For more read [[A Byteman tutorial>>https://community.jboss.org/wiki/ABytemanTutorial]] or the [[Reference documentation>>http://downloads.jboss.org/byteman/2.0.1/ProgrammersGuideSinglePage.html]].
Vincent Massol 10.1 212
Vincent Massol 39.1 213 === Examples ===
Vincent Massol 13.1 214
Vincent Massol 39.1 215 ==== Example 1 ====
216
Vincent Massol 13.1 217 In this example we'll print calls to ##CommonsConfigurationSource.containsKey(...)## with the parameters printed and the time it takes to execute. In addition we'll also print calls to ##XWiki.getDocument(String, XWikiContext)## which is a deprecated method which, for the purpose of this example, we think generate the calls to ##containsKey##.
218
219 {{code}}
220 RULE Create timer for containsKey
221 CLASS CommonsConfigurationSource
222 METHOD containsKey
223 AT ENTRY
224 IF TRUE
225 DO resetTimer("containsKey")
226 ENDRULE
227
228 RULE Calls to containsKey
229 CLASS CommonsConfigurationSource
230 METHOD containsKey
231 AT EXIT
232 IF TRUE
233 DO traceln("containsKey for [" + $1 + "] = [" + $! + "], time = [" + getElapsedTimeFromTimer("containsKey") + "]")
234 ENDRULE
235
236 RULE Calls to deprecated getDocument
237 CLASS com.xpn.xwiki.XWiki
238 METHOD getDocument(String, XWikiContext)
239 AT ENTRY
240 IF TRUE
Vincent Massol 14.1 241 DO traceStack("getDocument() called for [" + $1 + "] ", 3)
Vincent Massol 13.1 242 ENDRULE
243 {{/code}}
244
245 Generates:
246
247 {{code}}
248 ...
Vincent Massol 14.1 249 getDocument() called for [XWiki.Admin] com.xpn.xwiki.XWiki.getDocument(XWiki.java:-1)
250 com.xpn.xwiki.XWiki.getUserName(XWiki.java:5072)
251 com.xpn.xwiki.XWiki.getUserName(XWiki.java:5062)
252 . . .
Vincent Massol 13.1 253 containsKey for [model.reference.default.document] = [false], time = [0]
254 containsKey for [model.reference.default.document] = [false], time = [0]
255 containsKey for [model.reference.default.space] = [false], time = [0]
256 containsKey for [model.reference.default.space] = [false], time = [0]
257 containsKey for [model.reference.default.wiki] = [false], time = [0]
Vincent Massol 14.1 258 containsKey for [model.reference.default.wiki] = [false], time = [1]
259 getDocument() called for [XWiki.DefaultSkin] com.xpn.xwiki.XWiki.getDocument(XWiki.java:-1)
260 com.xpn.xwiki.XWiki.getSkinFile(XWiki.java:1955)
261 com.xpn.xwiki.XWiki.getSkinFile(XWiki.java:1918)
262 . . .
Vincent Massol 13.1 263 ...
264 {{/code}}
265
Vincent Massol 39.1 266 ==== Example 2 ====
267
268 Log calls to ##XWikiDocument#setLock()## and ##XWikiDocument#removeLock()##.
269
270 {{code}}
271 RULE XWiki Set Lock
272 CLASS XWikiDocument
273 METHOD setLock
274 AT ENTRY
275 IF TRUE
276 DO traceln("set lock for user [" + $1 + "], doc = [" + $this + "]")
277 ENDRULE
278
279 RULE XWiki Remove Lock
280 CLASS XWikiDocument
281 METHOD removeLock
282 AT ENTRY
283 IF TRUE
284 DO traceln("remove lock for doc = [" + $this + "]")
285 ENDRULE
Vincent Massol 40.1 286
287 RULE XWiki Get Lock
288 CLASS XWikiDocument
289 METHOD getLock
290 AT ENTRY
291 IF TRUE
292 DO traceln("get lock for doc = [" + $this + "]")
293 ENDRULE
Vincent Massol 39.1 294 {{/code}}
295
Vincent Massol 40.1 296 When you click edit and then cancel on a doc you get for example:
297
298 {{code}}
299 // Edit
300 get lock for doc = [Sandbox.WebHome]
301 set lock for user [XWiki.Admin], doc = [Sandbox.WebHome]
302 get lock for doc = [Sandbox.WebHome]
303 get lock for doc = [Sandbox.WebHome]
304 set lock for user [XWiki.Admin], doc = [Sandbox.WebHome]
305
306 // Cancel
307 get lock for doc = [Sandbox.WebHome]
308 remove lock for doc = [Sandbox.WebHome]
309 {{/code}}
310
Vincent Massol 39.1 311 When you click edit and then save on a doc you get for example:
312
313 {{code}}
Vincent Massol 40.1 314 // Edit
315 get lock for doc = [Sandbox.WebHome]
Vincent Massol 39.1 316 set lock for user [XWiki.Admin], doc = [Sandbox.WebHome]
Vincent Massol 40.1 317 get lock for doc = [Sandbox.WebHome]
318 get lock for doc = [Sandbox.WebHome]
Vincent Massol 39.1 319 set lock for user [XWiki.Admin], doc = [Sandbox.WebHome]
Vincent Massol 40.1 320
321 // Save
322 get lock for doc = [Sandbox.WebHome]
Vincent Massol 39.1 323 remove lock for doc = [Sandbox.WebHome]
Vincent Massol 40.1 324 get lock for doc = [Sandbox.WebHome]
Vincent Massol 39.1 325 {{/code}}
326
Vincent Massol 38.1 327 === Troubleshooting ===
328
329 ==== NoClassDefFoundError: com/sun/tools/attach/AttachNotSupportedException ====
330
331 If you get the following exception, it can mean that you're on Mac and that your ##tools.jar## is not added to the classpath. Apparently ##bminstall.sh## thinks that if you're on Mac then you don't need ##tools.jar## which is apparently wrong nowadays.
332
Thomas Mortagne 41.1 333 {{code language="none"}}
Vincent Massol 38.1 334 Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/AttachNotSupportedException
335 at java.lang.Class.getDeclaredMethods0(Native Method)
336 at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
337 at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
338 at java.lang.Class.getMethod0(Class.java:3018)
339 at java.lang.Class.getMethod(Class.java:1784)
340 at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
341 at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
342 Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.AttachNotSupportedException
343 at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
344 at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
345 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
346 at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
347 ... 7 more
348 {{/code}}
349
350 In this case, edit ##bminstall.sh## and add the following line below the ##OS=`uname`## line in order to override it:
351
Thomas Mortagne 41.1 352 {{code language="none"}}
Vincent Massol 38.1 353 OS=whatever
354 {{/code}}
355
Vincent Massol 15.2 356 = Debugging JavaScript =
Vincent Massol 15.1 357
Thomas Mortagne 53.1 358 One solution is to use the developer tools provided by the Browser for inspecting JavaScript and putting breakpoints in it. By default the XWiki build will minify and aggregate JavaScript files for performance reasons.
Vincent Massol 15.1 359
Marius Dumitru Florea 47.1 360 Open the developer tools provided by the browser and put the breakpoints using the Debugger / Sources tab. Look for the //non-minified// (source) JavaScript code (Ctrl+P). You should be able to find it most of the time because the minified version (which is used by default) indicates its source map which in turn indicates the source code. So the browser ends up loading all 3 when the developer tools are open (shouldn't be the case for end users), which means you can run the minified version while viewing the progress step by step over the source (non-minified) version. If the source map is missing or the source URL is wrong then you can still debug step by step using the source code by adding ##?minify=false## to the URL of the current page. This will force the browser to load the non-minified version (and only that).
361
362 Note that JavaScript minification is not only about removing whitespace and renaming local variables. Depending on the minifier used it may also mean code optimizations, syntax suggar replacement, polyfill injection, etc. So the differences between the minified version and the source code could be significant. As a consequence:
363
364 * debugging step by step may behave strangely when there's no 1 to 1 mapping between the minified code and its source
365 * the non-minified (source) version might not work on all browsers; that's why we recommend using ##?minify=false## only with the latest versions of Firefox and Chrome.
Thomas Mortagne 26.1 366
Vincent Massol 44.1 367 You can also set ##debug.minify## to ##false## in ##xwiki.properties## file instead of passing ##?minify=false## in the URL.
Vincent Massol 15.1 368
Manuel Leduc 48.1 369 == Debugging Vue.js ==
370
Manuel Leduc 49.1 371 The first step is to load a non-minified version of ##vue.js##. To do so, edit ##webapps/xwiki/resources/uicomponents/widgets/liveData.min.js## and replace {{code}}'vue': $services.webjars.url('vue', 'vue.min'){{/code}} by {{code}}'vue': $services.webjars.url('vue', 'vue'){{/code}}.
Manuel Leduc 48.1 372 Then, install [[Vue Devtools>>https://devtools.vuejs.org/]] in Firefox or Chrome.
373 You should now have access to the Vue tab in you browser debugger, with the ability to inspect the Vue applications deployed in the page.
374
Marius Dumitru Florea 8.1 375 = Debugging the WYSIWYG editor =
376
Vincent Massol 36.1 377 Example to debug JS code in ##macroSelector.js##:
Marius Dumitru Florea 8.1 378
Vincent Massol 43.2 379 * Modify the top level CKEditor ##pom.xml## to remove minification (the important part is to add {{code}}--leave-js-unminified{{/code}} as on the example below):(((
Vincent Massol 36.4 380 {{code language="xml"}}
381 ...
Vincent Massol 36.1 382 <plugin>
383 <groupId>org.codehaus.mojo</groupId>
384 <artifactId>exec-maven-plugin</artifactId>
385 <executions>
386 <!-- Build the CKEditor. -->
387 <execution>
388 <id>build-ckeditor</id>
389 <!-- Use a phase after compile because the Clirr Maven Plugin executes all the phases up to compile twice. -->
390 <phase>process-classes</phase>
391 <goals>
392 <goal>exec</goal>
393 </goals>
394 <configuration>
395 <executable>${ckeditor.builder.path}/build.sh</executable>
396 <arguments>
Vincent Massol 43.1 397 <!-- Exclude from release all plugins/skins that are not specified in build-config. -->
398 <argument>--skip-omitted-in-build-config</argument>
Vincent Massol 36.1 399 <argument>-s --leave-js-unminified</argument>
400 </arguments>
401 </configuration>
402 </execution>
403 </executions>
404 </plugin>
Vincent Massol 36.4 405 ...
406 {{/code}}
Vincent Massol 36.1 407 )))
408 * Rebuild the ##application-ckeditor-webjar## module (you'll also need to rebuild##application-ckeditor-plugins## if you made changes to it).
409 * Copy the generated ##application-ckeditor-webjar-<version>.jar## to an XWiki instance, in ##WEB-INF/lib## and restart XWiki
Vincent Massol 43.1 410 ** You could also remove the CKEditor extensions in the permanent's directory (in ##extensions/repository##) to be safe.
Vincent Massol 36.1 411 * In the wiki, edit ##CKEditor.EditSheet## in object mode and look for ###set ($macroWizardBundlePath = "${ckeditorBasePath}plugins/xwiki-macro/macroWizard.bundle.min")## and remove the ##.min## part. Note that in this case you have to know that the macro wizard is loaded separately in ##macroWizard.bundle.min.js##. Otherwise the JS is in ##ckeditor.js##.
412 * Use your browser's dev tools to put breakpoints in the JS.
Marius Dumitru Florea 8.1 413
Thomas Mortagne 32.1 414 = Analyze Out Of Memory issues =
415
Thomas Mortagne 41.1 416 You can enable automatic memory dump when using ##-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/where/to/save/the/memory/dumps ## which will generate a memory dump as soon as Java detect an Out Of memory error. See https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/clopts001.html#CHDFDIJI for more details.
Thomas Mortagne 32.1 417
Thomas Mortagne 56.1 418 This option is enabled by default in Jetty based distributions of XWiki, and the memory dump will ends up in ##data/## folder.
Thomas Mortagne 52.1 419
420 You can then navigate and analyze this memory dump with various tools, like [[Eclipse Memory Analyzer>>https://eclipse.dev/mat/]].

Get Connected