Skip to content

Commit 6ca1cfe

Browse files
committed
Add support for offline for COURSIER_MODE env var and coursier.mode java prop
1 parent a254163 commit 6ca1cfe

File tree

3 files changed

+52
-40
lines changed

3 files changed

+52
-40
lines changed

modules/cli/src/main/scala/scala/cli/commands/shared/CoursierOptions.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ final case class CoursierOptions(
4747
baseCache = baseCache.withTtl(ttl0)
4848
for (loc <- cache.filter(_.trim.nonEmpty))
4949
baseCache = baseCache.withLocation(loc)
50-
for (isOffline <- offline if isOffline)
50+
for (isOffline <- getOffline() if isOffline)
5151
baseCache = baseCache.withCachePolicies(Seq(CachePolicy.LocalOnly))
5252

5353
baseCache
5454
}
55+
56+
def getOffline(): Option[Boolean] = offline
57+
.orElse(Option(System.getenv("COURSIER_MODE")).map(_ == "offline"))
58+
.orElse(Option(System.getProperty("coursier.mode")).map(_ == "offline"))
5559
}
5660

5761
object CoursierOptions {

modules/cli/src/main/scala/scala/cli/commands/shared/SharedOptions.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ final case class SharedOptions(
403403
strictBloopJsonCheck = strictBloopJsonCheck,
404404
interactive = Some(() => interactive),
405405
exclude = exclude.map(Positioned.commandLine),
406-
offline = coursier.offline
406+
offline = coursier.getOffline()
407407
),
408408
notForBloopOptions = bo.PostBuildOptions(
409409
scalaJsLinkerOptions = linkerOptions(js),
@@ -552,9 +552,9 @@ final case class SharedOptions(
552552
config,
553553
threads.bloop,
554554
strictBloopJsonCheckOrDefault,
555-
coursier.offline.getOrElse(false)
555+
coursier.getOffline().getOrElse(false)
556556
))
557-
case Left(ex) if coursier.offline.contains(true) =>
557+
case Left(ex) if coursier.getOffline().contains(true) =>
558558
logger.diagnostic(WarningMessages.offlineModeBloopJvmNotFound, Severity.Warning)
559559
Right(SimpleScalaCompilerMaker("java", Nil))
560560
case Left(ex) => Left(ex)

modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
18901890
val depScalaVersion = actualScalaVersion match {
18911891
case sv if sv.startsWith("2.12") => "2.12"
18921892
case sv if sv.startsWith("2.13") => "2.13"
1893-
case _ => "3"
1893+
case _ => "3"
18941894
}
18951895

18961896
val dep = s"com.lihaoyi:os-lib_$depScalaVersion:0.9.1"
@@ -1919,14 +1919,14 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
19191919
val emptyCacheWalkSize = os.walk(cachePath).size
19201920

19211921
val noArtifactsRes = os.proc(
1922-
TestUtil.cli,
1923-
"--power",
1924-
"NoDeps.scala",
1925-
extraOptions,
1926-
"--offline",
1927-
"--cache",
1928-
cachePath.toString
1929-
)
1922+
TestUtil.cli,
1923+
"--power",
1924+
"NoDeps.scala",
1925+
extraOptions,
1926+
"--offline",
1927+
"--cache",
1928+
cachePath.toString
1929+
)
19301930
.call(cwd = root, check = false, mergeErrIntoOut = true)
19311931
expect(noArtifactsRes.exitCode == 1)
19321932

@@ -1946,16 +1946,16 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
19461946
val scalaJvmCacheWalkSize = os.walk(cachePath).size
19471947

19481948
val scalaAndJvmRes = os.proc(
1949-
TestUtil.cli,
1950-
"--power",
1951-
"NoDeps.scala",
1952-
extraOptions,
1953-
"--offline",
1954-
"--cache",
1955-
cachePath.toString,
1956-
"-v",
1957-
"-v"
1958-
)
1949+
TestUtil.cli,
1950+
"--power",
1951+
"NoDeps.scala",
1952+
extraOptions,
1953+
"--offline",
1954+
"--cache",
1955+
cachePath.toString,
1956+
"-v",
1957+
"-v"
1958+
)
19591959
.call(cwd = root, mergeErrIntoOut = true)
19601960
expect(scalaAndJvmRes.exitCode == 0)
19611961
expect(scalaAndJvmRes.out.trim().contains(
@@ -1967,21 +1967,29 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
19671967
expect(scalaJvmCacheWalkSize == os.walk(cachePath).size)
19681968

19691969
// Missing dependencies
1970-
val missingDepsRes = os.proc(
1970+
for {
1971+
(cliOption, extraEnvMode) <- Seq(
1972+
"--offline" -> Map.empty[String, String],
1973+
"-Dcoursier.mode=offline" -> Map.empty[String, String],
1974+
"" -> Map("COURSIER_MODE" -> "offline")
1975+
)
1976+
} {
1977+
val missingDepsRes = os.proc(
19711978
TestUtil.cli,
19721979
"--power",
1980+
cliOption,
19731981
"WithDeps.scala",
19741982
extraOptions,
1975-
"--offline",
19761983
"--cache",
19771984
cachePath.toString
19781985
)
1979-
.call(cwd = root, check = false, mergeErrIntoOut = true)
1980-
expect(missingDepsRes.exitCode == 1)
1981-
expect(missingDepsRes.out.trim().contains("Error downloading com.lihaoyi:os-lib"))
1986+
.call(cwd = root, check = false, mergeErrIntoOut = true, env = extraEnvMode)
1987+
expect(missingDepsRes.exitCode == 1)
1988+
expect(missingDepsRes.out.trim().contains("Error downloading com.lihaoyi:os-lib"))
19821989

1983-
// Cache unchanged
1984-
expect(scalaJvmCacheWalkSize == os.walk(cachePath).size)
1990+
// Cache unchanged
1991+
expect(scalaJvmCacheWalkSize == os.walk(cachePath).size)
1992+
}
19851993

19861994
// Download dependencies
19871995
os.proc(TestUtil.cs, "fetch", dep)
@@ -1990,16 +1998,16 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
19901998
val withDependencyCacheWalkSize = os.walk(cachePath).size
19911999

19922000
val depsRes = os.proc(
1993-
TestUtil.cli,
1994-
"--power",
1995-
"WithDeps.scala",
1996-
extraOptions,
1997-
"--offline",
1998-
"--cache",
1999-
cachePath.toString,
2000-
"-v",
2001-
"-v"
2002-
)
2001+
TestUtil.cli,
2002+
"--power",
2003+
"WithDeps.scala",
2004+
extraOptions,
2005+
"--offline",
2006+
"--cache",
2007+
cachePath.toString,
2008+
"-v",
2009+
"-v"
2010+
)
20032011
.call(cwd = root, mergeErrIntoOut = true)
20042012
expect(depsRes.exitCode == 0)
20052013
expect(

0 commit comments

Comments
 (0)