Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont show invalid sbt and scalajs versions #614

Merged
merged 10 commits into from
Apr 9, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ case class OtherPreRelease(o: String) extends PreRelease {
*/
case class SemanticVersion(
major: Long,
minor: Long = 0,
minor: Option[Long] = None,
patch: Option[Long] = None,
patch2: Option[Long] = None,
preRelease: Option[PreRelease] = None,
metadata: Option[String] = None
) extends Ordered[SemanticVersion] {

def isSemantic = {
def isSemantic: Boolean = {
patch.isDefined &&
!patch2.isDefined &&
preRelease.map(_.isSemantic).getOrElse(true)
patch2.isEmpty &&
preRelease.forall(_.isSemantic)
}

override def toString: String = {
val minorPart = minor.map(m => s".$m").getOrElse("")
adpi2 marked this conversation as resolved.
Show resolved Hide resolved
val patchPart = patch.map("." + _).getOrElse("")
val patch2Part = patch2.map("." + _).getOrElse("")

Expand All @@ -52,7 +53,7 @@ case class SemanticVersion(

val metadataPart = metadata.map("+" + _).getOrElse("")

major + "." + minor + patchPart + patch2Part + preReleasePart + metadataPart
major + minorPart + patchPart + patch2Part + preReleasePart + metadataPart
}

def binary: SemanticVersion =
Expand All @@ -61,57 +62,29 @@ case class SemanticVersion(

def forceBinary: SemanticVersion = SemanticVersion(major, minor)

private final val LT = -1
private final val GT = 1
private final val EQ = 0

private final val lcmp = implicitly[Ordering[Long]]
private final val scmp = implicitly[Ordering[String]]
private final val cmp =
implicitly[Ordering[(Long, Long, Option[Long], Option[Long])]]

override def compare(that: SemanticVersion): Int = {
val v1 = this
val v2 = that

def tupled(v: SemanticVersion) = (v.major, v.minor, v.patch, v.patch2)
val tv1 = tupled(v1)
val tv2 = tupled(v2)

def preCmp(pr1: Option[PreRelease], pr2: Option[PreRelease]): Int = {
// format: off
(pr1, pr2) match {
case (None, None) => EQ
case (None, Some(_)) => GT
case (Some(_), None) => LT
case (Some(ReleaseCandidate(rc1)), Some(ReleaseCandidate(rc2))) => lcmp.compare(rc1, rc2)
case (Some(ReleaseCandidate(_)) , Some(Milestone(_))) => GT
case (Some(Milestone(_)) , Some(ReleaseCandidate(_))) => LT
case (Some(Milestone(m1)) , Some(Milestone(m2))) => lcmp.compare(m1, m2)
case (Some(OtherPreRelease(pr1)) , Some(OtherPreRelease(pr2))) => scmp.compare(pr1, pr2)
case (Some(OtherPreRelease(_)) , Some(Milestone(_))) => LT
case (Some(OtherPreRelease(_)) , Some(ReleaseCandidate(_))) => LT
case (Some(_) , Some(OtherPreRelease(_))) => GT
case _ => EQ
}
// format: on
}

// Milestone < Release Candidate < Released
if (cmp.equiv(tv1, tv2)) preCmp(v1.preRelease, v2.preRelease)
else cmp.compare(tv1, tv2)
override def compare(that: SemanticVersion): PageIndex = {
SemanticVersion.ordering.compare(this, that)
}
}

object SemanticVersion extends Parsers {
import fastparse._
import fastparse.NoWhitespace._
private implicit val preReleaseOrdering: Ordering[PreRelease] = Ordering.by {
case ReleaseCandidate(rc) => (Some(rc), None, None)
case Milestone(m) => (None, Some(m), None)
case OtherPreRelease(pr) => (None, None, Some(pr))
}

implicit def ordering = new Ordering[SemanticVersion] {
def compare(v1: SemanticVersion, v2: SemanticVersion): Int =
v1.compare(v2)
implicit val ordering: Ordering[SemanticVersion] = Ordering.by {
x => (x.major, x.minor, x.patch, x.patch2, x.preRelease)
}

def apply(major: Long, minor: Long): SemanticVersion = {
SemanticVersion(major, Some(minor))
}

import fastparse._
import fastparse.NoWhitespace._

private def Number[_: P] = Digit.rep(1).!.map(_.toLong)
private def Major[_: P] = Number

Expand All @@ -127,12 +100,11 @@ object SemanticVersion extends Parsers {
// http://semver.org/#spec-item-10
private def MetaData[_: P] = "+" ~ AnyChar.rep.!

private def MinorP[_: P] =
("." ~ Number).?.map(_.getOrElse(0L)) // not really valid SemVer
private def MinorP[_: P] = ("." ~ Number).? // not really valid SemVer
private def PatchP[_: P] = ("." ~ Number).? // not really valid SemVer
private def Patch2P[_: P] = ("." ~ Number).? // not really valid SemVer

def Parser[_: P] = {
def Parser[_: P]: P[SemanticVersion] = {
("v".? ~ Major ~ MinorP ~ PatchP ~ Patch2P ~ PreRelease.? ~ MetaData.?)
.map {
case (major, minor, patch, patch2, preRelease, metadata) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,13 @@ object ScalaTarget {
val scalaVersion =
target.map(_.scalaVersion.forceBinary.toString)

val scalaJsVersion =
target.flatMap(_.scalaJsVersion.map(_.forceBinary.toString))
val scalaJsVersion = for {
target <- target
scalaJsVersion <- target.scalaJsVersion
} yield scalaJsVersion match {
case SemanticVersion(0, minor, _, _, _, _) => SemanticVersion(0, minor).toString
case _ => SemanticVersion(scalaJsVersion.major).toString
}

val scalaNativeVersion =
target.flatMap(_.scalaNativeVersion.map(_.forceBinary.toString))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,16 @@ class DataRepository(paths: DataPaths, githubDownload: GithubDownload)(
}

def getScalaVersions(params: SearchParams): Future[List[(String, Long)]] = {
versionAggregations("scalaVersion",
filteredSearchQuery(params),
filterScalaVersion)
versionAggregations("scalaVersion", filteredSearchQuery(params), filterScalaVersion)
.map(addLabelsIfMissing(params.scalaVersions.toSet))
}

def getAllScalaJsVersions(): Future[List[(String, Long)]] = {
versionAggregations("scalaJsVersion", notDeprecatedQuery, _ => true)
versionAggregations("scalaJsVersion", notDeprecatedQuery, filterScalaJsVersion)
}

def getScalaJsVersions(params: SearchParams): Future[List[(String, Long)]] = {
versionAggregations("scalaJsVersion",
filteredSearchQuery(params),
_ => true)
versionAggregations("scalaJsVersion", filteredSearchQuery(params), filterScalaJsVersion)
.map(addLabelsIfMissing(params.scalaJsVersions.toSet))
}

Expand All @@ -256,11 +252,11 @@ class DataRepository(paths: DataPaths, githubDownload: GithubDownload)(
}

def getAllSbtVersions(): Future[List[(String, Long)]] = {
versionAggregations("sbtVersion", notDeprecatedQuery, _ => true)
versionAggregations("sbtVersion", notDeprecatedQuery, filterSbtVersion)
}

def getSbtVersions(params: SearchParams): Future[List[(String, Long)]] = {
versionAggregations("sbtVersion", filteredSearchQuery(params), _ => true)
versionAggregations("sbtVersion", filteredSearchQuery(params), filterSbtVersion)
.map(addLabelsIfMissing(params.sbtVersions.toSet))
}

Expand Down Expand Up @@ -575,6 +571,19 @@ object DataRepository {
minScalaVersion <= version && version <= maxScalaVersion
}

private def minSbtVersion = SemanticVersion(0, 11)
private def maxSbtVersion = SemanticVersion(1, 3)

private def filterSbtVersion(version: SemanticVersion): Boolean = {
minSbtVersion <= version && version <= maxSbtVersion
}

private def minScalaJsVersion = SemanticVersion(0, 6)

private def filterScalaJsVersion(version: SemanticVersion): Boolean = {
minScalaJsVersion <= version
}

private def labelizeTargetType(targetType: String): String = {
if (targetType == "JVM") "Scala (Jvm)"
else targetType.take(1).map(_.toUpper) + targetType.drop(1).map(_.toLower)
Expand Down