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 ash template #1303

Merged
merged 3 commits into from
Feb 20, 2020
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 @@ -32,6 +32,10 @@ addJava () {
java_opts="$java_opts $1"
}

addResidual () {
residual_args="$residual_args $1"
}

# Allow user to specify java options. These get listed first per bash-template.
if [ -n "$JAVA_OPTS" ]
then
Expand All @@ -58,7 +62,7 @@ get_java_cmd() {
# Processes incoming arguments and places them in appropriate global variables. called by the run method.
process_args () {
local no_more_snp_opts=0
while [[ $# -gt 0 ]]; do
while [ $# -gt 0 ]; do
case "$1" in
--) shift && no_more_snp_opts=1 && break ;;
-h|-help) usage; exit 1 ;;
Expand All @@ -80,13 +84,14 @@ process_args () {
esac
done

if [[ no_more_snp_opts ]]; then
while [[ $# -gt 0 ]]; do
if [ $no_more_snp_opts ]; then
while [ $# -gt 0 ]; do
addResidual "$1" && shift
done
fi
}

residual_args=""
real_script_path="$(realpath "$0")"
app_home="$(realpath "$(dirname "$real_script_path")")"
lib_dir="$(realpath "${app_home}/../lib")"
Expand All @@ -102,4 +107,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")

exec "$java_cmd" $java_opts -classpath $app_classpath $opts $app_mainclass "$@"
exec "$java_cmd" $java_opts -classpath $app_classpath $opts $app_mainclass "$residual_args"
17 changes: 13 additions & 4 deletions src/sbt-test/ash/command-line-settings/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ name := "command-line-app"

version := "0.1.0-SNAPSHOT"

TaskKey[Unit]("runCheck") := {
val configArg = "-Dconfig.resource=/config.conf"
TaskKey[Unit]("checkSystemProperty") := {
val configArg = "config.resource=/config.conf"
val cwd = (stagingDirectory in Universal).value
val cmd = Seq((cwd / "bin" / packageName.value).getAbsolutePath, configArg)
val cmd = Seq((cwd / "bin" / packageName.value).getAbsolutePath, s"-D$configArg")

val output = (sys.process.Process(cmd, cwd).!!).replaceAll("\n", "")
assert(output.contains(configArg), s"Application did not receive command line configuration resource $configArg")
assert(output.contains(configArg), s"Application did not receive system property arg '$configArg'")
}

TaskKey[Unit]("checkResidual") := {
val arg = "residualArg"
val cwd = (stagingDirectory in Universal).value
val cmd = Seq((cwd / "bin" / packageName.value).getAbsolutePath, arg)

val output = (sys.process.Process(cmd, cwd).!!).replaceAll("\n", "")
assert(output.contains(arg), s"Application did not receive residual arg '$arg'")
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
object MainApp extends App {
object MainApp extends App {
println(sys.props.collect { case (k, v) => s"$k=$v" } mkString "\n")
println(args.mkString("|"))
}
3 changes: 2 additions & 1 deletion src/sbt-test/ash/command-line-settings/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Run the staging and check the script.
> stage
$ exists target/universal/stage/bin/command-line-app
> runCheck
> checkSystemProperty
> checkResidual