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

Added command line JAVA_OPTS support for AshScriptPlugin #1255

Merged
merged 1 commit into from
Aug 29, 2019
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
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ addCommandAlias("validate", "; clean ; update ; validateFormatting ; test ; mima
// List all scripted test separately to schedule them in different travis-ci jobs.
// Travis-CI has hard timeouts for jobs, so we run them in smaller jobs as the scripted
// tests take quite some time to run.
// Ultimatley we should run only those tests that are necessary for a change
// Ultimately we should run only those tests that are necessary for a change
addCommandAlias("validateUniversal", "scripted universal/*")
addCommandAlias("validateJar", "scripted jar/*")
addCommandAlias("validateBash", "scripted bash/*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,38 @@ get_java_cmd() {
fi
}

# 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
case "$1" in
--) shift && no_more_snp_opts=1 && break ;;
-h|-help) usage; exit 1 ;;
-v|-verbose) verbose=1 && shift ;;
-d|-debug) debug=1 && shift ;;

-no-version-check) no_version_check=1 && shift ;;

-mem) echo "!! WARNING !! -mem option is ignored. Please use -J-Xmx and -J-Xms" && shift 2 ;;
-jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;;

-main) custom_mainclass="$2" && shift 2 ;;

-java-home) require_arg path "$1" "$2" && jre=`eval echo $2` && java_cmd="$jre/bin/java" && shift 2 ;;

-D*|-agentlib*|-XX*) addJava "$1" && shift ;;
-J*) addJava "${1:2}" && shift ;;
*) addResidual "$1" && shift ;;
esac
done

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

real_script_path="$(realpath "$0")"
app_home="$(realpath "$(dirname "$real_script_path")")"
lib_dir="$(realpath "${app_home}/../lib")"
Expand All @@ -63,6 +95,8 @@ app_mainclass=${{app_mainclass}}

${{template_declares}}

process_args "$@"

java_cmd="$(get_java_cmd)"

# If a configuration file exist, read the contents to $opts
Expand Down
14 changes: 14 additions & 0 deletions src/sbt-test/ash/command-line-settings/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
enablePlugins(JavaAppPackaging, AshScriptPlugin)

name := "command-line-app"

version := "0.1.0-SNAPSHOT"

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

val output = (sys.process.Process(cmd, cwd).!!).replaceAll("\n", "")
assert(output.contains(configArg), s"Application did not receive command line configuration resource $configArg")
}
1 change: 1 addition & 0 deletions src/sbt-test/ash/command-line-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("|"))
}
4 changes: 4 additions & 0 deletions src/sbt-test/ash/command-line-settings/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Run the staging and check the script.
> stage
$ exists target/universal/stage/bin/command-line-app
> runCheck