Skip to content

Commit 905d425

Browse files
faricomuuki88
authored andcommitted
Added command line JAVA_OPTS support for AshScriptPlugin (#1255)
1 parent ed96325 commit 905d425

6 files changed

Lines changed: 57 additions & 1 deletion

File tree

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ addCommandAlias("validate", "; clean ; update ; validateFormatting ; test ; mima
115115
// List all scripted test separately to schedule them in different travis-ci jobs.
116116
// Travis-CI has hard timeouts for jobs, so we run them in smaller jobs as the scripted
117117
// tests take quite some time to run.
118-
// Ultimatley we should run only those tests that are necessary for a change
118+
// Ultimately we should run only those tests that are necessary for a change
119119
addCommandAlias("validateUniversal", "scripted universal/*")
120120
addCommandAlias("validateJar", "scripted jar/*")
121121
addCommandAlias("validateBash", "scripted bash/*")

src/main/resources/com/typesafe/sbt/packager/archetypes/scripts/ash-template

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,38 @@ get_java_cmd() {
5555
fi
5656
}
5757

58+
# Processes incoming arguments and places them in appropriate global variables. called by the run method.
59+
process_args () {
60+
local no_more_snp_opts=0
61+
while [[ $# -gt 0 ]]; do
62+
case "$1" in
63+
--) shift && no_more_snp_opts=1 && break ;;
64+
-h|-help) usage; exit 1 ;;
65+
-v|-verbose) verbose=1 && shift ;;
66+
-d|-debug) debug=1 && shift ;;
67+
68+
-no-version-check) no_version_check=1 && shift ;;
69+
70+
-mem) echo "!! WARNING !! -mem option is ignored. Please use -J-Xmx and -J-Xms" && shift 2 ;;
71+
-jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;;
72+
73+
-main) custom_mainclass="$2" && shift 2 ;;
74+
75+
-java-home) require_arg path "$1" "$2" && jre=`eval echo $2` && java_cmd="$jre/bin/java" && shift 2 ;;
76+
77+
-D*|-agentlib*|-XX*) addJava "$1" && shift ;;
78+
-J*) addJava "${1:2}" && shift ;;
79+
*) addResidual "$1" && shift ;;
80+
esac
81+
done
82+
83+
if [[ no_more_snp_opts ]]; then
84+
while [[ $# -gt 0 ]]; do
85+
addResidual "$1" && shift
86+
done
87+
fi
88+
}
89+
5890
real_script_path="$(realpath "$0")"
5991
app_home="$(realpath "$(dirname "$real_script_path")")"
6092
lib_dir="$(realpath "${app_home}/../lib")"
@@ -63,6 +95,8 @@ app_mainclass=${{app_mainclass}}
6395

6496
${{template_declares}}
6597

98+
process_args "$@"
99+
66100
java_cmd="$(get_java_cmd)"
67101

68102
# If a configuration file exist, read the contents to $opts
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
enablePlugins(JavaAppPackaging, AshScriptPlugin)
2+
3+
name := "command-line-app"
4+
5+
version := "0.1.0-SNAPSHOT"
6+
7+
TaskKey[Unit]("runCheck") := {
8+
val configArg = "-Dconfig.resource=/config.conf"
9+
val cwd = (stagingDirectory in Universal).value
10+
val cmd = Seq((cwd / "bin" / packageName.value).getAbsolutePath, configArg)
11+
12+
val output = (sys.process.Process(cmd, cwd).!!).replaceAll("\n", "")
13+
assert(output.contains(configArg), s"Application did not receive command line configuration resource $configArg")
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object MainApp extends App {
2+
println(args.mkString("|"))
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Run the staging and check the script.
2+
> stage
3+
$ exists target/universal/stage/bin/command-line-app
4+
> runCheck

0 commit comments

Comments
 (0)