Maven 1.x AspectJ Plugin

Optional Aspects

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 3.2
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    6

Description

We need the ability to weave in optional aspects.

  1. optional-aspects.diff
    03/Oct/04 11:48 AM
    8 kB
    Mark Proctor
  2. optional-aspects.diff
    21/Sep/04 5:28 PM
    3 kB
    Mark Proctor
  3. optional-aspects.diff
    02/Aug/04 4:25 PM
    2 kB
    Mark Proctor
  4. plugin.jelly
    21/Sep/04 5:29 PM
    9 kB
    Mark Proctor

Activity

Hide
Mark Proctor added a comment -

This diff allows optional aspects files to be included by specifying a comma delimited list in maven.aspectj.aspects. It uses the iajc argfiles propertly.

if you use maven.aspectj.aspects only those files are weaved, other aspects in your aspect source directory will be ignored.

The files specifed in maven.aspectj.aspects are line delimeted files either specifying the aspects to weave, or other line delimited files to process. Aspects are relative to the config file that specifies them.

Show
Mark Proctor added a comment - This diff allows optional aspects files to be included by specifying a comma delimited list in maven.aspectj.aspects. It uses the iajc argfiles propertly. if you use maven.aspectj.aspects only those files are weaved, other aspects in your aspect source directory will be ignored. The files specifed in maven.aspectj.aspects are line delimeted files either specifying the aspects to weave, or other line delimited files to process. Aspects are relative to the config file that specifies them.
Hide
Mark Proctor added a comment -

I have further enhanced this in drools and include for reference purposes.

So that users can specify features they want compiled in at runtime I create a file in src/aspects/conf that specifes the aspects to weave for that feature. That way I can just do the following to specify the features I want:
drools.aspects = event-model, trace

The code to achieve this is:

<preGoal name="java:compile">
<j:set var="droolsAspects" value="${drools.aspects}"/>

<j:if test="${droolsAspects != null}">
<util:tokenize var="tokens" delim="," trim="true">${droolsAspects}</util:tokenize>

<j:forEach var="token" items="${tokens}">
<j:set var="mavenAspects" value="${mavenAspects},src/aspects/conf/${token.trim()}.conf"/>
</j:forEach>

<j:if test="${mavenAspects != ''}">
<j:set var="maven.aspectj.aspects" value="${mavenAspects}" />

<attainGoal name="aspectj:compile"/>
</j:if>
</j:if>

</preGoal>

Show
Mark Proctor added a comment - I have further enhanced this in drools and include for reference purposes. So that users can specify features they want compiled in at runtime I create a file in src/aspects/conf that specifes the aspects to weave for that feature. That way I can just do the following to specify the features I want: drools.aspects = event-model, trace The code to achieve this is: <preGoal name="java:compile"> <j:set var="droolsAspects" value="${drools.aspects}"/> <j:if test="${droolsAspects != null}"> <util:tokenize var="tokens" delim="," trim="true">${droolsAspects}</util:tokenize> <j:forEach var="token" items="${tokens}"> <j:set var="mavenAspects" value="${mavenAspects},src/aspects/conf/${token.trim()}.conf"/> </j:forEach> <j:if test="${mavenAspects != ''}"> <j:set var="maven.aspectj.aspects" value="${mavenAspects}" /> <attainGoal name="aspectj:compile"/> </j:if> </j:if> </preGoal>
Hide
Carlos Sanchez added a comment -

Here's more info from the AJDT project http://tinyurl.com/4boct

Show
Carlos Sanchez added a comment - Here's more info from the AJDT project http://tinyurl.com/4boct
Hide
Carlos Sanchez added a comment -

I'm having trouble applying the patch, could you post it in unified diff format? (diff -u)

Show
Carlos Sanchez added a comment - I'm having trouble applying the patch, could you post it in unified diff format? (diff -u)
Hide
Mark Proctor added a comment -

ok I'll get that diff -U to you asap. do you still want the example, if so I'll try and knock up and something this weekend.

That link doesn't work.

Mark

Show
Mark Proctor added a comment - ok I'll get that diff -U to you asap. do you still want the example, if so I'll try and knock up and something this weekend. That link doesn't work. Mark
Hide
Carlos Sanchez added a comment -

Ok, if you can make the example I'll thank you.

This link works for me
http://tinyurl.com/4boct
else
http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/org.eclipse.ajdt/AJDT_30M9_src/org.eclipse.ajdt/doc/AJDTug/ajdt-newbuildconfigs.html

I think you'll find interesting the last section titled "Using .ajproperties files with Ant"

Show
Carlos Sanchez added a comment - Ok, if you can make the example I'll thank you. This link works for me http://tinyurl.com/4boct else http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/org.eclipse.ajdt/AJDT_30M9_src/org.eclipse.ajdt/doc/AJDTug/ajdt-newbuildconfigs.html I think you'll find interesting the last section titled "Using .ajproperties files with Ant"
Hide
Mark Proctor added a comment -

Sorry about slacking on this one. I held off while I was looking into .ajproperties as that seemed the better way of doing it, rather than with .lst - do you know the status of this, do the current release versions use this, or is it still a dev feature?

Mark

Show
Mark Proctor added a comment - Sorry about slacking on this one. I held off while I was looking into .ajproperties as that seemed the better way of doing it, rather than with .lst - do you know the status of this, do the current release versions use this, or is it still a dev feature? Mark
Hide
Carlos Sanchez added a comment -

No idea, you should ask in the aspectj mailing list

Show
Carlos Sanchez added a comment - No idea, you should ask in the aspectj mailing list
Hide
Mark Proctor added a comment -

It seems that ajproperties is not support by iajc yet, nor is it supported by the ant task AjcTask.

The docs in ajdt claims that you can use includes/excluds on the AjcTask, this is only ajc, iajc only supports SourceRoots and SourceRootsList.

For this reason I believe it makes sense to continue with the .lst format, untill ajproperties are better supported.

Show
Mark Proctor added a comment - It seems that ajproperties is not support by iajc yet, nor is it supported by the ant task AjcTask. The docs in ajdt claims that you can use includes/excluds on the AjcTask, this is only ajc, iajc only supports SourceRoots and SourceRootsList. For this reason I believe it makes sense to continue with the .lst format, untill ajproperties are better supported.
Hide
Mark Proctor added a comment -

optional-aspects.diff

Show
Mark Proctor added a comment - optional-aspects.diff
Hide
Mark Proctor added a comment -

fully jelly file if problems with diff

Show
Mark Proctor added a comment - fully jelly file if problems with diff
Hide
Mark Proctor added a comment -

Example application.

Change comments in project.properties file by uncommenting one of the maven.aspectj.aspects properties:
#maven.aspectj.aspects = hello.lst
maven.aspectj.aspects = goodbye.lst

Different message printed depending on which .lst file you specify

Show
Mark Proctor added a comment - Example application. Change comments in project.properties file by uncommenting one of the maven.aspectj.aspects properties: #maven.aspectj.aspects = hello.lst maven.aspectj.aspects = goodbye.lst Different message printed depending on which .lst file you specify
Hide
Mark Proctor added a comment -

To execute the example type "maven clean run"

Show
Mark Proctor added a comment - To execute the example type "maven clean run"
Hide
Carlos Sanchez added a comment -

Documentation and automated tests (check src/plugin-test) are required to commit the changes.
If I have to do them myself the commit will be delayed.

Show
Carlos Sanchez added a comment - Documentation and automated tests (check src/plugin-test) are required to commit the changes. If I have to do them myself the commit will be delayed.
Hide
Carlos Sanchez added a comment -

maven.aspectj.aspects should be renamed to maven.aspectj.argfiles, to be more exact.

Show
Carlos Sanchez added a comment - maven.aspectj.aspects should be renamed to maven.aspectj.argfiles, to be more exact.
Hide
Mark Proctor added a comment -

I'll update the property as you suggested and move the example I wrote to a unit test.

Show
Mark Proctor added a comment - I'll update the property as you suggested and move the example I wrote to a unit test.
Hide
Mark Proctor added a comment -

I'm not sure how to unit test this, as part of the standard Maven UnitTest framework; as each test would require a "maven clean" and a "maven jar" for re-compilation. Any ideas?

Mark

Show
Mark Proctor added a comment - I'm not sure how to unit test this, as part of the standard Maven UnitTest framework; as each test would require a "maven clean" and a "maven jar" for re-compilation. Any ideas? Mark
Hide
Mark Proctor added a comment -

Just chatting on #maven on irc and think I can alter maven.xml to do this, although I think it might get a little messy:
<goal name="testPlugin" prereqs="clean,test-aspectj-compile">
</goal>

<goal name="test-aspectj-compile">
<attainGoal name="aspectj:test-compile"/>
<attainGoal name="test:test"/>
<attainGoal name="clean"/>
</goal>

Show
Mark Proctor added a comment - Just chatting on #maven on irc and think I can alter maven.xml to do this, although I think it might get a little messy: <goal name="testPlugin" prereqs="clean,test-aspectj-compile"> </goal> <goal name="test-aspectj-compile"> <attainGoal name="aspectj:test-compile"/> <attainGoal name="test:test"/> <attainGoal name="clean"/> </goal>
Hide
Carlos Sanchez added a comment -

You can add a new aspect to the test e.g. throwing an exception, a .lst to ignore that aspect and then you won't need to modify maven.xml

Show
Carlos Sanchez added a comment - You can add a new aspect to the test e.g. throwing an exception, a .lst to ignore that aspect and then you won't need to modify maven.xml
Hide
Mark Proctor added a comment -

This is an updated diff which includes unit testing of optional aspects.

It runs the unit test twice. The first time for the standard aspectsSourceDirectory, the second time using the given .list file. A system property is provided so that the unit test knows which mode its in, and thus which tests to run.

Show
Mark Proctor added a comment - This is an updated diff which includes unit testing of optional aspects. It runs the unit test twice. The first time for the standard aspectsSourceDirectory, the second time using the given .list file. A system property is provided so that the unit test knows which mode its in, and thus which tests to run.
Hide
Mark Proctor added a comment -

Incase there are any problems with the diff I have included the entire aspectj folder as a zip file.

Show
Mark Proctor added a comment - Incase there are any problems with the diff I have included the entire aspectj folder as a zip file.
Hide
Carlos Sanchez added a comment -

Good work, thanks. I have changed a small thing, adding maven.aspectj.weaveAspectSources because argfiles can be used for other things than choosing aspects.

You can download it from http://cvs.apache.org/repository/maven/plugins/

If you check everything is correct I'll release the 3.2 version

Show
Carlos Sanchez added a comment - Good work, thanks. I have changed a small thing, adding maven.aspectj.weaveAspectSources because argfiles can be used for other things than choosing aspects. You can download it from http://cvs.apache.org/repository/maven/plugins/ If you check everything is correct I'll release the 3.2 version
Hide
Mark Proctor added a comment -

works great. Using the example goal above I can now specify my aspects to compile in project.properties as:
drools.aspects = event
#drools.aspects = profile
#drools.aspects = event, profile

This should make things a lot easier for everyone, 3.2 asap please

Show
Mark Proctor added a comment - works great. Using the example goal above I can now specify my aspects to compile in project.properties as: drools.aspects = event #drools.aspects = profile #drools.aspects = event, profile This should make things a lot easier for everyone, 3.2 asap please
Hide
Carlos Sanchez added a comment -

You can also use
maven whatever -Ddrools.aspects=event
maven whatever -Ddrools.aspects=profile
maven whatever -Ddrools.aspects=event,profile

Show
Carlos Sanchez added a comment - You can also use maven whatever -Ddrools.aspects=event maven whatever -Ddrools.aspects=profile maven whatever -Ddrools.aspects=event,profile

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: