Skip to content

Commit

Permalink
gradle: Escape path to original bndrun file
Browse files Browse the repository at this point in the history
In the off chance the bndrun file has a double quote in the name.

We also use `~` to allow the output bndrun file's -runbundles to not be
overwritten by the original bndrun file's -runbundles, if any.

Signed-off-by: BJ Hargrave <bj@hargrave.dev>
  • Loading branch information
bjhargrave committed Nov 16, 2022
1 parent 1a62b9f commit 1da40ee
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,27 @@ protected biz.aQute.resolve.Bndrun createBndrun(Workspace workspace, File bndrun
if (!Objects.equals(outputBndrunFile, bndrunFile)) {
try (Writer writer = IO.writer(outputBndrunFile)) {
UTF8Properties props = new UTF8Properties();
props.setProperty(Constants.INCLUDE, String.format("\"%s\"", IO.absolutePath(bndrunFile)));
props.setProperty(Constants.INCLUDE, String.format("\"~%s\"", escape(IO.absolutePath(bndrunFile))));
props.store(writer, null);
}
bndrunFile = outputBndrunFile;
}
return super.createBndrun(workspace, bndrunFile);
}

private String escape(String input) {
final int length = input.length();
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length;i++) {
char c = input.charAt(i);
if (c == '"') {
sb.append('\\');
}
sb.append(c);
}
return sb.length() == length ? input : sb.toString();
}

/**
* Resolve the Bndrun object.
*
Expand Down

0 comments on commit 1da40ee

Please sign in to comment.