Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-dev] Using WeavingHook in eclipse

No, weaving hooks are as low level as you can get.  You need to do that filtering yourself.  You can tell what bundle the class bytes are for by looking at the WovenClass that is passed into your weave method:

wovenClass.getBundleWiring().getBundle();
 
If you are using the OSGi WeavingHook you should not need the org.eclipse.equinox.weaving bundle nor the org.eclipse.equinox.region bundle.  I noticed an earlier message in this thread indicated you were trying to require these Equinox bundles.  Note that equinox.region is a system bundle fragment and cannot be required like that.  I would recommend you use Import-Package only for the org.osgi packages.
 
Finally, if you can manage it, low level hook implementations like the WeavingHook are best registered as a system.bundle fragment with an ExtensionBundle-Activator. 
 
 
This allows you weaving hook to be registered as part of the OSGi initialization which is before a single class is loaded out of the normal bundles.  But this does mean your weaving hook needs to be self-contained and cannot depend on any "normal" bundles, it must be able to work with only what the Framework and JVM provide.  I realize that is not always easy if you need some other class processing library to do the weaving.
 
I suggest you avoid using declarative services altogether to register such low level hooks.  There are several bug reports discussing the troubles had with registering weaving hooks with declarative services and still this Felix SCR issue open.
 
 

Tom
 
 
----- Original message -----
From: Gayan Perera <gayanper@xxxxxxxxx>
Sent by: platform-dev-bounces@xxxxxxxxxxx
To: "Eclipse platform general developers list." <platform-dev@xxxxxxxxxxx>
Cc:
Subject: [EXTERNAL] Re: [platform-dev] Using WeavingHook in eclipse
Date: Sun, Oct 25, 2020 1:30 PM
 
Ok Now my Hook is called, but it is called for all classes, I would only like to weave the ImageDescriptor class, is there a way i can tell only call my hook for jface bundle only ?
 
Gayan.
 
On Sun, Oct 25, 2020 at 7:04 PM Gayan Perera <gayanper@xxxxxxxxx> wrote:
Nice the p2.inf did the trick.
 
Thanks all.
 
On Sun, Oct 25, 2020 at 6:56 PM Gayan Perera <gayanper@xxxxxxxxx> wrote:
Thanks Christoph,
Mine is a eclipse plugin, i will try to p2.inf approach.
 
Gayan.
 
 
On Sun, Oct 25, 2020 at 6:52 PM Christoph Läubrich <laeubi@xxxxxxxxxxxxxx> wrote:
It all depends on the context.

If you run from a product for example, add your bundle to the
configuration, set its autostart=true and startlevel=1

If you bundle is just an eclipse-plugin you would need to provide a
p2.inf to configure appropriate start-levels and edit your runconfig
accordingly.

Am 25.10.20 um 18:48 schrieb Gayan Perera:
> Hi Christoph,
>
> How can i make my bundle start early as possible, I tried registering my
> hook at Activator, but i couldn't get the bundle to start. Thats why i
> though may be the service annotation would start my bundle early.
>
> Gayan
>
> On Sun, Oct 25, 2020 at 6:37 PM Christoph Läubrich
> <laeubi@xxxxxxxxxxxxxx <mailto:laeubi@xxxxxxxxxxxxxx>> wrote:
>
>     WeavingHooks require a good knowledge of how OSGi works as they have
>     several constraints and implications.
>
>     I can only recommend to start with an absolute minimal example (aka
>     Hook
>     with system.out), lazy loading is NOT sufficient for making
>     WeavingHooks
>     work, dependencies should be cut down to the absolute minimum as you
>     won't be able to (reliable) weave any class you depend on!
>
>     So the very first steps should include:
>     - create a bundle with only osgi+weaving requirements as PACKAGE(!)
>     imports
>     - make sure your bundle is startet AS EARLY as possible
>     - do not use DS or any other abstraction laver but register your
>     WeavinHook with an Activator
>     - make sure you are able to debug resolving/startup issues
>
>     If all that is done, you can try to enhance your bundle to do the
>     actual
>     tasks.
>
>
>     Am 25.10.20 um 18:22 schrieb Gayan Perera:
>      > I tried adding the correct dependencies, but i couldn't find the
>     bundles
>      > in bundle dependencies, i searched in update site and orbit as
>     well, but
>      > i could only find the source bundles. But for some reason the
>     classes
>      > seems to be resolved for compilation.
>      >
>      > Where can i get the correct bundles ? I'm using 4.18 Ibuild and 4.17
>      > release as my PDE target runtimes.
>      >
>      > Gayan.
>      >
>      > On Sun, Oct 25, 2020 at 6:17 PM Dirk Fauth
>     <dirk.fauth@xxxxxxxxxxxxxx <mailto:dirk.fauth@xxxxxxxxxxxxxx>
>      > <mailto:dirk.fauth@xxxxxxxxxxxxxx
>     <mailto:dirk.fauth@xxxxxxxxxxxxxx>>> wrote:
>      >
>      >     Well your bundle requirement looks very wrong since you
>     require the
>      >     source bundles that IMHO are not part of the runtime and of
>     course
>      >     you should never require sources! That is why your bundle
>     does not
>      >     start.
>      >
>      >     Gayan Perera <gayanper@xxxxxxxxx <mailto:gayanper@xxxxxxxxx>
>     <mailto:gayanper@xxxxxxxxx <mailto:gayanper@xxxxxxxxx>>>
>      >     schrieb am So., 25. Okt. 2020, 18:13:
>      >
>      >         Hi Dirk,
>      >         Yes PDE annotation are enabled.
>      >         The xml generated inside OSGI-INF looks like this
>      >
>      >         *<?xml version="1.0" encoding="UTF-8"?>*
>      >
>      >       
>       *<**scr:component**xmlns:scr=*/"http://www.osgi.org/xmlns/scr/v1.1.0 <http://www.osgi.org/xmlns/scr/v1.1.0>
>      >         <http://www.osgi.org/xmlns/scr/v1.1.0
>     <http://www.osgi.org/xmlns/scr/v1.1.0>>"/*immediate=*/"true"/*name=*/"org.gap.eclipse.plugins.eclipseiconpacks.core.IconPackWeavingHook"/*>*
>      >
>      >         *<service>*
>      >
>      >       
>       *<provide**interface=*/"org.osgi.framework.hooks.weaving.WeavingHook"/*/>*
>      >
>      >         *</service>*
>      >
>      >       
>       *<implementation**class=*/"org.gap.eclipse.plugins.eclipseiconpacks.core.IconPackWeavingHook"/*/>*
>      >
>      >         *</scr:component>*
>      >
>      >
>      >         My build.properties looks like this
>      >
>      >
>      >         source.. = src/main/java/
>      >
>      >         output.. = target/classes/
>      >
>      >         bin.includes = plugin.xml,\
>      >
>      >                         META-INF/,\
>      >
>      >                         .,\
>      >
>      >                         icons/,\
>      >
>      >                         OSGI-INF/
>      >
>      >
>      >         Manifest looks like this
>      >
>      >         *Manifest-Version**:*/1.0/
>      >
>      >         *Bundle-ManifestVersion**:*/2/
>      >
>      >         *Bundle-Name**:*/eclipse-icon-packs Core Plugin/
>      >
>      >       
>       *Bundle-SymbolicName**:*/eclipse-icon-packs.core;//singleton/*:=*/true/
>      >
>      >         *Bundle-Version**:*/0.0.1. <http://0.0.1.>qualifier/
>      >
>      >       
>       *Bundle-Activator**:*/org.gap.eclipse.plugins.eclipseiconpacks.core.Activator/
>      >
>      >         *Require-Bundle**:*/org.eclipse.core.runtime,/
>      >
>      >         / org.eclipse.osgi.services,/
>      >
>      >         / org.eclipse.equinox.region.source,/
>      >
>      >         / org.eclipse.equinox.weaving.hook.source/
>      >
>      >         *Bundle-RequiredExecutionEnvironment**:*/JavaSE-1.8/
>      >
>      >         *Bundle-ActivationPolicy**:*/lazy/
>      >
>      >       
>       *Service-Component**:*/OSGI-INF/org.gap.eclipse.plugins.eclipseiconpacks.core.IconPackWeavingHook.xml/
>      >
>      >       
>       *Export-Package**:*/org.gap.eclipse.plugins.eclipseiconpacks.core/
>      >
>      >         /
>      >         /
>      >         Gayan
>      >
>      >
>      >
>      >         On Sun, Oct 25, 2020 at 6:02 PM Dirk Fauth
>      >         <dirk.fauth@xxxxxxxxxxxxxx
>     <mailto:dirk.fauth@xxxxxxxxxxxxxx> <mailto:dirk.fauth@xxxxxxxxxxxxxx
>     <mailto:dirk.fauth@xxxxxxxxxxxxxx>>>
>      >         wrote:
>      >
>      >             Do you have pde ds annotations enabled? Because then the
>      >             bundle activation policy should be lazy by default.
>     And also
>      >             the @Component annotation is processed correctly.
>      >
>      >             Gayan Perera <gayanper@xxxxxxxxx
>     <mailto:gayanper@xxxxxxxxx>
>      >             <mailto:gayanper@xxxxxxxxx
>     <mailto:gayanper@xxxxxxxxx>>> schrieb am So., 25. Okt. 2020,
>      >             17:59:
>      >
>      >                 Hi Wim,
>      >
>      >                 No the bundle is not getting started, i thought
>     exposing
>      >                 the service descriptor should start the bundle.
>     But its
>      >                 not getting started, i put a break point in
>      >                 BundleActivator start method to see. It doesn't
>     get hit.
>      >
>      >                 Gayan.
>      >
>      >                 On Sun, Oct 25, 2020 at 4:49 PM Wim Jongman
>      >                 <wim.jongman@xxxxxxxxx
>     <mailto:wim.jongman@xxxxxxxxx> <mailto:wim.jongman@xxxxxxxxx
>     <mailto:wim.jongman@xxxxxxxxx>>>
>      >                 wrote:
>      >
>      >                     Hi,
>      >
>      >                     Is the bundle started?
>      >
>      >                     Cheers,
>      >
>      >                     Wim
>      >
>      >                     On Sun, Oct 25, 2020 at 1:58 PM Gayan Perera
>      >                     <gayanper@xxxxxxxxx
>     <mailto:gayanper@xxxxxxxxx> <mailto:gayanper@xxxxxxxxx
>     <mailto:gayanper@xxxxxxxxx>>> wrote:
>      >
>      >                         Hi,
>      >
>      >                         I’m trying to register a weavinghook using
>      >                         services descriptors. I annotated my
>     weavinghook
>      >                         class with component annotation and
>     inhave the
>      >                         osgi folder with the service descriptor
>     xml in
>      >                         place. The osgi folder is included in
>      >                         build.properties as well. But the
>     weavinghook is
>      >                         not getting called. Can someone guide me
>     how to
>      >                         get this working.
>      >
>      >                         My endgoal is to weave ImageDescriptor
>     class to
>      >                         support override bundle images.
>      >
>      >                         Best regards,
>      >                         Gayan.
>      >                       
>       _______________________________________________
>      >                         platform-dev mailing list
>      > platform-dev@xxxxxxxxxxx <mailto:platform-dev@xxxxxxxxxxx>
>      >                         <mailto:platform-dev@xxxxxxxxxxx
>     <mailto:platform-dev@xxxxxxxxxxx>>
>      >                         To unsubscribe from this list, visit
>      > https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>
>      >                       
>       <https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>>
>      >
>      >                     _______________________________________________
>      >                     platform-dev mailing list
>      > platform-dev@xxxxxxxxxxx <mailto:platform-dev@xxxxxxxxxxx>
>      >                     <mailto:platform-dev@xxxxxxxxxxx
>     <mailto:platform-dev@xxxxxxxxxxx>>
>      >                     To unsubscribe from this list, visit
>      > https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>
>     <https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>>
>      >
>      >                 _______________________________________________
>      >                 platform-dev mailing list
>      > platform-dev@xxxxxxxxxxx <mailto:platform-dev@xxxxxxxxxxx>
>     <mailto:platform-dev@xxxxxxxxxxx <mailto:platform-dev@xxxxxxxxxxx>>
>      >                 To unsubscribe from this list, visit
>      > https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>
>      >               
>       <https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>>
>      >
>      >             _______________________________________________
>      >             platform-dev mailing list
>      > platform-dev@xxxxxxxxxxx <mailto:platform-dev@xxxxxxxxxxx>
>     <mailto:platform-dev@xxxxxxxxxxx <mailto:platform-dev@xxxxxxxxxxx>>
>      >             To unsubscribe from this list, visit
>      > https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>
>      >           
>       <https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>>
>      >
>      >         _______________________________________________
>      >         platform-dev mailing list
>      > platform-dev@xxxxxxxxxxx <mailto:platform-dev@xxxxxxxxxxx>
>     <mailto:platform-dev@xxxxxxxxxxx <mailto:platform-dev@xxxxxxxxxxx>>
>      >         To unsubscribe from this list, visit
>      > https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>
>      >         <https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>>
>      >
>      >     _______________________________________________
>      >     platform-dev mailing list
>      > platform-dev@xxxxxxxxxxx <mailto:platform-dev@xxxxxxxxxxx>
>     <mailto:platform-dev@xxxxxxxxxxx <mailto:platform-dev@xxxxxxxxxxx>>
>      >     To unsubscribe from this list, visit
>      > https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>
>      >     <https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>>
>      >
>      >
>      > _______________________________________________
>      > platform-dev mailing list
>      > platform-dev@xxxxxxxxxxx <mailto:platform-dev@xxxxxxxxxxx>
>      > To unsubscribe from this list, visit
>     https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>
>      >
>     _______________________________________________
>     platform-dev mailing list
>     platform-dev@xxxxxxxxxxx <mailto:platform-dev@xxxxxxxxxxx>
>     To unsubscribe from this list, visit
>     https://www.eclipse.org/mailman/listinfo/platform-dev
>     <https://www.eclipse.org/mailman/listinfo/platform-dev>
>
>
> _______________________________________________
> platform-dev mailing list
> platform-dev@xxxxxxxxxxx
> To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/platform-dev
>
_______________________________________________
platform-dev mailing list
platform-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/platform-dev
_______________________________________________
platform-dev mailing list
platform-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/platform-dev
 


Back to the top