|
7 | 7 | import static java.util.stream.Collectors.toList;
|
8 | 8 |
|
9 | 9 | import java.io.FileNotFoundException;
|
10 |
| -import java.io.LineNumberReader; |
11 |
| -import java.io.Reader; |
| 10 | +import java.io.IOException; |
| 11 | +import java.net.URI; |
| 12 | +import java.nio.file.Files; |
12 | 13 | import java.nio.file.NoSuchFileException;
|
13 |
| -import java.util.ArrayList; |
14 |
| -import java.util.Collections; |
15 |
| -import java.util.List; |
| 14 | +import java.nio.file.Path; |
| 15 | +import java.util.HashSet; |
16 | 16 | import java.util.Map;
|
| 17 | +import java.util.Set; |
17 | 18 |
|
18 | 19 | import javax.annotation.processing.FilerException;
|
19 | 20 | import javax.lang.model.element.Modifier;
|
20 | 21 | import javax.lang.model.element.TypeElement;
|
21 |
| -import javax.tools.FileObject; |
22 | 22 | import javax.tools.StandardLocation;
|
23 | 23 |
|
24 | 24 | import io.avaje.http.generator.core.APContext;
|
@@ -64,32 +64,40 @@ void read() {
|
64 | 64 | }
|
65 | 65 | }
|
66 | 66 |
|
67 |
| - private List<String> loadMetaInf() { |
| 67 | + private Set<String> loadMetaInf() { |
| 68 | + var set = new HashSet<String>(); |
68 | 69 | try {
|
69 |
| - final FileObject fileObject = filer().getResource(StandardLocation.CLASS_OUTPUT, "", Constants.META_INF_COMPONENT); |
70 |
| - if (fileObject != null) { |
71 |
| - final List<String> lines = new ArrayList<>(); |
72 |
| - final Reader reader = fileObject.openReader(true); |
73 |
| - final LineNumberReader lineReader = new LineNumberReader(reader); |
74 |
| - String line; |
75 |
| - while ((line = lineReader.readLine()) != null) { |
76 |
| - line = line.trim(); |
77 |
| - if (!line.isEmpty()) { |
78 |
| - lines.add(line); |
79 |
| - } |
80 |
| - } |
81 |
| - return lines; |
82 |
| - } |
| 70 | + addLines(mainMetaInfURI(), set); |
| 71 | + addLines(metaInfURI(), set); |
| 72 | + } catch (final IOException e) { |
| 73 | + logWarn("Error reading services file: " + e.getMessage()); |
| 74 | + } |
| 75 | + return set; |
| 76 | + } |
83 | 77 |
|
| 78 | + private static void addLines(URI uri, HashSet<String> set) { |
| 79 | + try (var lines = Files.lines(Path.of(uri))) { |
| 80 | + lines.forEach(set::add); |
84 | 81 | } catch (FileNotFoundException | NoSuchFileException e) {
|
85 | 82 | // logDebug("no services file yet");
|
86 |
| - |
87 | 83 | } catch (final FilerException e) {
|
88 | 84 | logDebug("FilerException reading services file");
|
89 |
| - |
90 |
| - } catch (final Exception e) { |
| 85 | + } catch (Exception e) { |
91 | 86 | logWarn("Error reading services file: " + e.getMessage());
|
92 | 87 | }
|
93 |
| - return Collections.emptyList(); |
| 88 | + } |
| 89 | + |
| 90 | + private static URI mainMetaInfURI() throws IOException { |
| 91 | + return URI.create( |
| 92 | + metaInfURI() |
| 93 | + .toString() |
| 94 | + .replaceFirst("java/test", "java/main") |
| 95 | + .replaceFirst("test-classes", "classes")); |
| 96 | + } |
| 97 | + |
| 98 | + private static URI metaInfURI() throws IOException { |
| 99 | + return filer() |
| 100 | + .getResource(StandardLocation.CLASS_OUTPUT, "", Constants.META_INF_COMPONENT) |
| 101 | + .toUri(); |
94 | 102 | }
|
95 | 103 | }
|
0 commit comments