Hi Alex, The dump command can look like this (needs some enhancements since this one was a simplified version but it can be a good start): https://github.com/yupiik/jira-cli-native/blob/master/src/main/java/io/yupiik/jira/cli/command/impl/internal/dump/Dump.java#L58 The stable name setup is done with https://github.com/yupiik/jira-cli-native/blob/master/src/main/java/io/yupiik/jira/cli/Cli.java#L37 The Spy setup is done in OWB services properties (openwebbeans.properties or CDI SE properties: https://github.com/yupiik/jira-cli-native/blob/master/src/main/java/io/yupiik/jira/cli/Cli.java#L36 )
You can't really create the services (proxy factory and spy) manually but must let it be created by webbeanscontext which is the kind of IoC in OWB core so you will pass them in the map parameter of webbeanscontext - otherwise services will not be linked and you will not get the proxies bytes in the Spy class. Romain Manni-Bucau @rmannibucau <https://twitter.com/rmannibucau> | Blog <https://rmannibucau.metawerx.net/> | Old Blog <http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> | LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book <https://www.packtpub.com/application-development/java-ee-8-high-performance> Le mer. 5 août 2020 à 14:48, Alexander Fischer <fische...@mailbox.org.invalid> a écrit : > Hey Romain, > > thanks for the infos the other day. I'm having difficulties using the > Spy class that you mentioned though. > Right now as an example I'm manually selecting some test classes to > proxy and use the NormalScopeProxyFactory.createProxyClass() on them. > But as we need a bytearray as return, I was looking at > AbstractProxyFactory.generateProxy() instead. > I don't quite figure out how to use the Spy with its defineAndLoad() > method in this context yet, but it seems like the Spy would manage all > this anyway. > Could you elaborate a little bit further on this? > Here's my sample code: > > https://github.com/a-rekkusu/graalvm-native-image-example/blob/master/src/main/java/de/arekkusu/proxyGeneration/BuildTimeProxyGenerator.java > > Thanks and best regards, > Alex > > On 03.08.2020 16:00, Romain Manni-Bucau wrote: > > Hi Alexander, > > > > We have a property for that: > > > https://github.com/apache/openwebbeans/blob/master/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java#L85 > > After you can run at build time a cdi container with > > ClassLoaderProxyService.Spy on - can use CDI SE API, you iterate over all > > beans and trigger the proxy generation for all the ones needing ones > > (decorated, intercepted, ...) - just looking up an instance should be > > sufficient since instantiation is lazy normally, just ensure it does not > > trigger postconstruct or so. > > Once done you lookup in WebBeansContext the Spy instance (needs to be > > casted) then you have all proxies you can dump calling getProxies(). > > Finally the runtime just needs to setup ClassLoaderProxyService.LoadFirst > > and ensure to have the dumped proxies in the classpath. > > > > Just these steps avoid generating the proxies at runtime but load them > > assuming they exist (if not it will try to generate them). > > > > For GraalVM (native mode), you need to ensure the dumped proxies are in > the > > native-image classpath and part of the reflection metadata to ensure it > > works. > > > > Romain Manni-Bucau > > @rmannibucau <https://twitter.com/rmannibucau> | Blog > > <https://rmannibucau.metawerx.net/> | Old Blog > > <http://rmannibucau.wordpress.com> | Github < > https://github.com/rmannibucau> | > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book > > < > https://www.packtpub.com/application-development/java-ee-8-high-performance > > > > > > > > Le lun. 3 août 2020 à 15:32, Alexander Fischer > > <fische...@mailbox.org.invalid> a écrit : > > > >> Hey Romain, > >> > >> since our last mails I have started to work on the native part of the > >> story. I roughly got to know proxies, their use cases and bytecode > >> enhancement with Byte-Buddy (as it also uses ASM, like OWB). > >> For OWB, the next step towards a build time proxy generation is to apply > >> static naming for the generated proxies, as we need fixed look-up names > >> at native-image runtime. > >> I'm currently looking into how naming is done in OWB and wonder if > >> static proxy naming should be an option for the proxy generation or if > >> it should always be static after we tackled this issue. > >> Any thoughts on that? > >> > >> Thanks and best regards, > >> Alex > >> > >> >