|
17 | 17 |
|
18 | 18 | import java.io.File;
|
19 | 19 | import java.io.IOException;
|
20 |
| -import java.io.UncheckedIOException; |
21 | 20 | import java.net.JarURLConnection;
|
22 | 21 | import java.net.URL;
|
23 | 22 | import java.net.URLDecoder;
|
@@ -63,58 +62,50 @@ private static String normalizeBase(String base) {
|
63 | 62 | return b;
|
64 | 63 | }
|
65 | 64 |
|
66 |
| - private static Collection<String> scanFileUrl(URL url, String prefix) { |
67 |
| - try { |
68 |
| - Path root = Paths.get(URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8)); |
69 |
| - if (!Files.exists(root)) return List.of(); |
| 65 | + private static Collection<String> scanFileUrl(URL url, String prefix) throws IOException { |
| 66 | + Path root = Paths.get(URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8)); |
| 67 | + if (!Files.exists(root)) return List.of(); |
70 | 68 |
|
71 |
| - // If we resolved exactly "<classpathRoot>/<prefix>/", we should prepend "prefix/" |
72 |
| - // to the relativized filenames to mirror the JAR behaviour. |
73 |
| - String rootStr = root.normalize().toString().replace('\\', '/'); |
74 |
| - boolean rootIsPrefixDir = !prefix.isEmpty() && rootStr.endsWith("/" + prefix); |
| 69 | + // If we resolved exactly "<classpathRoot>/<prefix>/", we should prepend "prefix/" |
| 70 | + // to the relativized filenames to mirror the JAR behaviour. |
| 71 | + String rootStr = root.normalize().toString().replace('\\', '/'); |
| 72 | + boolean rootIsPrefixDir = !prefix.isEmpty() && rootStr.endsWith("/" + prefix); |
75 | 73 |
|
76 |
| - try (Stream<Path> s = Files.walk(root)) { |
77 |
| - return s.filter(Files::isRegularFile) |
78 |
| - .filter( |
79 |
| - p -> { |
80 |
| - String name = p.getFileName().toString().toLowerCase(Locale.ROOT); |
81 |
| - return name.endsWith(".yaml") || name.endsWith(".yml"); |
82 |
| - }) |
83 |
| - .map( |
84 |
| - p -> { |
85 |
| - String rel = root.relativize(p).toString().replace(File.separatorChar, '/'); |
86 |
| - // When scanning the specific prefix directory, add "prefix/" so callers get |
87 |
| - // paths relative to the classpath root, e.g. "workflows-samples/foo.yaml". |
88 |
| - return rootIsPrefixDir ? (prefix + "/" + rel) : rel; |
89 |
| - }) |
90 |
| - .collect(Collectors.toCollection(LinkedHashSet::new)); |
91 |
| - } |
92 |
| - } catch (IOException e) { |
93 |
| - throw new UncheckedIOException(e); |
| 74 | + try (Stream<Path> s = Files.walk(root)) { |
| 75 | + return s.filter(Files::isRegularFile) |
| 76 | + .filter( |
| 77 | + p -> { |
| 78 | + String name = p.getFileName().toString().toLowerCase(Locale.ROOT); |
| 79 | + return name.endsWith(".yaml") || name.endsWith(".yml"); |
| 80 | + }) |
| 81 | + .map( |
| 82 | + p -> { |
| 83 | + String rel = root.relativize(p).toString().replace(File.separatorChar, '/'); |
| 84 | + // When scanning the specific prefix directory, add "prefix/" so callers get |
| 85 | + // paths relative to the classpath root, e.g. "workflows-samples/foo.yaml". |
| 86 | + return rootIsPrefixDir ? (prefix + "/" + rel) : rel; |
| 87 | + }) |
| 88 | + .collect(Collectors.toCollection(LinkedHashSet::new)); |
94 | 89 | }
|
95 | 90 | }
|
96 | 91 |
|
97 |
| - private static Collection<String> scanJarUrl(URL url) { |
98 |
| - try { |
99 |
| - JarURLConnection conn = (JarURLConnection) url.openConnection(); |
100 |
| - try (JarFile jar = conn.getJarFile()) { |
101 |
| - String dir = ensureDirPrefix(conn.getEntryName()); |
102 |
| - List<String> out = new ArrayList<>(); |
103 |
| - Enumeration<JarEntry> entries = jar.entries(); |
104 |
| - while (entries.hasMoreElements()) { |
105 |
| - JarEntry je = entries.nextElement(); |
106 |
| - if (je.isDirectory()) continue; |
107 |
| - String name = je.getName(); |
108 |
| - if (!name.startsWith(dir)) continue; |
109 |
| - String lower = name.toLowerCase(Locale.ROOT); |
110 |
| - if (lower.endsWith(".yaml") || lower.endsWith(".yml")) { |
111 |
| - out.add(name); |
112 |
| - } |
| 92 | + private static Collection<String> scanJarUrl(URL url) throws IOException { |
| 93 | + JarURLConnection conn = (JarURLConnection) url.openConnection(); |
| 94 | + try (JarFile jar = conn.getJarFile()) { |
| 95 | + String dir = ensureDirPrefix(conn.getEntryName()); |
| 96 | + List<String> out = new ArrayList<>(); |
| 97 | + Enumeration<JarEntry> entries = jar.entries(); |
| 98 | + while (entries.hasMoreElements()) { |
| 99 | + JarEntry je = entries.nextElement(); |
| 100 | + if (je.isDirectory()) continue; |
| 101 | + String name = je.getName(); |
| 102 | + if (!name.startsWith(dir)) continue; |
| 103 | + String lower = name.toLowerCase(Locale.ROOT); |
| 104 | + if (lower.endsWith(".yaml") || lower.endsWith(".yml")) { |
| 105 | + out.add(name); |
113 | 106 | }
|
114 |
| - return out; |
115 | 107 | }
|
116 |
| - } catch (IOException e) { |
117 |
| - throw new UncheckedIOException(e); |
| 108 | + return out; |
118 | 109 | }
|
119 | 110 | }
|
120 | 111 |
|
|
0 commit comments