Groovy
  1. Groovy
  2. GROOVY-1512

When executing command-line scripts it should be possible to execute a BEGIN and an END method (akin to AWK or Perl)

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0-JSR-6
    • Fix Version/s: 1.8.1, 1.9-beta-1
    • Component/s: None
    • Labels:
      None
    • Flags:
      Patch

      Description

      When executing a command-line script e.g., via -pe it would sometimes be very useful to define a method BEGIN and a method END which are executed exactly once, BEGIN before the loop starts, and END after the loop has ended for all files to be processed. An example:

      groovy -a -ne "def BEGIN()

      {c=0}

      ;def END()

      {println c}

      ;c += split[0].toInteger()+split[-2].toInteger()" test.txt

      results in:
      39

      for the following test.txt:
      1 2 3 4
      1 2 3 4 5
      1 2 3 4 5 6
      1 2 3 4 5 6 7
      1 2 3 4 5 6 7 8
      1 2 3 4 5 6 7 8 9

      The patch provides this functionality and additionally that of GROOVY-1507 and GROOVY-1508. If a singular patch is necessary, I'll be happy to provide it.

      1. GROOVY-1512.patch
        2 kB
        Guillaume Delcroix
      2. GroovyMainAll.patch
        3 kB
        Joachim Baumann

        Activity

        Joachim Baumann created issue -
        Guillaume Delcroix made changes -
        Field Original Value New Value
        Fix Version/s 1.0-RC-1 [ 12104 ]
        Fix Version/s 1.0-final [ 10244 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.1 [ 10436 ]
        Fix Version/s 1.0 [ 10244 ]
        Guillaume Delcroix made changes -
        Assignee Guillaume Laforge [ guillaume ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.1-beta-2 [ 10436 ]
        Joachim Baumann made changes -
        Assignee Joachim Baumann [ jbaumann ]
        Hide
        Guillaume Delcroix added a comment -

        Patch supporting the definition of a begin() and end() method to be run once at the beginning of the processing of the files, and once at the end after all the processing.

        Show
        Guillaume Delcroix added a comment - Patch supporting the definition of a begin() and end() method to be run once at the beginning of the processing of the files, and once at the end after all the processing.
        Guillaume Delcroix made changes -
        Attachment GROOVY-1512.patch [ 54357 ]
        Guillaume Delcroix made changes -
        Assignee Joachim Baumann [ jbaumann ] Guillaume Laforge [ guillaume ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.9-beta-1 [ 17153 ]
        Fix Version/s 1.8.1 [ 17223 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12730644 ] Default workflow, editable Closed status [ 12742612 ]
        Mark Thomas made changes -
        Patch Info Patch Available [ 10960 ]
        Mark Thomas made changes -
        Flags Patch [ 10430 ]
        Patch attached Yes [ 10860 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12967245 ] Default workflow, editable Closed status [ 12974958 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        1667d 9m 1 Guillaume Delcroix 20/Apr/11 06:09
        Resolved Resolved Closed Closed
        92d 13h 57m 1 Paul King 21/Jul/11 20:06

          People

          • Assignee:
            Guillaume Delcroix
            Reporter:
            Joachim Baumann
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development