scala/scala — pull request #3169 by som-snytt (2013-11-20 20:03:38+00:00)
Title: SI-4841 Plugins get a class path

Let -Xplugin specify a class path (or multiple of them).

Each entry can be a jar or dir, and the first entry to supply
a plugin descriptor defines the plugin to load.

In the proposed scheme, each plugin gets a class loader so that
plugins are isolated from each other.

Presumably, if compiler plugins were a rich ecosystem, this would
have become a requirement by now.

Partest can't do multiple plugins yet, but this is what it looks like:

```
skalac -Xplugin:sample.jar:useful.jar:util,needful.jar:another.jar:util,needful.jar:util:exploded -Xplugin-require:sample,another,other foo.scala

skalac -Xplugin:sample.jar:useful.jar:util,needful.jar:another.jar:util,needful.jar:util:exploded -Xplugin-require:sample,other -Xplugin-disable:another foo.scala

skalac -Xplugin:sample.jar:useful.jar:util,sample.jar:useful.jar:util -Xplugin-require:sample foo.scala
```
The manual test shows three plugins with various permutations of jars and dirs.

The manual test demonstrates that plugins only see classes on their class path:

```
Initializing test.plugins.SamplePlugin
needful.Needful? Failure(java.lang.ClassNotFoundException: needful.Needful)
useful.Useful? Success(class useful.Useful)
Initializing more.plugins.AnotherPlugin
needful.Needful? Success(class needful.Needful)
useful.Useful? Failure(java.lang.ClassNotFoundException: useful.Useful)
Initializing other.plugins.OtherPlugin
```

Disabling a plugin results in a message instead of silent suppression:

```
Disabling plugin another
```

The duplicate plugin class test must still be honored:

```
Ignoring duplicate plugin sample (test.plugins.SamplePlugin)
Initializing test.plugins.SamplePlugin
needful.Needful? Failure(java.lang.ClassNotFoundException: needful.Needful)
useful.Useful? Success(class useful.Useful)
```

If the path is bad, then missing classes will report which plugin induced
the error:

```
Error: class not found: util/Probe required by test.plugins.SamplePlugin
Error: class not found: util/Probe required by more.plugins.AnotherPlugin
Initializing other.plugins.OtherPlugin
needful.Needful? Success(class needful.Needful)
useful.Useful? Failure(java.lang.ClassNotFoundException: useful.Useful)
error: Missing required plugin: sample
error: Missing required plugin: another
two errors found
```