Take into account --property options in bootstrap

This commit is contained in:
Alexandre Archambault 2018-04-30 00:02:02 +02:00
parent d0e9e41ca9
commit 962debc050
2 changed files with 29 additions and 6 deletions

View File

@ -76,9 +76,10 @@ object Bootstrap extends CaseApp[BootstrapOptions] {
}
val properties0 = validProperties.map { s =>
val idx = s.indexOf('=')
assert(idx >= 0)
(s.take(idx), s.drop(idx + 1))
s.split("=", 2) match {
case Array(k, v) => k -> v
case _ => sys.error("Cannot possibly happen")
}
}
val bootstrapJar =
@ -197,10 +198,27 @@ object Bootstrap extends CaseApp[BootstrapOptions] {
outputZip.close()
// escaping of javaOpt possibly a bit loose :-|
val javaCmd = Seq("java") ++
options
.options
.javaOpt
// escaping possibly a bit loose :-|
.map(s => "'" + s.replace("'", "\\'") + "'") ++
properties0
.map {
case (k, v) =>
// escaping possibly a bit loose :-|
s"'-D$k=${v.replace("'", "\\'")}'"
} ++
Seq(
"-jar",
"\"$0\"",
"\"$@\""
)
val shellPreamble = Seq(
"#!/usr/bin/env sh",
"exec java " + options.options.javaOpt.map(s => "'" + s.replace("'", "\\'") + "'").mkString(" ") + " -jar \"$0\" \"$@\""
"exec " + javaCmd.mkString(" ")
).mkString("", "\n", "\n")
try Files.write(output0.toPath, shellPreamble.getBytes(UTF_8) ++ buffer.toByteArray)

View File

@ -138,12 +138,17 @@ testBootstrap() {
# run via the launcher rather than via the sbt-pack scripts, because the latter interprets -Dfoo=baz itself
# rather than passing it to coursier since https://github.com/xerial/sbt-pack/pull/118
./coursier-test bootstrap -o cs-props -J -Dfoo=baz io.get-coursier:props:1.0.2
./coursier-test bootstrap -o cs-props -D other=thing -J -Dfoo=baz io.get-coursier:props:1.0.2
local OUT="$(./cs-props foo)"
if [ "$OUT" != baz ]; then
echo -e "Error: unexpected output from bootstrapped props command.\n$OUT" 1>&2
exit 1
fi
local OUT="$(./cs-props other)"
if [ "$OUT" != thing ]; then
echo -e "Error: unexpected output from bootstrapped props command.\n$OUT" 1>&2
exit 1
fi
fi
}