Skip to content

Commit 74821c4

Browse files
Atryclaude
andcommitted
Make all-libraries and jdk scripted tests pass on both sbt versions
Modernise the two fixtures so they run under both sbt 1.x and sbt 2.x, and remove the temporary sbt-2.x gating: - Bump their Scala versions (2.12.10 / 2.13.1 / 2.13.8 -> 2.12.20 / 2.13.16) so the sbt 2.x Zinc compiler bridge builds, and scalacheck to 1.18.1. - all-libraries: the scala-library and scalacheck api doc URLs differ by sbt version (autoAPIMappings reads the POM `apiURL` on sbt 1.x — e.g. https://www.scala-lang.org/api/<v>/ and https://www.javadoc.io/doc/<...> — while on sbt 2.x this plugin's own rules provide http://scala-lang.org/files/archive/ api/<v>/ and https://javadoc.io/page/<...>). Assert leniently (host + version) so one test covers both. - jdk: the scaladoc output directory is `target/api` on sbt 1.x but `target/out/jvm/<...>/api` on sbt 2.x, so the hard-coded `$ exists` / `jgrep` path no longer works. Move the file checks into a `checkDoc` task that locates the directory via `Compile / doc / target`. Verified locally (JDK 17): `++2.12.20 test` and `++3.8.4 test` both run all three scripted tests plus the unit test green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b0b8879 commit 74821c4

4 files changed

Lines changed: 55 additions & 70 deletions

File tree

build.sbt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,5 @@ scriptedLaunchOpts += s"-Dplugin.version=${version.value}"
5252

5353
(Test / test) := {
5454
(Test / test).value
55-
// The all-libraries and jdk scripted fixtures use very old Scala versions
56-
// (whose sbt 2.x compiler bridges don't build) and assert sbt 1.x-specific
57-
// behaviour (scaladoc output path, autoAPIMappings URLs). Until those fixtures
58-
// are modernised, run only keep-api-url under sbt 2.x; sbt 1.x runs them all.
59-
Def.taskDyn {
60-
if ((pluginCrossBuild / sbtVersion).value.startsWith("2."))
61-
scripted.toTask(" sbt-api-mappings/keep-api-url")
62-
else
63-
scripted.toTask("")
64-
}.value
55+
scripted.toTask("").value
6556
}

src/sbt-test/sbt-api-mappings/all-libraries/build.sbt

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
val check = TaskKey[Unit]("check")
22

3-
val scalacheckModuleId = "org.scalacheck" %% "scalacheck" % "1.14.3"
3+
val scalacheckModuleId = "org.scalacheck" %% "scalacheck" % "1.18.1"
44

55
// The classpath entry key is a File on sbt 1.x and a HashedVirtualFileRef on
66
// sbt 2.x; both render the jar path/name in toString, so look entries up by a
@@ -11,43 +11,50 @@ def findByName(mappings: Map[_, _], jarName: String): Option[String] =
1111
}
1212

1313
check := {
14-
// The expected URL is browsable but not accessible from JRE 8's java.net.HttpURLConnection
15-
val expectedScaladocUrl =
16-
"https://www.scala-lang.org/api/2.13.1/"
17-
18-
assert(
19-
findByName(
20-
(Compile / doc / apiMappings).value,
21-
"scala-library"
22-
).contains(expectedScaladocUrl)
23-
)
24-
assert(
25-
findByName(
26-
(Test / doc / apiMappings).value,
27-
"scala-library"
28-
).contains(expectedScaladocUrl)
29-
)
30-
14+
val compileMappings = (Compile / doc / apiMappings).value
15+
val testMappings = (Test / doc / apiMappings).value
16+
17+
// scala-library should map to a scala-lang.org scaladoc URL for this version.
18+
// The exact URL differs by sbt version (autoAPIMappings provides
19+
// https://www.scala-lang.org/api/<v>/ on sbt 1.x, while on sbt 2.x this
20+
// plugin's ScalaApiMappingRule provides http://scala-lang.org/files/archive/
21+
// api/<v>/), so assert leniently.
22+
def assertScalaLibrary(mappings: Map[_, _]): Unit =
23+
assert(
24+
findByName(mappings, "scala-library").exists { url =>
25+
url.contains("scala-lang.org") && url.contains(scalaVersion.value)
26+
},
27+
s"scala-library scaladoc mapping not found in $mappings"
28+
)
29+
assertScalaLibrary(compileMappings)
30+
assertScalaLibrary(testMappings)
31+
32+
// scalacheck (a Test-only dependency) should map to a javadoc.io URL. As with
33+
// scala-library the exact form differs by sbt version (autoAPIMappings reads
34+
// https://www.javadoc.io/doc/<...> from the POM on sbt 1.x, while on sbt 2.x
35+
// this plugin's JavadocIoApiMappingRule provides https://javadoc.io/page/<...>),
36+
// so assert leniently.
3137
val scalacheckJarName = Artifact.artifactName(
3238
ScalaVersion(scalaVersion.value, scalaBinaryVersion.value),
3339
scalacheckModuleId,
3440
Artifact("scalacheck")
3541
)
36-
37-
val expectedUrl =
38-
"https://javadoc.io/page/org.scalacheck/scalacheck_2.13/1.14.3/"
3942
assert(
40-
findByName((Test / doc / apiMappings).value, scalacheckJarName)
41-
.contains(expectedUrl)
43+
findByName(testMappings, scalacheckJarName).exists { url =>
44+
url.contains("javadoc.io") && url.contains("scalacheck") &&
45+
url.contains("1.18.1")
46+
},
47+
s"scalacheck javadoc mapping not found in $testMappings"
4248
)
4349
assert(
44-
findByName((Compile / doc / apiMappings).value, scalacheckJarName).isEmpty
50+
findByName(compileMappings, scalacheckJarName).isEmpty,
51+
s"scalacheck should not be on the Compile classpath: $compileMappings"
4552
)
4653
}
4754

48-
Global / scalaVersion := "2.13.1"
55+
Global / scalaVersion := "2.13.16"
4956

50-
crossScalaVersions := Seq("2.13.1")
57+
crossScalaVersions := Seq("2.13.16")
5158

5259
libraryDependencies += scalacheckModuleId % Test
5360

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
val check = TaskKey[Unit]("check")
2+
val checkDoc = TaskKey[Unit]("checkDoc")
23

34
def regexMatches(matcher: scala.util.matching.Regex)(str: String): Boolean = {
45
matcher.findFirstIn(str).isDefined
56
}
67

7-
Global / scalaVersion := "2.12.10"
8+
Global / scalaVersion := "2.12.20"
89

9-
crossScalaVersions := Seq("2.12.10", "2.13.8")
10-
11-
def javaVersion = VersionNumber(sys.props("java.specification.version"))
12-
13-
def isJava(x: Integer) = javaVersion match {
14-
case VersionNumber(Seq(y, _*), _, _) => x == y
15-
case _ => false
16-
}
10+
crossScalaVersions := Seq("2.12.20", "2.13.16")
1711

1812
check := {
1913

@@ -41,32 +35,27 @@ check := {
4135
}
4236
}
4337

44-
val fgrep = InputKey[Unit]("fgrep")
45-
46-
fgrep := {
47-
val args: Seq[String] = Def.spaceDelimited().parsed
48-
49-
val found = IO.readLines(file(args(1))).exists(_.contains(args(0)))
50-
51-
if (found) {
52-
println(s"Found '${args(0)}' in '${args(1)}'")
38+
// Verify the generated scaladoc, locating the output directory via
39+
// `Compile / doc / target` rather than a hard-coded path: on sbt 1.x that is
40+
// `target/api`, but on sbt 2.x it is `target/out/jvm/<...>/api`.
41+
checkDoc := {
42+
val docDir = (Compile / doc / target).value
5343

54-
} else {
55-
sys.error(s"Failed to fgrep '${args(0)}' '${args(1)}'")
44+
def requireFile(name: String): File = {
45+
val f = docDir / name
46+
if (!f.exists) sys.error(s"Expected generated doc file does not exist: $f")
47+
f
5648
}
57-
}
58-
59-
val jgrep = InputKey[Unit]("jgrep")
6049

61-
jgrep := {
62-
val args: Seq[String] = Def.spaceDelimited().parsed
63-
64-
val found = IO.readLines(file(args(1))).exists(regexMatches(args(0).r)(_))
65-
66-
if (found) {
67-
println(s"Found '${args(0)}' in '${args(1)}'")
50+
requireFile("index.html")
51+
val aHtml = requireFile("A.html")
6852

53+
val expect =
54+
"https://docs.oracle.com/(?:en/java/)?javase/\\d+/docs/api/(?:java.base/)?java/lang/Throwable.html".r
55+
val content = IO.readLines(aHtml)
56+
if (content.exists(regexMatches(expect))) {
57+
println(s"Found JDK javadoc link in $aHtml")
6958
} else {
70-
sys.error(s"Failed to jgrep '${args(0)}' '${args(1)}'")
59+
sys.error(s"Failed to find a JDK javadoc link in $aHtml")
7160
}
7261
}

src/sbt-test/sbt-api-mappings/jdk/test

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22
> 'set crossPaths := false'
33
> +check
44
> +doc
5-
$ exists target/api/index.html
6-
$ exists target/api/A.html
7-
> jgrep "https://docs.oracle.com/(?:en/java/)?javase/\\d+/docs/api/(?:java.base/)?java/lang/Throwable.html" "target/api/A.html"
5+
> +checkDoc

0 commit comments

Comments
 (0)