davsclaus commented on code in PR #28000: URL: https://github.com/apache/camel/pull/28000#discussion_r4302151957
########## docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-test-agent-run.adoc: ########## @@ -0,0 +1,43 @@ + +// AUTO-GENERATED by camel-package-maven-plugin - DO NOT EDIT THIS FILE += camel test agent run + +Runs tests on the agent server + +NOTE: This command is provided by the `test` plugin. Install it with `camel plugin add test`. + + +== Usage + +[source,bash] +---- +camel test agent run [options] +---- + + + +== Options + +[cols="2,5,1,2",options="header"] +|=== +| Option | Description | Default | Type +| `--async` | Should the test engine print verbose test summary information. | | boolean Review Comment: Right, and it is in Citrus: `AgentRun` of Citrus 5.0.2 has this description on `--async`, and its main branch still has it ([AgentRun.java](https://github.com/citrusframework/citrus/blob/main/tools/jbang/src/main/java/org/citrusframework/jbang/cli/commands/AgentRun.java)). The page is generated from the class as it is, so an edit here would be undone by the next build; it needs the fix in Citrus, and then comes with the Citrus upgrade that has it. _Claude Code on behalf of davsclaus_ ########## docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-test-agent-run.adoc: ########## @@ -0,0 +1,43 @@ + +// AUTO-GENERATED by camel-package-maven-plugin - DO NOT EDIT THIS FILE += camel test agent run + +Runs tests on the agent server + +NOTE: This command is provided by the `test` plugin. Install it with `camel plugin add test`. + + +== Usage + +[source,bash] +---- +camel test agent run [options] +---- + + + +== Options + +[cols="2,5,1,2",options="header"] +|=== +| Option | Description | Default | Type +| `--async` | Should the test engine print verbose test summary information. | | boolean +| `--background` | When enabled the command is not blocking for the test result response. | | boolean +| `--dep` | Set of additional Maven dependencies that should be loaded with the agent. | | String[] +| `--engine` | Name of the test engine that is used ti run tests. One of junit, junit-jupiter, junit4, testng, cucumber | | String Review Comment: The same: `ti run tests` is in `AgentRun` and `AgentStart` of Citrus (5.0.2 and its main branch), so it needs the fix in Citrus, and the pages follow with the upgrade that has it. _Claude Code on behalf of davsclaus_ ########## tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelJBangCommandsMojo.java: ########## @@ -375,6 +378,70 @@ private void processSubcommandLine( } } + /** + * The source that registers the commands, for the imports of their classes, or null when it cannot be parsed. + */ + private JavaSource<?> parseSource(File file) { + try { + return Roaster.parse(file) instanceof JavaSource<?> source ? source : null; + } catch (Exception e) { + getLog().debug("Could not parse: " + file + " - " + e.getMessage()); + return null; + } + } + + /** + * The command of a class: from its source when it is one of the command classes, or else from its class on the + * classpath of the project when the source that registers it imports it by name, such as a command of a library + * that a plugin adds as it is (camel test run is the Run of Citrus). + */ + private CommandInfo commandInfo( + String className, Map<String, CommandInfo> commandsByClassName, JavaSource<?> registering) { + CommandInfo info = commandsByClassName.get(className); + if (info == null && registering != null) { + String imported = importedByName(registering, className); + if (imported != null) { + info = parseCommandFromClass(imported); + } + } + return info; + } + + /** + * Parses a command from the picocli annotations of its class on the classpath of the project, read by reflection, + * as picocli is not a dependency of this plugin. + */ + @SuppressWarnings("unchecked") + private CommandInfo parseCommandFromClass(String className) { + try { + ClassLoader loader = getProjectClassLoader(); + Class<?> clazz = loader.loadClass(className); + Annotation command + = clazz.getAnnotation((Class<? extends Annotation>) loader.loadClass("picocli.CommandLine$Command")); + if (command == null) { + return null; + } + CommandInfo info = new CommandInfo(); + info.className = clazz.getSimpleName(); + info.qualifiedName = clazz.getName(); + info.name = (String) attribute(command, "name"); + String description = String.join(" ", (String[]) attribute(command, "description")); + // without the hint to the help, as for a command of the sources + if (description.contains("(use")) { + description = description.substring(0, description.indexOf("(use")).trim(); + } + info.description = description.isEmpty() ? null : description; + info.hidden = (Boolean) attribute(command, "hidden"); + info.deprecated = clazz.isAnnotationPresent(Deprecated.class); + info.options = new ArrayList<>(); + parseOptionsFromClass(className, info.options); + return info; + } catch (Exception | LinkageError e) { + getLog().debug("Could not read the command of class: " + className + " - " + e.getMessage()); Review Comment: Done in the latest commit, for the options of a library class too (both paths): the build warns that the command or the options are then missing from the documentation. None of the 8 camel-jbang modules warns today. _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]
