diff --git a/core/src/main/java/hudson/tools/JDKInstaller.java b/core/src/main/java/hudson/tools/JDKInstaller.java index ac5e311dbbbfb44418e04a59b354f3f8d6163f07..66a4f10fd69e5a9cd9adc8ee642e857deae58dd9 100644 --- a/core/src/main/java/hudson/tools/JDKInstaller.java +++ b/core/src/main/java/hudson/tools/JDKInstaller.java @@ -224,16 +224,33 @@ public class JDKInstaller extends ToolInstaller { */ String logFile = jdkBundle+".install.log"; + expectedLocation = expectedLocation.trim(); + if (expectedLocation.endsWith("\\")) { + // Prevent a trailing slash from escaping quotes + expectedLocation = expectedLocation.substring(0, expectedLocation.length() - 1); + } ArgumentListBuilder args = new ArgumentListBuilder(); - args.add(jdkBundle); + assert (new File(expectedLocation).exists()) : expectedLocation + + " must exist, otherwise /L will cause the installer to fail with error 1622"; if (isJava15() || isJava14()) { - args.add("/s","/v/qn REBOOT=ReallySuppress INSTALLDIR=\""+ expectedLocation +"\" /L \""+logFile+"\""); + // Installer uses InstallShield. + args.add("CMD.EXE", "/C"); + + // CMD.EXE /C must be followed by a single parameter (do not split it!) + args.add(jdkBundle + " /s /v\"/qn REBOOT=ReallySuppress INSTALLDIR=\\\"" + + expectedLocation + "\\\" /L \\\"" + expectedLocation + + "\\jdk.exe.install.log\\\"\""); } else { - // modern version supports arguments in more sane format. - args.add("/s","/v","/qn","/L","\""+logFile+"\"","REBOOT=ReallySuppress","INSTALLDIR=\""+ expectedLocation+"\""); + // Installed uses Windows Installer (MSI) + args.add(jdkBundle, "/s"); + + // Create a private JRE by omitting "PublicjreFeature" + // @see http://docs.oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html#jdk-silent-installation + args.add("ADDLOCAL=\"ToolsFeature\""); + + args.add("REBOOT=ReallySuppress", "INSTALLDIR=" + expectedLocation, + "/L \\\"" + expectedLocation + "\\jdk.exe.install.log\\\""); } - // according to http://community.acresso.com/showthread.php?t=83301, \" is the trick to quote values with whitespaces. - // Oh Windows, oh windows, why do you have to be so difficult? int r = launcher.launch().cmds(args).stdout(out) .pwd(new FilePath(launcher.getChannel(), expectedLocation)).join(); if (r != 0) {