Skip to content

Commit

Permalink
Updated: build.sbt with Scala 2.13 support
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-lee committed Sep 17, 2019
1 parent 723bdbd commit 0f1dd61
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 63 deletions.
54 changes: 31 additions & 23 deletions build.sbt
Expand Up @@ -4,44 +4,52 @@ import kevinlee.sbt.SbtCommon.crossVersionProps
import kevinlee.semver.{Major, Minor, SemanticVersion}
import org.scoverage.coveralls.Imports.CoverallsKeys._

lazy val root = (project in file("."))
ThisBuild / scalaVersion := ProjectScalaVersion
ThisBuild / organization := "kevinlee"
ThisBuild / version := ProjectVersion
ThisBuild / crossScalaVersions := CrossScalaVersions
ThisBuild / developers := List(
Developer("Kevin-Lee", "Kevin Lee", "kevin.code@kevinlee.io", url("https://github.com/Kevin-Lee"))
)

lazy val justSemVer = (project in file("."))
.settings(
organization := "kevinlee"
, name := "just-semver"
, scalaVersion := ProjectScalaVersion
, version := ProjectVersion
name := "just-semver"
, description := "Semantic Versioning (SemVer) for Scala"
, developers := List(
Developer("Kevin-Lee", "Kevin Lee", "kevin.code@kevinlee.io", url("https://github.com/Kevin-Lee"))
)
, crossScalaVersions := CrossScalaVersions
, scalacOptions :=
crossVersionProps(Seq.empty, SemanticVersion.parseUnsafe(scalaVersion.value)) {
case (Major(2), Minor(12)) =>
scalacOptions.value ++ commonScalacOptions
case (Major(2), Minor(11)) =>
(scalacOptions.value ++ commonScalacOptions).filter(_ != "-Ywarn-unused-import")
case (Major(2), Minor(10)) =>
scalacOptions.value.filter(option => option != "-Ywarn-numeric-widen")
case _ =>
(scalacOptions.value ++ commonScalacOptions)
.filter(option =>
option != "-Ywarn-unused-import" && option != "-Ywarn-numeric-widen"
)
scalacOptions.value
}.distinct
, unmanagedSourceDirectories in Compile ++= {
val sharedSourceDir = (baseDirectory in ThisBuild).value / "src/main"
if (scalaVersion.value.startsWith("2.13") || scalaVersion.value.startsWith("2.12"))
Seq(sharedSourceDir / "scala-2.12_2.13")
else
Seq(sharedSourceDir / "scala-2.10_2.11")
}
, wartremoverErrors in (Compile, compile) ++= commonWarts
, wartremoverErrors in (Test, compile) ++= commonWarts
, resolvers += hedgehogRepo
, libraryDependencies ++= hedgehogLibs
, dependencyOverrides ++= crossVersionProps(Seq.empty[ModuleID], SemanticVersion.parseUnsafe(scalaVersion.value)) {
case (Major(2), Minor(10)) =>
Seq("org.wartremover" %% "wartremover" % "2.3.7")
case x =>
Seq.empty
}
, dependencyOverrides ++=
crossVersionProps(
Seq.empty[ModuleID]
, SemanticVersion.parseUnsafe(scalaVersion.value)
) {
case (Major(2), Minor(10)) =>
Seq("org.wartremover" %% "wartremover" % "2.3.7")
case x =>
Seq.empty
}
, testFrameworks ++= Seq(TestFramework("hedgehog.sbt.Framework"))

/* Bintray { */
, bintrayPackageLabels := Seq("Scala", "SemanticVersion", "SemVer")
, bintrayVcsUrl := Some("""git@github.com:Kevin-Lee/just-semver.git""")
, licenses += ("MIT", url("http://opensource.org/licenses/MIT"))
/* } Bintray */

, initialCommands in console := """import kevinlee.semver._"""
Expand Down
6 changes: 1 addition & 5 deletions project/Dependencies.scala
@@ -1,7 +1,7 @@
import sbt._

object Dependencies {
val hedgehogVersion = "14aa04a77eece609f831684913288f7d7e6c1408"
val hedgehogVersion = "06b22e95ca1a32a2569914824ffe6fc4cfd62c62"
val hedgehogRepo =
Resolver.url(
"bintray-scala-hedgehog",
Expand All @@ -14,8 +14,4 @@ object Dependencies {
, "hedgehog" %% "hedgehog-sbt" % hedgehogVersion % Test
)

val wartRemover: ModuleID = "org.wartremover" % "sbt-wartremover" % "2.2.1"

val scoverage: ModuleID = "org.scoverage" % "sbt-scoverage" % "1.5.1"

}
23 changes: 3 additions & 20 deletions project/ProjectInfo.scala
Expand Up @@ -6,27 +6,10 @@ import wartremover.WartRemover.autoImport.{Wart, Warts}
*/
object ProjectInfo {

val ProjectScalaVersion: String = "2.12.8"
val CrossScalaVersions: Seq[String] = Seq("2.10.7", "2.11.12", ProjectScalaVersion)
val ProjectScalaVersion: String = "2.13.0"
val CrossScalaVersions: Seq[String] = Seq("2.10.7", "2.11.12", "2.12.10", ProjectScalaVersion)

val ProjectVersion: String = "0.1.0-SNAPSHOT"

val commonScalacOptions: Seq[String] = Seq(
"-deprecation"
, "-unchecked"
, "-feature"
, "-Ywarn-value-discard"
, "-Yno-adapted-args"
, "-Xlint"
, "-Xfatal-warnings"
, "-Ywarn-dead-code"
, "-Ywarn-inaccessible"
, "-Ywarn-nullary-unit"
, "-Ywarn-nullary-override"
, "-encoding", "UTF-8"
, "-Ywarn-unused-import"
, "-Ywarn-numeric-widen"
)
val ProjectVersion: String = "0.1.0"

val commonWarts: Seq[wartremover.Wart] = Warts.allBut(Wart.DefaultArguments, Wart.Overloading, Wart.Any, Wart.Nothing, Wart.NonUnitStatements)

Expand Down
8 changes: 4 additions & 4 deletions project/plugins.sbt
@@ -1,11 +1,11 @@
logLevel := sbt.Level.Warn

addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.5")

addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.4.1")
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.4.2")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0")

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

addSbtPlugin("kevinlee" % "sbt-devoops" % "0.2.0")
addSbtPlugin("kevinlee" % "sbt-devoops" % "0.3.1")
11 changes: 11 additions & 0 deletions src/main/scala-2.10_2.11/just/EitherCompat.scala
@@ -0,0 +1,11 @@
package just

object EitherCompat {

@inline final def map[A, B, C](either: Either[A, B])(f: B => C): Either[A, C] =
either.right.map(f)

@inline final def flatMap[A, B, C](either: Either[A, B])(f: B => Either[A, C]): Either[A, C] =
either.right.flatMap(f)

}
11 changes: 11 additions & 0 deletions src/main/scala-2.12_2.13/just/EitherCompat.scala
@@ -0,0 +1,11 @@
package just

object EitherCompat {

@inline final def map[A, B, C](either: Either[A, B])(f: B => C): Either[A, C] =
either.map(f)

@inline final def flatMap[A, B, C](either: Either[A, B])(f: B => Either[A, C]): Either[A, C] =
either.flatMap(f)

}
26 changes: 15 additions & 11 deletions src/main/scala/kevinlee/semver/versions.scala
Expand Up @@ -4,6 +4,8 @@ import kevinlee.Common._
import kevinlee.CommonPredef._
import kevinlee.semver.AdditionalInfo.{BuildMetaInfo, PreRelease}

import just.EitherCompat

import scala.annotation.tailrec
import scala.util.matching.Regex

Expand Down Expand Up @@ -72,7 +74,7 @@ object AlphaNumHyphenGroup {
ParseError.invalidAlphaNumHyphenError(x, xs)
)

result.right.map(groups => AlphaNumHyphenGroup(groups.toList))
EitherCompat.map(result)(groups => AlphaNumHyphenGroup(groups.toList))

case Nil =>
Left(ParseError.emptyAlphaNumHyphenError)
Expand All @@ -88,7 +90,7 @@ sealed trait AlphaNumHyphen extends Ordered[AlphaNumHyphen] {
override def compare(that: AlphaNumHyphen): Int =
(this, that) match {
case (Num(thisValue), Num(thatValue)) =>
thisValue.toInt.compareTo(thatValue.toInt)
Ordering[Int].compare(thisValue.toInt, thatValue.toInt)
case (Num(_), Alphabet(_)) =>
-1
case (Num(_), Hyphen) =>
Expand Down Expand Up @@ -157,18 +159,18 @@ object AdditionalInfo {
final case class BuildMetaInfo(identifier: Identifier)

def parsePreRelease(value: String): Either[ParseError, Option[PreRelease]] =
parse(value, {
EitherCompat.map(parse(value, {
case a @ AlphaNumHyphenGroup(Num(n) :: Nil) =>
if ((n === "0") || n.takeWhile(_ === '0').length === 0)
Right(a)
else
Left(ParseError.leadingZeroNumError(n))
case a @ AlphaNumHyphenGroup(_) =>
Right(a)
}).right.map(_.map(PreRelease))
}))(_.map(PreRelease))

def parseBuildMetaInfo(value: String): Either[ParseError, Option[BuildMetaInfo]] =
parse(value, Right.apply).right.map(_.map(BuildMetaInfo))
EitherCompat.map(parse(value, Right.apply))(_.map(BuildMetaInfo))

def parse(
value: String
Expand All @@ -181,17 +183,17 @@ object AdditionalInfo {
case Some(preRelease) =>
preRelease.foldRight[Either[ParseError, List[AlphaNumHyphenGroup]]](Right(List.empty)){
(x, acc) =>
x.right.flatMap(validator) match {
EitherCompat.flatMap(x)(validator) match {
case Right(alp) =>
acc.right.map(alps => alp :: alps)
EitherCompat.map(acc)(alps => alp :: alps)
case Left(error) =>
Left(error)
}
}
case None =>
Right(List.empty)
}
alphaNumHyphens.right.map {
EitherCompat.map(alphaNumHyphens) {
case Nil =>
None
case xs =>
Expand Down Expand Up @@ -248,7 +250,8 @@ final case class SemVer(
}

def render: String =
s"${major.major}.${minor.minor}.${patch.patch}" + ((pre, buildMetadata) match {
s"${major.major.toString}.${minor.minor.toString}.${patch.patch.toString}" + (
(pre, buildMetadata) match {
case (Some(p), Some(m)) =>
s"-${Identifier.render(p.identifier)}+${Identifier.render(m.identifier)}"
case (Some(p), None) =>
Expand All @@ -257,7 +260,8 @@ final case class SemVer(
s"+${Identifier.render(m.identifier)}"
case (None, None) =>
""
}).toString
}
).toString
}

object SemVer {
Expand Down Expand Up @@ -332,7 +336,7 @@ object ParseError {
@SuppressWarnings(Array("org.wartremover.warts.Recursion"))
def render(parseError: ParseError): String = parseError match {
case InvalidAlphaNumHyphenError(c, rest) =>
s"Invalid char for AlphaNumHyphen found. value: $c / rest: $rest"
s"Invalid char for AlphaNumHyphen found. value: ${c.toString} / rest: ${rest.toString}"

case EmptyAlphaNumHyphenError =>
"AlphaNumHyphen cannot be empty but the given value is an empty String."
Expand Down

0 comments on commit 0f1dd61

Please sign in to comment.