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


##########
script/ci/CiComputeBuildScopes.java:
##########
@@ -202,6 +220,102 @@ private static void writeLines(Path out, 
Collection<String> lines) throws IOExce
         Files.write(out, sorted);
     }
 
+    private static final List<String> EXPECTED_CATEGORIES = 
List.of("optaplanner", "kogito-runtimes", "kogito-apps");
+
+    static Map<String, Set<Path>> parseModuleCategories(Path rootPom, Path 
cwd) throws IOException {
+        Map<String, Set<Path>> categories = new LinkedHashMap<>();
+        categories.put("drools", new LinkedHashSet<>());
+        for (String cat : EXPECTED_CATEGORIES) {
+            categories.put(cat, new LinkedHashSet<>());
+        }
+
+        String currentCategory = "drools";
+        boolean inModules = false;
+        Set<String> seenBegins = new HashSet<>();
+        Set<String> seenEnds = new HashSet<>();
+
+        Pattern beginPattern = 
Pattern.compile("<!--\\s*BEGIN\\s+(\\S+)\\s+modules\\s+\\(auto\\)\\s*-->");
+        Pattern endPattern = 
Pattern.compile("<!--\\s*END\\s+(\\S+)\\s+modules\\s+\\(auto\\)\\s*-->");
+        Pattern modulePattern = Pattern.compile("<module>(.+)</module>");
+
+        for (String line : Files.readAllLines(rootPom)) {
+            String trimmed = line.trim();
+
+            if (trimmed.equals("<modules>")) {
+                inModules = true;
+                continue;
+            }
+            if (trimmed.equals("</modules>")) {
+                break;
+            }
+            if (!inModules) continue;
+
+            Matcher beginMatcher = beginPattern.matcher(trimmed);
+            if (beginMatcher.matches()) {
+                currentCategory = beginMatcher.group(1);
+                if (!categories.containsKey(currentCategory)) {
+                    System.err.println("ERROR: unknown module category '" + 
currentCategory
+                            + "' in pom.xml marker. Expected one of: " + 
EXPECTED_CATEGORIES);
+                    System.exit(1);
+                }
+                seenBegins.add(currentCategory);
+                continue;
+            }
+
+            Matcher endMatcher = endPattern.matcher(trimmed);
+            if (endMatcher.matches()) {
+                seenEnds.add(endMatcher.group(1));
+                currentCategory = "drools";
+                continue;
+            }
+
+            Matcher moduleMatcher = modulePattern.matcher(trimmed);
+            if (moduleMatcher.matches()) {
+                String modulePath = moduleMatcher.group(1);
+                
categories.get(currentCategory).add(cwd.resolve(modulePath).toAbsolutePath().normalize());
+            }
+        }
+
+        for (String cat : EXPECTED_CATEGORIES) {
+            if (!seenBegins.contains(cat)) {
+                System.err.println("ERROR: missing '<!-- BEGIN " + cat
+                        + " modules (auto) -->' marker in pom.xml");
+                System.exit(1);
+            }
+            if (!seenEnds.contains(cat)) {
+                System.err.println("ERROR: missing '<!-- END " + cat
+                        + " modules (auto) -->' marker in pom.xml");
+                System.exit(1);
+            }
+        }
+
+        return categories;
+    }
+
+    private static String categorizeGa(String ga, Map<String, Path> gaToDir,
+                                        Map<String, Set<Path>> categories) {
+        Path dir = gaToDir.get(ga);
+        if (dir == null) return "drools";
+        dir = dir.toAbsolutePath().normalize();
+        for (var entry : categories.entrySet()) {
+            for (Path catPath : entry.getValue()) {
+                if (dir.equals(catPath) || dir.startsWith(catPath + "/")) {
+                    return entry.getKey();
+                }
+            }
+        }
+        return "drools";
+    }

Review Comment:
   outdated



-- 
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