Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if rt.jar is still necessary #4206

Merged
merged 4 commits into from
Dec 30, 2024
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
37 changes: 1 addition & 36 deletions main/api/src/mill/api/ClassLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ package mill.api

import java.net.{URL, URLClassLoader}

import java.nio.file.{FileAlreadyExistsException, FileSystemException}

import mill.java9rtexport.Export
import scala.util.Properties

/**
* Utilities for creating classloaders for running compiled Java/Scala code in
* isolated classpaths.
Expand All @@ -22,10 +17,7 @@ object ClassLoader {
sharedPrefixes: Seq[String] = Seq(),
logger: Option[mill.api.Logger] = None
)(implicit ctx: Ctx.Home): URLClassLoader = {
new URLClassLoader(
makeUrls(urls).toArray,
refinePlatformParent(parent)
) {
new URLClassLoader(urls.toArray, refinePlatformParent(parent)) {
override def findClass(name: String): Class[?] = {
if (sharedPrefixes.exists(name.startsWith)) {
logger.foreach(
Expand Down Expand Up @@ -73,31 +65,4 @@ object ClassLoader {
appClassLoader.getParent()
}
}

private def makeUrls(urls: Seq[URL])(implicit ctx: Ctx.Home): Seq[URL] = {
if (java9OrAbove) {
val java90rtJar = ctx.home / Export.rtJarName
if (!os.exists(java90rtJar)) {
// Time between retries should go from 100 ms to around 10s, which should
// leave plenty of time for another process to write fully this 50+ MB file
val retry = Retry(
count = 7,
backoffMillis = 100,
filter = {
case (_, _: FileSystemException) if Properties.isWin => true
case _ => false
}
)
retry {
try os.copy(os.Path(Export.rt()), java90rtJar, createFolders = true)
catch {
case e: FileAlreadyExistsException => /* someone else already did this */
}
}
}
urls :+ java90rtJar.toIO.toURI().toURL()
} else {
urls
}
}
}
11 changes: 0 additions & 11 deletions runner/src/mill/runner/MillMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import java.nio.file.StandardOpenOption
import java.util.Locale
import scala.jdk.CollectionConverters.*
import scala.util.Properties
import mill.java9rtexport.Export
import mill.api.{MillException, SystemStreams, WorkspaceRoot, internal}
import mill.bsp.{BspContext, BspServerResult}
import mill.main.BuildInfo
Expand Down Expand Up @@ -195,16 +194,6 @@ object MillMain {

val threadCount = Some(maybeThreadCount.toOption.get)

if (mill.main.client.Util.isJava9OrAbove) {
val rt = config.home / Export.rtJarName
if (!os.exists(rt)) {
streams.err.println(
s"Preparing Java ${System.getProperty("java.version")} runtime; this may take a minute or two ..."
)
Export.rtTo(rt.toIO, false)
}
}

val bspContext =
if (bspMode) Some(new BspContext(streams, bspLog, config.home)) else None

Expand Down
Loading