Skip to content
This repository was archived by the owner on Mar 8, 2023. It is now read-only.

Commit b3e85ed

Browse files
committed
use reflections8 instead of spring
1 parent b1765f8 commit b3e85ed

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

quarkus-extension-deployment/src/main/java/io/javaoperatorsdk/quarkus/resources/TestResourceRecorder.java

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,66 @@
11
package io.javaoperatorsdk.quarkus.resources;
22

33
import io.quarkus.runtime.annotations.Recorder;
4+
45
import java.io.IOException;
5-
import java.util.ArrayList;
6-
import java.util.Arrays;
7-
import java.util.List;
6+
import java.util.*;
87
import java.util.function.Supplier;
98
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;
1213

1314
@Recorder
1415
public class TestResourceRecorder {
1516

1617
private List<String> resourcePaths = new ArrayList<>();
1718

1819
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+
2041
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);
3544
} catch (IOException e) {
3645
e.printStackTrace();
3746
}
3847
}
3948

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+
4064
public Supplier<ResourceLocator> getSupplier() {
4165
return () -> new ResourceLocator(resourcePaths);
4266
}

0 commit comments

Comments
 (0)