Equinox Weaving QuickStart

From Eclipsepedia

Jump to: navigation, search
Note.png
This page replaces the out-of-date "Equinox Aspects Quick-Start Guide"


As of Eclipse Juno (for 2012), these are the steps to enable Equinox Weaving with AspectJ, as cribbed together from various sources. Note that the aop.xml file is no longer necessary.

  • Install the AspectJ Development Tooling (AJDT) and Equinox Weaving from the AJDT Downloads.
  • Define your aspect(s) in a bundle.
  • Configure your bundle's MANIFEST.MF to (i) export its aspects, and (ii) specify the bundles that its aspects advise. The former is done by adding a parameter on the Export-Package header. The latter is done through the Eclipse-SupplementBundle header. For example, a bundle with an aspect swing.edt.EdtRuleChecker, advising bundles com.example.core and com.example.ui would specify:
Export-Package: swing.edt;aspects="EdtRuleChecker"
Eclipse-SupplementBundle: com.example.core,com.example.ui
  • Add the following bundles to your launch configuration
    • org.aspectj.weaver
    • org.eclipse.equinox.weaving.aspectj
    • org.eclipse.equinox.weaving.caching
    • org.eclipse.equinox.weaving.hook
  • Ensure org.eclipse.equinox.weaving.aspectj is auto-started at, say, level 2
  • Add the following VM argument to instruct OSGi to load the weaving hooks:
-Dosgi.framework.extensions=org.eclipse.equinox.weaving.hook

Basically, Eclipse-BundleSupplement effectively causes the specified bundles to import the packages that are exported by the aspects bundle.

Aspects can be defined as opt-in (bundles have to explicitly ask for the aspects to be installed) or opt-out (bundles must explicitly opt-out from weaving). Opt-out is the default policy. For example, to change the policy to opt-in:

Export-Package: swing.debug; aspects="EdtRuleChecker"; aspect-policy:=opt-in

A bundle can explicitly accept or forbid aspects through the apply-aspects parameter on Import-Package:

Import-Package: swing.debug; apply-aspects:=false

true indicates that aspects should be woven into the bundle (the default), whereas false indicates that aspects should not be applied. These parameters override any supplying bundle's aspect-policy.

For debugging output, add the following VM arguments:

-Daj.weaving.verbose=true
-Dorg.aspectj.weaver.showWeaveInfo=true
-Dorg.aspectj.osgi.verbose=true

Sources