gcubed

Gel Debug Trick

Discussion created by gcubed Champion on Mar 6, 2014
Latest reply on Jun 7, 2018 by gcubed

 

Well I have been writing Gel scripts for the last few of months, I find I really miss “Active” debugging via a IDE.  Call me spoiled (but my roots are buried in the IBM punch card generation), but I really miss being able to break my script and taking a look at my variables.  So, I started tinkering around with running Gel in an IDE (I used Intellij but any Java IDE should work).

So here is the trick I worked out.

Create a java console application.
In the lib directory include all of the jars in the Gel lib.
Copy the .setup directory to your project directory.
Create a static class (GelClientDebug) that calls the main method of the GelClient and pass on the command line args.
Create a custom tag lib (DebugTagLibrary) that registers one tag – a DebugTag class. (Jelly documentation, Web search jelly doTag for examples)
Place a break in the doTag method in the DebugTag
Place your new debug tag into your Gel script and run the IDE in debug mode.
When the GelClient hits your debug tag, the IDE will stop the Gel script execution an allow you to view the Gel context which is where all the vars are kept.

Here is an example of how it works.

My Gel script to debug.

<?xml version="1.0" encoding="utf-8"?>
<gel:script
        xmlns:core="jelly:core"
        xmlns:xog="http://www.niku.com/xog"
        xmlns:x="jelly:org.apache.commons.jelly.tags.xml.XMLTagLibrary"
        xmlns:ggg="jelly:com.ggreiff.gel.DebugTagLibrary"
        xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
        xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:nikuq="http://www.niku.com/xog/Query"
        xmlns:util="jelly:util"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <!-- simple core set -->
    <core:set value="TestOne" var="TestOne" />
    <gel:log>${testOne}</gel:log>


    <!-- complex with new arrayList -->
    <core:set var="dummyStoredProjectIds" value="2,3,16,1,8,9"/>
    <core:set var="arrayStoredProjectIds" value='${dummyStoredProjectIds.split(",")}' />

    <core:new className="java.util.ArrayList" escapeText="false" var="arrayListStoredProjectIds" />
    <core:forEach items="${arrayStoredProjectIds}" var="id">
        <core:invokeStatic className="java.lang.Integer" method="parseInt" var="intId">
            <core:arg value="${id}" />
        </core:invokeStatic>
        <core:mute>${arrayListStoredProjectIds.add(intId)}</core:mute>
        <gel:out>${intId}</gel:out>
    </core:forEach>
    <util:sort var="sortedListStoredProjectIds" items="${arrayListStoredProjectIds}" />

    <!-- gel parse test -->
    <gel:parse var="writeInstance">
        <customObjectInstances objectCode="mhs_financialtask">
            <instance instanceCode="${code}" objectCode="mhs_financialtask">
                <CustomInformation>
                    <ColumnValue name="page_layout">odf.mhs_financialtaskFrame</ColumnValue>
                    <ColumnValue name="${columnNames[2]}">${mhs_xxxcmtd}</ColumnValue>
                    <ColumnValue name="${columnNames[4]}">${mhs_xxxoblg}</ColumnValue>
                </CustomInformation>
            </instance>
        </customObjectInstances>
    </gel:parse>

    <!-- our ide break -->
    <ggg:break/>
</gel:script>

 

Notice the new taglib ggg and our <ggg:break> tag.

So when I run this script in the GelScriptDebug client and when the script hits the <ggg:break> tag the IDE stops the execution and provides access to the JellyContext.



With the debug window, I can see all my vars (dummyStoredProjectIds, sortedListStoredProjectIds, writeInstance, ...) and when I expand one of the vars (sortedListStoredProjectIds), I even get to see the underlining type.


V/r,
Gene

 

 

Outcomes