Chapin, Peter @ VTC | 17 Jun 2012 15:43
Favicon

Strange behavior loading plugin jars into the compiler.

I’m working on a compiler plugin for Scala v2.9.1. I have an ant task that compiles a sample program using my plugin. That task makes use of a scalac task as follows:

 

<scalac deprecation="on"

      srcdir="${blink.main.sources.dir}"

      destdir="${blink.main.classes.dir}"

      classpathref="blink.build.classpath"

      addparams="-Xpluginsdir ${distribution.dir} -Xplugin:Scalaness.jar,antlr-3.4.jar -P:Scalaness:configFile:${blink.configuration}">

  <include name="**/*.scala"/>

</scalac>

 

Notice that in addition to loading my plugin (Scalaness.jar) I also need to load the ANTLR jar since my plugin depends on it. My plugin is also configurable and that’s what the –P option is all about.

 

The above doesn’t work. I get this:

 

   [scalac] Compiling 1 source file to C:\Users\pcc09070\Desktop\Projects\Scalaness\Samples\Blink\

classes\main

   [scalac] Warning: could not load descriptor for plugin Scalaness.jar

   [scalac] Warning: could not load descriptor for plugin antlr-3.4.jar

   [scalac] java.lang.reflect.InvocationTargetException

   [scalac]     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

   [scalac]     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessor

Impl.java:57)

   [scalac]     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructor

AccessorImpl.java:45)

   … etc

 

I’m a little confused about why it can’t load the descriptor for Scalaness.jar as scala-plugin.xml and plugin.properties are both in that jar and I think they are ok (maybe not). Anyway, that’s not my question right now.

 

If I change the ant task to look like this:

 

    <scalac deprecation="on"

            srcdir="${blink.main.sources.dir}"

            destdir="${blink.main.classes.dir}"

            classpathref="blink.build.classpath"

            addparams="-Xpluginsdir ${distribution.dir} -Xplugin:Scalaness.jar -Xplugin:${distribution.dir}/antlr-3.4.jar -P:Scalaness:configFile:${blink.configuration}">

      <include name="**/*.scala"/>

    </scalac>

 

It works. In particular I get:

 

   [scalac] Compiling 1 source file to C:\Users\pcc09070\Desktop\Projects\Scalaness\Samples\Blink\

classes\main

   [scalac] Warning: could not load descriptor for plugin Scalaness.jar

   [scalac] Warning: could not load descriptor for plugin C:\Users\pcc09070\Desktop\Projects\Scala

ness\lib\antlr-3.4.jar

   [scalac]

   [scalac] **** Parsing Mininess inclusion: Samples\Blink\src\InitialConstantsC.nc

   [scalac] **** Interface Unwrapping

   [scalac] **** Symbol Processing

   [scalac] **** Type Checking

   [scalac]

 

The messages are normal… they are from the plugin as it does its thing. Notice that in my ant task I now have a separate –Xplugin option for the ANTLR jar but that the previous –Xpluginsdir option doesn’t seem to apply to it so I need to provide the full path to the jar.

 

I guess my question is why does the behavior work when two –Xplugin options are used, but not when a single one is used… despite the fact that the first form is what appears to be documented?

 

Thanks.

 

Peter


Gmane