aboutsummaryrefslogtreecommitdiff
path: root/sbt-bridge/src/xsbt/ScaladocInterface.scala
blob: 1eae8374d28b03a982db06ba4337f03caaaeeb08 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* sbt -- Simple Build Tool
 * Copyright 2008, 2009 Mark Harrah
 */
package xsbt

import xsbti.{ Logger, Severity }
import java.net.URL

class ScaladocInterface {
  def run(args: Array[String], log: Logger, delegate: xsbti.Reporter) =
    (new DottydocRunner(args, log, delegate)).run()
}

class DottydocRunner(args: Array[String], log: Logger, delegate: xsbti.Reporter) {
  def run(): Unit = delegate.log(
    NoPosition,
    """|The dotty sbt-bridge currently does not support doc generation directly
       |via sbt. Please see the dotty documentation at dotty.epfl.ch""".stripMargin,
    Severity.Error
  )

  private[this] val NoPosition = new xsbti.Position {
    val line = xsbti.Maybe.nothing[Integer]
    val lineContent = ""
    val offset = xsbti.Maybe.nothing[Integer]
    val sourcePath = xsbti.Maybe.nothing[String]
    val sourceFile = xsbti.Maybe.nothing[java.io.File]
    val pointer = xsbti.Maybe.nothing[Integer]
    val pointerSpace = xsbti.Maybe.nothing[String]
  }

  private def getStringSetting(name: String): Option[String] =
    args find (_.startsWith(name)) map (_.drop(name.length))

  private def getOutputFolder(args: Array[String]): Option[String] =
    args sliding(2) find { case Array(x, _) => x == "-d" } map (_.tail.head.trim)

  private def getTemplate(resources: List[URL]): Option[URL] =
    resources.find(_.getFile.endsWith("template.html"))

  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)
  }
}