Login | Register
My pages Projects Community openCollabNet

Discussions > dev > [phing-dev] Making it easy to add new inherited types to phing

phing
Discussion topic

Back to topic list

[phing-dev] Making it easy to add new inherited types to phing

Author cweiske
Full name Christian Weiske
Date 2011-09-11 23:26:36 PDT
Message Hi all,


As seen in my last mails, my goal is to add a new fileset type to phing.
It extends the original FileSet type (is API-compatible) and is to be
used in addition to normal filesets.

I've had trouble using it in my build files, because the phing tasks
do not have support for the new fileset type (and never should need to
support it, since it has the same API as the already supported FileSet).

>> [me:]
>> So now my question: How can I make the second example work without
>> adding a "createPearPackageFileset" method to every single task?
> [Michiel:]
> ... I don't think you can. You need a set/add/create method for
> distinct sub elements.

This bothers me. I thought about it and have several possible solutions:

0. Add a new creator/adder method to each of the 42 tasks that support
   filesets. This is no option, since extending phing the next time
   will not be easier than now.

1. Re-use the same <fileset> tag for several fileset types, and
   distinguish them with a "type" attribute. This way, the
   creator/adder methods are already there. The creator methods would
   need to get passed the real class name, otherwise we'd still get
   normal FileSet instances.

2. Use the class inheritance tree to find a matching adder method for
   the new type - e.g. when "pearPackageFileSet extends FileSet" and
   the task has a addFileSet, but no addPearPackageFileSet method, the
   addFileSet one is used.
   This does not work with creator methods, so we need to pass the
   type class name to the task like in #1.

3. New types provide a "compatible to" method that returns the name of
   the type tag they are compatible to, e.g. pearPackageFileSet would
   return FileSet.

Do you have other ideas? I'd love to hear them.


Option 0: Not really an option because it requires to change the code
          every time a new compatible type is added.

Option 1: Introduces ambiguity into the code and makes it less
          readable. Also, creator methods need to be changed - we
          don't save work.

Option 2: This is my preferred option since with inheritance resolution,
          creator/adder detection is fully automatic.

Option 3: Similar to option 2, but without automatic tag detection.
          I prefer option 2 to this since writing a method less in the
          types is better than saving some LOC in the phing core code.


For me, option 2 is the way to go. It requires several steps:
0. Move as many createFileset methods in tasks as possible to
   addFileset, because most do not do anything special in their creation
   methods.
1. Let create methods in get an optional targetclassname parameter
   which they may ignore. Phing needs to check the returned type and
   throw a BuildException if they do not return the correct type,
   though.
2. Add the automatic creator/adder method detection to phing.

In the end, phing will be more extendable.


Example:
- new type pearPackageFileSet extends FileSet
- build file has contains for example
  <copy>
   <pearpackagefileset .../>
  </copy>
- phing detects pearpackagefileset, and that copy has no
  createPearPackageFil​eSet/addPearPackageF​ileSet method.
- phing looks up the class hierarchy: fileset. Since copytask has a
  addFileSet method, phing creates the instance and calls
  $copytask->addFi​leSet($pearPackageF​ileSetInstance)
- if copytask had only a createFileSet method, it'd call
  $copytask->creat​eFileSet('pearPackag​eFileSet')


--
Regards/Mit freundlichen Grüßen
Christian Weiske

-=≡ Geeking around in the name of science since 1982 ≡=-
Attachments

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

[phing-dev] Making it easy to add new inherited types to phing cweiske Christian Weiske 2011-09-11 23:26:36 PDT
Messages per page: