-
Notifications
You must be signed in to change notification settings - Fork 446
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
Windows batch script improvements #1042
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1f52b2a
bat: refactor argument loop into functions
dwickern fa6b453
bat: remove unused goto labels
dwickern 9239c24
bat: refactor out config file parse function
dwickern 3e4ecc4
bat: use APP_HOME instead of dynamic environment variable
dwickern b05d1a5
bat: add application.ini support
dwickern b57fb6f
bat: escape arguments with special characters
dwickern 8988e78
bat: add test for javaOptions
dwickern 89c8783
bat: add test for extra jvm arg with APP_HOME expansion
dwickern f6d3953
bat: allow <APP_NAME>_HOME to be used in batScriptExtraDefines
dwickern 7dbdb59
bat: document add_java/add_app methods
dwickern 3eeed22
bat: remove note about <APP_NAME>_config.txt file
dwickern c1eba47
add javadoc comment to ApplicationIniGenerator
dwickern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/ApplicationIniGenerator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.typesafe.sbt.packager.archetypes.scripts | ||
|
||
import java.io.File | ||
|
||
import sbt._ | ||
|
||
trait ApplicationIniGenerator { | ||
def generateApplicationIni(universalMappings: Seq[(File, String)], | ||
javaOptions: Seq[String], | ||
bashScriptConfigLocation: Option[String], | ||
tmpDir: File, | ||
log: Logger): Seq[(File, String)] = | ||
bashScriptConfigLocation | ||
.collect { | ||
case location if javaOptions.nonEmpty => | ||
val configFile = tmpDir / "tmp" / "conf" / "application.ini" | ||
val pathMapping = cleanApplicationIniPath(location) | ||
//Do not use writeLines here because of issue #637 | ||
IO.write(configFile, ("# options from build" +: javaOptions).mkString("\n")) | ||
val hasConflict = universalMappings.exists { | ||
case (file, path) => file != configFile && path == pathMapping | ||
} | ||
// Warn the user if he tries to specify options | ||
if (hasConflict) { | ||
log.warn("--------!!! JVM Options are defined twice !!!-----------") | ||
log.warn( | ||
"application.ini is already present in output package. Will be overridden by 'javaOptions in Universal'" | ||
) | ||
} | ||
(configFile -> pathMapping) +: universalMappings | ||
|
||
} | ||
.getOrElse(universalMappings) | ||
|
||
/** | ||
* @param path that could be relative to app_home | ||
* @return path relative to app_home | ||
*/ | ||
protected def cleanApplicationIniPath(path: String): String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import com.typesafe.sbt.packager.Compat._ | ||
|
||
enablePlugins(JavaAppPackaging) | ||
|
||
name := "simple-app" | ||
|
||
version := "0.1.0" | ||
|
||
batScriptExtraDefines += """call :add_java "-Dconfig.file=%APP_HOME%\conf\production.conf"""" | ||
|
||
TaskKey[Unit]("runCheck") := { | ||
val cwd = (stagingDirectory in Universal).value | ||
val cmd = Seq((cwd / "bin" / s"${packageName.value}.bat").getAbsolutePath) | ||
val configFile = (sys.process.Process(cmd, cwd).!!).replaceAll("\r\n", "") | ||
assert(configFile.contains("""stage\bin\\\..\conf\production.conf"""), "Output didn't contain config file path: " + configFile) | ||
} |
1 change: 1 addition & 0 deletions
1
src/sbt-test/windows/app-home-var-expansion/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
4
src/sbt-test/windows/app-home-var-expansion/src/main/scala/MainApp.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
object MainApp extends App { | ||
val config = sys.props("config.file") ensuring (_ ne null, "didn't pick up -Dconfig.file argument") | ||
print(config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Run the staging and check the script. | ||
> stage | ||
> runCheck |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add some scaladoc here: