You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Trent DiBacco <tr...@headwire.com> on 2014/12/17 23:02:41 UTC

Sling and AOP?

I would like to instrument a few classes using AOP.
These classes are not service, nor are they interfaces, so I would like the
AOP to happen either compile time, or in the class loader.
I want to wrap functionality, not merely inject dependencies.

It would appear that Adobe CRXDE Supportcom.day.crx.crxde-support bundle
uses ASM. http://asm.ow2.org/

Any recommendations?

- Trent




Re: Sling and AOP?

Posted by Robert Munteanu <ro...@apache.org>.
On Wed, 2014-12-17 at 14:02 -0800, Trent DiBacco wrote:
> I would like to instrument a few classes using AOP.
> These classes are not service, nor are they interfaces, so I would like the
> AOP to happen either compile time, or in the class loader.
> I want to wrap functionality, not merely inject dependencies.

If weaving happens at compile time, without affecting depedencies, it
should just work (tm). The only thing to worry about is adding extra
dependencies when weaving, as these need to be reflected in the
Import-Package statements in your MANIFEST.MF . This might be handled by
the maven-bundle-plugin automatically ( if you use that ) or not ,
haven't tried it so far.

Cheers,

Robert



Re: Sling and AOP?

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Wed, Dec 17, 2014 at 11:02 PM, Trent DiBacco <tr...@headwire.com> wrote:
> I would like to instrument a few classes using AOP...

Registering an OSGi WeavingHook [1] service allows you to instrument
classes provided by bundles, before they are used.

You can for example register a WeavingHook in a bundle Activator, and
use bytecode manipulation in that service's weave(...) method.

The WeavingHook needs to be registered before any classes that need
manipulation are loaded, so you might need to start that bundle at a
low OSGi start level.

I'm not familiar enough with bytecode manipulation to recommend one
library over another. The maven-scr-plugin that we are using uses ASM,
source code at [2] if you want to have a look.

-Bertrand

[1] http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/hooks/weaving/WeavingHook.html

[2] http://svn.apache.org/repos/asf/felix/trunk/scrplugin/generator