Hi,

the exact goal is to load a list of maven artifacts and their dependencies 
inside of a the groovy macro, to have access to the classes of the belonging 
jar files.
Using an URLStreamHandler means, I can only load one jar URL per artifact but I 
want to load multiple jar URLs per maven artifact (the dependencies of the 
artifact). 
Currently I created an delegating class loader (inside of an extended groovy 
macro) which loads these maven artifacts.  This works, but it produces a memory 
leak, because the creaded AttachmentClassLoader is stored inside of the 
execution context. So the classes are loaded each time the macro is loaded. 
Therefore I look for an alternative way to load these URLs.

I hope you can help me?

Roman

-----Ursprüngliche Nachricht-----
Von: users [mailto:[email protected]] Im Auftrag von Thomas Mortagne
Gesendet: Dienstag, 8. Juli 2014 16:02
An: XWiki Users
Betreff: Re: [xwiki-users] exchanging the ScriptMacro ClassLoader

On Tue, Jul 8, 2014 at 1:35 PM, Summer, Roman <[email protected]> wrote:
> Hi,
> while I tried to implement the org.xwiki.classloader.ExtendedURLStreamHandler 
> in the described way I recognized some problems:
>
>
> -      First, the class 
> org.xwiki.rendering.internal.macro.script.ScriptClassLoaderHandlerListener 
> uses the 
> org.xwiki.rendering.internal.macro.script.AttachmentClassLoaderFactory which 
> only constructs AttachmentClassLoaders which uses 
> org.xwiki.classloader.internal.protocol.attachmentjar.AttachmentURLStreamHandler.
>  Last one cannot be exchanged.
>
> In the current implementation this is no problem because the ScriptMacro only 
> supports the protocol “attach” and the URL Format itself. The 
> AttachmentURLStreamHandler can handle this.
>
>
>
> I think the Used ClassLoaderFactory should automatically get the right Class 
> Loader depending on the used protocol.
>
>
>
> -      Second, I also have to resolve the dependencies of the given maven 
> artifact in the URL. So I have to put more than one jar-URL in the URL 
> Connection. Otherwise I have to declare all the dependencies in the URL 
> String.
>
> Do you know a solution for my problems?

What is the goal exactly ? From what I understood (and how I see
http://jira.xwiki.org/browse/XWIKI-6211) the feature is to support an url that 
just contains the extension id (and optionally maybe the version, need to 
define a syntax for that) which is then requested with extension manager in the 
registered repositories. Extension Manager API gives you the dependencies of 
the extension. The simplest here is probably to generate an install plan and 
load all the extension listed in the plan.

>
> Thanks
>
> Roman
>
>
>
> Von: Vincent Massol [mailto:[email protected]] Im Auftrag von 
> [email protected]
> Gesendet: Freitag, 4. Juli 2014 14:30
> An: Summer, Roman; XWiki Users
> Betreff: Re: [xwiki-users] exchanging the ScriptMacro ClassLoader
>
> Hi Roman,
>
> On 4 Jul 2014 at 13:11:23, Summer, Roman 
> ([email protected](mailto:[email protected]))<mailto:[email protected](mailto:[email protected]))>
>  wrote:
>
>> Hello
>>
>> I want to write a java script macro
>
> I had to read this 3 times to understand it ;) (I kept thinking about 
> "javascript macro”).
>
>> which is able to load jars from an external currently not supported source 
>> (e.g. from a maven repository). Therefore I want to exchange the used class 
>> loader. Overriding the ScriptMacroParameters#getJars() method is not 
>> possible for me, because I only want to load the classes in view and not in 
>> edit mode.
>>
>> My question: How is it possible to exchange the currently injected 
>> implementation of the interface 
>> org.xwiki.rendering.internal.macro.script.AttachmentClassLoaderFactor
>> y for my macro to exchange the used class loader or is there another 
>> recommended official way to ream my aim.
>
> See 
> http://extensions.xwiki.org/xwiki/bin/view/Extension/ClassLoader+API#H
> AddinganewURLStreamHandler
>
> Thanks
> -Vincent
>
> PS1: You should checkout OPS4J Pax URL: 
> https://ops4j1.jira.com/wiki/display/paxurl/Mvn+Protocol
>
> PS2: I think we would be interested by such a contribution. Actually a great 
> contribution would be to bridge our code to use PAX URL (not even sure 
> anything is needed for that!). We probably just need a tutorial explaining 
> how to use PAX URL in XWiki.
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/users



--
Thomas Mortagne
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to