Do cflow targets need to be woven?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Do cflow targets need to be woven?

Eric B
I'm trying to use cflow to limit the scope of my pointcut, but it when I add the cflow argument, the pointcut is not intercepting the call at all.  In my build process, the cflow target is not part of the weaving at all.  Does the cflow target need to be part of the build/weave process?  Or is my pointcut wrong?

@Aspect
class MultiChoiceNullAspect{
@Pointcut("cflowbelow(execution( void javax.faces.webapp.FacesServlet.service(..) ) && !within(MultiChoiceNullAspect))")
public void facesServletCFlow(){}
@Pointcut("facesServletCFlow() && execution( public org.model.questionnaire.MultiChoiceItem* get*(..))")
public void multiChoiceObjects() {}
@Around("multiChoiceObjects()")
public Object emptyMultiChoice( final ProceedingJoinPoint pjp) throws Throwable{
Object o = pjp.proceed();
// if the return object is null, create an empty MultiChoice object instead 
if( o == null ){
return new MultiChoiceItem();
}

return o;
}
}



And my build instructions:
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.10</version>
                <configuration>
                    <showWeaveInfo>true</showWeaveInfo>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <complianceLevel>${java.version}</complianceLevel>
                    <encoding>UTF-8</encoding>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>



Essentially, I'm trying to advise the execution of all getters that return MultiChoiceItem* when they are as part of the javax.faces.webapp.FacesServlet.service() method/flow.

Does the FacesServlet class need to be passed to the ajc compiler as well?  Or are the cflow() arguments just evaluated at runtime and don't need to be present in the compiler?  If the later, what am I doing wrong - why is my pointcut not triggering?

Thanks,

Eric


_______________________________________________
aspectj-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users
Reply | Threaded
Open this post in threaded view
|

Re: Do cflow targets need to be woven?

Andy Clement
Yes, the cflow target is woven to indicate 'this cflow is being entered' then at the real target place to weave it is a very simple/quick check to see 'are we in the cflow?'. There would be a less optimal implementation that looks at the stack trace at the actual join point target but we've never investigated implementing that. I suppose as a sub-optimal workaround you could inspect that stack yourself in your advice if you really can't weave the actual cflow target.

cheers,
Andy

On 24 April 2017 at 21:21, Eric B <[hidden email]> wrote:
I'm trying to use cflow to limit the scope of my pointcut, but it when I add the cflow argument, the pointcut is not intercepting the call at all.  In my build process, the cflow target is not part of the weaving at all.  Does the cflow target need to be part of the build/weave process?  Or is my pointcut wrong?

@Aspect
class MultiChoiceNullAspect{
@Pointcut("cflowbelow(execution( void javax.faces.webapp.FacesServlet.service(..) ) && !within(MultiChoiceNullAspect))")
public void facesServletCFlow(){}
@Pointcut("facesServletCFlow() && execution( public org.model.questionnaire.MultiChoiceItem* get*(..))")
public void multiChoiceObjects() {}
@Around("multiChoiceObjects()")
public Object emptyMultiChoice( final ProceedingJoinPoint pjp) throws Throwable{
Object o = pjp.proceed();
// if the return object is null, create an empty MultiChoice object instead 
if( o == null ){
return new MultiChoiceItem();
}

return o;
}
}



And my build instructions:
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.10</version>
                <configuration>
                    <showWeaveInfo>true</showWeaveInfo>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <complianceLevel>${java.version}</complianceLevel>
                    <encoding>UTF-8</encoding>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>



Essentially, I'm trying to advise the execution of all getters that return MultiChoiceItem* when they are as part of the javax.faces.webapp.FacesServlet.service() method/flow.

Does the FacesServlet class need to be passed to the ajc compiler as well?  Or are the cflow() arguments just evaluated at runtime and don't need to be present in the compiler?  If the later, what am I doing wrong - why is my pointcut not triggering?

Thanks,

Eric


_______________________________________________
aspectj-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users