Clarity

  • 1.  Gel Debug Trick

    Posted Mar 06, 2014 01:42 AM

     

    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

     

     



  • 2.  RE: Gel Debug Trick

     
    Posted Mar 10, 2014 05:26 PM
    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

     

     

     

    Thanks for sharing this tip with the community Gene!
     



  • 3.  Re: Gel Debug Trick

    Posted Jun 06, 2018 12:41 PM
    where do I get the below debugging tag library from. Please assist.
    xmlns:ggg="jelly:com.ggreiff.gel.DebugTagLibrary"


  • 4.  Re: Gel Debug Trick

    Posted Jun 07, 2018 02:54 PM

    I found it easier to just dump the context within my gel script instead of running it an IDE.

     

    Try this to see what is in your context.

     

    <?xml version="1.0" encoding="UTF-8"?>
    <gel:script
         xmlns:core="jelly:core"
         xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    >

         <core:new className="java.util.Date" var="now" />
         <core:new var="jobId2" className="java.lang.Long">
              <core:arg type="java.lang.String" value="5001007" />
         </core:new>

         <core:set var="TestOne" value="TestOne" />
         <core:expr value='${context.variables.put("TestTwo", "TestTwo")}' />
         <gel:log>TestOne = ${context.variables.get("TestOne")}</gel:log>

         <core:set var="entries" value="${context.getVariables().entrySet().toArray()}" />
         <core:forEach var="entry" items="${entries}">
              <core:if test="${!entry.getKey().equalsIgnoreCase('systemScope')}" >
                   <gel:log> ${entry.getKey()} | ${entry.getValue()} |  ${entry.getValue().getClass().getName()}</gel:log>
              </core:if>
         </core:forEach>
    </gel:script>

     

     

    V/r,

    Gene