Grails
  1. Grails
  2. GRAILS-2524

Add more closure customization hooks for grails war in Config.groovy

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0.1
    • Fix Version/s: 1.0.5
    • Component/s: ContinuousBuild
    • Labels:
      None
    • Environment:
      all versions

      Description

      Hi,
      We would like to be able to hook into the War.groovy process for such things as excluding/including files in the staging directory that gets put into the WAR based on the arguments passed to "grails war"

      For example, we would like to provide a custom fileset to the copy of $baseDir/web-app -> staging. I customized the War.groovy to grab a closure from Config.groovy. Basically we are requesting that hooks like this be added to War.groovy

      		Ant.copy(todir:stagingDir, overwrite:true) {
      			if(config.grails.war.copyToWebApp.fileset instanceof Closure) {
      				def dirset = config.grails.war.copyToWebApp.fileset
      				dirset.delegate = delegate
      				dirset.resolveStrategy = Closure.DELEGATE_FIRST
      				dirset(args) // arguments
      			} else {
      				fileset(dir:"${basedir}/web-app", includes:"**") 
      			}
      		} 
      

        Activity

        Hide
        InterZ added a comment -

        also it would be great if the "args" variable could be passed to the closure as an argument

        Show
        InterZ added a comment - also it would be great if the "args" variable could be passed to the closure as an argument
        Hide
        InterZ added a comment -

        Lastly, it would be nice to have another closure hook after the WAR process is complete. After the StatusFinal event occurs, call config closure: such as

        if(config.grails.war.warEnd instanceof Closure)

        { def warEnd = config.grails.war.warEnd warEnd.delegate = delegate warEnd.resolveStrategy = Closure.DELEGATE_FIRST warEnd(basedir,warName,args) }
        Show
        InterZ added a comment - Lastly, it would be nice to have another closure hook after the WAR process is complete. After the StatusFinal event occurs, call config closure: such as if(config.grails.war.warEnd instanceof Closure) { def warEnd = config.grails.war.warEnd warEnd.delegate = delegate warEnd.resolveStrategy = Closure.DELEGATE_FIRST warEnd(basedir,warName,args) }
        Hide
        InterZ added a comment -

        Just uploaded a modified War.groovy showing all the places where it would be nice to have customizations.

        Basically the ability to customize the staging fileset, pass the "args" to config.grails.war.resources, and lastly a custom closure call after cleanup when the WAR is complete.

        Attatched is the custom War file that we are currently carrying to customize our build process.

        Look for the // #### CUSTOM comments

        Show
        InterZ added a comment - Just uploaded a modified War.groovy showing all the places where it would be nice to have customizations. Basically the ability to customize the staging fileset, pass the "args" to config.grails.war.resources, and lastly a custom closure call after cleanup when the WAR is complete. Attatched is the custom War file that we are currently carrying to customize our build process. Look for the // #### CUSTOM comments
        Hide
        Peter Ledbrook added a comment -

        I think WarEnd would be better implemented as an event. Does that not work for you?

        Show
        Peter Ledbrook added a comment - I think WarEnd would be better implemented as an event. Does that not work for you?
        Hide
        Peter Ledbrook added a comment -

        Added in r7103. I left out the "grails.war.warEnd" hook because I believe this is better achieved with the existing events. If this doesn't work for you, please re-open the issue with a description of the problem.

        Show
        Peter Ledbrook added a comment - Added in r7103. I left out the "grails.war.warEnd" hook because I believe this is better achieved with the existing events. If this doesn't work for you, please re-open the issue with a description of the problem.
        Hide
        InterZ added a comment -

        Hi,
        The reason for needing the last closure at war end is because I need those parameters (baseDir, warName, and the arguments passed to war.groovy)

        // #### CUSTOM (pass in args)

        if(config.grails.war.warEnd instanceof Closure)

        { def warEnd = config.grails.war.warEnd warEnd.delegate = delegate warEnd.resolveStrategy = Closure.DELEGATE_FIRST warEnd(basedir,warName,args) }
        Show
        InterZ added a comment - Hi, The reason for needing the last closure at war end is because I need those parameters (baseDir, warName, and the arguments passed to war.groovy) // #### CUSTOM (pass in args) if(config.grails.war.warEnd instanceof Closure) { def warEnd = config.grails.war.warEnd warEnd.delegate = delegate warEnd.resolveStrategy = Closure.DELEGATE_FIRST warEnd(basedir,warName,args) }
        Hide
        Peter Ledbrook added a comment -

        I have modified the War events so that they pass the name of the WAR file to the event closure. "basedir" and "args" should already be available to your Events script (if not, try including the targets from Init.groovy). Please try that and let me know how it goes.

        Show
        Peter Ledbrook added a comment - I have modified the War events so that they pass the name of the WAR file to the event closure. "basedir" and "args" should already be available to your Events script (if not, try including the targets from Init.groovy). Please try that and let me know how it goes.
        Hide
        Peter Ledbrook added a comment -

        Moving to 1.0.4 as I believe that the events are sufficient and we want to get 1.0.3 out this week. Leaving open for discussion though.

        Show
        Peter Ledbrook added a comment - Moving to 1.0.4 as I believe that the events are sufficient and we want to get 1.0.3 out this week. Leaving open for discussion though.
        Hide
        Peter Ledbrook added a comment -

        No more feedback, so resolving for now. Add a comment to re-open if necessary, or raise a separate issue.

        Show
        Peter Ledbrook added a comment - No more feedback, so resolving for now. Add a comment to re-open if necessary, or raise a separate issue.

          People

          • Assignee:
            Peter Ledbrook
            Reporter:
            InterZ
          • Votes:
            6 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development