Skip to content

Commit

Permalink
Add support for offline for COURSIER_MODE env var and coursier.mode j…
Browse files Browse the repository at this point in the history
…ava prop
  • Loading branch information
MaciejG604 committed Oct 9, 2023
1 parent a254163 commit 6ca1cfe
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ final case class CoursierOptions(
baseCache = baseCache.withTtl(ttl0)
for (loc <- cache.filter(_.trim.nonEmpty))
baseCache = baseCache.withLocation(loc)
for (isOffline <- offline if isOffline)
for (isOffline <- getOffline() if isOffline)
baseCache = baseCache.withCachePolicies(Seq(CachePolicy.LocalOnly))

baseCache
}

def getOffline(): Option[Boolean] = offline
.orElse(Option(System.getenv("COURSIER_MODE")).map(_ == "offline"))
.orElse(Option(System.getProperty("coursier.mode")).map(_ == "offline"))
}

object CoursierOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ final case class SharedOptions(
strictBloopJsonCheck = strictBloopJsonCheck,
interactive = Some(() => interactive),
exclude = exclude.map(Positioned.commandLine),
offline = coursier.offline
offline = coursier.getOffline()
),
notForBloopOptions = bo.PostBuildOptions(
scalaJsLinkerOptions = linkerOptions(js),
Expand Down Expand Up @@ -552,9 +552,9 @@ final case class SharedOptions(
config,
threads.bloop,
strictBloopJsonCheckOrDefault,
coursier.offline.getOrElse(false)
coursier.getOffline().getOrElse(false)
))
case Left(ex) if coursier.offline.contains(true) =>
case Left(ex) if coursier.getOffline().contains(true) =>
logger.diagnostic(WarningMessages.offlineModeBloopJvmNotFound, Severity.Warning)
Right(SimpleScalaCompilerMaker("java", Nil))
case Left(ex) => Left(ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,7 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
val depScalaVersion = actualScalaVersion match {
case sv if sv.startsWith("2.12") => "2.12"
case sv if sv.startsWith("2.13") => "2.13"
case _ => "3"
case _ => "3"
}

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

val noArtifactsRes = os.proc(
TestUtil.cli,
"--power",
"NoDeps.scala",
extraOptions,
"--offline",
"--cache",
cachePath.toString
)
TestUtil.cli,
"--power",
"NoDeps.scala",
extraOptions,
"--offline",
"--cache",
cachePath.toString
)
.call(cwd = root, check = false, mergeErrIntoOut = true)
expect(noArtifactsRes.exitCode == 1)

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

val scalaAndJvmRes = os.proc(
TestUtil.cli,
"--power",
"NoDeps.scala",
extraOptions,
"--offline",
"--cache",
cachePath.toString,
"-v",
"-v"
)
TestUtil.cli,
"--power",
"NoDeps.scala",
extraOptions,
"--offline",
"--cache",
cachePath.toString,
"-v",
"-v"
)
.call(cwd = root, mergeErrIntoOut = true)
expect(scalaAndJvmRes.exitCode == 0)
expect(scalaAndJvmRes.out.trim().contains(
Expand All @@ -1967,21 +1967,29 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
expect(scalaJvmCacheWalkSize == os.walk(cachePath).size)

// Missing dependencies
val missingDepsRes = os.proc(
for {
(cliOption, extraEnvMode) <- Seq(
"--offline" -> Map.empty[String, String],
"-Dcoursier.mode=offline" -> Map.empty[String, String],
"" -> Map("COURSIER_MODE" -> "offline")
)
} {
val missingDepsRes = os.proc(
TestUtil.cli,
"--power",
cliOption,
"WithDeps.scala",
extraOptions,
"--offline",
"--cache",
cachePath.toString
)
.call(cwd = root, check = false, mergeErrIntoOut = true)
expect(missingDepsRes.exitCode == 1)
expect(missingDepsRes.out.trim().contains("Error downloading com.lihaoyi:os-lib"))
.call(cwd = root, check = false, mergeErrIntoOut = true, env = extraEnvMode)
expect(missingDepsRes.exitCode == 1)
expect(missingDepsRes.out.trim().contains("Error downloading com.lihaoyi:os-lib"))

// Cache unchanged
expect(scalaJvmCacheWalkSize == os.walk(cachePath).size)
// Cache unchanged
expect(scalaJvmCacheWalkSize == os.walk(cachePath).size)
}

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

val depsRes = os.proc(
TestUtil.cli,
"--power",
"WithDeps.scala",
extraOptions,
"--offline",
"--cache",
cachePath.toString,
"-v",
"-v"
)
TestUtil.cli,
"--power",
"WithDeps.scala",
extraOptions,
"--offline",
"--cache",
cachePath.toString,
"-v",
"-v"
)
.call(cwd = root, mergeErrIntoOut = true)
expect(depsRes.exitCode == 0)
expect(
Expand Down

0 comments on commit 6ca1cfe

Please sign in to comment.