Skip to content

Commit

Permalink
Merge be19c3b into 2c0a004
Browse files Browse the repository at this point in the history
  • Loading branch information
blemale committed Mar 21, 2020
2 parents 2c0a004 + be19c3b commit 502e839
Show file tree
Hide file tree
Showing 25 changed files with 892 additions and 725 deletions.
23 changes: 23 additions & 0 deletions .scalafmt.conf
@@ -0,0 +1,23 @@
version=2.4.1
maxColumn = 80
align = more
assumeStandardLibraryStripMargin = true
importSelectors = singleLine
indentYieldKeyword = false
newlines.alwaysBeforeTopLevelStatements = true
project.git = true

rewrite.rules = [
prefercurlyfors
redundantbraces
redundantparens
sortimports
sortmodifiers
]
rewrite.redundantBraces.stringInterpolation = true

rewriteTokens = {
"⇒": "=>"
"←": "<-"
"→": "->"
}
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -27,7 +27,7 @@ stages:
jobs:
include:
- stage: test
script: sbt clean coverage +test +doc && sbt coverageReport coveralls
script: sbt clean scalafmtSbtCheck scalafmtCheck coverage +test +doc && sbt coverageReport coveralls
- stage: publish
script: sbt +publish

Expand Down
157 changes: 82 additions & 75 deletions build.sbt
Expand Up @@ -14,85 +14,92 @@ scalaVersion := "2.11.12"

libraryDependencies ++=
Seq(
"com.github.ben-manes.caffeine" % "caffeine" % CaffeineVersion.value,
"org.scala-lang.modules" %% "scala-java8-compat" % "0.9.1",
"com.google.code.findbugs" % "jsr305" % "3.0.2" % "provided",
"org.scalactic" %% "scalactic" % "3.2.0-M4" % "test",
"org.scalatest" %% "scalatest" % "3.2.0-M4" % "test"
"com.github.ben-manes.caffeine" % "caffeine" % CaffeineVersion.value,
"org.scala-lang.modules" %% "scala-java8-compat" % "0.9.1",
"com.google.code.findbugs" % "jsr305" % "3.0.2" % "provided",
"org.scalactic" %% "scalactic" % "3.2.0-M4" % "test",
"org.scalatest" %% "scalatest" % "3.2.0-M4" % "test"
)

scalafmtOnCompile := true

scalacOptions ++= Seq("-target:jvm-1.8")

scalacOptions ++=
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) =>
Seq(
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Xfatal-warnings",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture",
"-Ywarn-unused-import"
)
case Some((2, 12)) =>
Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding", "utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:experimental.macros", // Allow macro definition (besides implementation and application)
"-language:higherKinds", // Allow higher-kinded types
"-language:implicitConversions", // Allow definition of implicit functions called views
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
"-Xfatal-warnings", // Fail the compilation if there are any warnings.
"-Xfuture", // Turn on future language features.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.
"-Ypartial-unification", // Enable partial unification in type constructor inference
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Ywarn-nullary-unit", // Warn when nullary methods return Unit.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
)
case _ =>
Nil
})
case Some((2, 11)) =>
Seq(
"-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Xfatal-warnings",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture",
"-Ywarn-unused-import"
)
case Some((2, 12)) =>
Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding",
"utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:experimental.macros", // Allow macro definition (besides implementation and application)
"-language:higherKinds", // Allow higher-kinded types
"-language:implicitConversions", // Allow definition of implicit functions called views
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
"-Xfatal-warnings", // Fail the compilation if there are any warnings.
"-Xfuture", // Turn on future language features.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.
"-Ypartial-unification", // Enable partial unification in type constructor inference
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Ywarn-nullary-unit", // Warn when nullary methods return Unit.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
)
case _ =>
Nil
})

scalacOptions in (Compile, console) --= Seq("-Ywarn-unused:imports", "-Xfatal-warnings")
scalacOptions in (Compile, console) --= Seq(
"-Ywarn-unused:imports",
"-Xfatal-warnings"
)
7 changes: 0 additions & 7 deletions formatting.sbt

This file was deleted.

2 changes: 1 addition & 1 deletion project/CaffeineVersion.scala
@@ -1,5 +1,5 @@
object CaffeineVersion {

val value: String = "2.8.1"

}
23 changes: 12 additions & 11 deletions project/TravisCredentials.scala
Expand Up @@ -2,14 +2,15 @@ import sbt.Keys._
import sbt._

object TravisCredentials {
def updateCredentials() = (for {
username <- Option(System.getenv().get("SONATYPE_USERNAME"))
password <- Option(System.getenv().get("SONATYPE_PASSWORD"))
} yield
credentials += Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
username,
password)
).getOrElse(credentials ++= Seq())
}

def updateCredentials() =
(for {
username <- Option(System.getenv().get("SONATYPE_USERNAME"))
password <- Option(System.getenv().get("SONATYPE_PASSWORD"))
} yield credentials += Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
username,
password
)).getOrElse(credentials ++= Seq())
}
2 changes: 1 addition & 1 deletion project/plugins.sbt
Expand Up @@ -2,7 +2,7 @@ addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")

addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.7")

addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.2")

addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")

Expand Down
7 changes: 5 additions & 2 deletions release.sbt
Expand Up @@ -8,7 +8,10 @@ releaseProcess := Seq[ReleaseStep](
setReleaseVersion,
commitReleaseVersion,
tagRelease,
ReleaseStep(action = Command.process("publishSigned", _), enableCrossBuild = true),
ReleaseStep(
action = Command.process("publishSigned", _),
enableCrossBuild = true
),
setNextVersion,
commitNextVersion,
ReleaseStep(action = Command.process("sonatypeReleaseAll", _)),
Expand All @@ -24,7 +27,7 @@ publishMavenStyle := true
TravisCredentials.updateCredentials()

pomExtra in Global := {
<scm>
<scm>
<connection>scm:git:github.com/blemale/scaffeine.git</connection>
<developerConnection>scm:git:git@github.com:blemale/scaffeine.git</developerConnection>
<url>github.com/blemale/scaffeine.git</url>
Expand Down
47 changes: 30 additions & 17 deletions scaladoc.sbt
Expand Up @@ -5,50 +5,63 @@ autoAPIMappings := true

apiMappings ++= {
val cp = (fullClasspath in Compile).value
val bootClasspath = System.getProperty("sun.boot.class.path").split(":").map(file(_))
val bootClasspath =
System.getProperty("sun.boot.class.path").split(":").map(file(_))

def findManagedDependency(organization: String, name: String): File =
(for {
entry <- cp
module <- entry.get(moduleID.key)
if module.organization == organization
if module.name.startsWith(name)
jarFile = entry.data
} yield jarFile
).head
entry <- cp
module <- entry.get(moduleID.key)
if module.organization == organization
if module.name.startsWith(name)
jarFile = entry.data
} yield jarFile).head

Map(
bootClasspath.find(_.getPath.endsWith("rt.jar")).get -> url("http://docs.oracle.com/javase/8/docs/api/"),
findManagedDependency("com.github.ben-manes.caffeine", "caffeine") -> url(s"http://static.javadoc.io/com.github.ben-manes.caffeine/caffeine/${CaffeineVersion.value}/")
bootClasspath.find(_.getPath.endsWith("rt.jar")).get -> url(
"http://docs.oracle.com/javase/8/docs/api/"
),
findManagedDependency("com.github.ben-manes.caffeine", "caffeine") -> url(
s"http://static.javadoc.io/com.github.ben-manes.caffeine/caffeine/${CaffeineVersion.value}/"
)
)
}

lazy val fixJavaLinksTask = taskKey[Unit](
"Fix Java links in scaladoc"
)

val jdkApiLink = """\"(http://docs\.oracle\.com/javase/8/docs/api/index\.html)#([^"]*)\"""".r
val caffeineApiLink = ("""\"(http://static\.javadoc\.io/com\.github\.ben-manes\.caffeine/caffeine/""" + CaffeineVersion.value.replace(".", "\\.") + """/)index\.html#([^"]*)\"""").r
val jdkApiLink =
"""\"(http://docs\.oracle\.com/javase/8/docs/api/index\.html)#([^"]*)\"""".r

val caffeineApiLink =
("""\"(http://static\.javadoc\.io/com\.github\.ben-manes\.caffeine/caffeine/""" + CaffeineVersion.value
.replace(".", "\\.") + """/)index\.html#([^"]*)\"""").r

def hasJavadocLink(f: File): Boolean = {
val content = IO.read(f)
(jdkApiLink findFirstIn content).nonEmpty || (caffeineApiLink findFirstIn content).nonEmpty
}

val fixJdkLinks: Match => String = m => m.group(1) + "?" + m.group(2).replace(".", "/") + ".html"
val fixJdkLinks: Match => String = m =>
m.group(1) + "?" + m.group(2).replace(".", "/") + ".html"
val replaceJdkLinks: String => String = jdkApiLink.replaceAllIn(_, fixJdkLinks)

val fixCaffeineLinks: Match => String = m => m.group(1) + m.group(2).replace(".", "/") + ".html"
val replaceCaffeineLinks: String => String = caffeineApiLink.replaceAllIn(_, fixCaffeineLinks)
val fixCaffeineLinks: Match => String = m =>
m.group(1) + m.group(2).replace(".", "/") + ".html"

val replaceCaffeineLinks: String => String =
caffeineApiLink.replaceAllIn(_, fixCaffeineLinks)

fixJavaLinksTask := {
val log = streams.value.log
log.info("Fixing Java links")
val t = (target in(Compile, doc)).value
val t = (target in (Compile, doc)).value
(t ** "*.html").get.filter(hasJavadocLink).foreach { f =>
try {
log.info("Fixing " + f)
val fixedContent = replaceCaffeineLinks.andThen(replaceJdkLinks).apply(IO.read(f))
val fixedContent =
replaceCaffeineLinks.andThen(replaceJdkLinks).apply(IO.read(f))
IO.write(f, fixedContent)
} catch {
case NonFatal(e) => log.error(s"Failed to replace links in $f")
Expand Down

0 comments on commit 502e839

Please sign in to comment.