Browse Source

Ensure empty layers are written to the index file

Update the `LayersIndex` class to ensure that layers that do not contain
content are still written.

Closes gh-20858
pull/20874/head
Phillip Webb 6 years ago
parent
commit
464c15e52c
  1. 4
      spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LayersIndex.java
  2. 2
      spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/LayersIndexTests.java
  3. 1
      spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/resources/org/springframework/boot/loader/tools/LayersIndexTests-writeToWhenAllFilesInFolderAreInSameLayerUsesFolder.txt
  4. 1
      spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/resources/org/springframework/boot/loader/tools/LayersIndexTests-writeToWhenLayerNotUsedDoesNotSkipLayer.txt

4
spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LayersIndex.java

@ -96,8 +96,8 @@ public class LayersIndex {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));
for (Layer layer : this.layers) { for (Layer layer : this.layers) {
List<String> names = index.get(layer); List<String> names = index.get(layer);
if (names != null && !names.isEmpty()) { writer.write("- \"" + layer + "\":\n");
writer.write("- \"" + layer + "\":\n"); if (names != null) {
for (String name : names) { for (String name : names) {
writer.write(" - \"" + name + "\"\n"); writer.write(" - \"" + name + "\"\n");
} }

2
spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/LayersIndexTests.java

@ -75,7 +75,7 @@ class LayersIndexTests {
} }
@Test @Test
void writeToWhenLayerNotUsedSkipsLayer() { void writeToWhenLayerNotUsedDoesNotSkipLayer() {
LayersIndex index = new LayersIndex(LAYER_A, LAYER_B, LAYER_C); LayersIndex index = new LayersIndex(LAYER_A, LAYER_B, LAYER_C);
index.add(LAYER_A, "a1"); index.add(LAYER_A, "a1");
index.add(LAYER_A, "a2"); index.add(LAYER_A, "a2");

1
spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/resources/org/springframework/boot/loader/tools/LayersIndexTests-writeToWhenAllFilesInFolderAreInSameLayerUsesFolder.txt

@ -2,3 +2,4 @@
- "a1/" - "a1/"
- "b": - "b":
- "a2/" - "a2/"
- "c":

1
spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/resources/org/springframework/boot/loader/tools/LayersIndexTests-writeToWhenLayerNotUsedSkipsLayer.txt → spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/resources/org/springframework/boot/loader/tools/LayersIndexTests-writeToWhenLayerNotUsedDoesNotSkipLayer.txt

@ -1,6 +1,7 @@
- "a": - "a":
- "a1" - "a1"
- "a2" - "a2"
- "b":
- "c": - "c":
- "c1" - "c1"
- "c2" - "c2"
Loading…
Cancel
Save