Skip to content

Commit

Permalink
Add addApp function to align with bash version (#1339)
Browse files Browse the repository at this point in the history
Co-authored-by: Nepomuk Seiler <muuki88@users.noreply.github.com>
  • Loading branch information
olsio and muuki88 authored May 11, 2020
1 parent 0c076d2 commit 0c62462
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ addJava () {
java_opts="$java_opts $1"
}

addApp () {
app_commands="$app_commands $1"
}

addResidual () {
residual_args="$residual_args \"$1\""
}
Expand Down Expand Up @@ -91,6 +95,7 @@ process_args () {
fi
}

app_commands=""
residual_args=""
real_script_path="$(realpath "$0")"
app_home="$(realpath "$(dirname "$real_script_path")")"
Expand All @@ -107,4 +112,4 @@ java_cmd="$(get_java_cmd)"
# If a configuration file exist, read the contents to $opts
[ -f "$script_conf_file" ] && opts=$(loadConfigFile "$script_conf_file")

eval "exec $java_cmd $java_opts -classpath $app_classpath $opts $app_mainclass $residual_args"
eval "exec $java_cmd $java_opts -classpath $app_classpath $opts $app_mainclass $app_commands $residual_args"
23 changes: 23 additions & 0 deletions src/sbt-test/ash/add-app-settings/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
enablePlugins(JavaAppPackaging, AshScriptPlugin)

name := "simple-app"

version := "0.1.0"

bashScriptExtraDefines ++= Seq("""addApp "info"""", """addApp "help"""")

TaskKey[Unit]("scriptCheck") := {
val startScript = (stagingDirectory in Universal).value / "bin" / executableScriptName.value
val options = IO.read(startScript)
assert(options contains """addApp "info"""", "Script doesn't contain app setting:\n" + options)
assert(options contains """addApp "help"""", "Script doesn't contain app setting:\n" + options)
}

TaskKey[Unit]("runCheck") := {
val cwd = (stagingDirectory in Universal).value
val cmd = Seq((cwd / "bin" / packageName.value).getAbsolutePath)
val output = (sys.process.Process(cmd, cwd).!!).replaceAll("\n", "")

assert(output.contains("info"), s"Application did not receive residual arg 'info'")
assert(output.contains("help"), s"Application did not receive residual arg 'help'")
}
1 change: 1 addition & 0 deletions src/sbt-test/ash/add-app-settings/project/plugins.sbt
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,3 @@
object MainApp extends App {
println(args.mkString("|"))
}
5 changes: 5 additions & 0 deletions src/sbt-test/ash/add-app-settings/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/bin/simple-app
> scriptCheck
> runCheck

0 comments on commit 0c62462

Please sign in to comment.