luigidemasi commented on code in PR #238:
URL: https://github.com/apache/camel-kit/pull/238#discussion_r4781718726
##########
kit/camel-kit-packs/MigrationPack.java:
##########
@@ -0,0 +1,94 @@
+package org.apache.camel.kit.packs;
+
+import org.apache.camel.kit.graph.ProjectGraph;
+import org.apache.camel.kit.graph.model.GraphTypeAdapter;
+import org.apache.camel.kit.graph.parser.MigrationParser;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Base interface for migration packs.
+ * Each migration family (Mule, BizTalk, Camel upgrade, Fuse) is responsible
for:
+ * - Source detection
+ * - Parser integrations
+ * - Graph adapters
+ * - Version-specific rules
+ * - Migration guides
+ *
+ * This architecture implements Issue #200: "Convert Mule, BizTalk, Camel
upgrade
+ * and Fuse migrations into bundled packs"
+ */
+public interface MigrationPack {
+
+ /**
+ * @return Unique identifier for this pack (e.g., "mule", "biztalk",
"camel-upgrade", "fuse")
+ */
+ String packId();
+
+ /**
+ * @return Human-readable name (e.g., "MuleSoft Migration", "BizTalk
Migration")
+ */
+ String displayName();
+
+ /**
+ * @return Version-specific variants this pack supports (e.g., ["3.x",
"4.x"] for Mule)
+ */
+ List<String> supportedVersions();
+
+ /**
+ * Detect if this pack applies to the given project.
+ *
+ * @param graph Project graph to analyze
+ * @return Detection confidence (0.0 = no evidence, 1.0 = definitive match)
+ */
+ double detectSource(ProjectGraph graph);
+
+ /**
+ * Get the graph adapter for this migration pack.
+ *
+ * @return Graph type adapter for this pack's node/edge types
+ */
+ GraphTypeAdapter getGraphAdapter();
+
+ /**
+ * Get parsers for this migration pack.
+ *
+ * @return List of parsers that can read this pack's source formats
+ */
+ List<MigrationParser> getParsers();
Review Comment:
**Make the parser factories compile against the public contract.** Direct
Java 21 compilation failed in all four `getParsers()` implementations. For
example, `DataWeaveParser` implements `GraphParser`, and the BizTalk list
includes helpers that the top-level parser calls internally. Register providers
that implement `MigrationParser` and keep those helpers behind their provider.
_AI-generated by Codex on behalf of @luigidemasi._
##########
kit/camel-kit-packs/MigrationPackSelector.java:
##########
@@ -0,0 +1,151 @@
+package org.apache.camel.kit.packs;
+
+import org.apache.camel.kit.graph.ProjectGraph;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 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(" - %s (confidence: %.2f)",
+ entry.getKey().displayName(), entry.getValue()));
+ }
+ System.err.println(String.format("Selected: %s",
selected.displayName()));
+ System.err.println("To explicitly choose, use --source-platform="
+ selected.packId());
+ return Optional.of(selected);
Review Comment:
**Let the user choose the migration and source directory.** On a directory
containing a Mule flow and a BizTalk orchestration, the selector scored them
0.50 and 0.40, printed the warning, and returned Mule. The result carries no
source path. Return both candidates with their paths and wait for an explicit
choice in guided and direct migration. Please also preserve the existing
`mulesoft` and `camel` values. Both returned empty through the
explicit-selection branch.
_AI-generated by Codex on behalf of @luigidemasi._
##########
kit/camel-kit-graph/src/test/java/org/apache/camel/kit/graph/GraphBuilderTest.java:
##########
@@ -237,6 +237,48 @@ void
migrationParserReceivesOnlyMatchingFilesAndKeepsPartialDiagnostics(@TempDir
assertEquals(0, empty.graph().nodeCount());
}
+ @Test
+ void muleParserRegistrationWorksWhenMovedIntoPack() {
+ // Issue #200: Verify parser registration doesn't break when parser
moves into pack
+ // Test with real Mule 3.x and 4.x fixtures to validate graph structure
+
+ // Test Mule 3.x fixture
Review Comment:
**Exercise the installed pack through the public workflow.** The new test
uses the default `GraphBuilder`, which already registers the Mule parser. I
removed Mule from `MigrationPackRegistry` and all 27 focused graph cases still
passed. Maven discovered zero `MigrationPackTest` cases, and the packaged
catalog contained only `core` and `developer-tasks`. Please register Mule
through the existing pack descriptor, build its test sources in the reactor,
and run these fixtures through the installed catalog. Removing the registration
should then fail the test.
_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,60 @@
+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.
+ */
+public final class CamelGraphAdapter implements GraphTypeAdapter {
+ public static final NodeType ROUTE = new NodeType("camel:route");
+ public static final NodeType ENDPOINT = new NodeType("camel:endpoint");
+ public static final NodeType PROCESSOR = new NodeType("camel:processor");
+ 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() {
+ return Map.ofEntries(
+ Map.entry("CAMEL_ROUTE", ROUTE),
Review Comment:
**Reuse the core Camel route types.** `GraphTypeRegistry` rejects this
adapter because core already owns `CAMEL_ROUTE`, `CAMEL_ENDPOINT` and
`CAMEL_PROCESSOR`. The repository XML fixture produced two core routes, while
the adapter counted zero and returned an empty summary. Use the existing core
types and verify the adapter against a graph produced by the real parser.
_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,120 @@
+package org.apache.camel.kit.packs.camel;
+
+import org.apache.camel.kit.graph.ProjectGraph;
+import org.apache.camel.kit.graph.RuntimeDetector;
+import org.apache.camel.kit.graph.model.GraphTypeAdapter;
+import org.apache.camel.kit.graph.parser.MigrationParser;
+import org.apache.camel.kit.graph.parser.XmlRouteParser;
+import org.apache.camel.kit.graph.parser.JavaGraphParser;
+import org.apache.camel.kit.graph.adapter.camel.CamelGraphAdapter;
+import org.apache.camel.kit.packs.MigrationPack;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * 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(CamelGraphAdapter.ROUTE).size();
+ if (routes > 0 && confidence == 0.0) {
+ confidence = 0.5; // Might be Camel even without version info
+ }
+
+ return confidence;
+ }
+
+ @Override
+ public GraphTypeAdapter getGraphAdapter() {
+ return graphAdapter;
+ }
+
+ @Override
+ public List<MigrationParser> getParsers() {
+ return List.of(
+ new XmlRouteParser(),
+ new JavaGraphParser()
+ );
+ }
+
+ @Override
+ public List<String> getMigrationGuides() {
+ return List.of(
+ "skills/camel-migrate/guides/camel-2x-to-4x.md",
Review Comment:
**Resolve the guides from the built catalog.** All four paths in this list
and all four in `FuseMigrationPack.getMigrationGuides()` were missing from the
packaged catalog. Running packaged `init` with `--source-platform fuse`
recorded the value but installed the same migration instructions as
`--source-platform camel`. Point each pack at shipped guides and test that the
installed workflow can open them for each documented selection.
_AI-generated by Codex on behalf of @luigidemasi._
##########
kit/camel-kit-packs/fuse-migration-pack/src/main/java/org/apache/camel/kit/packs/fuse/FuseMigrationPack.java:
##########
@@ -0,0 +1,138 @@
+package org.apache.camel.kit.packs.fuse;
+
+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.parser.JavaGraphParser;
+import org.apache.camel.kit.graph.parser.MigrationParser;
+import org.apache.camel.kit.graph.parser.XmlRouteParser;
+import org.apache.camel.kit.packs.MigrationPack;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Fuse migration pack - handles JBoss Fuse 6.x and 7.x to modern Camel 4.x
migrations.
+ *
+ * This pack is responsible for:
+ * - Detecting JBoss Fuse 6.x and 7.x projects
+ * - Migrating to Camel 4.x with YAML DSL
+ * - Handling Red Hat-specific components and configurations
+ * - Dealing with Fuse-specific dependencies (redhat-/fuse- version qualifiers)
+ *
+ * Separated from Camel upgrade pack per Issue #200.
+ * Each version (6.x and 7.x) needs separate testing.
+ */
+public class FuseMigrationPack implements MigrationPack {
+
+ private final CamelGraphAdapter graphAdapter = new CamelGraphAdapter();
+
+ @Override
+ public String packId() {
+ return "fuse";
+ }
+
+ @Override
+ public String displayName() {
+ return "JBoss Fuse Migration (6.x/7.x → Camel 4.x)";
+ }
+
+ @Override
+ public List<String> supportedVersions() {
+ // Separate testing required for each version per Issue #200
+ return List.of("6.x", "7.x");
+ }
+
+ @Override
+ public double detectSource(ProjectGraph graph) {
+ // Check for Fuse-specific indicators
+ double confidence = 0.0;
+
+ // Check for redhat-fuse BOM
+ String bomVersion = RuntimeDetector.findArtifactVersion(graph,
"org.jboss.redhat-fuse", "fuse-springboot-bom");
Review Comment:
**Read imported Fuse BOMs from dependency management.** An imported
`org.jboss.redhat-fuse:fuse-springboot-bom` produced no candidate. Adding
`camel.version=2.23.2` selected upstream Camel. `PomParser` records the import
as a managed dependency, while this lookup reads direct artifacts. Please use
the managed BOM evidence for the selected module and cover both POMs. A Red Hat
Camel 3 version also selected Fuse, so the qualifier check needs to distinguish
that product from Fuse 6/7.
_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]