Skip to content

Commit 32e6faa

Browse files
committed
remove xml file
1 parent d2a63fb commit 32e6faa

File tree

10 files changed

+43
-90
lines changed

10 files changed

+43
-90
lines changed

compiler/src/dotty/tools/dotc/plugins/Plugin.scala

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import dotty.tools.io._
88
import transform.MegaPhase.MiniPhase
99

1010
import java.io.InputStream
11+
import java.util.Scanner
1112

1213
import scala.collection.mutable
1314
import scala.util.{ Try, Success, Failure }
@@ -58,7 +59,7 @@ trait ResearchPlugin extends Plugin {
5859

5960
object Plugin {
6061

61-
private val PluginXML = "scalac-plugin.xml"
62+
private val PluginFile = "plugin"
6263

6364
/** Create a class loader with the specified locations plus
6465
* the loader that loaded the Scala compiler.
@@ -96,27 +97,34 @@ object Plugin {
9697
def loadAllFrom(
9798
paths: List[List[Path]],
9899
dirs: List[Path],
99-
ignoring: List[String]): List[Try[AnyClass]] =
100+
ignoring: List[String]): List[Try[Plugin]] =
100101
{
101102

102-
def loadDescriptionFromDir(f: Path): Try[PluginDescription] =
103-
Try(PluginDescription.fromXML(new java.io.FileInputStream((f / PluginXML).jpath.toFile)))
103+
def fromFile(inputStream: InputStream): String = {
104+
val s = new Scanner(inputStream)
104105

105-
def loadDescriptionFromJar(jarp: Path): Try[PluginDescription] = {
106+
if (s.hasNext) s.nextLine.trim
107+
else throw new RuntimeException("Bad plugin descriptor.")
108+
}
109+
110+
def loadDescriptionFromDir(f: Path): Try[String] =
111+
Try(fromFile(new java.io.FileInputStream((f / PluginFile).jpath.toFile)))
112+
113+
def loadDescriptionFromJar(jarp: Path): Try[String] = {
106114
// XXX Return to this once we have more ARM support
107115
def read(is: InputStream) =
108-
if (is == null) throw new PluginLoadException(jarp.path, s"Missing $PluginXML in $jarp")
109-
else PluginDescription.fromXML(is)
116+
if (is == null) throw new PluginLoadException(jarp.path, s"Missing $PluginFile in $jarp")
117+
else fromFile(is)
110118

111-
val xmlEntry = new java.util.jar.JarEntry(PluginXML)
112-
Try(read(new Jar(jarp.jpath.toFile).getEntryStream(xmlEntry)))
119+
val fileEntry = new java.util.jar.JarEntry(PluginFile)
120+
Try(read(new Jar(jarp.jpath.toFile).getEntryStream(fileEntry)))
113121
}
114122

115123
// List[(jar, Try(descriptor))] in dir
116124
def scan(d: Directory) =
117125
d.files.toList sortBy (_.name) filter (Jar isJarOrZip _) map (j => (j, loadDescriptionFromJar(j)))
118126

119-
type PDResults = List[Try[(PluginDescription, ClassLoader)]]
127+
type PDResults = List[Try[(String, ClassLoader)]]
120128

121129
// scan plugin dirs for jars containing plugins, ignoring dirs with none and other jars
122130
val fromDirs: PDResults = dirs filter (_.isDirectory) flatMap { d =>
@@ -128,7 +136,7 @@ object Plugin {
128136
// scan jar paths for plugins, taking the first plugin you find.
129137
// a path element can be either a plugin.jar or an exploded dir.
130138
def findDescriptor(ps: List[Path]) = {
131-
def loop(qs: List[Path]): Try[PluginDescription] = qs match {
139+
def loop(qs: List[Path]): Try[String] = qs match {
132140
case Nil => Failure(new MissingPluginException(ps))
133141
case p :: rest =>
134142
if (p.isDirectory) loadDescriptionFromDir(p.toDirectory) orElse loop(rest)
@@ -137,21 +145,27 @@ object Plugin {
137145
}
138146
loop(ps)
139147
}
140-
val fromPaths: PDResults = paths map (p => (p, findDescriptor(p))) map {
141-
case (p, Success(pd)) => Success((pd, loaderFor(p)))
142-
case (_, Failure(e)) => Failure(e)
143-
}
148+
149+
val fromPaths: PDResults = paths map (p => findDescriptor(p) match {
150+
case Success(classname) => Success((classname, loaderFor(p)))
151+
case Failure(e) => Failure(e)
152+
})
144153

145154
val seen = mutable.HashSet[String]()
146155
val enabled = (fromPaths ::: fromDirs) map(_.flatMap {
147-
case (pd, loader) if seen(pd.classname) =>
156+
case (classname, loader) =>
148157
// a nod to scala/bug#7494, take the plugin classes distinctly
149-
Failure(new PluginLoadException(pd.name, s"Ignoring duplicate plugin ${pd.name} (${pd.classname})"))
150-
case (pd, loader) if ignoring contains pd.name =>
151-
Failure(new PluginLoadException(pd.name, s"Disabling plugin ${pd.name}"))
152-
case (pd, loader) =>
153-
seen += pd.classname
154-
Plugin.load(pd.classname, loader)
158+
Plugin.load(classname, loader).flatMap { clazz =>
159+
val plugin = instantiate(clazz)
160+
if (seen(classname))
161+
Failure(new PluginLoadException(plugin.name, s"Ignoring duplicate plugin ${plugin.name} (${classname})"))
162+
else if (ignoring contains plugin.name)
163+
Failure(new PluginLoadException(plugin.name, s"Disabling plugin ${plugin.name}"))
164+
else {
165+
seen += classname
166+
Success(plugin)
167+
}
168+
}
155169
})
156170
enabled // distinct and not disabled
157171
}

compiler/src/dotty/tools/dotc/plugins/PluginDescription.scala

Lines changed: 0 additions & 48 deletions
This file was deleted.

compiler/src/dotty/tools/dotc/plugins/Plugins.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ trait Plugins {
3939
case e: MissingPluginException => warning(e.getMessage)
4040
case e: Exception => inform(e.getMessage)
4141
})
42-
val classes = goods map (_.get) // flatten
4342

44-
// Each plugin must only be instantiated once. A common pattern
45-
// is to register annotation checkers during object construction, so
46-
// creating multiple plugin instances will leave behind stale checkers.
47-
classes map (Plugin.instantiate(_))
43+
goods map (_.get)
4844
}
4945

5046
private var _roughPluginsList: List[Plugin] = _

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ class CompilationTests extends ParallelTesting {
314314
}
315315

316316
@Test def testPlugins: Unit = {
317-
val xmlFile = "scalac-plugin.xml"
317+
val pluginFile = "plugin"
318318

319319
// 1. hack with absolute path for -Xplugin
320-
// 2. copy `xmlFile` to destination
320+
// 2. copy `pluginFile` to destination
321321
def compileFilesInDir(dir: String): CompilationTest = {
322322
val outDir = defaultOutputDir + "testPlugins/"
323323
val sourceDir = new JFile(dir)
@@ -329,7 +329,7 @@ class CompilationTests extends ParallelTesting {
329329
val targets = dirs.map { dir =>
330330
val compileDir = createOutputDirsForDir(dir, sourceDir, outDir)
331331
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
332-
Files.copy(dir.toPath.resolve(xmlFile), compileDir.toPath.resolve(xmlFile), REPLACE_EXISTING)
332+
Files.copy(dir.toPath.resolve(pluginFile), compileDir.toPath.resolve(pluginFile), REPLACE_EXISTING)
333333
val flags = TestFlags(classPath, noCheckOptions) and ("-Xplugin:" + compileDir.getAbsolutePath)
334334
SeparateCompilationSource("testPlugins", dir, flags, compileDir)
335335
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dividezero.DivideZero

sbt-dotty/sbt-test/sbt-dotty/compiler-plugin/plugin/src/main/resources/scalac-plugin.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DivideZero

tests/plugins/neg/divideZero-research/scalac-plugin.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/plugins/neg/divideZero/plugin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DivideZero

tests/plugins/neg/divideZero/scalac-plugin.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)