|
18 | 18 | * this plugin ships: what {@code mvn metaobjects:eject -Dundo=true} removes, and what |
19 | 19 | * {@code metaobjects:generate} mentions in one advisory line. |
20 | 20 | * |
21 | | - * <p>Maven-free, like {@link EjectSupport}: it takes a directory and a resource reader. "Identical" |
| 21 | + * <p>Maven-free, like {@link EjectSupport}: it takes directories and a resource reader. "Identical" |
22 | 22 | * is {@link EjectSupport#compare} over every file the eject wrote for the generator: the generator, |
23 | 23 | * the classes copied with it and the page templates it reads (a file gone missing counts as |
24 | | - * differing). The shared support and runtime copies are not part of that verdict: other owned |
25 | | - * generators import them, so undo leaves them and names them. |
| 24 | + * differing), and the shared support and helper runtime copies it reaches. Undo never deletes the |
| 25 | + * shared copies (other owned generators import them) and names them instead; but a change to one |
| 26 | + * keeps the generator out of "identical", because the shipped generator imports the shipped |
| 27 | + * support and runtime, so the change would stop reaching the generated code. |
26 | 28 | */ |
27 | 29 | final class OwnedStock { |
28 | 30 |
|
@@ -76,8 +78,34 @@ static final class Copy { |
76 | 78 | String stockClassname() { return entry.classname; } |
77 | 79 | } |
78 | 80 |
|
79 | | - /** Every owned copy under {@code codegenRoot}, in catalog order; empty when there is none. */ |
80 | | - static List<Copy> find(Path codegenRoot, Reader reader) throws IOException { |
| 81 | + /** The source roots an owned helper runtime may sit under: {@code base}'s and each module's |
| 82 | + * {@code src/main/java}. */ |
| 83 | + static List<Path> runtimeRoots(Path base, List<String> modules) { |
| 84 | + List<Path> roots = new ArrayList<>(); |
| 85 | + roots.add(base.resolve("src/main/java")); |
| 86 | + if (modules != null) { |
| 87 | + for (String module : modules) roots.add(base.resolve(module).resolve("src/main/java")); |
| 88 | + } |
| 89 | + return roots; |
| 90 | + } |
| 91 | + |
| 92 | + /** The owned runtime copy of {@code simple} under {@code roots}, recognised by its ownership |
| 93 | + * marker, or {@code null}. */ |
| 94 | + static Path findOwnedRuntime(List<Path> roots, String simple) throws IOException { |
| 95 | + for (Path root : roots) { |
| 96 | + if (!Files.isDirectory(root)) continue; |
| 97 | + try (var walk = Files.walk(root)) { |
| 98 | + for (Path p : (Iterable<Path>) walk.filter(f -> f.getFileName().toString().equals(simple + ".java"))::iterator) { |
| 99 | + if (EjectSupport.isOwnedRuntime(Files.readString(p, StandardCharsets.UTF_8))) return p; |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + return null; |
| 104 | + } |
| 105 | + |
| 106 | + /** Every owned copy under {@code codegenRoot}, in catalog order; empty when there is none. The |
| 107 | + * helper runtime its output imports is looked for under {@code runtimeRoots}. */ |
| 108 | + static List<Copy> find(Path codegenRoot, List<Path> runtimeRoots, Reader reader) throws IOException { |
81 | 109 | List<Copy> out = new ArrayList<>(); |
82 | 110 | if (codegenRoot == null || !Files.isDirectory(codegenRoot)) return out; |
83 | 111 | for (EjectSupport.Entry e : EjectSupport.allEntries()) { |
@@ -117,6 +145,22 @@ static List<Copy> find(Path codegenRoot, Reader reader) throws IOException { |
117 | 145 | owned, reader.read(GeneratorRegistry.EJECT_TEMPLATE_RESOURCE_ROOT |
118 | 146 | + ref + EjectSupport.TEMPLATE_EXTENSION))); |
119 | 147 | } |
| 148 | + Set<String> support = new LinkedHashSet<>(); |
| 149 | + for (String source : e.sources()) support.addAll(EjectSupport.supportFor(reader.read(e.resourceOf(source)))); |
| 150 | + for (String simple : support) { |
| 151 | + Path owned = MetaDataEjectMojo.findOwned(codegenRoot, "java", simple + ".java"); |
| 152 | + if (owned == null) continue; |
| 153 | + fold(totals, differing, simple + ".java", EjectSupport.compare( |
| 154 | + Files.readString(owned, StandardCharsets.UTF_8), |
| 155 | + reader.read(GeneratorRegistry.EJECT_SUPPORT_RESOURCE_ROOT + simple + ".java"))); |
| 156 | + } |
| 157 | + for (String simple : e.runtime) { |
| 158 | + Path owned = findOwnedRuntime(runtimeRoots, simple); |
| 159 | + if (owned == null) continue; |
| 160 | + fold(totals, differing, simple + ".java", EjectSupport.compare( |
| 161 | + Files.readString(owned, StandardCharsets.UTF_8), |
| 162 | + reader.read(GeneratorRegistry.EJECT_RUNTIME_RESOURCE_ROOT + simple + ".java"))); |
| 163 | + } |
120 | 164 | } |
121 | 165 | out.add(new Copy(e, ownedPackage, files, differing, totals[0], totals[1], |
122 | 166 | shared(codegenRoot, e, reader))); |
|
0 commit comments