aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bridge/src/main/scala/xsbt/ScaladocInterface.scala34
-rw-r--r--dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java7
-rw-r--r--dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala5
-rw-r--r--dottydoc/src/dotty/tools/dottydoc/util/OutputWriter.scala38
-rw-r--r--dottydoc/test/WhitelistedStdLibMain.scala5
-rw-r--r--project/Build.scala1
6 files changed, 57 insertions, 33 deletions
diff --git a/bridge/src/main/scala/xsbt/ScaladocInterface.scala b/bridge/src/main/scala/xsbt/ScaladocInterface.scala
index 42f4296fe..3ad9c7941 100644
--- a/bridge/src/main/scala/xsbt/ScaladocInterface.scala
+++ b/bridge/src/main/scala/xsbt/ScaladocInterface.scala
@@ -5,6 +5,7 @@ package xsbt
import xsbti.Logger
import dotty.tools.dottydoc.api.scala.Dottydoc
+import java.net.URL
class ScaladocInterface {
def run(args: Array[String], log: Logger, delegate: xsbti.Reporter) =
@@ -14,8 +15,8 @@ class ScaladocInterface {
class DottydocRunner(args: Array[String], log: Logger, delegate: xsbti.Reporter) extends Dottydoc {
def run(): Unit = getOutputFolder(args).map { outputFolder =>
val index = createIndex(args)
- val template = getTemplate(args)
val resources = getResources(args)
+ val template = getTemplate(resources)
template.fold(writeJson(index, outputFolder)) { tpl =>
buildDocs(outputFolder, tpl, resources, index)
@@ -44,15 +45,28 @@ class DottydocRunner(args: Array[String], log: Logger, delegate: xsbti.Reporter)
private def getOutputFolder(args: Array[String]): Option[String] =
args sliding(2) find { case Array(x, _) => x == "-d" } map (_.tail.head.trim)
- private def getTemplate(args: Array[String]): Option[String] =
- getStringSetting("-template:")
+ private def getTemplate(resources: List[URL]): Option[URL] =
+ resources.find(_.getFile.endsWith("template.html"))
- private def getResources(args: Array[String]): List[String] =
- getStringSetting("-resources:").map { path =>
- val dir = new java.io.File(path)
- if (dir.exists && dir.isDirectory)
- dir.listFiles.filter(_.isFile).map(_.getAbsolutePath).toList
- else Nil
- }.getOrElse(Nil)
+ private def getResources(args: Array[String]): List[URL] = {
+ val cp = args sliding (2) find { case Array(x, _) => x == "-classpath" } map (_.tail.head.trim) getOrElse ""
+ cp.split(":").find(_.endsWith("dottydoc-client.jar")).map { resourceJar =>
+ import java.util.jar.JarFile
+ val jarEntries = (new JarFile(resourceJar)).entries
+ var entries: List[URL] = Nil
+
+ while (jarEntries.hasMoreElements) {
+ val entry = jarEntries.nextElement()
+
+ if (!entry.isDirectory()) {
+ val path = s"jar:file:$resourceJar!/${entry.getName}"
+ val url = new URL(path)
+ entries = url :: entries
+ }
+ }
+
+ entries
+ } getOrElse (Nil)
+ }
}
diff --git a/dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java b/dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java
index b461c3096..dbe3f6f41 100644
--- a/dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java
+++ b/dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java
@@ -5,6 +5,7 @@ import dotty.tools.dottydoc.model.Package;
import dotty.tools.dottydoc.util.OutputWriter;
import java.util.Map;
import java.util.List;
+import java.net.URL;
/** FIXME: document me! */
public class Dottydoc extends DocDriver {
@@ -18,11 +19,11 @@ public class Dottydoc extends DocDriver {
public void buildDocs(
String outputDir,
- String templatePath,
- List<String> resources,
+ URL template,
+ List<URL> resources,
Map<String, Package> index
) {
- new OutputWriter().writeJava(index, templatePath, outputDir, resources);
+ new OutputWriter().writeJava(index, outputDir, template, resources);
}
public void writeJson(Map<String, Package> index, String outputDir) {
diff --git a/dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala b/dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala
index dce994f5d..a2c42d38c 100644
--- a/dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala
+++ b/dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala
@@ -5,14 +5,15 @@ import dotty.tools.dottydoc.model.Package
import dotty.tools.dottydoc.util.OutputWriter
import scala.collection.Map
+import java.net.URL
/** FIXME: document this class plz */
trait Dottydoc extends DocDriver {
def createIndex(args: Array[String]): Map[String, Package] =
compiledDocs(args)
- def buildDocs(outDir: String, templatePath: String, resources: List[String], index: Map[String, Package]) =
- new OutputWriter().write(index, templatePath, outDir, resources)
+ def buildDocs(outDir: String, template: URL, resources: List[URL], index: Map[String, Package]) =
+ new OutputWriter().write(index, outDir, template, resources)
def writeJson(index: Map[String, Package], outputDir: String) =
new OutputWriter().writeJson(index, outputDir)
diff --git a/dottydoc/src/dotty/tools/dottydoc/util/OutputWriter.scala b/dottydoc/src/dotty/tools/dottydoc/util/OutputWriter.scala
index d5a48912f..2084e0a97 100644
--- a/dottydoc/src/dotty/tools/dottydoc/util/OutputWriter.scala
+++ b/dottydoc/src/dotty/tools/dottydoc/util/OutputWriter.scala
@@ -8,11 +8,13 @@ import _root_.java.io.{
PrintWriter => JPrintWriter,
FileReader => JFileReader,
BufferedInputStream,
- FileInputStream,
+ InputStream,
+ InputStreamReader,
FileOutputStream,
BufferedOutputStream,
FileNotFoundException
}
+import _root_.java.net.URL
import _root_.java.util.{ Map => JMap, List => JList }
import model.{ Entity, Package }
import model.json._
@@ -21,16 +23,16 @@ import scala.collection.JavaConverters._
class OutputWriter {
- def writeJava(packs: JMap[String, Package], templatePath: String, outPath: String, resources: JList[String]): Unit = {
- write(packs.asScala, templatePath, outPath, resources.asScala)
+ def writeJava(packs: JMap[String, Package], outPath: String, template: URL, resources: JList[URL]): Unit = {
+ write(packs.asScala, outPath, template, resources.asScala)
}
- def write(packs: collection.Map[String, Package], templatePath: String, outPath: String, resources: Iterable[String]): Unit = {
+ def write(packs: collection.Map[String, Package], outPath: String, template: URL, resources: Traversable[URL]): Unit = {
// Write all packages to `outPath`
for (pack <- packs.values) {
println(s"""Writing '${pack.path.mkString(".")}'""")
writeFile(
- expandTemplate(templatePath, pack, outPath),
+ expandTemplate(template, pack, outPath),
outPath + pack.path.mkString("/", "/", "/"),
"index.html")
@@ -41,7 +43,7 @@ class OutputWriter {
} {
println(s"""Writing '${child.path.mkString(".")}'""")
writeFile(
- expandTemplate(templatePath, child, outPath),
+ expandTemplate(template, child, outPath),
outPath + child.path.dropRight(1).mkString("/", "/", "/"),
child.path.last + ".html")
}
@@ -55,7 +57,10 @@ class OutputWriter {
// Write resources to outPath
println("Copying CSS/JS resources to destination...")
assert(resources.nonEmpty)
- resources.map(s => copy(new JFile(s), outPath))
+
+ // TODO: splitting the URL by '/' and taking the last means that we don't
+ // allow folders among the resources
+ resources.foreach(url => copy(url.openStream, outPath, url.getFile.split("/").last))
println("Done writing static material, building js-app")
}
@@ -66,14 +71,15 @@ class OutputWriter {
def writeJson(index: collection.Map[String, Package], outputDir: String): Unit =
writeFile(index.json, outputDir + "/", "index.json")
- def expandTemplate(templatePath: String, entity: Entity, outPath: String): String = try {
+ def expandTemplate(template: URL, entity: Entity, outPath: String): String = try {
import model.json._
import model.java._
+ val inputStream = template.openStream
val writer = new _root_.java.io.StringWriter()
val mf = new DefaultMustacheFactory()
- def toRoot = "../" * (entity.path.length - 1)
+ def toRoot = "../" * (entity.path.length - { if (entity.isInstanceOf[Package]) 0 else 1 })
val entityWithExtras = entity.asJava(Map(
"assets" -> s"${toRoot}docassets",
@@ -81,14 +87,15 @@ class OutputWriter {
"currentEntity" -> entity.json
))
- mf.compile(new JFileReader(templatePath), "template")
+ mf.compile(new InputStreamReader(inputStream), "template")
.execute(writer, entityWithExtras)
+ inputStream.close()
writer.flush()
writer.toString
} catch {
case fnf: FileNotFoundException =>
- dottydoc.println(s"""Couldn't find the template: "$templatePath"...exiting""")
+ dottydoc.println(s"""Couldn't find the template: "${template.getFile}"...exiting""")
System.exit(1); ""
}
@@ -107,11 +114,12 @@ class OutputWriter {
printToFile(new JFile(path + file))(printer => bytes.foreach(printer.print))
}
- def copy(src: JFile, path: String): Unit = {
- val reader = new BufferedInputStream(new FileInputStream(src))
+ def copy(src: InputStream, path: String, name: String): Unit = {
+ val reader = new BufferedInputStream(src)
try {
- val bytes = Stream.continually(reader.read).takeWhile(-1 != _).map(_.toByte)
- writeFile(bytes.toArray, path + "/docassets/", src.getName)
+ val bytes = Stream.continually(reader.read).takeWhile(-1 != _).map(_.toByte)
+ writeFile(bytes.toArray, path + "/docassets/", name)
+ src.close()
} finally reader.close()
}
}
diff --git a/dottydoc/test/WhitelistedStdLibMain.scala b/dottydoc/test/WhitelistedStdLibMain.scala
index 95d4afbae..fcd08e50d 100644
--- a/dottydoc/test/WhitelistedStdLibMain.scala
+++ b/dottydoc/test/WhitelistedStdLibMain.scala
@@ -3,7 +3,7 @@ package dottydoc
import scala.io.Source
-object WhitelistedStandardLib extends dottydoc.api.java.Dottydoc {
+object WhitelistedStandardLib extends dottydoc.api.scala.Dottydoc {
import scala.collection.JavaConverters._
val files: List[String] = {
@@ -16,7 +16,6 @@ object WhitelistedStandardLib extends dottydoc.api.java.Dottydoc {
.map(_.takeWhile(_ != '#').trim) // allow comments in the end of line
.filter(_.nonEmpty)
.filterNot(_.endsWith("package.scala"))
- .map("." + _)
.toList
}
@@ -42,6 +41,6 @@ object WhitelistedStandardLib extends dottydoc.api.java.Dottydoc {
"-language:Scala2" +: "-Ydoc-output" +: "../build/dottydoc" +: files.toArray
val index = createIndex(compilerArgs)
- buildDocs("../build/dottydoc", "../../dottydoc-client/resources/template.html", resources.asJava, index)
+ buildDocs("../build/dottydoc", "../../dottydoc-client/resources/template.html", resources, index)
}
}
diff --git a/project/Build.scala b/project/Build.scala
index 7a9d83a50..cd17f2d07 100644
--- a/project/Build.scala
+++ b/project/Build.scala
@@ -100,6 +100,7 @@ object DottyBuild extends Build {
libraryDependencies ++= partestDeps.value,
libraryDependencies ++= Seq("org.scala-lang.modules" %% "scala-xml" % "1.0.1",
"org.scala-lang.modules" %% "scala-partest" % "1.0.11" % "test",
+ "ch.epfl.lamp" % "dottydoc-client" % "0.1-SNAPSHOT",
"com.novocode" % "junit-interface" % "0.11" % "test",
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0",
"com.github.spullara.mustache.java" % "compiler" % "0.9.3",