tkobayas commented on code in PR #6860:
URL: https://github.com/apache/incubator-kie/pull/6860#discussion_r3893084975


##########
script/ci/CiComputeBuildScopes.java:
##########
@@ -241,6 +277,104 @@ private static void writeLines(Path out, 
Collection<String> lines) throws IOExce
         Files.write(out, sorted);
     }
 
+    private static Set<String> imageProducersIn(Set<String> modules, 
Set<String> imageProducers) {
+        Set<String> result = new LinkedHashSet<>(modules);
+        result.retainAll(imageProducers);
+        return result;
+    }
+
+    static class Partition {
+        final String name;
+        final Set<String> entries;
+        Set<String> closure = Set.of();
+        Set<String> assigned = new LinkedHashSet<>();
+        Set<String> upstream = new LinkedHashSet<>();
+        Partition(String name, Set<String> entries) {
+            this.name = name;
+            this.entries = entries;
+        }
+    }
+
+    static List<Partition> readPartitionFiles(Path partitionsDir, Map<Path, 
String> dirToGa, Path cwd) throws IOException {
+        List<Path> files;
+        try (Stream<Path> s = Files.list(partitionsDir)) {
+            files = s.filter(f -> 
f.getFileName().toString().startsWith("partition") && 
f.getFileName().toString().endsWith(".txt"))
+                     .sorted()
+                     .collect(Collectors.toList());
+        }
+        List<Partition> result = new ArrayList<>();
+        for (Path file : files) {
+            String partName = 
file.getFileName().toString().replaceFirst("\\.txt$", "");
+            result.add(new Partition(partName, readModuleFile(file, dirToGa, 
cwd, partName)));
+        }
+        return result;
+    }
+
+    static Set<String> readModuleFile(Path file, Map<Path, String> dirToGa, 
Path cwd, String listName) throws IOException {
+        Set<String> modules = new LinkedHashSet<>();
+        for (String line : Files.readAllLines(file)) {
+            String trimmed = line.trim();
+            if (trimmed.isEmpty() || trimmed.startsWith("#")) continue;
+            Path modDir = cwd.resolve(trimmed).toAbsolutePath().normalize();
+            String ga = dirToGa.get(modDir);
+            if (ga == null) {
+                System.err.println("ERROR: " + listName + ": '" + trimmed + "' 
does not resolve to a reactor module");
+                System.exit(1);
+            }
+            modules.add(ga);
+        }
+        return modules;
+    }
+
+    private static void computePartitionClosures(List<Partition> partitions, 
DepGraph graph) {
+        for (Partition p : partitions) {
+            p.closure = DepGraph.traverse(p.entries, graph.upstreamOf);
+        }
+    }
+
+    private static void assignToPartitionsExclusive(Set<String> affected, 
List<Partition> partitions,
+                                                      Partition 
defaultPartition) {
+        List<Partition> explicit = partitions.stream()
+                .filter(p -> p != defaultPartition)
+                .collect(Collectors.toList());
+        for (String ga : affected) {
+            Partition sole = null;
+            int count = 0;
+            for (Partition p : explicit) {
+                if (p.closure.contains(ga)) {
+                    sole = p;
+                    count++;
+                    if (count > 1) break;
+                }
+            }
+            if (count == 1) {
+                sole.assigned.add(ga);
+            } else {
+                defaultPartition.assigned.add(ga);
+            }
+        }
+    }
+
+    // The upstream set intentionally includes the partition's own affected 
modules.
+    // Without them, an upstream module from another partition could fail to 
resolve
+    // dependencies on this partition's affected modules (e.g., shared module 
U depends
+    // on affected module V — if V is removed from upstream, building U fails).
+    private static void computePerPartitionUpstream(List<Partition> 
partitions, DepGraph graph) {
+        for (Partition p : partitions) {
+            if (p.assigned.isEmpty()) continue;
+            p.upstream = DepGraph.traverse(p.assigned, graph.upstreamOf);

Review Comment:
   The overlap is intentional: phase 1 compiles affected modules in parallel 
with tests and Quarkus skipped, so the serial test pass largely reuses those 
outputs. Removing them would shift compilation into the slower serial pass and 
could also break upstream or image-producer builds whose snapshot dependencies 
are assigned to the same partition. Since phase 1 takes only 2–7 minutes versus 
9–79 minutes for testing, the duplicated overhead is small.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to