Skip to content

Commit

Permalink
Merge pull request #91 from olafurpg/upgrade
Browse files Browse the repository at this point in the history
Upgrade dependencies
  • Loading branch information
olafurpg authored Sep 10, 2018
2 parents ecb37f3 + dc394c6 commit be16a3a
Show file tree
Hide file tree
Showing 21 changed files with 7,309 additions and 323 deletions.
32 changes: 19 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
language: scala
scala: 2.12.4
scala: 2.12.6
jdk: oraclejdk8
sudo: false
dist: trusty

stages:
- name: test
- name: release
if: (branch = master AND type = push) OR (tag IS present)


env:
global:
- TRAVIS_NODE_VERSION="8"
- TRAVIS_YARN_VERSION="1.3.2"

matrix:
jobs:
include:
- script: sbt ci-test
env: CI_PUBLISH=true
deploy:
provider: script
script: bash bin/ci-publish.sh
- script: sbt ";^^$SCRIPTED_SBT_VERSION; scripted"
env: SCRIPTED_SBT_VERSION="0.13.17"
- script: sbt ";^^$SCRIPTED_SBT_VERSION; scripted"
env: SCRIPTED_SBT_VERSION="1.0.4"
- script: ./bin/scalafmt --test
env: SCALAFMT=true
- env: TEST="sbt test"
script: sbt ci-test
- env: SCRIPTED_SBT_VERSION="0.13.17"
script: sbt ";^^$SCRIPTED_SBT_VERSION; scripted"
- env: SCRIPTED_SBT_VERSION="1.2.1"
script: sbt ";^^$SCRIPTED_SBT_VERSION; scripted"
- env: TEST=scalafmt
script: ./bin/scalafmt --test
- stage: release
script: sbt ci-release

cache:
yarn: true
Expand All @@ -38,6 +43,7 @@ before_install:
- nvm install "$TRAVIS_NODE_VERSION"
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version "$TRAVIS_YARN_VERSION"
- export PATH=$HOME/.yarn/bin:$PATH
- yarn config set ignore-engines true

before_cache:
- du -h -d 1 $HOME/.ivy2/cache
Expand Down
Binary file modified bin/scalafmt
Binary file not shown.
14 changes: 6 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import scalapb.compiler.Version.scalapbVersion
import scalajsbundler.util.JSON._
import sbtcrossproject.{crossProject, CrossType}

inThisBuild(
List(
Expand Down Expand Up @@ -45,9 +46,9 @@ inThisBuild(
)

lazy val Version = new {
def scala = "2.12.4"
def scala = "2.12.6"
def scala210 = "2.10.6"
def scalameta = "3.7.0"
def scalameta = "4.0.0-M11"
def sbt = "1.1.1"
def sbt013 = "0.13.17"
}
Expand All @@ -71,7 +72,6 @@ lazy val allSettings = Seq(

lazy val example = project
.in(file("paiges") / "core")
.disablePlugins(ScriptedPlugin) // sbt/sbt#3514 fixed in sbt 1.2
.settings(
noPublish,
addCompilerPlugin(
Expand All @@ -86,7 +86,6 @@ lazy val example = project

lazy val cli = project
.in(file("metadoc-cli"))
.disablePlugins(ScriptedPlugin) // sbt/sbt#3514 fixed in sbt 1.2
.settings(
allSettings,
moduleName := "metadoc-cli",
Expand Down Expand Up @@ -119,7 +118,6 @@ lazy val cli = project

lazy val js = project
.in(file("metadoc-js"))
.disablePlugins(ScriptedPlugin) // sbt/sbt#3514 fixed in sbt 1.2
.settings(
noPublish,
moduleName := "metadoc-js",
Expand Down Expand Up @@ -160,10 +158,9 @@ lazy val js = project
.dependsOn(coreJS)
.enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin)

lazy val core = crossProject
lazy val core = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure)
.in(file("metadoc-core"))
.disablePlugins(ScriptedPlugin) // sbt/sbt#3514 fixed in sbt 1.2
.jsSettings(noPublish)
.settings(
allSettings,
Expand All @@ -178,7 +175,7 @@ lazy val core = crossProject
baseDirectory.value./("../src/main/protobuf")
),
libraryDependencies ++= List(
"org.scalameta" %%% "langmeta" % Version.scalameta,
"org.scalameta" %%% "scalameta" % Version.scalameta,
"com.thesamet.scalapb" %%% "scalapb-runtime" % scalapbVersion
)
)
Expand Down Expand Up @@ -229,6 +226,7 @@ val sbtPlugin = project
scalaBinaryVersion.in(coreJVM)
)
)
.enablePlugins(ScriptedPlugin)

lazy val tests = project
.in(file("metadoc-tests"))
Expand Down
20 changes: 20 additions & 0 deletions metadoc-cli/src/main/scala/metadoc/cli/FingerprintOps.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package metadoc.cli

import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets
import java.security.MessageDigest
import javax.xml.bind.DatatypeConverter

object FingerprintOps {

def md5(string: String): String = {
md5(ByteBuffer.wrap(string.getBytes(StandardCharsets.UTF_8)))
}

def md5(buffer: ByteBuffer): String = {
val md = MessageDigest.getInstance("MD5")
md.update(buffer)
DatatypeConverter.printHexBinary(md.digest())
}

}
97 changes: 72 additions & 25 deletions metadoc-cli/src/main/scala/metadoc/cli/MetadocCli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,27 @@ import scalapb.json4s.JsonFormat
import metadoc.schema
import metadoc.schema.SymbolIndex
import metadoc.{schema => d}
import org.langmeta._
import scala.meta.internal.{semanticdb3 => s}
import scala.meta._
import scala.meta.internal.{semanticdb => s}
import scala.meta.internal.semanticdb.Scala._
import metadoc.MetadocEnrichments._
import scala.meta.internal.io.FileIO
import scala.meta.internal.io.PathIO
import scala.meta.internal.metadoc.ScalametaInternals

@AppName("metadoc")
@AppVersion("0.1.0-SNAPSHOT")
@AppVersion("<version>")
@ProgName("metadoc")
case class MetadocOptions(
@HelpMessage(
"The output directory to generate the metadoc site. (required)"
)
target: Option[String] = None,
@HelpMessage(
"The SemanticDB sourceroot used to compiled sources, must match the compiler option -P:semanticdb:sourceroot:<value>. " +
"Defaults to the working directory if empty."
)
sourceroot: Option[String] = None,
@HelpMessage(
"Clean the target directory before generating new site. " +
"All files will be deleted so be careful."
Expand All @@ -51,14 +60,22 @@ case class MetadocOptions(
)
zip: Boolean = false,
@HelpMessage("Disable fancy progress bar")
nonInteractive: Boolean = false
nonInteractive: Boolean = false,
@HelpMessage(
"The working directory used to relativize file directories, default to sys.props('user.dir') if empty."
)
cwd: Option[String] = None,
) {
def targetPath: AbsolutePath = AbsolutePath(target.get)
}

case class Target(target: AbsolutePath, onClose: () => Unit)

class CliRunner(classpath: Seq[AbsolutePath], options: MetadocOptions) {
private implicit val cwd: AbsolutePath =
options.cwd.fold(PathIO.workingDirectory)(AbsolutePath(_))
private val sourceroot: AbsolutePath =
options.sourceroot.fold(PathIO.workingDirectory)(AbsolutePath(_))
val Target(target, onClose) = if (options.zip) {
// For large corpora (>1M LOC) writing the symbol/ directory is the
// bottle-neck unless --zip is enabled.
Expand Down Expand Up @@ -163,6 +180,29 @@ class CliRunner(classpath: Seq[AbsolutePath], options: MetadocOptions) {
files.result()
}

private def updateText(doc: s.TextDocument): s.TextDocument = {
if (doc.text.isEmpty) {
val abspath = sourceroot.resolve(doc.uri)
if (abspath.isFile) {
val text = FileIO.slurp(abspath, StandardCharsets.UTF_8)
val md5 = FingerprintOps.md5(text)
if (md5 != doc.md5) {
System.err.println(
s"error: md5 fingerprint mismatch for document ${doc.uri}"
)
}
doc.withText(text)
} else {
System.err.println(
s"error: No file on disc for document ${doc.uri}"
)
doc
}
} else {
doc
}
}

private def parseDatabase(path: AbsolutePath): s.TextDocuments = {
val filename = path.toNIO.getFileName.toString
val bytes = path.readAllBytes
Expand All @@ -182,7 +222,8 @@ class CliRunner(classpath: Seq[AbsolutePath], options: MetadocOptions) {
try {
tick()
val db = parseDatabase(path)
db.documents.foreach { document =>
db.documents.foreach { noTextDocument =>
val document = updateText(noTextDocument)
document.occurrences.foreach {
case s.SymbolOccurrence(_, sym, _)
if !sym.endsWith(".") && !sym.endsWith("#") =>
Expand Down Expand Up @@ -247,35 +288,41 @@ class CliRunner(classpath: Seq[AbsolutePath], options: MetadocOptions) {
private def updateReferencesForType(
symbolsMap: concurrent.Map[Symbol, AtomicReference[SymbolIndex]],
symbolIndex: SymbolIndex
) = {
Symbol(symbolIndex.symbol) match {
case Symbol.Global(owner, Signature.Type(name)) =>
(for {
): SymbolIndex = {
if (symbolIndex.symbol.isType) {
try {
val (owner, desc) = ScalametaInternals.ownerAndDesc(symbolIndex.symbol)
val maybeTermInfo = for {
syntheticObjRef <- symbolsMap.get(
Symbol.Global(owner, Signature.Term(name)).syntax
Symbols.Global(owner, Descriptor.Term(desc.name.value))
)
if syntheticObjRef.get().definition.isEmpty
} yield
symbolIndex.copy(references = syntheticObjRef.get().references))
.getOrElse(symbolIndex)
case _ => symbolIndex
} yield symbolIndex.copy(references = syntheticObjRef.get().references)
maybeTermInfo.getOrElse(symbolIndex)
} catch {
case NonFatal(e) =>
symbolIndex
}
} else {
symbolIndex
}
}

private def updateDefinitionsForTerm(
symbolsMap: concurrent.Map[Symbol, AtomicReference[SymbolIndex]],
symbolIndex: SymbolIndex
) = {
Symbol(symbolIndex.symbol) match {
case Symbol.Global(owner, Signature.Term(name)) =>
(for {
typeRef <- symbolsMap.get(
Symbol.Global(owner, Signature.Type(name)).syntax
)
definition <- typeRef.get().definition
} yield symbolIndex.copy(definition = Some(definition)))
.getOrElse(symbolIndex)
case _ => symbolIndex
): SymbolIndex = {
if (symbolIndex.symbol.isTerm) {
val (owner, desc) = ScalametaInternals.ownerAndDesc(symbolIndex.symbol)
val maybeTypeInfo = for {
typeRef <- symbolsMap.get(
Symbols.Global(owner, Descriptor.Type(desc.name.value))
)
definition <- typeRef.get().definition
} yield symbolIndex.copy(definition = Some(definition))
maybeTypeInfo.getOrElse(symbolIndex)
} else {
symbolIndex
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package scala.meta.internal.metadoc

import scala.meta.internal.semanticdb.Scala._

object ScalametaInternals {
def ownerAndDesc(symbol: String): (String, Descriptor) = {
DescriptorParser(symbol).swap
}
}
3 changes: 1 addition & 2 deletions metadoc-core/src/main/scala/metadoc/MetadocEnrichments.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package metadoc

import metadoc.{schema => d}
import org.{langmeta => m}
import scala.meta.internal.{semanticdb3 => s}
import scala.meta.internal.{semanticdb => s}

object MetadocEnrichments {
implicit class XtensionMetadocRange(val r: d.Range) extends AnyVal {
Expand Down
2 changes: 1 addition & 1 deletion metadoc-core/src/main/scala/metadoc/MetadocEvent.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package metadoc

import scala.meta.internal.{semanticdb3 => s}
import scala.meta.internal.{semanticdb => s}

sealed abstract class MetadocEvent
object MetadocEvent {
Expand Down
Loading

0 comments on commit be16a3a

Please sign in to comment.