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

Fix launcher jar paths not being quoted on Windows #1040

Merged
merged 1 commit into from
Oct 21, 2017
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 @@ -196,7 +196,7 @@ object BashStartScriptPlugin extends AutoPlugin {
def apply(mainClass: String, config: BashScriptConfig, targetDir: File, mainClasses: Seq[String]): File = {
val template = resolveTemplate(config.bashScriptTemplateLocation)
val replacements = Seq(
"app_mainclass" -> mainClassReplacement(mainClass),
"app_mainclass" -> mainClass,
"available_main_classes" -> usageMainClassReplacement(mainClasses)
) ++ config.bashScriptReplacements

Expand All @@ -208,15 +208,6 @@ object BashStartScriptPlugin extends AutoPlugin {
script
}

private[this] def mainClassReplacement(mainClass: String): String = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning this up. The quoting is now done at a much better place :)

val jarPrefixed = """^\-jar (.*)""".r
val args = mainClass match {
case jarPrefixed(jarName) => Seq("-jar", jarName)
case className => Seq(className)
}
args.map(s => "\"" + s + "\"").mkString(" ")
}

private[this] def usageMainClassReplacement(mainClasses: Seq[String]): String =
if (mainClasses.nonEmpty)
mainClasses.mkString("Available main classes:\n\t", "\n\t", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ object LauncherJarPlugin extends AutoPlugin {
artifact.classifier.fold("")("-" + _) + "." + artifact.extension
},
mainClass in (Compile, bashScriptDefines) := {
Some("-jar $lib_dir/" + (artifactPath in packageJavaLauncherJar).value.getName)
Some(s"""-jar "$$lib_dir/${(artifactPath in packageJavaLauncherJar).value.getName}"""")
},
scriptClasspath in bashScriptDefines := Nil,
mainClass in (Compile, batScriptReplacements) := {
Some("-jar %APP_LIB_DIR%\\" + (artifactPath in packageJavaLauncherJar).value.getName)
Some(s"""-jar "%APP_LIB_DIR%\\${(artifactPath in packageJavaLauncherJar).value.getName}"""")
},
scriptClasspath in batScriptReplacements := Nil,
mappings in Universal += {
Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/jar/launcher-jar with spaces/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ TaskKey[Unit]("checkClasspath") := {
val bat = IO.read(dir / "bin" / "launcher-jar-test.bat")
assert(bat contains "set \"APP_CLASSPATH=\"", "bat should set APP_CLASSPATH:\n" + bat)
assert(
bat contains "set \"APP_MAIN_CLASS=-jar %APP_LIB_DIR%\\launcher-jar-test.launcher-jar-test-0.1.0-launcher.jar\"",
bat contains "set \"APP_MAIN_CLASS=-jar \"%APP_LIB_DIR%\\launcher-jar-test.launcher-jar-test-0.1.0-launcher.jar\"\"",
"bat should set APP_MAIN_CLASS:\n" + bat
)
val bash = IO.read(dir / "bin" / "launcher-jar-test")
assert(bash contains "declare -r app_classpath=\"\"", "bash should declare app_classpath:\n" + bash)
assert(
bash contains "declare -a app_mainclass=(\"-jar\" \"$lib_dir/launcher-jar-test.launcher-jar-test-0.1.0-launcher.jar\")",
bash contains "declare -a app_mainclass=(-jar \"$lib_dir/launcher-jar-test.launcher-jar-test-0.1.0-launcher.jar\")",
"bash should declare app_mainclass:\n" + bash
)
val jar = new java.util.jar.JarFile(dir / "lib" / "launcher-jar-test.launcher-jar-test-0.1.0-launcher.jar")
Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/jar/launcher-jar/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ TaskKey[Unit]("checkClasspath") := {
val bat = IO.read(dir / "bin" / "launcher-jar-test.bat")
assert(bat contains "set \"APP_CLASSPATH=\"", "bat should set APP_CLASSPATH:\n" + bat)
assert(
bat contains "set \"APP_MAIN_CLASS=-jar %APP_LIB_DIR%\\launcher-jar-test.launcher-jar-test-0.1.0-launcher.jar\"",
bat contains "set \"APP_MAIN_CLASS=-jar \"%APP_LIB_DIR%\\launcher-jar-test.launcher-jar-test-0.1.0-launcher.jar\"\"",
"bat should set APP_MAIN_CLASS:\n" + bat
)
val bash = IO.read(dir / "bin" / "launcher-jar-test")
assert(bash contains "declare -r app_classpath=\"\"", "bash should declare app_classpath:\n" + bash)
assert(
bash contains "declare -a app_mainclass=(\"-jar\" \"$lib_dir/launcher-jar-test.launcher-jar-test-0.1.0-launcher.jar\")",
bash contains "declare -a app_mainclass=(-jar \"$lib_dir/launcher-jar-test.launcher-jar-test-0.1.0-launcher.jar\")",
"bash should declare app_mainclass:\n" + bash
)
val jar = new java.util.jar.JarFile(dir / "lib" / "launcher-jar-test.launcher-jar-test-0.1.0-launcher.jar")
Expand Down