This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Option to extend Plug-in Classpaths?

4 replies
Mirko Stocker
Joined: 2009-09-10,
User offline. Last seen 45 weeks 6 days ago.

Hi,

I have a compiler plug-in that has a dependency on a third-party jar,
so I somehow need to get that onto the classpath for the plug-in. When
using scalac directly, I can use the "toolcp" option, but from what I
can see, this option is only used in the shell script:

misto@pin6108475 ~/repos/scala 0 (2.9.x)
% ack toolcp
src/compiler/scala/tools/ant/templates/tool-unix.tmpl
131: -toolcp)

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
30: val toolcp = PathSetting("-toolcp", "Add to the runner classpath.", "")

Is there any other way to get something on the plug-in's classpath? In
particular I need a way that also works with SBT, because ultimately
the compiler plug-in is used in the Scala IDE. My current workaround
is to also add the jar dependeny as a plug-in, which works but results
in a compiler warning.. :-)

In the compiler, plug-ins are loaded like this:

val compilerLoader = classOf[Plugin].getClassLoader
val jarurls = jarfiles map (_.toURL)
new URLClassLoader(jarurls.toArray, compilerLoader)

Could we simply add the "toolcp" to this classloader?

Cheers,

Mirko

gkossakowski
Joined: 2010-03-11,
User offline. Last seen 33 weeks 5 days ago.
Re: Option to extend Plug-in Classpaths?
On 16 December 2011 10:37, Mirko Stocker <me [at] misto [dot] ch> wrote:
Hi,

I have a compiler plug-in that has a dependency on a third-party jar,
so I somehow need to get that onto the classpath for the plug-in. When
using scalac directly, I can use the "toolcp" option, but from what I
can see, this option is only used in the shell script:

misto@pin6108475 ~/repos/scala 0 (2.9.x)
% ack toolcp
src/compiler/scala/tools/ant/templates/tool-unix.tmpl
131:    -toolcp)

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
30:  val toolcp   = PathSetting("-toolcp", "Add to the runner classpath.", "")

Is there any other way to get something on the plug-in's classpath? In
particular I need a way that also works with SBT, because ultimately
the compiler plug-in is used in the Scala IDE. My current workaround
is to also add the jar dependeny as a plug-in, which works but results
in a compiler warning.. :-)

What about packaging dependency into plug-in jar? Sort of what sbt-assembly plug-in does.
--
Grzegorz Kossakowski

Mirko Stocker
Joined: 2009-09-10,
User offline. Last seen 45 weeks 6 days ago.
Re: Option to extend Plug-in Classpaths?

Hi Grzegorz

On Fri, Dec 16, 2011 at 10:44, Grzegorz Kossakowski
wrote:
> What about packaging dependency into plug-in jar? Sort of what sbt-assembly
> plug-in does.

Hm, yes that would be another (better) option right now. The question
is, should there be a way to extend the plug-in classpath or are "fat
plugins" preferred?

Cheers,

Mirko

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Option to extend Plug-in Classpaths?

On Fri, Dec 16, 2011 at 1:58 AM, Mirko Stocker wrote:
> Hm, yes that would be another (better) option right now. The question
> is, should there be a way to extend the plug-in classpath or are "fat
> plugins" preferred?

https://issues.scala-lang.org/browse/SI-4841

I haven't applied the patch because I am attempting to avoid sprouting
any more ad-hoc mechanisms for manipulating the classpath in favor of
a more uniform mechanism.

Mirko Stocker
Joined: 2009-09-10,
User offline. Last seen 45 weeks 6 days ago.
Re: Option to extend Plug-in Classpaths?

On Friday 16 December 2011 06:28:07 Paul Phillips wrote:
> I haven't applied the patch because I am attempting to avoid sprouting
> any more ad-hoc mechanisms for manipulating the classpath in favor of
> a more uniform mechanism.

Oh, I missed that ticket.. thanks!

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland