davsclaus commented on code in PR #30239:
URL: https://github.com/apache/camel/pull/30239#discussion_r4596717969


##########
dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgentStart.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.dsl.jbang.core.commands.test;
+
+import org.aesh.command.CommandException;
+import org.aesh.command.CommandResult;
+import org.aesh.command.invocation.CommandInvocation;
+import org.apache.camel.dsl.jbang.run.common.RuntimeUtil;
+import org.citrusframework.jbang.cli.CitrusJBangMain;
+import org.citrusframework.jbang.cli.commands.AgentStart;
+
+/**
+ * Resolves citrus-agent artifacts into the plugin classloader before the 
Citrus agent start command runs. This avoids a
+ * classloader identity conflict in {@code 
ClassLoaderHelper.instantiateType()}: the Citrus {@code AgentStart} command
+ * dynamically resolves the citrus-agent module and wraps the TCCL in an 
{@code OpenURLClassLoader}. When the plugin
+ * runs inside Camel JBang, the {@code CitrusAgentConfiguration} class loaded 
by that wrapper can differ (by classloader
+ * identity) from the one on the plugin classloader, causing the constructor 
lookup to fail. Pre-loading the artifacts
+ * into the plugin classloader keeps everything on one classloader so the 
identity check passes.
+ */
+public class TestAgentStart extends AgentStart {
+
+    public TestAgentStart(CitrusJBangMain citrus) {
+        super(citrus);
+    }
+
+    @Override
+    public CommandResult execute(CommandInvocation invocation) throws 
CommandException, InterruptedException {
+        return TestPlugin.withClassLoader(inv -> {
+            try {
+                RuntimeUtil.configureLog("info", true, false, false, false, 
null, null);
+            } catch (Exception e) {
+                printer().printErr("Failed to configure logging for agent 
start command '%s': %s"
+                        .formatted(e.getClass(), e.getMessage()));

Review Comment:
   Fixed in c2e4374: `TestAgentStart` now uses `e.getClass().getName()`.
   
   _Claude Code on behalf of davsclaus_



##########
dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestRun.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.dsl.jbang.core.commands.test;
+
+import org.aesh.command.CommandException;
+import org.aesh.command.CommandResult;
+import org.aesh.command.invocation.CommandInvocation;
+import org.apache.camel.catalog.VersionHelper;
+import org.apache.camel.dsl.jbang.run.common.RuntimeUtil;
+import org.citrusframework.CitrusVersion;
+import org.citrusframework.jbang.cli.CitrusJBangMain;
+import org.citrusframework.jbang.cli.commands.Run;
+
+/**
+ * Sets the Camel JBang version and adjusts the thread context class loader 
for the duration of the Citrus test run so
+ * that Citrus can resolve its resources.
+ */
+public class TestRun extends Run {
+
+    public TestRun(CitrusJBangMain citrus) {
+        super(citrus);
+    }
+
+    @Override
+    public CommandResult execute(CommandInvocation invocation) throws 
CommandException, InterruptedException {
+        System.setProperty("citrus.jbang.version", CitrusVersion.version());
+        System.setProperty("citrus.camel.jbang.version", new 
VersionHelper().getVersion());
+
+        return TestPlugin.withClassLoader(inv -> {
+            configureLogging();
+            return super.execute(inv);
+        }, invocation);
+    }
+
+    /**
+     * Reconfigure the existing Log4j2 context so that Citrus SLF4J log output 
appears on the console. Citrus's
+     * LoggingSupport creates a separate named context that the SLF4J loggers 
do not use.
+     */
+    private void configureLogging() {
+        try {
+            boolean logging = TestPlugin.readField(Run.class, "logging", this);
+            boolean loggingColor = TestPlugin.readField(Run.class, 
"loggingColor", this);
+            String loggingLevel = TestPlugin.readField(Run.class, 
"loggingLevel", this);
+
+            if (logging) {
+                RuntimeUtil.configureLog(loggingLevel, loggingColor, false, 
false, false, null, null);
+            } else {
+                RuntimeUtil.configureLog("off", false, false, false, false, 
null, null);
+            }
+        } catch (Exception e) {
+            printer().printErr("Failed to configure logging for run command 
'%s': %s"
+                    .formatted(e.getClass(), e.getMessage()));

Review Comment:
   Fixed in c2e4374: `TestRun` now uses `e.getClass().getName()`.
   
   _Claude Code on behalf of davsclaus_



##########
dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestRun.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.dsl.jbang.core.commands.test;
+
+import org.aesh.command.CommandException;
+import org.aesh.command.CommandResult;
+import org.aesh.command.invocation.CommandInvocation;
+import org.apache.camel.catalog.VersionHelper;
+import org.apache.camel.dsl.jbang.run.common.RuntimeUtil;
+import org.citrusframework.CitrusVersion;
+import org.citrusframework.jbang.cli.CitrusJBangMain;
+import org.citrusframework.jbang.cli.commands.Run;
+
+/**
+ * Sets the Camel JBang version and adjusts the thread context class loader 
for the duration of the Citrus test run so
+ * that Citrus can resolve its resources.
+ */
+public class TestRun extends Run {
+
+    public TestRun(CitrusJBangMain citrus) {
+        super(citrus);
+    }
+
+    @Override
+    public CommandResult execute(CommandInvocation invocation) throws 
CommandException, InterruptedException {
+        System.setProperty("citrus.jbang.version", CitrusVersion.version());
+        System.setProperty("citrus.camel.jbang.version", new 
VersionHelper().getVersion());

Review Comment:
   Fixed in c2e4374: both properties are now set in 
`TestPlugin.withClassLoader`, which every wrapped Citrus command goes through, 
`agent start` included.
   
   _Claude Code on behalf of davsclaus_



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