mirror of
https://github.com/sbt/sbt.git
synced 2026-10-06 10:03:56 +02:00
[2.0.x] Update user-agent to major.minor (#9818)
To avoid user-agent being used for tracking, use only major.minor.
This commit is contained in:
committed by
Eugene Yokota
parent
6ad195b249
commit
cf340eccc5
@@ -604,6 +604,8 @@ object CoursierDependencyResolution:
|
||||
.toOption
|
||||
.flatten
|
||||
}
|
||||
.flatMap(CrossVersion.partialVersion)
|
||||
.map((major, minor) => s"$major.$minor")
|
||||
.getOrElse("2.1")
|
||||
s"Coursier/$version (+https://github.com/coursier)"
|
||||
|
||||
|
||||
@@ -38,7 +38,11 @@ object LMCoursier {
|
||||
def defaultUserAgent(sbtVer: String): String =
|
||||
sys.props.get("sbt.http.agent").getOrElse {
|
||||
val cs = CoursierDependencyResolution.coursierUserAgent
|
||||
s"$cs sbt/$sbtVer (+https://www.scala-sbt.org/)".trim
|
||||
val sbtMajorMinor = CrossVersion
|
||||
.partialVersion(sbtVer)
|
||||
.map((major, minor) => s"$major.$minor")
|
||||
.getOrElse(sbtVer)
|
||||
s"$cs sbt/$sbtMajorMinor (+https://www.scala-sbt.org/)".trim
|
||||
}
|
||||
|
||||
def defaultCacheLocation: File =
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* sbt
|
||||
* Copyright 2023, Scala center
|
||||
* Copyright 2011 - 2022, Lightbend, Inc.
|
||||
* Copyright 2008 - 2010, Mark Harrah
|
||||
* Licensed under Apache License 2.0 (see LICENSE)
|
||||
*/
|
||||
|
||||
package sbt.coursierint
|
||||
|
||||
import hedgehog.*
|
||||
import hedgehog.runner.*
|
||||
|
||||
object UserAgentSpec extends Properties:
|
||||
private val UserAgent =
|
||||
raw"""Coursier/\d+\.\d+ \(\+https://github\.com/coursier\) sbt/2\.0 \(\+https://www\.scala-sbt\.org/\)""".r
|
||||
|
||||
override def tests: List[Test] =
|
||||
List(
|
||||
property(
|
||||
"defaultUserAgent only includes major.minor of sbt",
|
||||
versionGen.forAll.map { (major, minor, rest) =>
|
||||
val ua = LMCoursier.defaultUserAgent(s"$major.$minor$rest")
|
||||
Result.assert(ua.endsWith(s" sbt/$major.$minor (+https://www.scala-sbt.org/)"))
|
||||
}
|
||||
),
|
||||
example(
|
||||
"defaultUserAgent only includes major.minor of Coursier",
|
||||
Result.assert(UserAgent.matches(LMCoursier.defaultUserAgent("2.0.0")))
|
||||
),
|
||||
)
|
||||
|
||||
private def versionGen: Gen[(Int, Int, String)] =
|
||||
for
|
||||
major <- Gen.int(Range.linear(0, 100))
|
||||
minor <- Gen.int(Range.linear(0, 100))
|
||||
patch <- Gen.int(Range.linear(0, 100))
|
||||
suffix <- Gen.element1("", "-M2", "-RC1", "-SNAPSHOT", "-bin-20260924")
|
||||
rest <- Gen.element1("", s".$patch$suffix")
|
||||
yield (major, minor, rest)
|
||||
end UserAgentSpec
|
||||
Reference in New Issue
Block a user