|
1 | 1 | package io.javaoperatorsdk.quarkus.resources; |
2 | 2 |
|
3 | 3 | import io.quarkus.runtime.annotations.Recorder; |
| 4 | + |
4 | 5 | import java.io.IOException; |
5 | | -import java.util.ArrayList; |
6 | | -import java.util.Arrays; |
7 | | -import java.util.List; |
| 6 | +import java.util.*; |
8 | 7 | import java.util.function.Supplier; |
9 | 8 | import java.util.stream.Collectors; |
10 | | -import org.springframework.core.io.Resource; |
11 | | -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
| 9 | + |
| 10 | +import org.reflections8.Reflections; |
| 11 | +import org.reflections8.scanners.ResourcesScanner; |
| 12 | +import org.reflections8.util.Utils; |
12 | 13 |
|
13 | 14 | @Recorder |
14 | 15 | public class TestResourceRecorder { |
15 | 16 |
|
16 | 17 | private List<String> resourcePaths = new ArrayList<>(); |
17 | 18 |
|
18 | 19 | public TestResourceRecorder() { |
19 | | - PathMatchingResourcePatternResolver s = new PathMatchingResourcePatternResolver(); |
| 20 | + // PathMatchingResourcePatternResolver s = new PathMatchingResourcePatternResolver(); |
| 21 | + // try { |
| 22 | + // Resource[] resources = s.getResources("templates/**"); |
| 23 | + // resourcePaths = |
| 24 | + // Arrays.stream(resources) |
| 25 | + // .map( |
| 26 | + // r -> { |
| 27 | + // try { |
| 28 | + // final var splitted = |
| 29 | + // r.getURL().getPath().split("!"); |
| 30 | + // return splitted[splitted.length - 1]; |
| 31 | + // } catch (IOException e) { |
| 32 | + // e.printStackTrace(); |
| 33 | + // return null; |
| 34 | + // } |
| 35 | + // }) |
| 36 | + // .collect(Collectors.toList()); |
| 37 | + // } catch (IOException e) { |
| 38 | + // e.printStackTrace(); |
| 39 | + // } |
| 40 | + |
20 | 41 | try { |
21 | | - Resource[] resources = s.getResources("templates/**"); |
22 | | - resourcePaths = |
23 | | - Arrays.stream(resources) |
24 | | - .map( |
25 | | - r -> { |
26 | | - try { |
27 | | - final var splitted = r.getURL().getPath().split("!"); |
28 | | - return splitted[splitted.length - 1]; |
29 | | - } catch (IOException e) { |
30 | | - e.printStackTrace(); |
31 | | - return null; |
32 | | - } |
33 | | - }) |
34 | | - .collect(Collectors.toList()); |
| 42 | + List<String> resources = getResourceFiles("templates"); |
| 43 | + resourcePaths.addAll(resources); |
35 | 44 | } catch (IOException e) { |
36 | 45 | e.printStackTrace(); |
37 | 46 | } |
38 | 47 | } |
39 | 48 |
|
| 49 | + private List<String> getResourceFiles(String path) { |
| 50 | + Reflections reflections = new Reflections(null, new ResourcesScanner()); |
| 51 | + final var resources = |
| 52 | + reflections.getStore().get(Utils.index(ResourcesScanner.class)).values().stream() |
| 53 | + .flatMap(Set::stream) |
| 54 | + .filter( |
| 55 | + p -> { |
| 56 | + System.out.println(p); |
| 57 | + return p.contains(path); |
| 58 | + }) |
| 59 | + .collect(Collectors.toList()); |
| 60 | + |
| 61 | + return new ArrayList<>(resources); |
| 62 | + } |
| 63 | + |
40 | 64 | public Supplier<ResourceLocator> getSupplier() { |
41 | 65 | return () -> new ResourceLocator(resourcePaths); |
42 | 66 | } |
|
0 commit comments