|
1 | 1 | package io.avaje.inject.generator;
|
2 | 2 |
|
3 |
| -import java.io.BufferedReader; |
4 |
| -import java.io.IOException; |
5 |
| -import java.io.InputStreamReader; |
6 |
| -import java.net.URL; |
7 |
| -import java.util.HashSet; |
8 |
| -import java.util.LinkedHashSet; |
9 |
| -import java.util.ServiceLoader; |
10 |
| -import java.util.Set; |
| 3 | +import io.avaje.inject.Component; |
| 4 | +import io.avaje.inject.Factory; |
| 5 | +import io.avaje.inject.InjectModule; |
| 6 | +import io.avaje.inject.Prototype; |
| 7 | +import io.avaje.inject.spi.Plugin; |
| 8 | +import io.avaje.inject.spi.Proxy; |
| 9 | +import jakarta.inject.Scope; |
| 10 | +import jakarta.inject.Singleton; |
11 | 11 |
|
12 | 12 | import javax.annotation.processing.AbstractProcessor;
|
13 | 13 | import javax.annotation.processing.Filer;
|
|
20 | 20 | import javax.lang.model.element.TypeElement;
|
21 | 21 | import javax.lang.model.util.Elements;
|
22 | 22 | import javax.tools.StandardLocation;
|
23 |
| - |
24 |
| -import io.avaje.inject.Component; |
25 |
| -import io.avaje.inject.Factory; |
26 |
| -import io.avaje.inject.InjectModule; |
27 |
| -import io.avaje.inject.Prototype; |
28 |
| -import io.avaje.inject.spi.Plugin; |
29 |
| -import io.avaje.inject.spi.Proxy; |
30 |
| -import jakarta.inject.Scope; |
31 |
| -import jakarta.inject.Singleton; |
| 23 | +import java.io.BufferedReader; |
| 24 | +import java.io.IOException; |
| 25 | +import java.io.InputStreamReader; |
| 26 | +import java.net.URL; |
| 27 | +import java.util.*; |
| 28 | +import java.util.stream.Collectors; |
| 29 | +import java.util.stream.Stream; |
32 | 30 |
|
33 | 31 | public final class Processor extends AbstractProcessor {
|
34 | 32 |
|
@@ -56,38 +54,37 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
|
56 | 54 | registerPluginProvidedTypes();
|
57 | 55 | }
|
58 | 56 |
|
59 |
| - /** Loads provider files generated by auto-requires-plugin */ |
| 57 | + /** |
| 58 | + * Loads provider files generated by avaje-inject-maven-plugin |
| 59 | + */ |
60 | 60 | void loadProvidedFiles(Filer filer) {
|
| 61 | + targetProvidesLines(filer, "target/avaje-plugin-provides.txt") |
| 62 | + .forEach(pluginFileProvided::add); |
61 | 63 |
|
62 |
| - try { |
63 |
| - final var resource = |
64 |
| - filer |
65 |
| - .getResource(StandardLocation.CLASS_OUTPUT, "", "target/avaje-plugin-provides.txt") |
66 |
| - .toUri() |
67 |
| - .toString() |
68 |
| - .replace("/target/classes", ""); |
69 |
| - try (var inputStream = new URL(resource).openStream(); |
70 |
| - var reader = new BufferedReader(new InputStreamReader(inputStream))) { |
71 |
| - reader.lines().forEach(pluginFileProvided::add); |
72 |
| - } |
73 |
| - } catch (final IOException e2) { |
74 |
| - } |
| 64 | + targetProvidesLines(filer, "target/avaje-module-provides.txt") |
| 65 | + .forEach(moduleFileProvided::add); |
| 66 | + } |
75 | 67 |
|
| 68 | + private static List<String> targetProvidesLines(Filer filer, String relativeName) { |
76 | 69 | try {
|
77 |
| - final var resource = |
78 |
| - filer |
79 |
| - .getResource(StandardLocation.CLASS_OUTPUT, "", "target/avaje-module-provides.txt") |
80 |
| - .toUri() |
81 |
| - .toString() |
82 |
| - .replace("/target/classes", ""); |
| 70 | + final String resource = targetProvides(filer, relativeName); |
83 | 71 | try (var inputStream = new URL(resource).openStream();
|
84 |
| - var reader = new BufferedReader(new InputStreamReader(inputStream))) { |
85 |
| - reader.lines().forEach(moduleFileProvided::add); |
| 72 | + var reader = new BufferedReader(new InputStreamReader(inputStream))) { |
| 73 | + return reader.lines().collect(Collectors.toList()); |
86 | 74 | }
|
87 |
| - } catch (final IOException e2) { |
| 75 | + } catch (final IOException e) { |
| 76 | + return Collections.emptyList(); |
88 | 77 | }
|
89 | 78 | }
|
90 | 79 |
|
| 80 | + private static String targetProvides(Filer filer, String relativeName) throws IOException { |
| 81 | + return filer |
| 82 | + .getResource(StandardLocation.CLASS_OUTPUT, "", relativeName) |
| 83 | + .toUri() |
| 84 | + .toString() |
| 85 | + .replace("/target/classes", ""); |
| 86 | + } |
| 87 | + |
91 | 88 | /**
|
92 | 89 | * Register types provided by the plugin so no compiler error when we have a dependency
|
93 | 90 | * on these types and the only thing providing them is the plugin.
|
|
0 commit comments