Jarlister utility with ant task and man page#4456
Jarlister utility with ant task and man page#4456rjolly wants to merge 3 commits intoscala:2.11.xfrom
Conversation
|
Can you give a recap over the way that the contents of the manifest are used by the JSR-233 implementation? What does a sample manifest look like? Are we following a convention established by other JSR-223 implementations, or have we created our own convention? I've been looking at 3a30af1#diff-58f7fb77a943765504dc8346cf02d0bdR125 for some insights, but that commit seems a bit short on commentary. |
|
I've found some more documentation in your ScalaDays slidedeck: http://jscl-meditor.sourceforge.net/scalaint-slides.pdf |
|
I also now understand that the The problems of packages not being enumerable is also present in the toolbox compiler in runtime reflection: https://issues.scala-lang.org/browse/SI-6393. This isn't surprising, as |
|
The problem with URLClassLoader is when URLs have a different protocol than file. For instance with java web start the protocol is http and contents is cached in a java proprietary way, and basically impossible to retrieve in any other fashion than through the ClassLoader. You also have problems with web containers, whose security generally forbids to directly open arbitrary jar files. OSGI is yet another matter, as it will isolate classloaders from one another, making jars in one bundle unavailable to others and to the script engine for that matter. |
|
Yep, it is a rather annoying limitation. Perhaps we should work towards a best-effort hybrid solution, both in JSR scripting and in With regards to this PR and its expanded manifest in scala-library: I feel like we should be uniform, rather than just doing this for scala-library.jar. |
|
Yes, but to be really uniform, any possible jar on the planet (or maybe just sonatype) should be jarlisted. Instead, I think we should document properly how to jarlist a library (and I started to do that with the man page) and let the users do it as needed. Regarding scala-{reflect, compiler}, the point is that they are rarely needed in common cases. Making them available to the script engine is akin to using the standard scala repl in power mode : not everyone needs it (and moreover, it is dangerous). I would special-case scala-library.jar , because it allows to run the script engine out of the box with jrunscript. And most importantly, it allows to include it in tests. But I can understand your concern about uniformity, that is why I separated the commits, and we can perfectly drop the inclusion in the build for the moment. |
ceb864d to
5f389b6
Compare
|
retargeting for 2.11.8, unless @retronym wants to fast-track it |
To take full advantage of JSR-223 compatibility, added in 2.11, one must list a jar's classes into its manifest, to make the library visible from the interpreter when run with jrunscript. This is necessary for scala-library.jar, but also any third party library. This commit provides a jarlister utility, together with ant task and documentation. I made an independent jarlister project available on github, but users are afraid of using it, as it is not official, see the comments in scala#2238
446fb0c to
7c03870
Compare
|
/rebuild |
|
re-review by @retronym? |
|
@retronym , I have added an option to get the classpath from the URLClassloader if available. I think it could be used from ToolBox but, as far as I can tell, it would have to be rewritten to use the normal Global and not ReflectGlobal. I don't know what was the rationale behind the creation of the latter. |
|
Answering myself, I think @odersky introduced ReflectGlobal in e1a9fd9 , and he might have overlooked this relative import problem, and that to "use reflection to get class infos, instead of reading class or source files" is not enough. Perhaps Martin, you would care to comment on this issue, and give us some advice/direction ? |
|
I think the inability to enumerate the classpath was just taken as a fundamental limitation of a compiler based purely on the vanilla Classloader API / Java reflection, but despite this, runtime compilation was still useful enough to include in the experimental reflection module. I hadn't heard of the technique to read the list of classes from the manifest until I looked at this PR. It seems a clean use of a standard metadata format, but is somewhat limited as it requires library authors to opt in when publishing, or, failing that, added complexity in your own build chain using something like I suggested the approach of downcasting to a The Toolbox compiler can be started wth an explicit classpath, using Stepping back for a second, scala-reflect remains experimental, so we have to timebox our efforts in this area, to make sure the non-experimental parts of the compiler and library get enough attention. That's why I've been a bit so slow in reviewing this PR. While it all seems like an improvement, there are a lot of moving parts in reflection, the interpreter, classpaths and classloaders, and we don't have a lot of testing around these. I do feel that The second part of this PR,
|
As prior art: The twitter-eval module also calculated the "implied classpath" by probing the classloader, and this traverses up the classloader heirarchy, and also attempts to honour the "Class-Path" entry in the manifest. |
5b24db4 to
780d3da
Compare
|
Jason, I have created a new PR for the URLClassLoader mechanism. I have addressed your remarks 1 and 2. I am currently investigating the third one (embeddedDefaults), but according to my extensive tests at the time of the manifest classpath mechanism, the context classloader was working fine in a lot of challenging/embedded/restricted situations like applets, servets and so on.
That way, Scala would be free of the jarlister but the manifest classpath mechanism would still be exercized (it is important for me as it was a huge piece of work). Is it ok for you ? |
I agree. It is valuable — but this isn't the right repo for it. Hence, closing this PR. |
To take full advantage of JSR-223 compatibility, added in 2.11, one must
list a jar's classes into its manifest, to make the library visible from
the interpreter when run with jrunscript. This is necessary for
scala-library.jar, but also any third party library. This commit provides
a jarlister utility, together with ant task and documentation. I made an
independent jarlister project available on github, but users are afraid of
using it, as it is not official, see the comments in
#2238