Pärse groovy with jars

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Pärse groovy with jars

jerem
Hello XWiki Community,

Got some issue with executing groovy in a page ...

I have a page with a groovy class, that needs some jars dependencies.
The following "works":

{{groovy jars="attach:toto.jar,..."}}

import ...

public class MyClass {
...
}

def myobj = new MyClass()
// do something with myobj ...
{{/groovy}}

Then I'd like to execute this code from another page.
So I removed the {{groovy}} macro tags and the isolated code at the end,
leaving only the class declaration and imports.
From the other page I use the following version of parseGroovyFromPage:
http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/com/xpn/xwiki/api/XWiki.html#parseGroovyFromPage(java.lang.String,%20java.lang.String)

I provide it with the name of the page containing my groovy class, twice
(once for the script and once for the jars).
It results in a page loading infinitely until it time-outs ... From the
logs it seems my class never gets executed.

Any idea ?

Note: I think it's a "crappy" method, and I plan to put this as a java
component, but in a "proof of concept" stage the groovy script is very
useful.

Thanks,
Jeremie
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Pärse groovy with jars

Eduard Moraru
Hi,

I haven`t played with groovy in XWiki enough. My only suggestion is to
debug the problem by reducing it to a state that works (even an empty
groovy page) and then add stuff until it breaks to identify the cause.

Hope this helps,
Eduard


On Tue, Aug 5, 2014 at 4:37 PM, Jeremie BOUSQUET <[hidden email]
> wrote:

> Hello XWiki Community,
>
> Got some issue with executing groovy in a page ...
>
> I have a page with a groovy class, that needs some jars dependencies.
> The following "works":
>
> {{groovy jars="attach:toto.jar,..."}}
>
> import ...
>
> public class MyClass {
> ...
> }
>
> def myobj = new MyClass()
> // do something with myobj ...
> {{/groovy}}
>
> Then I'd like to execute this code from another page.
> So I removed the {{groovy}} macro tags and the isolated code at the end,
> leaving only the class declaration and imports.
> From the other page I use the following version of parseGroovyFromPage:
>
> http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/com/xpn/xwiki/api/XWiki.html#parseGroovyFromPage(java.lang.String,%20java.lang.String)
>
> I provide it with the name of the page containing my groovy class, twice
> (once for the script and once for the jars).
> It results in a page loading infinitely until it time-outs ... From the
> logs it seems my class never gets executed.
>
> Any idea ?
>
> Note: I think it's a "crappy" method, and I plan to put this as a java
> component, but in a "proof of concept" stage the groovy script is very
> useful.
>
> Thanks,
> Jeremie
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Pärse groovy with jars

vmassol
Administrator
In reply to this post by jerem
 



On 5 Aug 2014 at 15:48:27, Jeremie BOUSQUET ([hidden email](mailto:[hidden email])) wrote:

> Hello XWiki Community,
>  
> Got some issue with executing groovy in a page ...
>  
> I have a page with a groovy class, that needs some jars dependencies.
> The following "works":
>  
> {{groovy jars="attach:toto.jar,..."}}
>  
> import ...
>  
> public class MyClass {
> ...
> }
>  
> def myobj = new MyClass()
> // do something with myobj ...
> {{/groovy}}
>  
> Then I'd like to execute this code from another page.
> So I removed the {{groovy}} macro tags and the isolated code at the end,
> leaving only the class declaration and imports.
> From the other page I use the following version of parseGroovyFromPage:
> http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/com/xpn/xwiki/api/XWiki.html#parseGroovyFromPage(java.lang.String,%20java.lang.String)

Why not keep the {{groovy}} macro and instead use {{include reference=“…”/}} from the calling page? Using parseGroovyFromPage is the old way of doing it.

Thanks
-Vincent

> I provide it with the name of the page containing my groovy class, twice
> (once for the script and once for the jars).
> It results in a page loading infinitely until it time-outs ... From the
> logs it seems my class never gets executed.
>  
> Any idea ?
>  
> Note: I think it's a "crappy" method, and I plan to put this as a java
> component, but in a "proof of concept" stage the groovy script is very
> useful.
>  
> Thanks,
> Jeremie
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Pärse groovy with jars

jerem
Hi Vincent,
Le 16 août 2014 21:42, "[hidden email]" <[hidden email]> a écrit :
>
>
>
>
>
> On 5 Aug 2014 at 15:48:27, Jeremie BOUSQUET ([hidden email]
(mailto:[hidden email])) wrote:

>
> > Hello XWiki Community,
> >
> > Got some issue with executing groovy in a page ...
> >
> > I have a page with a groovy class, that needs some jars dependencies.
> > The following "works":
> >
> > {{groovy jars="attach:toto.jar,..."}}
> >
> > import ...
> >
> > public class MyClass {
> > ...
> > }
> >
> > def myobj = new MyClass()
> > // do something with myobj ...
> > {{/groovy}}
> >
> > Then I'd like to execute this code from another page.
> > So I removed the {{groovy}} macro tags and the isolated code at the end,
> > leaving only the class declaration and imports.
> > From the other page I use the following version of parseGroovyFromPage:
> >
http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/com/xpn/xwiki/api/XWiki.html#parseGroovyFromPage(java.lang.String,%20java.lang.String)
>
> Why not keep the {{groovy}} macro and instead use {{include
reference=“…”/}} from the calling page? Using parseGroovyFromPage is the
old way of doing it.

Right, but in a scheduler job I can only put groovy, not wiki syntax, isn't
it ?

>
> Thanks
> -Vincent
>
> > I provide it with the name of the page containing my groovy class, twice
> > (once for the script and once for the jars).
> > It results in a page loading infinitely until it time-outs ... From the
> > logs it seems my class never gets executed.
> >
> > Any idea ?
> >
> > Note: I think it's a "crappy" method, and I plan to put this as a java
> > component, but in a "proof of concept" stage the groovy script is very
> > useful.
> >
> > Thanks,
> > Jeremie
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Pärse groovy with jars

vmassol
Administrator
 



On 16 Aug 2014 at 22:31:24, Jeremie BOUSQUET ([hidden email](mailto:[hidden email])) wrote:

>  
> Hi Vincent,
> Le 16 août 2014 21:42, "[hidden email](mailto:[hidden email])" a écrit :
> >
> >  
> >
> >
> >
> > On 5 Aug 2014 at 15:48:27, Jeremie BOUSQUET ([hidden email](mailto:[hidden email])(mailto:[hidden email])) wrote:
> >
> > > Hello XWiki Community,
> > >
> > > Got some issue with executing groovy in a page ...
> > >
> > > I have a page with a groovy class, that needs some jars dependencies.
> > > The following "works":
> > >
> > > {{groovy jars="attach:toto.jar,..."}}
> > >
> > > import ...
> > >
> > > public class MyClass {
> > > ...
> > > }
> > >
> > > def myobj = new MyClass()
> > > // do something with myobj ...
> > > {{/groovy}}
> > >
> > > Then I'd like to execute this code from another page.
> > > So I removed the {{groovy}} macro tags and the isolated code at the end,
> > > leaving only the class declaration and imports.
> > > From the other page I use the following version of parseGroovyFromPage:
> > > http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/com/xpn/xwiki/api/XWiki.html#parseGroovyFromPage(java.lang.String,%20java.lang.String)
> >
> > Why not keep the {{groovy}} macro and instead use {{include reference=“…”/}} from the calling page? Using parseGroovyFromPage is the old way of doing it.
>  
>  
> Right, but in a scheduler job I can only put groovy, not wiki syntax, isn't it ?

Indeed, something we really need to fix… You could still render a page using $doc.getRenderedContent() from a scheduler job and use wiki syntax 2.x in that page ;)

Thanks
-Vincent

> > Thanks
> > -Vincent
> >
> > > I provide it with the name of the page containing my groovy class, twice
> > > (once for the script and once for the jars).
> > > It results in a page loading infinitely until it time-outs ... From the
> > > logs it seems my class never gets executed.
> > >
> > > Any idea ?
> > >
> > > Note: I think it's a "crappy" method, and I plan to put this as a java
> > > component, but in a "proof of concept" stage the groovy script is very
> > > useful.
> > >
> > > Thanks,
> > > Jeremie
>  
>  
>  
>  


_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Pärse groovy with jars

Thomas Mortagne
Administrator
And you really don't want to install those jars as extensions ?


The jars parameter of the script macro is not really nice for
performance as it create a new classloader and reload those jar each
time you execute the macro.

An alternative is to use Groovy @Grab feature, see
http://groovy.codehaus.org/Grape.

On Sat, Aug 16, 2014 at 10:42 PM, [hidden email] <[hidden email]> wrote:

>
>
>
>
> On 16 Aug 2014 at 22:31:24, Jeremie BOUSQUET ([hidden email](mailto:[hidden email])) wrote:
>
>>
>> Hi Vincent,
>> Le 16 août 2014 21:42, "[hidden email](mailto:[hidden email])" a écrit :
>> >
>> >
>> >
>> >
>> >
>> > On 5 Aug 2014 at 15:48:27, Jeremie BOUSQUET ([hidden email](mailto:[hidden email])(mailto:[hidden email])) wrote:
>> >
>> > > Hello XWiki Community,
>> > >
>> > > Got some issue with executing groovy in a page ...
>> > >
>> > > I have a page with a groovy class, that needs some jars dependencies.
>> > > The following "works":
>> > >
>> > > {{groovy jars="attach:toto.jar,..."}}
>> > >
>> > > import ...
>> > >
>> > > public class MyClass {
>> > > ...
>> > > }
>> > >
>> > > def myobj = new MyClass()
>> > > // do something with myobj ...
>> > > {{/groovy}}
>> > >
>> > > Then I'd like to execute this code from another page.
>> > > So I removed the {{groovy}} macro tags and the isolated code at the end,
>> > > leaving only the class declaration and imports.
>> > > From the other page I use the following version of parseGroovyFromPage:
>> > > http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/com/xpn/xwiki/api/XWiki.html#parseGroovyFromPage(java.lang.String,%20java.lang.String)
>> >
>> > Why not keep the {{groovy}} macro and instead use {{include reference=“…”/}} from the calling page? Using parseGroovyFromPage is the old way of doing it.
>>
>>
>> Right, but in a scheduler job I can only put groovy, not wiki syntax, isn't it ?
>
> Indeed, something we really need to fix… You could still render a page using $doc.getRenderedContent() from a scheduler job and use wiki syntax 2.x in that page ;)
>
> Thanks
> -Vincent
>
>> > Thanks
>> > -Vincent
>> >
>> > > I provide it with the name of the page containing my groovy class, twice
>> > > (once for the script and once for the jars).
>> > > It results in a page loading infinitely until it time-outs ... From the
>> > > logs it seems my class never gets executed.
>> > >
>> > > Any idea ?
>> > >
>> > > Note: I think it's a "crappy" method, and I plan to put this as a java
>> > > component, but in a "proof of concept" stage the groovy script is very
>> > > useful.
>> > >
>> > > Thanks,
>> > > Jeremie
>>
>>
>>
>>
>
>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users



--
Thomas Mortagne
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Pärse groovy with jars

jerem
Hi Thomas,

Le 27 août 2014 10:43, "Thomas Mortagne" <[hidden email]> a
écrit :
>
> And you really don't want to install those jars as extensions ?
>

What I'm not fond of, is that they would be added to the classloader
globally though their use will be very limited. Also those are not
currently available in a maven repo because of licensing, and I'd have to
manage this in my own repo.
But, why not.

>
> The jars parameter of the script macro is not really nice for
> performance as it create a new classloader and reload those jar each
> time you execute the macro.
>
> An alternative is to use Groovy @Grab feature, see
> http://groovy.codehaus.org/Grape.

Yes I thought about it also.
I'll see how I 'll manage this, thanks everyone !

>
> On Sat, Aug 16, 2014 at 10:42 PM, [hidden email] <[hidden email]>
wrote:
> >
> >
> >
> >
> > On 16 Aug 2014 at 22:31:24, Jeremie BOUSQUET ([hidden email]
(mailto:[hidden email])) wrote:
> >
> >>
> >> Hi Vincent,
> >> Le 16 août 2014 21:42, "[hidden email](mailto:[hidden email])"
a écrit :
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > On 5 Aug 2014 at 15:48:27, Jeremie BOUSQUET (
[hidden email](mailto:[hidden email])(mailto:
[hidden email])) wrote:
> >> >
> >> > > Hello XWiki Community,
> >> > >
> >> > > Got some issue with executing groovy in a page ...
> >> > >
> >> > > I have a page with a groovy class, that needs some jars
dependencies.

> >> > > The following "works":
> >> > >
> >> > > {{groovy jars="attach:toto.jar,..."}}
> >> > >
> >> > > import ...
> >> > >
> >> > > public class MyClass {
> >> > > ...
> >> > > }
> >> > >
> >> > > def myobj = new MyClass()
> >> > > // do something with myobj ...
> >> > > {{/groovy}}
> >> > >
> >> > > Then I'd like to execute this code from another page.
> >> > > So I removed the {{groovy}} macro tags and the isolated code at
the end,
> >> > > leaving only the class declaration and imports.
> >> > > From the other page I use the following version of
parseGroovyFromPage:
> >> > >
http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/com/xpn/xwiki/api/XWiki.html#parseGroovyFromPage(java.lang.String,%20java.lang.String)
> >> >
> >> > Why not keep the {{groovy}} macro and instead use {{include
reference=“…”/}} from the calling page? Using parseGroovyFromPage is the
old way of doing it.
> >>
> >>
> >> Right, but in a scheduler job I can only put groovy, not wiki syntax,
isn't it ?
> >
> > Indeed, something we really need to fix… You could still render a page
using $doc.getRenderedContent() from a scheduler job and use wiki syntax
2.x in that page ;)
> >
> > Thanks
> > -Vincent
> >
> >> > Thanks
> >> > -Vincent
> >> >
> >> > > I provide it with the name of the page containing my groovy class,
twice
> >> > > (once for the script and once for the jars).
> >> > > It results in a page loading infinitely until it time-outs ...
From the
> >> > > logs it seems my class never gets executed.
> >> > >
> >> > > Any idea ?
> >> > >
> >> > > Note: I think it's a "crappy" method, and I plan to put this as a
java
> >> > > component, but in a "proof of concept" stage the groovy script is
very

> >> > > useful.
> >> > >
> >> > > Thanks,
> >> > > Jeremie
> >>
> >>
> >>
> >>
> >
> >
> > _______________________________________________
> > users mailing list
> > [hidden email]
> > http://lists.xwiki.org/mailman/listinfo/users
>
>
>
> --
> Thomas Mortagne
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users