Posted tagged ‘aop’

Let Ant tasks choose the attribute values by themself

30. Oktober 2009

For a long time an idea travelled in my head. But now it arrived.

In my several Ant build files I have constructs like

<javac source=”${javac.source}” debug=”${javac.debug}” target=”${javac.target}” …

and the according properties defined in an external file. Now have a compile run for the source code and the test code and you have doubled this amount of configuration. And I thought that just writing a <javac> and starting with an -autoconf option would be easier.

The idea is: apply the properties directly before the task execution.

So I could implement a method call in oata.Task.perform() direclty before calling the execute() method.
Hhm …. I don’t want to change the Ant core that deeply because so many external tasks exist and I don’t want to (maybe) break their build.

Another idea is using an AOP framework like AspectJ for jumping in: before <? extends Task>.execute() : applyAttributeValues()
(I am not familiar with AspectJ but you get the idea.)
But then I would depend on the AOP library. That’s nothing for the Core. And Ant options should not depend on any further libraries.
I could implement it as a task:

  <project><autoconf/><javac/></project>    

Better. But I have to learn AspectJ … so not for now…

On the Hudson dev-mailinglist I heard from the Hudson Clover Plugin. It gatheres code coverage from Ant jobs WITHOUT configuring the job itself.-It adds a BuildListener which stores the srcdir and destdir values from <javac> tasks.
Nice idea …. use the Listeners taskStarted(event) and taskFinished(event) methods for doing AOP-stuff.

This results in the <autoconf> task, currently in the sandbox and feedback is welcome.

The goal:

  • apply attribute values from properties
  • do not overwrite user specified values
  • switch on/off the behaviour
  • support name prefix for using different values for different targets

While the last two points are easily to implement (add/remove the listener, use a prefix for property search) the first two are difficult.

apply attribute values from properties / which attributes are supported by a given task?

Why is this difficult? Just ask mytask.getClass() for declared setters ….

The problem is that you don’t get the task object. Due lazy instantiation/configuration the only thing you get from the BuildEvent is an UnknownElement. And therefore you cannot just ask getClass() for the class object you need.

I saw three different strategies according to that value:

  • if it is a <macrodef> I could ask it directly for its <attribute>s
  • if it is a normal task I ask the class object
  • if it is a <presetdef> I ask the class object from preset.getTypeClass()

do not overwrite user specified values

I could ask an object for its values, but which are set by the user and which are just implementation defaults? From the Java perspective you cannot distinguish between them…

My strategy is using a “clean” object (I called it template object) and compare its values with the values from the given object.

Werbung

IT-News 2007.10.10

10. Oktober 2007

PHP-Videotutorials for Webdesigners

(English) Article: Concurrency Testing in Java Applications

Create Web services in two clicks thanks to Apache CXF and AOP
This sounds really cool – enhancing existing classes with webservice capability by using AOP. But I could also think about another aproach: deploy a POJO into a container and just describe which methods should be opened … mmh, sounds like Java6 with the information of the annotions in an extra file … But I think document centric development would be better because of interoperability with other languages.

Eclipse ETranslator
Nice – a plugin which translates I18N resource files into other languages … but you (or better a native speaker) should check the results – I dont trust automatic translations …