Skip to content

Commit

Permalink
Merge pull request #1270 from nigredo-tori/1266-jlink-large-classpath
Browse files Browse the repository at this point in the history
JlinkPlugin: add support for huge classpaths
  • Loading branch information
nigredo-tori authored Oct 25, 2019
2 parents a568bbe + 2b6a9bb commit 4b7d917
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ libraryDependencies ++= Seq(
"org.apache.commons" % "commons-compress" % "1.18",
// for jdkpackager
"org.apache.ant" % "ant" % "1.10.5",
// workaround for the command line size limit
"com.github.eldis" % "tool-launcher" % "0.2.1",
"org.scalatest" %% "scalatest" % "3.0.5" % Test
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object JlinkPlugin extends AutoPlugin {

// Jdeps has a few convenient options (like --print-module-deps), but those
// are not flexible enough - we need to parse the full output.
val jdepsOutput = runForOutput(run("jdeps", "--multi-release" +: javaVersion +: "-R" +: paths), log)
val jdepsOutput = run("jdeps", "--multi-release" +: javaVersion +: "-R" +: paths)

val deps = jdepsOutput.linesIterator
// There are headers in some of the lines - ignore those.
Expand Down Expand Up @@ -146,7 +146,7 @@ object JlinkPlugin extends AutoPlugin {

IO.delete(outDir)

runForOutput(run("jlink", jlinkOptions.value), log)
run("jlink", jlinkOptions.value)

outDir
},
Expand Down Expand Up @@ -176,12 +176,26 @@ object JlinkPlugin extends AutoPlugin {
private lazy val defaultJavaHome: File =
file(sys.props.getOrElse("java.home", sys.error("no java.home")))

private def runJavaTool(jvm: File, log: Logger)(exeName: String, args: Seq[String]): ProcessBuilder = {
val exe = (jvm / "bin" / exeName).getAbsolutePath
private def runJavaTool(jvm: File, log: Logger)(toolName: String, args: Seq[String]): String = {
log.info("Running: " + (toolName +: args).mkString(" "))

log.info("Running: " + (exe +: args).mkString(" "))
val toolLauncherClass = classOf[ru.eldis.toollauncher.ToolLauncher]
val toolLauncherJar = file(
// This assumes that the code source is a file or a directory (as opposed
// to a remote URL) - but that should hold.
toolLauncherClass.getProtectionDomain.getCodeSource.getLocation.getPath
).getAbsolutePath

Process(exe, args)
val javaExe = (jvm / "bin" / "java").getAbsolutePath

IO.withTemporaryFile(s"snp-$toolName-", "args") { argFile =>
IO.writeLines(argFile, args)

val argFileArg = "@" + argFile.getAbsolutePath
val builder = Process(Vector(javaExe, "-jar", toolLauncherJar, "-tool", toolName, argFileArg))

runForOutput(builder, log)
}
}

// Like `ProcessBuilder.!!`, but this logs the output in case of a non-zero
Expand Down
18 changes: 18 additions & 0 deletions src/sbt-test/jlink/test-jlink-misc/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,21 @@ val issue1247JakartaJavaModules = project
),
runChecks := jlinkBuildImage.value
)

// Should succeed for large classpaths.
val issue1266 = project
.enablePlugins(JlinkPlugin)
.settings(
// An arbitrary JAR with a non-platform module.
libraryDependencies += "com.sun.xml.fastinfoset" % "FastInfoset" % "1.2.16",
// A lot of "dummy" dependencies, so that the resulting classpath is over
// the command line limit (2MB on my machine)
unmanagedJars in Compile ++= {
def mkPath(ix: Int) = target.value / s"there-is-no-such-file-$ix.jar"

1.to(300000).map(mkPath)
},
logLevel in jlinkModules := Level.Error,

runChecks := jlinkBuildImage.value
)
3 changes: 2 additions & 1 deletion src/sbt-test/jlink/test-jlink-misc/test
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
> issue1243/runChecks
> issue1247BadAutoModuleName/runChecks
> issue1247ExternalModule/runChecks
> issue1247JakartaJavaModules/runChecks
> issue1247JakartaJavaModules/runChecks
> issue1266/runChecks

0 comments on commit 4b7d917

Please sign in to comment.