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

re #577 fix for running the bash file in a path with spaces #581

Merged
merged 1 commit into from
May 27, 2015
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 @@ -235,9 +235,9 @@ run() {
fi

if [ -n "$custom_mainclass" ]; then
mainclass="$custom_mainclass"
mainclass=("$custom_mainclass")
Copy link
Contributor

Choose a reason for hiding this comment

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

what do the round brackets achieve here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needs to be an array (see also declare -a and [@] stuff)

else
mainclass="$app_mainclass"
mainclass=("${app_mainclass[@]}")
fi

# Now we check to see if there are any java opts on the environment. These get listed first, with the script able to override them.
Expand All @@ -250,7 +250,7 @@ run() {
${java_opts[@]} \
"${java_args[@]}" \
-cp "$(fix_classpath "$app_classpath")" \
$mainclass \
"${mainclass[@]}" \
"${app_commands[@]}" \
"${residual_args[@]}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ object JavaAppBashScript {
def configFileDefine(configFile: String) =
"declare -r script_conf_file=\"%s\"" format (configFile)

def mainClassDefine(mainClass: String) =
"declare -r app_mainclass=\"%s\"\n" format (mainClass)
def mainClassDefine(mainClass: String) = {
val jarPrefixed = """^\-jar (.*)""".r
val args = mainClass match {
case jarPrefixed(jarName) => Seq("-jar", jarName)
case className => Seq(className)
}
val quotedArgsSpaceSeparated = args.map(s => "\"" + s + "\"").mkString(" ")
"declare -a app_mainclass=(%s)\n" format (quotedArgsSpaceSeparated)
}

}
39 changes: 39 additions & 0 deletions src/sbt-test/jar/launcher-jar with spaces/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
enablePlugins(LauncherJarPlugin)

name := "launcher-jar-test"

version := "0.1.0"

// test dependencies sample
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-kernel" % "2.3.4"
)

TaskKey[Unit]("check-classpath") := {
val dir = (stagingDirectory in Universal).value
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 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 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")
val attributes = jar.getManifest().getMainAttributes()
assert(attributes.getValue("Class-Path").toString() contains "com.typesafe.akka.akka-actor",
"MANIFEST Class-Path should contain akka-actor:\n" + attributes.getValue("Class-Path").toString())
assert(attributes.getValue("Main-Class").toString() contains "test.Test",
"MANIFEST Main-Class should contain test.Test:\n" + attributes.getValue("Main-Class").toString())
jar close
}

TaskKey[Unit]("run-check") := {
val dir = (stagingDirectory in Universal).value
val cmd = if(System.getProperty("os.name").contains("Windows")){
Seq("cmd", "/c", (dir / "bin" / "launcher-jar-test.bat").getAbsolutePath)
}else{
Seq((dir / "bin" / "launcher-jar-test").getAbsolutePath)
}
assert(Process(cmd).!! contains "SUCCESS!")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package test

// use dependency library

import akka.actor._
import akka.routing.RoundRobinRouter

class PrintActor extends Actor{
def receive = {
case msg => println(msg)
}
}

object Test extends App {
val system = ActorSystem("testSystem")
val router = system.actorOf(Props[PrintActor])
router ! "SUCCESS!!"
system.shutdown
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@echo off
rem this template is minimal for test independent

@setlocal enabledelayedexpansion
@echo off

set "@@APP_ENV_NAME@@_HOME=%~dp0\\.."

set "APP_LIB_DIR=%@@APP_ENV_NAME@@_HOME%\lib\"

set _JAVACMD=%JAVACMD%

if "%_JAVACMD%"=="" (
if not "%JAVA_HOME%"=="" (
if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe"
)
)

@@APP_DEFINES@@

"%_JAVACMD%" -cp "%APP_CLASSPATH%" %APP_MAIN_CLASS% %*
5 changes: 5 additions & 0 deletions src/sbt-test/jar/launcher-jar with spaces/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Run the staging and check the script.
> stage
$ exists target/universal/stage/lib/launcher-jar-test.launcher-jar-test-0.1.0-launcher.jar
> check-classpath
> run-check
2 changes: 1 addition & 1 deletion src/sbt-test/jar/launcher-jar/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TaskKey[Unit]("check-classpath") := {
"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 -r app_mainclass=\"-jar $lib_dir/launcher-jar-test.launcher-jar-test-0.1.0-launcher.jar\"",
assert(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")
val attributes = jar.getManifest().getMainAttributes()
Expand Down