Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package scala.cli.integration
import java.util.concurrent.TimeUnit

import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.util.Properties

abstract class ScalaCliSuite extends munit.FunSuite {
implicit class BeforeEachOpts(munitContext: BeforeEach) {
Expand All @@ -28,6 +29,13 @@ abstract class ScalaCliSuite extends munit.FunSuite {
s"X==== ${Console.CYAN}Finishing '${context.test.name}' from $fileName${Console.RESET}"
)
}

override def afterAll(): Unit = {
super.afterAll()
// Clean up cached JDKs after all tests have run on Linux native CI runners
if isCI && Properties.isLinux then TestUtil.cleanCachedJdks()
else System.err.println("Skipping cached JDKs cleanup")
}
}

override def munitTimeout: Duration = new FiniteDuration(300, TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect
import coursier.paths.CoursierPaths

import java.io.File
import java.net.ServerSocket
Expand Down Expand Up @@ -443,4 +444,25 @@ object TestUtil {
args.map(a => if a.contains(" ") then "\"" + a.replace("\"", "\\\"") + "\"" else a)
else args
}

def cleanCoursierCache(pathToCleanContainsAnyKeyword: Seq[String] = Seq.empty): Unit = {
val csCache = os.Path(CoursierPaths.cacheDirectoryPath())
if pathToCleanContainsAnyKeyword.isEmpty && os.exists(csCache) && os.isDir(csCache) then
System.err.println(s"Cleaning Coursier cache at $csCache")
os.remove.all(csCache)
else if pathToCleanContainsAnyKeyword.nonEmpty then
os.walk(csCache)
.filter(d => !os.isDir(d)) // skip containing dirs
.filter(p => pathToCleanContainsAnyKeyword.exists(p.toString.contains))
.foreach { p =>
System.err.println(s"Cleaning from Coursier cache: $p")
os.remove(p)
}
else System.err.println("Nothing to clean")
}

def cleanCachedJdks(): Unit = {
System.err.println("Cleaning cached JDKs in Coursier cache…")
cleanCoursierCache(Seq("zulu", "temurin", "adoptium", "corretto", "liberica", "graalvm"))
}
}