diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-02-19 22:25:07 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-02-19 22:25:07 +1000 |
commit | 681800976ffe727d6b37fe055fbd1997568648ef (patch) | |
tree | e0bc3c13b3b395095e7f35adfb8a8b624ea28435 /src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala | |
parent | 42626365fd4972d6578a251c264b4622ed4ba1a4 (diff) | |
download | scala-681800976ffe727d6b37fe055fbd1997568648ef.tar.gz scala-681800976ffe727d6b37fe055fbd1997568648ef.tar.bz2 scala-681800976ffe727d6b37fe055fbd1997568648ef.zip |
SI-9164 Fix thread safety of Scaladoc diagram generator
In a bug reminiscent of SI-7603 / ab8a223, when running multiple
instances of Scaladoc in one JVM/classloader, we are exposed to
race conditions in unprotected mutable state in a top-level object.
This commit moves that state into the `Universe` object, which
corresponds to a single Scaladoc instance. It also removes a little
premature abstraction from the code.
Note: the statistics code is still not thread safe, but this is no
worse than the compiler itself, and not a real problem, as they are
only enabled begind a `-Y` option.
Diffstat (limited to 'src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala')
-rw-r--r-- | src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala b/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala index a0dd154d2e..61ab18d42d 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala @@ -13,8 +13,6 @@ import io.{ Streamable, Directory } import scala.collection._ import page.diagram._ -import html.page.diagram.DiagramGenerator - /** A class that can generate Scaladoc sites to some fixed root folder. * @author David Bernard * @author Gilles Dubochet */ @@ -121,28 +119,27 @@ class HtmlFactory(val universe: doc.Universe, index: doc.Index) { finally out.close() } - DiagramGenerator.initialize(universe.settings) - libResources foreach (s => copyResource("lib/" + s)) new page.Index(universe, index) writeFor this new page.IndexScript(universe, index) writeFor this - - writeTemplates(_ writeFor this) - - for (letter <- index.firstLetterIndex) { - new html.page.ReferenceIndex(letter._1, index, universe) writeFor this + try { + writeTemplates(_ writeFor this) + for (letter <- index.firstLetterIndex) { + new html.page.ReferenceIndex(letter._1, index, universe) writeFor this + } + } finally { + DiagramStats.printStats(universe.settings) + universe.dotRunner.cleanup() } - - DiagramGenerator.cleanup() } def writeTemplates(writeForThis: HtmlPage => Unit) { val written = mutable.HashSet.empty[DocTemplateEntity] - val diagramGenerator: DiagramGenerator = new DotDiagramGenerator(universe.settings) def writeTemplate(tpl: DocTemplateEntity) { if (!(written contains tpl)) { + val diagramGenerator: DiagramGenerator = new DotDiagramGenerator(universe.settings, universe.dotRunner) writeForThis(new page.Template(universe, diagramGenerator, tpl)) written += tpl tpl.templates collect { case d: DocTemplateEntity => d } map writeTemplate |