Skip to content

Commit a252074

Browse files
committed
Implement bridge that generates json on doc command
1 parent b1defa0 commit a252074

File tree

5 files changed

+33
-56
lines changed

5 files changed

+33
-56
lines changed

bridge/src/main/scala/xsbt/ScaladocInterface.scala

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,20 @@ class ScaladocInterface {
1212
}
1313

1414
class DottydocRunner(args: Array[String], log: Logger, delegate: xsbti.Reporter) extends Dottydoc {
15-
def run(): Unit = {
16-
println(args.mkString("Args = List (\n ",",\n ",")"))
17-
//val index = createIndex(args)
18-
//buildDocs(outputDir, templatePath, resources, index)
15+
def run(): Unit = getOutputFolder(args).map { outputFolder =>
16+
val index = createIndex(args)
17+
val template = getTemplate(args)
18+
val resources = getResources(args)
19+
20+
template.fold(writeJson(index, outputFolder)) { tpl =>
21+
buildDocs(outputFolder, tpl, resources, index)
22+
}
1923
}
24+
25+
private def getOutputFolder(args: Array[String]): Option[String] =
26+
args sliding(2) find { case Array(x, _) => x == "-d" } map (_.tail.head)
27+
28+
private def getTemplate(args: Array[String]): Option[String] = None
29+
30+
private def getResources(args: Array[String]): List[String] = Nil
2031
}

dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ public void buildDocs(
2424
) {
2525
new OutputWriter().writeJava(index, templatePath, outputDir, resources);
2626
}
27+
28+
public void writeJson(Map<String, Package> index, String outputDir) {
29+
new OutputWriter().writeJsonJava(index, outputDir);
30+
}
2731
}

dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ import dotty.tools.dottydoc.util.OutputWriter
66

77
import scala.collection.Map
88

9+
/** FIXME: document this class plz */
910
trait Dottydoc extends DottyDocDriver {
1011
def createIndex(args: Array[String]): Map[String, Package] =
1112
compiledDocs(args)
1213

1314
def buildDocs(outDir: String, templatePath: String, resources: List[String], index: Map[String, Package]) =
1415
new OutputWriter().write(index, templatePath, outDir, resources)
16+
17+
def writeJson(index: Map[String, Package], outputDir: String) =
18+
new OutputWriter().writeJson(index, outputDir)
1519
}

dottydoc/src/dotty/tools/dottydoc/util/OutputWriter.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ import _root_.java.util.{ Map => JMap, List => JList }
1717
import model.{ Entity, Package }
1818
import model.json._
1919
import com.github.mustachejava.DefaultMustacheFactory
20-
20+
import scala.collection.JavaConverters._
2121

2222
class OutputWriter {
2323

2424
def writeJava(packs: JMap[String, Package], templatePath: String, outPath: String, resources: JList[String]): Unit = {
25-
import scala.collection.JavaConverters._
2625
write(packs.asScala, templatePath, outPath, resources.asScala)
2726
}
2827

@@ -61,6 +60,12 @@ class OutputWriter {
6160
println("Done writing static material, building js-app")
6261
}
6362

63+
def writeJsonJava(index: JMap[String, Package], outputDir: String): Unit =
64+
writeJson(index.asScala, outputDir)
65+
66+
def writeJson(index: collection.Map[String, Package], outputDir: String): Unit =
67+
writeFile(index.json, outputDir + "/", "index.json")
68+
6469
def expandTemplate(templatePath: String, entity: Entity, outPath: String): String = try {
6570
import model.json._
6671
import model.java._

project/Build.scala

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ object DottyBuild extends Build {
7373
javaSource in Test := baseDirectory.value / "test",
7474
resourceDirectory in Compile := baseDirectory.value / "resources",
7575
unmanagedSourceDirectories in Compile := Seq((scalaSource in Compile).value),
76+
unmanagedSourceDirectories in Compile += baseDirectory.value / "dottydoc" / "src",
7677
unmanagedSourceDirectories in Test := Seq((scalaSource in Test).value),
78+
unmanagedSourceDirectories in Test += baseDirectory.value / "dottydoc" / "test",
7779

7880
// set system in/out for repl
7981
connectInput in run := true,
@@ -100,6 +102,7 @@ object DottyBuild extends Build {
100102
"org.scala-lang.modules" %% "scala-partest" % "1.0.11" % "test",
101103
"com.novocode" % "junit-interface" % "0.11" % "test",
102104
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0",
105+
"com.github.spullara.mustache.java" % "compiler" % "0.9.3",
103106
"com.typesafe.sbt" % "sbt-interface" % sbtVersion.value),
104107
// enable improved incremental compilation algorithm
105108
incOptions := incOptions.value.withNameHashing(true),
@@ -206,7 +209,6 @@ object DottyBuild extends Build {
206209

207210
lazy val `dotty-bridge` = project.in(file("bridge")).
208211
dependsOn(dotty).
209-
dependsOn(dottydoc).
210212
settings(
211213
overrideScalaVersionSetting,
212214

@@ -265,55 +267,6 @@ object DottyInjectedPlugin extends AutoPlugin {
265267
).
266268
settings(publishing)
267269

268-
lazy val dottydoc = project.in(file("dottydoc")).dependsOn(dotty).settings(
269-
//resources in Compile += (fastOptJS in (dottydocJS, Compile)).value.data,
270-
resourceDirectory in Compile := baseDirectory.value / "resources",
271-
scalaSource in Compile := baseDirectory.value / "src",
272-
javaSource in Compile := baseDirectory.value / "src",
273-
scalaSource in Test := baseDirectory.value / "test",
274-
javaSource in Test := baseDirectory.value / "test",
275-
276-
libraryDependencies ++= Seq(
277-
"com.novocode" % "junit-interface" % "0.11" % "test",
278-
"com.github.spullara.mustache.java" % "compiler" % "0.9.3"
279-
),
280-
281-
// enable improved incremental compilation algorithm
282-
incOptions := incOptions.value.withNameHashing(true),
283-
284-
mainClass in (Compile, run) := Some("dotty.tools.dottydoc.Main"),
285-
fork in run := true,
286-
fork in Test := true,
287-
parallelExecution in Test := false,
288-
289-
// http://grokbase.com/t/gg/simple-build-tool/135ke5y90p/sbt-setting-jvm-boot-paramaters-for-scala
290-
javaOptions <++= (dependencyClasspath in Runtime, packageBin in Compile) map { (attList, bin) =>
291-
// put the Scala {library, reflect} in the classpath
292-
val path = for {
293-
file <- attList.map(_.data)
294-
path = file.getAbsolutePath
295-
} yield "-Xbootclasspath/p:" + path
296-
// dotty itself needs to be in the bootclasspath
297-
val fullpath = ("-Xbootclasspath/a:" + bin) :: path.toList
298-
// System.err.println("BOOTPATH: " + fullpath)
299-
300-
val travis_build = // propagate if this is a travis build
301-
if (sys.props.isDefinedAt(JENKINS_BUILD))
302-
List(s"-D$JENKINS_BUILD=${sys.props(JENKINS_BUILD)}") ::: jenkinsMemLimit
303-
else
304-
List()
305-
306-
val tuning =
307-
if (sys.props.isDefinedAt("Oshort"))
308-
// Optimize for short-running applications, see https://github.com/lampepfl/dotty/issues/222
309-
List("-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1")
310-
else
311-
List()
312-
313-
("-DpartestParentID=" + pid) :: tuning ::: agentOptions ::: travis_build ::: fullpath
314-
}
315-
).settings(publishing)
316-
317270
/** A sandbox to play with the Scala.js back-end of dotty.
318271
*
319272
* This sandbox is compiled with dotty with support for Scala.js. It can be

0 commit comments

Comments
 (0)