8278311: Debian packaging doesn't work
Reviewed-by: almatvee
This commit is contained in:
parent
352435581e
commit
8ef1a232b1
src/jdk.jpackage/share/classes/jdk/jpackage/internal
test/jdk/tools/jpackage/junit/jdk/jpackage/internal
@ -36,6 +36,8 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -279,11 +281,35 @@ final class OverridableResource {
|
||||
|
||||
private static Stream<String> substitute(Stream<String> lines,
|
||||
Map<String, String> substitutionData) {
|
||||
// Order substitution data by the length of keys.
|
||||
// Longer keys go first.
|
||||
// This is needed to properly handle cases when one key is
|
||||
// a subtring of another and try the later first.
|
||||
var orderedEntries = substitutionData.entrySet().stream()
|
||||
.sorted(Map.Entry.<String, String>comparingByKey(
|
||||
Comparator.comparingInt(String::length)).reversed())
|
||||
.toList();
|
||||
return lines.map(line -> {
|
||||
String result = line;
|
||||
for (var entry : substitutionData.entrySet()) {
|
||||
result = result.replace(entry.getKey(), Optional.ofNullable(
|
||||
entry.getValue()).orElse(""));
|
||||
var workEntries = orderedEntries;
|
||||
var it = workEntries.listIterator();
|
||||
while (it.hasNext()) {
|
||||
var entry = it.next();
|
||||
String newResult = result.replace(entry.getKey(),
|
||||
Optional.ofNullable(entry.getValue()).orElse(""));
|
||||
if (!newResult.equals(result)) {
|
||||
// Substitution occured.
|
||||
// Remove the matching substitution key from the list and
|
||||
// go over the list of substitution entries again.
|
||||
if (workEntries == orderedEntries) {
|
||||
workEntries = new ArrayList<>(orderedEntries);
|
||||
it = workEntries.listIterator(it.nextIndex() - 1);
|
||||
it.next();
|
||||
}
|
||||
it.remove();
|
||||
it = workEntries.listIterator();
|
||||
result = newResult;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
@ -136,16 +136,16 @@ public class OverridableResourceTest {
|
||||
}
|
||||
|
||||
private void testCustomtWithSubstitution(String defaultName) throws IOException {
|
||||
final List<String> resourceData = List.of("A", "[BB]", "C", "Foo",
|
||||
"GoodbyeHello");
|
||||
final List<String> resourceData = List.of("A", "[BB]", "C", "Foo", "Foo",
|
||||
"GoodbyeHello", "_B");
|
||||
final Path customFile = createCustomFile("foo", resourceData);
|
||||
|
||||
final Map<String, String> substitutionData = new HashMap(Map.of("B",
|
||||
"Bar", "Foo", "B"));
|
||||
"Bar", "Foo", "B", "_B", "JJ"));
|
||||
substitutionData.put("Hello", null);
|
||||
|
||||
final List<String> expectedResourceData = List.of("A", "[BarBar]", "C",
|
||||
"B", "Goodbye");
|
||||
"Bar", "Bar", "Goodbye", "JJ");
|
||||
|
||||
final List<String> actualResourceData = convertToStringList(saveToFile(
|
||||
new OverridableResource(defaultName)
|
||||
|
Loading…
x
Reference in New Issue
Block a user