Search code examples
osgiaspectjequinoxload-time-weavingbndtools

How can I use Equinox Weaving with bndtools


How can I use equinox Weaving with bndtools because the equinox Weaving example is old and can't get it to work?

update:

when trying to run the weaving sample for Hello world

I have two bundles:

public class HelloService  implements BundleActivator {

    public void start(final BundleContext context) throws Exception {
        System.out.println("Hello world!");
    }



    public void stop(final BundleContext context) throws Exception {
        System.out.println("Good bye world!");
    }
}

bnd.bnd

-buildpath:  \
osgi.core,\
osgi.cmpn,\
biz.aQute.bnd.annotation,\
${junit}
Bundle-Version: 0.0.0.${tstamp}
Require-Bundle: helloaspect
Export-Package:  \
com.weaving.hellohistorytest
Bundle-Activator: com.weaving.hellohistorytest.HelloService

aspect bundle:

@Component
@Aspect
public class HelloAspect  {

/**
 * Replaces the "Hello world!" output with "Hi from HelloAspect ;-)".
 */
@Before("execution(* HelloService+.*(..))")
public void advice() {
   System.out.println("hello aspect");
}
}

bnd.bnd

-buildpath:  \
osgi.core,\
osgi.cmpn,\
biz.aQute.bnd.annotation,\
${junit},\
aspectjrt-1.7.3,\
aspectjweaver,\
org.eclipse.equinox.supplement
Bundle-Version: 0.0.0.${tstamp}
Service-Component:  \
    *
Export-Package:  \
com.weaving.helloaspect;aspects="HelloAspect"

Eclipse-SupplementBundle: com.weaving.hellohistorytest

launch.bndrun

runbundles:  \
org.apache.felix.gogo.runtime,\
org.apache.felix.gogo.shell,\
org.apache.felix.gogo.command,\
org.eclipse.equinox.weaving.aspectj,\
org.eclipse.equinox.weaving.hook,\
aspectjweaver,\
aspectjrt-1.7.3,\
osgi.cmpn,\
osgi.core,\
cnf.run.equinox.common,\
org.apache.felix.framework,\
osgi.enterprise,\
org.eclipse.equinox.supplement,\
    helloaspect;version=latest,\
hellohistorytest;version=latest,\

-runproperties:\
osgi.framework.extensions=org.eclipse.equinox.weaving.hook


 -runrequires:\
 osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.shell)',\
 osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)'

-runvm: -Dosgi.framework.extensions=org.eclipse.equinox.weaving.hook,\
-Daj.weaving.verbose=true,\
-Dorg.aspectj.weaver.showWeaveInfo=true,\
-Dorg.aspectj.osgi.verbose=true

when i run the launch: I get Hello world not hello aspect also, Aspect Weaving Hooks Plug-in (Incubation) is set Resolved

what is the problem?


Solution

  • An working source-code example can be found here on GitHub

    Generally the instructions here are also valid for usage with bndtools.

    Add the required bundles

    -runbundles: \
      org.eclipse.equinox.weaving.aspectj,\
      org.aspectj.runtime,\
      org.aspectj.weaver
    

    Make sure that the org.eclipse.equinox.weaving.hook is co-located

    -runpath: org.eclipse.equinox.weaving.hook
    

    And the you need to provide the following runproperties inside the *.bndrun

    -runproperties:\
       osgi.framework.extensions=org.eclipse.equinox.weaving.hook
    

    The following runtime properties are optionally available for debugging. Note that the output goes always to std.err stream even if they work normally).

    aj.weaving.verbose=true,\
    org.aspectj.weaver.showWeaveInfo=true,\
    org.aspectj.osgi.verbose=true,\