querying classpaths

74 views
Skip to first unread message

Florian Hars

unread,
Jun 18, 2011, 8:58:18 AM6/18/11
to sbt
How do I get at the classpaths in 0.10 ?

Since 0.10 removed lib_managed and so broke ensime, I thought, hey,
I might get some of the functionality back and even learn something
about the architecture of my build environment by writing a small
plugin that writes an .ensime file in the project directory that tells
ensime about the classpath for all dependencies. That shouldn't be too
hard, the documentation even contains example code on how to access the
classpath:

// get the full classpath in the 'compile' configuration, or Nil if it isn't defined
val cp: Seq[Attributed[File]] = fullClasspath in (currentRef, Compile) get structure.data getOrElse Nil

Except that that doesn't even compile:

[error] found : Product
[error] required: Seq[sbt.Attributed[sbt.package.File]]
[error] val cp : Seq[Attributed[File]] = fullClasspath in (currentRef, Compile) get structure.data getOrElse Nil
[error] ^

So, how do I get, say, the test classpath?

(And am I the only one who thinks that the current scaladoc is nigh
useless for codebases that rely heavily on implicits? Where does that "in"
come from, and whereever it comes from, it doesn't seem to return anything
with a "get" method...)

- Florian.
--
#!/bin/sh -
set - `type -p $0` 'tr [a-m][n-z]RUXJAKBOZ [n-z][a-m]EH$W/@OBM' fu XUBZRA.fvt\
angher echo;while [ "$5" != "" ];do shift;done;$4 "gbhpu $3;fraqznvy sKunef.q\
r<$3&&frq -a -rc "`$4 "$0"|$1`">$3;rpub 'Jr ner Svt bs Obet.'"|$1|`$4 $2|$1`

Mark Harrah

unread,
Jun 18, 2011, 11:37:36 PM6/18/11
to simple-b...@googlegroups.com
Hi Florian,

On Sat, 18 Jun 2011 14:58:18 +0200
Florian Hars <flo...@hars.de> wrote:

> How do I get at the classpaths in 0.10 ?
>
> Since 0.10 removed lib_managed and so broke ensime, I thought, hey,
> I might get some of the functionality back and even learn something
> about the architecture of my build environment by writing a small
> plugin that writes an .ensime file in the project directory that tells
> ensime about the classpath for all dependencies.

I think this is a good idea. From what I can tell, it is generally the case that plugin authors pick up the underlying concepts. Sorry about the bad documentation though...

> That shouldn't be too
> hard, the documentation even contains example code on how to access the
> classpath:
>
> // get the full classpath in the 'compile' configuration, or Nil if it isn't defined
> val cp: Seq[Attributed[File]] = fullClasspath in (currentRef, Compile) get structure.data getOrElse Nil
>
> Except that that doesn't even compile:
>
> [error] found : Product
> [error] required: Seq[sbt.Attributed[sbt.package.File]]
> [error] val cp : Seq[Attributed[File]] = fullClasspath in (currentRef, Compile) get structure.data getOrElse Nil
> [error] ^
>
> So, how do I get, say, the test classpath?

Sorry, that documentation was clearly incorrect. I've fixed it. You get back a task that you have to run. See the Running Tasks section of Build State[1]. Also, see the IDE plugins linked to on the 0.10 plugins page[2].

> (And am I the only one who thinks that the current scaladoc is nigh
> useless for codebases that rely heavily on implicits? Where does that "in"
> come from, and whereever it comes from, it doesn't seem to return anything
> with a "get" method...)

Yes, the onus is currently on the library author to come up with a good way of documenting it. Scaladoc is more useful for heavy classes. I've tried some things for the settings API, but nothing as simple as I'd like and definitely nothing automated.

-Mark

[1] https://github.com/harrah/xsbt/wiki/Build-State
[2] https://github.com/harrah/xsbt/wiki/sbt-0.10-plugins-list

Florian Hars

unread,
Jun 19, 2011, 2:40:54 PM6/19/11
to simple-b...@googlegroups.com
On Sat, Jun 18, 2011 at 11:37:36PM -0400, Mark Harrah wrote:
> Sorry, that documentation was clearly incorrect. I've fixed it.

Oh thanks, that looks good. Now I just have to use part of my
copious spare time to actually write a plugin...

Florian Hars

unread,
Jun 23, 2011, 2:55:41 PM6/23/11
to simple-b...@googlegroups.com
On Sat, Jun 18, 2011 at 02:58:18PM +0200, Florian Hars wrote:
> Since 0.10 removed lib_managed and so broke ensime, I thought, hey,
> I might get some of the functionality back and even learn something
> about the architecture of my build environment by writing a small
> plugin that writes an .ensime file in the project directory that tells
> ensime about the classpath for all dependencies.

Thanks to the updated documentation I have managed to get at the classpath
and write a little plugin that writes all the ~/.ivy2/cache/...jar paths
to a simple .ensime file. That is not really a final solution for sbt-0.10
support in ensime, but for simple projects it seems to work. Code is there:

https://github.com/fhars/sbt-ensime-plugin

Mark Harrah

unread,
Jun 23, 2011, 8:14:58 PM6/23/11
to simple-b...@googlegroups.com
On Thu, 23 Jun 2011 20:55:41 +0200
Florian Hars <flo...@hars.de> wrote:

> On Sat, Jun 18, 2011 at 02:58:18PM +0200, Florian Hars wrote:
> > Since 0.10 removed lib_managed and so broke ensime, I thought, hey,
> > I might get some of the functionality back and even learn something
> > about the architecture of my build environment by writing a small
> > plugin that writes an .ensime file in the project directory that tells
> > ensime about the classpath for all dependencies.
>
> Thanks to the updated documentation I have managed to get at the classpath
> and write a little plugin that writes all the ~/.ivy2/cache/...jar paths
> to a simple .ensime file. That is not really a final solution for sbt-0.10
> support in ensime, but for simple projects it seems to work. Code is there:
>
> https://github.com/fhars/sbt-ensime-plugin

Looks good. Consider adding it to the 0.10 plugins list:

https://github.com/harrah/xsbt/wiki/sbt-0.10-plugins-list

-Mark

Erick Fleming

unread,
Jun 24, 2011, 2:50:43 PM6/24/11
to simple-b...@googlegroups.com
I'm writing a task, not a command, so where do I get the state to pass to evaluateTask?  I want the same information (classpath).

Erick

Erick Fleming

unread,
Jun 24, 2011, 2:59:44 PM6/24/11
to simple-b...@googlegroups.com
Ah, minutes after I posted I figured out what I needed.

val sample = TaskKey[Unit]("sample")

def sampleTask(cp:Classpath) = {
    cp.map(_.data).foreach(println)
}

lazy val mySettings = Seq(
    sample        <<= (fullClasspath in Runtime) map sampleTask)
Reply all
Reply to author
Forward
0 new messages