Classpath of a plugin (Using the compiler in a plugin)

17 views
Skip to first unread message

Oscar Forero

unread,
Jul 12, 2011, 12:54:45 PM7/12/11
to simple-build-tool
Hello,

I am trying to write a template plugin using scalate to generate Scala/
Java code, the problem is that a simple call to scalate fails
compiling the template.

org.fusesource.scalate.TemplateException: object List does not have a
member apply
at
org.fusesource.scalate.TemplateEngine.compileAndLoad(TemplateEngine.scala:
775)
at
org.fusesource.scalate.TemplateEngine.compileAndLoadEntry(TemplateEngine.scala:
637)

https://gist.github.com/1077937

The example of the usage is in https://github.com/oforero/sbt-cool-plugins/tree/master/templinator-plugin-test
, calling process-templates produces the error, a similar stand alone
class (calling the same two methods) works. My suspicion is that there
is a problem in the classpath, so the first question is how can I find
out the effective classpath of a plugin?

Using and example I found here I add a task to copy all the jars in
the main project, that works but I am not sure is the same CP than the
one the plugin gets while running. The same copy-task fails in the
BuildPlugins.scala because the fullClassPath in Runtime is not
Initialized.

https://github.com/oforero/sbt-cool-plugins/blob/master/project/CoolPluginsBuild.scala

running the standalone class with the jar files produced by the copy
task works, any pointers on how further troubleshoot this will be
greatly appreciated.

regards,

Oscar

Jason Zaugg

unread,
Jul 12, 2011, 3:25:56 PM7/12/11
to simple-b...@googlegroups.com
Am Dienstag, 12. Juli 2011 18:54:45 UTC+2 schrieb Oscar Forero:
I am trying to write a template plugin using scalate to generate Scala/
Java code, the problem is that a simple call to scalate fails
compiling the template.

That simple call ain't so simple -- Scalate needs to invoke scalac. I would try to get this done in a forked JVM, then you don't need to jump through so many classloader hoops.

-jason

Oscar Forero

unread,
Jul 12, 2011, 4:46:49 PM7/12/11
to simple-build-tool
Hi,

I was thinking about that, I remember that using the compiler inside
SBT was a no-no in the 0.7 series.
Is that still true?

Which will be the best way to fork a JVM from the build? using
Process?

regards,

Oscar

Oscar Forero

unread,
Jul 12, 2011, 4:56:30 PM7/12/11
to simple-build-tool
Hi,

I guess is using Fork ;-) ... now I just need to figure out how to set
the class path,
or better say find out the classes I need for the plugin.

are there any examples of using Fork in plugins?

regards,

Oscar

Jason Zaugg

unread,
Jul 12, 2011, 6:21:49 PM7/12/11
to simple-b...@googlegroups.com
Am Dienstag, 12. Juli 2011 22:56:30 UTC+2 schrieb Oscar Forero:
I guess is using Fork ;-) ... now I just need to figure out how to set
the class path,
or better say find out the classes I need for the plugin.

are there any examples of using Fork in plugins?

This might get you started:


Disclaimer: it's a hacked together bit of API guesswork, don't take is as the One True Way :)

-jason 

James Strachan

unread,
Jul 13, 2011, 3:38:11 AM7/13/11
to simple-b...@googlegroups.com
Wonder if this helps?
https://groups.google.com/forum/m/#!topic/simple-build-tool/5aDu94lnBE0

> --
> You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
> To post to this group, send email to simple-b...@googlegroups.com.
> To unsubscribe from this group, send email to simple-build-t...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/simple-build-tool?hl=en.
>
>

--
James
-------
FuseSource
Email: ja...@fusesource.com
Web: http://fusesource.com
Twitter: jstrachan, fusenews
Blog: http://macstrac.blogspot.com/

Open Source Integration and Messaging

Jason Zaugg

unread,
Jul 13, 2011, 5:28:25 AM7/13/11
to simple-b...@googlegroups.com

Am Mittwoch, 13. Juli 2011 09:38:11 UTC+2 schrieb James Strachan:
Wonder if this helps?
https://groups.google.com/forum/m/#!topic/simple-build-tool/5aDu94lnBE0

That post describes how to use Scalate from your application, as run by SBT. Oscar is trying to run Scalate from within an SBT plugin, which is a touch different. It's no doubt possible in-process; but perhaps more straightforward in a forked JVM.

-jason

Crias

unread,
Jul 14, 2011, 1:50:25 AM7/14/11
to simple-build-tool
The guy here made it work: https://github.com/zentrope/xsbt-scalate-precompile-plugin

He hooked into the "compile" step.

I've spent 2 days trying to make Scalate templates compile in my own
plugin, and got nowhere. Luckily, the templates I want to use are all
internal to my plugin so I can use xsbt-scalate to precompile, but you
might be able to learn from his source to achieve what you're looking
for.

On Jul 12, 10:54 am, Oscar Forero <omfor...@googlemail.com> wrote:
> Hello,
>
> I am trying to write a template plugin using scalate to generate Scala/
> Java code, the problem is that a simple call to scalate fails
> compiling the template.
>
> org.fusesource.scalate.TemplateException:objectListdoesnothaveamemberapply
>         at
> org.fusesource.scalate.TemplateEngine.compileAndLoad(TemplateEngine.scala:
> 775)
>         at
> org.fusesource.scalate.TemplateEngine.compileAndLoadEntry(TemplateEngine.sc ala:
> 637)
>
> https://gist.github.com/1077937
>
> The example of the usage is inhttps://github.com/oforero/sbt-cool-plugins/tree/master/templinator-p...
> , calling process-templates produces the error, a similar stand alone
> class (calling the same two methods) works. My suspicion is that there
> is a problem in the classpath, so the first question is how can I find
> out the effective classpath of a plugin?
>
> Using and example I found here I add a task to copy all the jars in
> the main project, that works but I amnotsure is the same CP than the
> one the plugin gets while running. The same copy-task fails in the
> BuildPlugins.scala because the fullClassPath in Runtime isnot
> Initialized.
>
> https://github.com/oforero/sbt-cool-plugins/blob/master/project/CoolP...
Reply all
Reply to author
Forward
0 new messages