Allow default value for CONF_FOLDER to be set at build time

Closes gh-6549
This commit is contained in:
Andy Wilkinson 2016-08-11 20:25:59 +01:00
parent 1d58247ecc
commit 8c106af384
4 changed files with 11 additions and 3 deletions

View File

@ -608,6 +608,9 @@ for Gradle and to `${project.name}` for Maven.
|`initInfoChkconfig`
|The `chkconfig` section of "`INIT INFO`". Defaults to `2345 99 01`.
|`confFolder`
|The default value for `CONF_FOLDER`. Defaults to the folder containing the jar.
|`logFolder`
|The default value for `LOG_FOLDER`. Only valid for an `init.d` service.

View File

@ -42,7 +42,7 @@ public class DefaultLaunchScript implements LaunchScript {
private static final int BUFFER_SIZE = 4096;
private static final Pattern PLACEHOLDER_PATTERN = Pattern
.compile("\\{\\{(\\w+)(:.*?)?\\}\\}");
.compile("\\{\\{(\\w+)(:.*?)?\\}\\}(?!\\})");
private final String content;
@ -97,7 +97,7 @@ public class DefaultLaunchScript implements LaunchScript {
else {
value = (value == null ? matcher.group(0) : value.substring(1));
}
matcher.appendReplacement(expanded, value);
matcher.appendReplacement(expanded, value.replace("$", "\\$"));
}
matcher.appendTail(expanded);
return expanded.toString();

View File

@ -44,7 +44,7 @@ cd "$WORKING_DIR" || exit 1
configfile="$(basename "${jarfile%.*}.conf")"
# Initialize CONF_FOLDER location defaulting to jarfolder
[[ -z "$CONF_FOLDER" ]] && CONF_FOLDER="${jarfolder}"
[[ -z "$CONF_FOLDER" ]] && CONF_FOLDER="{{confFolder:${jarfolder}}}"
# shellcheck source=/dev/null
[[ -r "${CONF_FOLDER}/${configfile}" ]] && source "${CONF_FOLDER}/${configfile}"

View File

@ -86,6 +86,11 @@ public class DefaultLaunchScriptTests {
assertThatPlaceholderCanBeReplaced("pidFolder");
}
@Test
public void confFolderCanBeReplaced() throws Exception {
assertThatPlaceholderCanBeReplaced("confFolder");
}
@Test
public void defaultForUseStartStopDaemonIsTrue() throws Exception {
DefaultLaunchScript script = new DefaultLaunchScript(null, null);