luigidemasi commented on code in PR #238:
URL: https://github.com/apache/camel-kit/pull/238#discussion_r4786029979


##########
kit/pom.xml:
##########
@@ -54,6 +54,7 @@
         <module>camel-kit-main</module>
         <module>camel-kit-core</module>
         <module>camel-kit-graph</module>
+        <module>camel-kit-packs</module>

Review Comment:
   **Ship the selected packs with the CLI**
   
   This reactor entry builds four JARs. The packaged core and JBang plugin 
still contain only the `core` and `developer-tasks` catalog entries. The CLI 
runtime discovers zero `MigrationPack` implementations. Please include the 
selected artifacts in the distribution and have `init` and the migration 
workflow use the resulting catalog. An installed-CLI test that removes the Mule 
registration should fail. The new graph test still constructs `new 
GraphBuilder()`, which supplies Mule on its own.
   
   _AI-generated by Codex on behalf of @luigidemasi._



##########
kit/camel-kit-packs/mule-migration-pack/src/main/resources/META-INF/camel-kit/packs/mule/pack.yaml:
##########
@@ -0,0 +1,19 @@
+id: mule
+schema: 1
+skillTrees: [camel-migrate]

Review Comment:
   **Make each descriptor assemble from its own JAR**
   
   With all four built JARs on the classpath, selecting any pack individually 
fails with `missing skill tree camel-migrate`. Each declares that tree, but it 
lives in core. Keep the shared entry point in core and package each family’s 
guides with its owning descriptor. The four Camel guide paths and four Fuse 
guide paths are still absent. With only the missing-tree declaration removed in 
a test copy, Mule hits a second error at `provider/mule-dataweave`: 
`DataWeaveParser` implements `GraphParser`, while the descriptor requires 
`MigrationParser`.
   
   _AI-generated by Codex on behalf of @luigidemasi._



##########
kit/camel-kit-packs/camel-upgrade-pack/src/main/resources/META-INF/camel-kit/packs/camel-upgrade/pack.yaml:
##########
@@ -0,0 +1,19 @@
+id: camel-upgrade
+schema: 1
+skillTrees: [camel-migrate]
+add:
+  provider/xml-route:
+    contract: 1
+    provider:
+      service: org.apache.camel.kit.graph.parser.MigrationParser
+      implementation: org.apache.camel.kit.graph.parser.XmlRouteParser

Review Comment:
   **Register each parser once and preserve its input filtering**
   
   `GraphBuilder` already adds `XmlRouteParser`. Selecting it again through 
this provider parsed the same two routes twice. In a catalog probe with the 
missing-tree declaration removed, the unchanged fixture went from 6 edges to 12 
with both Camel and Fuse. The BizTalk provider likewise reported `pom.xml` and 
a Camel route as scanned inputs. Give each parser one registration and preserve 
the source filters in the provider hook. Compare edge counts and scanned 
filenames with the existing graph.
   
   _AI-generated by Codex on behalf of @luigidemasi._



##########
kit/camel-kit-graph/src/main/java/org/apache/camel/kit/graph/adapter/camel/CamelGraphAdapter.java:
##########
@@ -0,0 +1,62 @@
+package org.apache.camel.kit.graph.adapter.camel;
+
+import java.util.Map;
+import java.util.Optional;
+
+import org.apache.camel.kit.graph.ProjectGraph;
+import org.apache.camel.kit.graph.RuntimeDetector;
+import org.apache.camel.kit.graph.model.*;
+
+/**
+ * Graph adapter for Apache Camel routes and components. Used by the Camel 
upgrade pack for 2.x→4.x and 3.x→4.x
+ * migrations.
+ *
+ * This adapter uses the core Camel types (CAMEL_ROUTE, CAMEL_ENDPOINT, 
CAMEL_PROCESSOR) already owned by the core type
+ * registry, rather than creating duplicate types.
+ */
+public final class CamelGraphAdapter implements GraphTypeAdapter {
+    // Additional types not in core
+    public static final NodeType BEAN = new NodeType("CAMEL_BEAN");
+    public static final NodeType ROUTE_CONFIGURATION = new 
NodeType("CAMEL_ROUTE_CONFIGURATION");
+    public static final EdgeType ROUTE_CONTAINS = new 
EdgeType("CAMEL_ROUTE_CONTAINS");
+    public static final EdgeType CALLS_ROUTE = new 
EdgeType("CAMEL_CALLS_ROUTE");
+    public static final EdgeType USES_BEAN = new EdgeType("CAMEL_USES_BEAN");
+
+    @Override
+    public Map<String, NodeType> nodeTypes() {
+        // Reuse core types for route, endpoint, processor to avoid registry 
conflicts
+        return Map.ofEntries(
+                Map.entry("CAMEL_ROUTE", NodeType.CAMEL_ROUTE),

Review Comment:
   **Register only types owned by the adapter**
   
   The summary now correctly counts two existing `CAMEL_ROUTE` nodes. 
Registration still fails because the declared types must use the provider ID as 
their namespace. This mapping redeclares a core-owned type. The descriptors 
also register `mule-adapter` and `biztalk-adapter`, while their types use 
`mule:` and `biztalk:`. Read the core types when summarizing and align each 
pack-owned declaration with its provider namespace. Check 
`graphTypes().unavailable()` for every selected pack.
   
   _AI-generated by Codex on behalf of @luigidemasi._



##########
kit/camel-kit-graph/src/main/java/org/apache/camel/kit/packs/MigrationPackSelector.java:
##########
@@ -0,0 +1,150 @@
+package org.apache.camel.kit.packs;
+
+import java.util.*;
+import java.util.Locale;
+import java.util.stream.Collectors;
+
+import org.apache.camel.kit.graph.ProjectGraph;
+
+/**
+ * Handles scope selection when multiple migration packs detect the same 
project.
+ *
+ * Per Issue #200: "Only one migration and source scope per run." When testing 
mixed projects (e.g., Mule/BizTalk
+ * directory or Fuse with Camel dependencies), the system should request user 
choice when evidence is ambiguous.
+ *
+ * Both guided and direct migration modes must be preserved.
+ */
+public class MigrationPackSelector {
+
+    private final List<MigrationPack> availablePacks;
+    private final double CONFIDENCE_THRESHOLD = 0.3;
+    private final double AMBIGUOUS_THRESHOLD = 0.2; // If two packs are within 
this range, ask user
+
+    public MigrationPackSelector(List<MigrationPack> availablePacks) {
+        this.availablePacks = availablePacks;
+    }
+
+    /**
+     * Detect and select the appropriate migration pack for the given project.
+     *
+     * @param  graph             Project graph to analyze
+     * @param  userSpecifiedPack User-specified pack ID (from 
--source-platform), or null for auto-detect
+     * @return                   Selected migration pack, or empty if none 
applicable
+     */
+    public Optional<MigrationPack> selectPack(ProjectGraph graph, String 
userSpecifiedPack) {
+        // Direct mode: user specified a pack explicitly
+        if (userSpecifiedPack != null && !userSpecifiedPack.equals("auto")) {
+            return availablePacks.stream()
+                    .filter(pack -> pack.packId().equals(userSpecifiedPack))
+                    .findFirst();
+        }
+
+        // Guided mode: auto-detect
+        Map<MigrationPack, Double> confidenceScores = detectAll(graph);
+
+        // Filter out packs below threshold
+        List<Map.Entry<MigrationPack, Double>> candidates = 
confidenceScores.entrySet().stream()
+                .filter(entry -> entry.getValue() >= CONFIDENCE_THRESHOLD)
+                .sorted(Map.Entry.<MigrationPack, 
Double>comparingByValue().reversed())
+                .collect(Collectors.toList());
+
+        if (candidates.isEmpty()) {
+            return Optional.empty();
+        }
+
+        // Single clear candidate
+        if (candidates.size() == 1) {
+            return Optional.of(candidates.get(0).getKey());
+        }
+
+        // Multiple candidates - check if ambiguous
+        double topScore = candidates.get(0).getValue();
+        double secondScore = candidates.get(1).getValue();
+
+        if (Math.abs(topScore - secondScore) <= AMBIGUOUS_THRESHOLD) {
+            // Ambiguous - would need to prompt user
+            // For now, return the highest scoring pack but mark as ambiguous
+            MigrationPack selected = candidates.get(0).getKey();
+            System.err.println("WARN: Multiple migration sources detected:");
+            for (Map.Entry<MigrationPack, Double> entry : candidates) {
+                System.err.println(String.format(Locale.ROOT, "  - %s 
(confidence: %.2f)",
+                        entry.getKey().displayName(), entry.getValue()));
+            }
+            System.err.println(String.format(Locale.ROOT, "Selected: %s", 
selected.displayName()));
+            System.err.println("To explicitly choose, use --source-platform=" 
+ selected.packId());
+            return Optional.of(selected);

Review Comment:
   **Wait for a source choice when detection is ambiguous**
   
   With the four pack JARs loaded, a mixed Mule/BizTalk directory scored 0.50 
and 0.40 and immediately selected Mule. The result carries no candidate 
directories. The explicit `mulesoft` and `camel` values also returned empty. 
Preserve those existing values and return the candidate families and source 
paths so guided and direct migration can wait for the user’s choice.
   
   _AI-generated by Codex on behalf of @luigidemasi._



##########
kit/camel-kit-graph/src/main/java/org/apache/camel/kit/graph/RuntimeDetector.java:
##########
@@ -47,4 +47,62 @@ public static String findArtifactVersion(ProjectGraph graph, 
String groupId, Str
         }
         return null;
     }
+
+    /**
+     * Detect if the project uses Red Hat Fuse (6.x or 7.x).
+     *
+     * @param  graph Project graph
+     * @return       true if Fuse BOM or Fuse-specific artifacts are present
+     */
+    public static boolean isFuseProject(ProjectGraph graph) {
+        // Check for Fuse BOM in managed dependencies
+        boolean hasFuseBom = graph.findByType(NodeType.MAVEN_ARTIFACT).stream()

Review Comment:
   **Use managed BOM evidence and distinguish Fuse releases**
   
   A POM importing `fuse-springboot-bom` produced no candidate. Adding 
`camel.version=2.23.2` selected upstream Camel. `PomParser` stores imported 
BOMs as `CONFIG_PROPERTY` nodes with `kind=managed`, outside this scan. The 
previously recognized `2.23.2.fuse-7_11_1-00015` is now missed, while 
`3.20.1.redhat-00001` selects Fuse. Please cover these cases with real POMs and 
reuse the same version evidence for detection and reporting.
   
   _AI-generated by Codex on behalf of @luigidemasi._



##########
kit/camel-kit-packs/camel-upgrade-pack/src/main/java/org/apache/camel/kit/packs/camel/CamelUpgradePack.java:
##########
@@ -0,0 +1,107 @@
+package org.apache.camel.kit.packs.camel;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.camel.kit.graph.ProjectGraph;
+import org.apache.camel.kit.graph.RuntimeDetector;
+import org.apache.camel.kit.graph.adapter.camel.CamelGraphAdapter;
+import org.apache.camel.kit.graph.model.GraphTypeAdapter;
+import org.apache.camel.kit.graph.model.NodeType;
+import org.apache.camel.kit.packs.MigrationPack;
+
+/**
+ * Camel upgrade pack - handles Apache Camel 2.x and 3.x to Camel 4.x 
migrations.
+ *
+ * This pack is responsible for: - Detecting Camel 2.x and 3.x projects - 
Upgrading to Camel 4.x with YAML DSL -
+ * Handling breaking API changes - Component deprecations and replacements
+ *
+ * Separated from Fuse migration per Issue #200. Note: Does NOT include JBoss 
Fuse - see FuseMigrationPack for that.
+ */
+public class CamelUpgradePack implements MigrationPack {
+
+    private final CamelGraphAdapter graphAdapter = new CamelGraphAdapter();
+
+    @Override
+    public String packId() {
+        return "camel-upgrade";
+    }
+
+    @Override
+    public String displayName() {
+        return "Apache Camel Upgrade (2.x/3.x → 4.x)";
+    }
+
+    @Override
+    public List<String> supportedVersions() {
+        // Separate testing required for each version per Issue #200
+        return List.of("2.x", "3.x");
+    }
+
+    @Override
+    public double detectSource(ProjectGraph graph) {
+        // Check for Apache Camel dependencies (but NOT Fuse)
+        double confidence = 0.0;
+
+        String camelVersion = RuntimeDetector.findArtifactVersion(graph, 
"org.apache.camel", "camel-core");
+        if (camelVersion == null) {
+            camelVersion = RuntimeDetector.findMavenProperty(graph, 
"camel.version");
+        }
+
+        if (camelVersion != null) {
+            // Check it's NOT a Fuse/Red Hat version
+            if (!camelVersion.contains("redhat") && 
!camelVersion.contains("fuse")) {
+                if (camelVersion.startsWith("2.") || 
camelVersion.startsWith("3.")) {
+                    confidence = 1.0;
+                }
+            }
+        }
+
+        // Check for Camel routes
+        int routes = graph.findByType(NodeType.CAMEL_ROUTE).size();
+        if (routes > 0 && confidence == 0.0) {

Review Comment:
   **Keep known Camel 4 projects out of the legacy upgrade workflow**
   
   A project with `camel.version=4.22.1` and two Camel routes selected the 
2.x/3.x upgrade pack at 50% confidence. The fallback runs even when a known 
version has already ruled out an upgrade. Limit route-only detection to 
genuinely missing version evidence and cover a current Camel project alongside 
the 2.x and 3.x fixtures.
   
   _AI-generated by Codex on behalf of @luigidemasi._



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

Reply via email to