[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] How to provide external pcd definition?

Hi,

On the Pattern Testing project (http://patterntesting.sf.net), we have
aspects that enforce some design rules. For example:

public abstract aspect AbstractDatabaseTestAspect
{
    /**
     * Specify what is application code that should be subject to the
     * pattern test.
     * 
     * Ex: <code>pointcut applicationCode():
within(patterntesting.*)</code>
     */
    public abstract pointcut applicationCode();

    /**
     * Specify which classes are allowed to call JDBC.
     */
    public abstract pointcut allowedCode();

    /**
     * Specify which JDBC calls are forbidden.
     */
    pointcut forbiddenCalls() :
        call(public * java.sql..*(..)) ||
        call(public * javax.sql..*(..));
    
    /**
     * Raise error if violations found.
     */
    declare error: (applicationCode() && forbiddenCalls()) &&
!allowedCode() :
        "It is not allowed to use the JDBC API from here";
}

Now, the question is: How can we make the applicationCode and
allowedCode pointcuts configurable by the end users? 

Of course one solution is to have create classes that extend the
abstract aspect. However that sounds complex when compared to simple
configuration data (the end users would need to create a project where
to put the code, etc).

Any idea?

Note: The solution we're using so far (but which I don't like because
it's tied to the build system) is to use Ant filters:

public aspect DatabaseTestAspect extends AbstractDatabaseTestAspect
{
    public pointcut applicationCode() :
        @maven.patterntesting.suite.java.database.applicationCode@;
    public pointcut allowedCode() :
        @maven.patterntesting.suite.java.database.allowedCode@;
}

Thanks
-Vincent