I know I'm going to read this and provide more feedback later, but....
initial readings comments:

A build-file (read plugin) may want to have multiple, different call backs,
e.g. war, ear etc for the j2ee plugin. I think we need to extend the
mechanism to allow this. It works for the current j2ee war task, but ear is
next on my list....
--
dIon Gillard, Multitask Consulting
Work:      http://www.multitask.com.au
Developers: http://adslgateway.multitask.com.au/developers


                                                                                       
                           
                    "Glenn A.                                                          
                           
                    McAllister"          To:     Maven Dev List 
<[EMAIL PROTECTED]>            
                    <glenn@somanet       cc:                                           
                           
                    works.com>           Subject:     [PATCH] build-j2ee.xml update 
and a generic callback        
                                          mechanism                                    
                           
                    05/02/02 08:19                                                     
                           
                    AM                                                                 
                           
                    Please respond                                                     
                           
                    to                                                                 
                           
                    turbine-maven-                                                     
                           
                    dev                                                                
                           
                                                                                       
                           
                                                                                       
                           





<warning-long-email/>

This patch includes the following changes:

1. Support for adding arbitrary callbacks to a build that follows a
   similar pattern that Jason did for preparing Java source.

2. Changes to build-j2ee.xml:

2a: use the new generic callback mechanism
2b: use the jars specified by the project dependencies
2c: use the nested <manifest> element of the <war> task the way the
    current <jar> targets do
2d: create the resulting .war file in the same place as the .jar goes

3. Fix to build-maven.xml to use the correct ${maven.organization}
   property so the manifest has the correct organization name.

Generic Callbacks
=================

Jason introduced the concept of a "callback" into a non-maven build file
for the purposes of giving the Maven user a way to do "something" during
the build process.  Specifically, he introduced a way to prepare source
code before the actual compilation. I (amongst others I'm sure) *really*
liked this, and decided to make it easy to add callbacks into a build.

A callback depends on two properties that have to be set by the end user:

maven.callback.<callbackName>.buildFile
maven.callback.<callbackName>.buildTarget

These are (obviously) the build file and target to call using the <ant>
task.  If either of these attributes are not set, then the callback will
not be "fired."

The callback target will automatically be passed all of the current
properties, but it won't be passed references due to a limitation in Ant
1.4.1.  The "classpath" path (which holds all of a project's dependencies)
is passed to the target as the property "maven.build.classpath", which can
be used like

<some_task_that_needs_a_classpath>
  <classpath path="${maven.build.classpath}" />
</some_task_that_needs_a_classpath>

Adding a Generic Callback
=========================

To add a callback into a build-*.xml, you need to do the following:

1) Insert the following lines at the top of your build-*.xml file:

#set( $callbackCategory = "j2ee" )
#parse("build.init.target")
#set( $callbackCategory = "" )

(where j2ee is your "category" name)

2) In your target's depends attribute, do the following to add the
   callback (example taken from build-j2ee.xml):

   <target name="war"
        depends="local-init,
                 war-error,
                 war-init,
                 #callback("preprocess-war"),
                 war-build,
                 #callback("postprocess-war")"
        description="o Create a war file" />

3) In your Control-*.vm file, adding the following:

callbacks.put( "j2ee", [ "preprocess-war", "postprocess-war" ] );

(where j2ee is your "cateory", and the array are the callback targets you
want to add to your build).

What the Callbacks look like
============================

In your final build-*.xml the targets look like the following (taken from
build-j2ee.xml) :

  <target name="preprocess-war-callback-check">
    <condition property="maven.callback.preprocess-war.ok">
      <not>
        <or>
          <equals arg1="${maven.callback.preprocess-war.buildFile}"
                  arg2="$${maven.callback.preprocess-war.buildFile}" />
          <equals arg1="${maven.callback.preprocess-war.buildTarget}"
                  arg2="$${maven.callback.preprocess-war.buildTarget}" />
        </or>
      </not>
    </condition>
  </target>

  <target name="preprocess-war-callback"
          depends="preprocess-war-callback-check"
          if="maven.callback.preprocess-war.ok">

    <ant antfile="${maven.callback.preprocess-war.buildFile}"
         target="${maven.callback.preprocess-war.buildTarget}">
      <property name="maven.build.classpath" value="classpath" />
    </ant>

  </target>

And the target that depends on these callback targets looks like the
following (taken from build-j2ee.xml) :

    <target name="war"
        depends="local-init,
                 war-error,
                 war-init,
                 preprocess-war-callback,
                 war-build,
                 postprocess-war-callback"
        description="o Create a war file" />


Glenn McAllister
SOMA Networks, Inc.

(See attached file: war-patch.txt)

Attachment: war-patch.txt
Description: Binary data

Reply via email to