|
26 | 26 | import java.io.UncheckedIOException;
|
27 | 27 | import java.nio.charset.StandardCharsets;
|
28 | 28 | import java.util.Properties;
|
| 29 | +import java.util.stream.Stream; |
29 | 30 |
|
30 | 31 | @ValueClass
|
31 | 32 | public abstract class BuildInfoProperties {
|
@@ -81,18 +82,23 @@ private static BuildInfoProperties infoProperties() throws IOException {
|
81 | 82 | private static final Object INFO_PROPERTIES = loadProperties();
|
82 | 83 |
|
83 | 84 | private static Object loadProperties() {
|
84 |
| - var properties = new Properties(); |
85 |
| - var classLoader = Thread.currentThread().getContextClassLoader(); |
86 |
| - try (var infoStream = classLoader.getResourceAsStream(INFO_FILE)) { |
87 |
| - if (infoStream != null) { |
88 |
| - try (var infoReader = new InputStreamReader(infoStream, StandardCharsets.UTF_8)) { |
89 |
| - properties.load(infoReader); |
| 85 | + return Stream.of( |
| 86 | + Thread.currentThread().getContextClassLoader(), |
| 87 | + BuildInfoProperties.class.getClassLoader() |
| 88 | + ).flatMap(cl -> Stream.ofNullable(cl.getResourceAsStream(INFO_FILE))) |
| 89 | + .findFirst() |
| 90 | + .map(infoStream -> { |
| 91 | + try (infoStream) { |
| 92 | + try (var infoReader = new InputStreamReader(infoStream, StandardCharsets.UTF_8)) { |
| 93 | + var properties = new Properties(); |
| 94 | + properties.load(infoReader); |
| 95 | + return from(properties); |
| 96 | + } |
| 97 | + } catch (IOException exception) { |
| 98 | + return exception; |
90 | 99 | }
|
91 |
| - } |
92 |
| - } catch (IOException exception) { |
93 |
| - return exception; |
94 |
| - } |
95 |
| - return from(properties); |
| 100 | + }) |
| 101 | + .orElseGet(() -> new IOException("Could not find " + INFO_FILE)); |
96 | 102 | }
|
97 | 103 | }
|
98 | 104 | }
|
0 commit comments