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

Define addJava in ash-template #944

Merged
merged 2 commits into from
Mar 16, 2017
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 @@ -27,6 +27,17 @@ realpath () {
)
}

# Allow user and template_declares (see below) to add java options.
addJava () {
java_opts="$java_opts $1"
}

# Allow user to specify java options. These get listed first per bash-template.
if [ -n "$JAVA_OPTS" ]
then
addJava "$JAVA_OPTS"
fi

# Loads a configuration file full of default command line options for this script.
loadConfigFile() {
cat "$1" | sed '/^\#/d' | sed 's/^-J-X/-X/' | tr '\r\n' ' '
Expand All @@ -44,4 +55,4 @@ ${{template_declares}}
# If a configuration file exist, read the contents to $opts
[ -f "$script_conf_file" ] && opts=$(loadConfigFile "$script_conf_file")

exec java -classpath $app_classpath $opts $app_mainclass $@
exec java $java_opts -classpath $app_classpath $opts $app_mainclass $@
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ object AshScriptPlugin extends AutoPlugin {

override def projectSettings = Seq(
bashScriptTemplateLocation := (sourceDirectory.value / "templates" / ashTemplate),
bashScriptDefines := Defines((scriptClasspath in bashScriptDefines).value, bashScriptConfigLocation.value)
bashScriptDefines := Defines((scriptClasspath in bashScriptDefines).value, bashScriptConfigLocation.value),
bashScriptDefines ++= bashScriptExtraDefines.value
)

/**
Expand Down
24 changes: 24 additions & 0 deletions src/sbt-test/ash/memory-settings/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
enablePlugins(JavaAppPackaging, AshScriptPlugin)

name := "simple-app"

version := "0.1.0"

bashScriptExtraDefines ++= Seq(
"""addJava "-Xms64m"""",
"""addJava "-Xmx64m""""
)

TaskKey[Unit]("script-check") := {
val startScript = (stagingDirectory in Universal).value / "bin" / executableScriptName.value
val options = IO.read(startScript)
assert(options contains """addJava "-Xms64m"""", "Script doesn't contain xmx setting:\n" + options)
assert(options contains """addJava "-Xmx64m"""", "Script doesn't contain xms setting:\n" + options)
}

TaskKey[Unit]("run-check") := {
val cwd = (stagingDirectory in Universal).value
val cmd = Seq((cwd / "bin" / packageName.value).getAbsolutePath)
val memory = (Process(cmd, cwd).!!).replaceAll("\n", "")
assert(memory.toLong <= 64, "Runtime memory is bigger then 64m < " + memory + "m")
}
1 change: 1 addition & 0 deletions src/sbt-test/ash/memory-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"))
4 changes: 4 additions & 0 deletions src/sbt-test/ash/memory-settings/src/main/scala/MainApp.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object MainApp extends App {
val memory = Runtime.getRuntime.maxMemory() / (1024L * 1024L)
print(memory)
}
5 changes: 5 additions & 0 deletions src/sbt-test/ash/memory-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
> script-check
> run-check