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

OSGi compile-time checking via plugin?

6 replies
matlik
Joined: 2008-09-07,
User offline. Last seen 2 years 43 weeks ago.
Does anyone know of a compiler plug-in for scalac that can enforce OSGi package visibility at compile time?  I am an OSGi noob (just exploring really) and have no experience building compiler plug-ins, but it seems such a tool would have a relatively simple feature set and be a boon for OSGi development in Scala.  Basically, the manifest file of each JAR included on the classpath would have to be interrogated to identify the visible packages.  If a reference to a class doesn't exist outside of a JAR file or in the visible package list from the JARs, a compile error to that effect could be generated.  Ideally, an informative message stating "the referenced class exists but is not available due to OSGi controlled visibility" would be generated.

Thanks,
James
Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 6 days ago.
Re: OSGi compile-time checking via plugin?
I'm working on one, but it definitely is not complete:

http://github.com/jsuereth/osgi-scalac-plugin/tree/master

On Sat, May 30, 2009 at 4:34 PM, James Matlik <james [dot] matlik [at] gmail [dot] com> wrote:
Does anyone know of a compiler plug-in for scalac that can enforce OSGi package visibility at compile time?  I am an OSGi noob (just exploring really) and have no experience building compiler plug-ins, but it seems such a tool would have a relatively simple feature set and be a boon for OSGi development in Scala.  Basically, the manifest file of each JAR included on the classpath would have to be interrogated to identify the visible packages.  If a reference to a class doesn't exist outside of a JAR file or in the visible package list from the JARs, a compile error to that effect could be generated.  Ideally, an informative message stating "the referenced class exists but is not available due to OSGi controlled visibility" would be generated.

Thanks,
James

Michael
Joined: 2009-02-23,
User offline. Last seen 20 weeks 1 day ago.
Re: OSGi compile-time checking via plugin?

James Matlik writes:

>
> Does anyone know of a compiler plug-in for scalac that can enforce OSGi
package visibility at compile time? 

I have done something similar for integrating the Scala compiler with Apache
Sling [1]. Manifest header parsing is not implemented though.

[1]
http://svn.apache.org/repos/asf/incubator/sling/trunk/contrib/scripting/...

Grey
Joined: 2009-01-03,
User offline. Last seen 42 years 45 weeks ago.
Re: OSGi compile-time checking via plugin?
I'm interested in all things Scala/OSGI as well, which includes the various endeavours mentioned on this thread.  On my part I've done some preliminary work with adding OSGI support to SBT.  (I also have a small emacs sbt-mode for those using Scala + Maven + Emacs and are now are trying Scala + SBT + Emacs.)

On Sat, May 30, 2009 at 4:34 PM, James Matlik <james [dot] matlik [at] gmail [dot] com> wrote:
Does anyone know of a compiler plug-in for scalac that can enforce OSGi package visibility at compile time?  I am an OSGi noob (just exploring really) and have no experience building compiler plug-ins, but it seems such a tool would have a relatively simple feature set and be a boon for OSGi development in Scala.  Basically, the manifest file of each JAR included on the classpath would have to be interrogated to identify the visible packages.  If a reference to a class doesn't exist outside of a JAR file or in the visible package list from the JARs, a compile error to that effect could be generated.  Ideally, an informative message stating "the referenced class exists but is not available due to OSGi controlled visibility" would be generated.

Thanks,
James

matlik
Joined: 2008-09-07,
User offline. Last seen 2 years 43 weeks ago.
Re: OSGi compile-time checking via plugin?
Hi Ray,

Please share what you've done with SBT and OSGi.  I've only recently found SBT and was instantly drawn to it.  Actually, I heard about scalab a long time ago and would every month or so do a Google search to see if any progress was made on it, without success.  I'm guessing SBT is scalab "rebranded" with a different name, but don't know for sure.  Basically, SBT is everything I wished Maven could be, and now I feel I've finally found a build tool that I can feel comfortable with.  I happen to be delving into SBT along with OSGi, and am finding that it is a lot to digest at once.  I've got some ideas for integrating BND (with versioned downloads) into the build process and hope to add something like pax-exam as a secondary test phase.  Of course, a plugin similar to what Josh is working on (only briefly poked through the code) would address a whole category of test cases addressed by pax-exam, hence my original question.

On Mon, Jun 1, 2009 at 8:50 AM, Ray Racine <ray [dot] racine [at] gmail [dot] com> wrote:
I'm interested in all things Scala/OSGI as well, which includes the various endeavours mentioned on this thread.  On my part I've done some preliminary work with adding OSGI support to SBT.  (I also have a small emacs sbt-mode for those using Scala + Maven + Emacs and are now are trying Scala + SBT + Emacs.)

On Sat, May 30, 2009 at 4:34 PM, James Matlik <james [dot] matlik [at] gmail [dot] com> wrote:
Does anyone know of a compiler plug-in for scalac that can enforce OSGi package visibility at compile time?  I am an OSGi noob (just exploring really) and have no experience building compiler plug-ins, but it seems such a tool would have a relatively simple feature set and be a boon for OSGi development in Scala.  Basically, the manifest file of each JAR included on the classpath would have to be interrogated to identify the visible packages.  If a reference to a class doesn't exist outside of a JAR file or in the visible package list from the JARs, a compile error to that effect could be generated.  Ideally, an informative message stating "the referenced class exists but is not available due to OSGi controlled visibility" would be generated.

Thanks,
James


matlik
Joined: 2008-09-07,
User offline. Last seen 2 years 43 weeks ago.
Re: OSGi compile-time checking via plugin?
Hi Josh,
 
I hope to look at your compiler plugin in greater detail.  Though considering I'm at the early stages of understanding OSGi, I can't say I'll be able to contribute much that is useful, at least for a while.  Could you give me a feel of how usable (or how close to usable) your plugin is in its current state?

On Sat, May 30, 2009 at 11:11 PM, Josh Suereth <joshua [dot] suereth [at] gmail [dot] com> wrote:
I'm working on one, but it definitely is not complete:

http://github.com/jsuereth/osgi-scalac-plugin/tree/master

On Sat, May 30, 2009 at 4:34 PM, James Matlik <james [dot] matlik [at] gmail [dot] com> wrote:
Does anyone know of a compiler plug-in for scalac that can enforce OSGi package visibility at compile time?  I am an OSGi noob (just exploring really) and have no experience building compiler plug-ins, but it seems such a tool would have a relatively simple feature set and be a boon for OSGi development in Scala.  Basically, the manifest file of each JAR included on the classpath would have to be interrogated to identify the visible packages.  If a reference to a class doesn't exist outside of a JAR file or in the visible package list from the JARs, a compile error to that effect could be generated.  Ideally, an informative message stating "the referenced class exists but is not available due to OSGi controlled visibility" would be generated.

Thanks,
James


Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 6 days ago.
Re: OSGi compile-time checking via plugin?
Right now... It's not at all usable (for real projects)

- I spent some time on a basic Manifest parser.  This may require some future work, but my goals was mostly to parse valid manifest and extract OSGi data while ignoring the rest.  I am currently able to discover exported packages via the manifest

- The plugin currently computes an "allowed" list of packages by
  • Automatically accepting anything that's inside the scala package (yes... this is hack)
  • Adding any package in the currently compiling code to the allowed list
  • Adding any packages exported by OSGi modules on the classpath
- The plugin currently looks at the "icode" generated by Scala and verifies that any "new foo" or static method call is from a package in the "allowed" list.  If it is not allowed, it creates an error marker at the definiton with an error message that says something like "Package is not visible inside an OSGi container"


There's still a lot of work to do to get this going.  I've been recently completely side-tracked from OSGi as my "new" company doesn't use it.  However, I would love to see this plugin come to fruition for no other reason than to enforce visibility concerns in the eclipse plugin at compile time!

In terms of what work needs to be done I see the following:

1) Fleshing out the allowed list to be slightly more useful.  Perhaps passing in a "current manifest" or "do the right thing" flag would be helpful.  Also verifing not just that a package is exported by a dependency but that the class exists *in that particular dependency*  (in the case of multiple dependencies with similar package structures).  

2) We need to remove the scala-library hack and force compilation against the "scala-library-osgi.jar"

3) Improving Manifest parsing.  What I have right now works, but is not quite what I would consider "production ready".  I was eventually intending manifest parsing to also include "modify and export" based on what you are currently compiling.

Anyway, if you're interested I can add you as a comitter.  I fully intend to use OSGi in the future, but currently don't have much time to contribute to things that aren't directly affecting my current projects.


Cheers!
- Josh



On Mon, Jun 1, 2009 at 7:49 PM, James Matlik <james [dot] matlik [at] gmail [dot] com> wrote:
Hi Josh,
 
I hope to look at your compiler plugin in greater detail.  Though considering I'm at the early stages of understanding OSGi, I can't say I'll be able to contribute much that is useful, at least for a while.  Could you give me a feel of how usable (or how close to usable) your plugin is in its current state?

On Sat, May 30, 2009 at 11:11 PM, Josh Suereth <joshua [dot] suereth [at] gmail [dot] com> wrote:
I'm working on one, but it definitely is not complete:

http://github.com/jsuereth/osgi-scalac-plugin/tree/master

On Sat, May 30, 2009 at 4:34 PM, James Matlik <james [dot] matlik [at] gmail [dot] com> wrote:
Does anyone know of a compiler plug-in for scalac that can enforce OSGi package visibility at compile time?  I am an OSGi noob (just exploring really) and have no experience building compiler plug-ins, but it seems such a tool would have a relatively simple feature set and be a boon for OSGi development in Scala.  Basically, the manifest file of each JAR included on the classpath would have to be interrogated to identify the visible packages.  If a reference to a class doesn't exist outside of a JAR file or in the visible package list from the JARs, a compile error to that effect could be generated.  Ideally, an informative message stating "the referenced class exists but is not available due to OSGi controlled visibility" would be generated.

Thanks,
James



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