Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0
    • Component/s: None
    • Labels:
      None

      Description

      For debugging scripts, it would sometimes be useful to have access to the context within a VM script.
      For example, one could then print out all the variables that are defined in the context.

      The suggestion is to enable this via a properties file or a system property.

      If the property is defined, its value would be used as the name of the variable holding the context.

      e.g. -Dvelocity.context.variable=ctx

      Obviously feel free to choose a better property name.

        Activity

        Hide
        claude Claude Brisson added a comment -

        Doing so would be confusing in frameworks like VelocityTools that use a ContextTool to do so. The ContextTool also provides several usefull Context introspection methods.

        And it's a single line Java call to do this:
        context.put("zeContext", context);

        Most frameworks using Velocity provide a way to customize the context in one way or the other.

        Show
        claude Claude Brisson added a comment - Doing so would be confusing in frameworks like VelocityTools that use a ContextTool to do so. The ContextTool also provides several usefull Context introspection methods. And it's a single line Java call to do this: context.put("zeContext", context); Most frameworks using Velocity provide a way to customize the context in one way or the other.
        Hide
        sebb@apache.org Sebb added a comment -

        The problem is some products using Velocity do not provide any way to customise the context.
        For example Maven.

        Show
        sebb@apache.org Sebb added a comment - The problem is some products using Velocity do not provide any way to customise the context. For example Maven.
        Hide
        claude Claude Brisson added a comment -

        I see.
        And a "maven velocity customize context" search leads to two unanswered stackoverflow questions, so it may be worth...

        would a properties file solution be enough?

        Show
        claude Claude Brisson added a comment - I see. And a "maven velocity customize context" search leads to two unanswered stackoverflow questions, so it may be worth... would a properties file solution be enough?
        Hide
        claude Claude Brisson added a comment -

        Fixed in 2.x.
        The new configuration property context.autoreference.key allows to specify the key under which the context will be put in itself.

        Show
        claude Claude Brisson added a comment - Fixed in 2.x. The new configuration property context.autoreference.key allows to specify the key under which the context will be put in itself.
        Hide
        sdumitriu Sergiu Dumitriu added a comment - - edited

        I'm not sure, but I think jsr233 (or whatever the name of the java scripting API) actually requires that the context is available under the context binding/variable.

        Show
        sdumitriu Sergiu Dumitriu added a comment - - edited I'm not sure, but I think jsr233 (or whatever the name of the java scripting API) actually requires that the context is available under the context binding/variable.
        Hide
        sebb@apache.org Sebb added a comment -

        That should be sufficient for debugging.

        Show
        sebb@apache.org Sebb added a comment - That should be sufficient for debugging.
        Hide
        claude Claude Brisson added a comment -

        You are right, the spec says:

        In all cases, the ScriptContext used during a script execution must be a value
        in the Engine Scope of the ScriptEngine whose key is the String “context”

        So it's not exactly an autoreference key, but it's close: the ScriptContext contains nested scoped Bindings, plus references to the reader, the writer and the errorReader, and it should be visible its own engine scope bindings.

        But it should be enforced, and after a little check it appears our implementation was not correct because I took the liberty of renaming the key to 'script_context'. I fixed it.

        Show
        claude Claude Brisson added a comment - You are right, the spec says: In all cases, the ScriptContext used during a script execution must be a value in the Engine Scope of the ScriptEngine whose key is the String “context” So it's not exactly an autoreference key, but it's close: the ScriptContext contains nested scoped Bindings, plus references to the reader, the writer and the errorReader, and it should be visible its own engine scope bindings. But it should be enforced, and after a little check it appears our implementation was not correct because I took the liberty of renaming the key to 'script_context'. I fixed it.

          People

          • Assignee:
            claude Claude Brisson
            Reporter:
            sebb@apache.org Sebb
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development