summaryrefslogtreecommitdiff
path: root/test/files/run/t4841-isolate-plugins/t4841-isolate-plugin.scala
blob: 5421922c9c8da8eb834f7aba3c1f55d4001e7dd5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import tools.nsc.plugins.PluginDescription
import tools.partest.DirectTest

import java.io.File

// show that plugins are on isolated class loaders
object Test extends DirectTest {
  override def code = "class Code"

  override def extraSettings = s"-usejavacp"

  // plugin named ploogin1_1 or ploogin1_2, but not ploogin2_x
  // Although the samples are in different classloaders, the plugin
  // loader checks for distinctness by class name, so the names must differ.
  def pluginCode(index: Int) = s"""
    |package t4841 {
    |  class SamplePloogin$index(global: scala.tools.nsc.Global) extends Ploogin(global, s"$${PlooginCounter.named}_$index")
    |  object PlooginCounter {
    |    val count = new java.util.concurrent.atomic.AtomicInteger
    |    def named = s"ploogin$${count.incrementAndGet}"
    |  }
    |}""".stripMargin.trim

  def compilePlugin(i: Int) = {
    val out  = (testOutput / s"p$i").createDirectory()
    val args = Seq("-usejavacp", "-d", out.path)
    compileString(newCompiler(args: _*))(pluginCode(i))
    val xml  = PluginDescription(s"p$i", s"t4841.SamplePloogin$i").toXML
    (out / "scalac-plugin.xml").toFile writeAll xml
    out
  }

  override def show() = {
    val dirs = 1 to 2 map (compilePlugin(_))
    compile("-Xdev", s"-Xplugin:${dirs mkString ","}", "-usejavacp", "-d", testOutput.path)
  }
}