Skip to content

Commit f2a22b5

Browse files
authored
CAMEL-23438: camel-jbang - Wrapper to install scripts as camel instead of camelw (#23016)
1 parent 1b002ba commit f2a22b5

5 files changed

Lines changed: 50 additions & 16 deletions

File tree

docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ Previously these nodes were flattened to the same level as their parent `choice`
3636
with the tree structure exposed by `getChildren()`. This affects level values reported via JMX (`ManagedProcessor.getLevel()`)
3737
and dev consoles for nodes inside Choice EIP branches.
3838

39+
=== camel-jbang
40+
41+
The `camel wrapper` command now installs the scripts as `camel` instead of `camelw`.
42+
You can use the `--command-name=camelw` to use the old name.
43+
3944
=== camel-yaml-dsl
4045

4146
A new canonical JSON Schema variant (`camelYamlDsl-canonical.json`) has been added alongside the existing classic

docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-wrapper.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ camel wrapper [options]
2020
|===
2121
| Option | Description | Default | Type
2222
| `--camel-version` | Camel version to pin (defaults to current version) | | String
23+
| `--command-name` | The name of the command to use (camel or camelw) | camel | String
2324
| `--dir,--directory` | Directory where wrapper files will be created | . | String
2425
| `--repo-url` | Maven repository URL for downloading the launcher | DEFAULT_REPO_URL | String
2526
| `-h,--help` | Display the help and sub-commands | | boolean

dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
{ "name": "transform", "fullName": "transform", "description": "Transform message or Camel routes", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.TransformCommand", "options": [ { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ], "subcommands": [ { "name": "dataweave", "fullName": "transform dataweave", "description": "Convert DataWeave scripts to DataSonnet format", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.TransformDataWeave", "options": [ { "names": "--expression,-e", "description": "Inline DataWeave expression to convert", "javaType": "java.lang.String", "type": "string" }, { "names": "--include-comments", "description": "Include conversion notes as comments in output", "defaultValue": "true", "javaType": "boolean", "type": "boolean" }, { "names": "--input,-i", "description": "Input .dwl file or directory containing .dwl files", "javaType": "java.lang.String", "type": "string" }, { "names": "--output,-o", "description": "Output .ds file or directory (defaults to stdout)", "javaType": "java.lang.String", "type": "string" }, { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ] }, { "name": "message", "fullName": "transform message", "description": "Transform message from one format to another via an existing running Camel integration", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.action.TransformMessageAction", "options": [ { "names": "--body", "description": "Message body to send (prefix with file: to refer to loading message body from file)", "javaType": "java.lang.String", "type": "string", "required": true }, { "names": "--camel-version", "description": "To run using a different Camel version than the default version.", "javaType": "java.lang.String", "type": "string" }, { "names": "--component", "description": "The component to use for message transformation", "javaType": "java.lang.String", "type": "string" }, { "names": "--dataformat", "description": "The dataformat to use for message transformation", "javaType": "java.lang.String", "type": "string" }, { "names": "--header", "description": "Message header (key=value)", "javaType": "java.util.List", "type": "array" }, { "names": "--language", "description": "The language to use for message transformation", "javaType": "java.lang.String", "type": "string" }, { "names": "--logging-color", "description": "Use colored logging", "defaultValue": "true", "javaType": "boolean", "type": "boolean" }, { "names": "--option", "description": "Option for additional configuration of the used language, component or dataformat (key=value)", "javaType": "java.util.List", "type": "array" }, { "names": "--output", "description": "File to store output. If none provide then output is printed to console.", "javaType": "java.lang.String", "type": "string" }, { "names": "--pretty", "description": "Pretty print message body when using JSon or XML format", "javaType": "boolean", "type": "boolean" }, { "names": "--repo,--repos", "description": "Additional maven repositories (Use commas to separate multiple repositories)", "javaType": "java.lang.String", "type": "string" }, { "names": "--show-body", "description": "Show message body from the output message", "defaultValue": "true", "javaType": "boolean", "type": "boolean" }, { "names": "--show-exception", "description": "Show exception and stacktrace for failed transformation", "defaultValue": "true", "javaType": "boolean", "type": "boolean" }, { "names": "--show-exchange-properties", "description": "Show exchange properties from the output message", "defaultValue": "false", "javaType": "boolean", "type": "boolean" }, { "names": "--show-headers", "description": "Show message headers from the output message", "defaultValue": "true", "javaType": "boolean", "type": "boolean" }, { "names": "--source", "description": "Instead of using external template file then refer to an existing Camel route source with inlined Camel language expression in a route. (use :line-number or :id to refer to the exact location of the EIP to use)", "javaType": "java.lang.String", "type": "string" }, { "names": "--template", "description": "The template to use for message transformation (prefix with file: to refer to loading template from file)", "javaType": "java.lang.String", "type": "string" }, { "names": "--timeout", "description": "Timeout in millis waiting for message to be transformed", "defaultValue": "20000", "javaType": "long", "type": "integer" }, { "names": "--watch", "description": "Execute periodically and showing output fullscreen", "javaType": "boolean", "type": "boolean" }, { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ] }, { "name": "route", "fullName": "transform route", "description": "Transform Camel routes to XML or YAML format", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.TransformRoute", "options": [ { "names": "--format", "description": "Output format (xml, yaml), if only yaml files are provided, the format defaults to xml and vice versa", "javaType": "java.lang.String", "type": "string" }, { "names": "--ignore-loading-error", "description": "Whether to ignore route loading and compilation errors (use this with care!)", "javaType": "boolean", "type": "boolean" }, { "names": "--output", "description": "File or directory to store transformed files. If none provide then output is printed to console. Use clipboard as name to copy content into clipboard.", "javaType": "java.lang.String", "type": "string" }, { "names": "--resolve-placeholders", "description": "Whether to resolve property placeholders in the dumped output", "defaultValue": "false", "javaType": "boolean", "type": "boolean" }, { "names": "--uri-as-parameters", "description": "Whether to expand URIs into separated key\/value parameters (only in use for YAML format)", "defaultValue": "true", "javaType": "boolean", "type": "boolean" }, { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ] } ] },
3333
{ "name": "update", "fullName": "update", "description": "Update Camel project", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.update.UpdateCommand", "options": [ { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ], "subcommands": [ { "name": "list", "fullName": "update list", "description": "List available update versions for Camel and its runtime variants", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.update.UpdateList", "options": [ { "names": "--json", "description": "Output in JSON Format", "javaType": "boolean", "type": "boolean" }, { "names": "--repo,--repos", "description": "Additional maven repositories for download on-demand (Use commas to separate multiple repositories)", "javaType": "java.lang.String", "type": "string" }, { "names": "--use-cache", "description": "Use Maven cache", "javaType": "boolean", "type": "boolean" }, { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ] }, { "name": "run", "fullName": "update run", "description": "Update Camel project", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.update.UpdateRun", "options": [ { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ] } ] },
3434
{ "name": "version", "fullName": "version", "description": "Manage Camel versions", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.version.VersionCommand", "options": [ { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ], "subcommands": [ { "name": "get", "fullName": "version get", "description": "Displays current Camel version", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.version.VersionGet", "options": [ { "names": "--global", "description": "Use global or local configuration", "javaType": "boolean", "type": "boolean" }, { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ] }, { "name": "list", "fullName": "version list", "description": "Displays available Camel versions", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.version.VersionList", "options": [ { "names": "--date-format", "description": "The format to show the date (such as dd-MM-yyyy)", "defaultValue": "DEFAULT_DATE_FORMAT", "javaType": "java.lang.String", "type": "string" }, { "names": "--days", "description": "Whether to include days since release", "defaultValue": "true", "javaType": "boolean", "type": "boolean" }, { "names": "--download", "description": "Whether to allow automatic downloading JAR dependencies (over the internet)", "defaultValue": "true", "javaType": "boolean", "type": "boolean" }, { "names": "--eol", "description": "Include releases that are end-of-life", "defaultValue": "true", "javaType": "boolean", "type": "boolean" }, { "names": "--fresh", "description": "Make sure we use fresh (i.e. non-cached) resources", "defaultValue": "false", "javaType": "boolean", "type": "boolean" }, { "names": "--from-date", "description": "Filter by release date (inclusive)", "javaType": "java.lang.String", "type": "string" }, { "names": "--from-version", "description": "Filter by Camel version (inclusive). Will start from 4.0 if no version ranges provided.", "javaType": "java.lang.String", "type": "string" }, { "names": "--json", "description": "Output in JSON Format", "defaultValue": "false", "javaType": "boolean", "type": "boolean" }, { "names": "--lts", "description": "Only show LTS supported releases", "defaultValue": "false", "javaType": "boolean", "type": "boolean" }, { "names": "--patch", "description": "Whether to include patch releases (x.y.z)", "defaultValue": "true", "javaType": "boolean", "type": "boolean" }, { "names": "--rc", "description": "Include also milestone or RC releases", "defaultValue": "false", "javaType": "boolean", "type": "boolean" }, { "names": "--repo,--repos", "description": "Additional maven repositories (Use commas to separate multiple repositories)", "javaType": "java.lang.String", "type": "string" }, { "names": "--runtime", "description": "Runtime (camel-main, spring-boot, quarkus)", "defaultValue": "camel-main", "javaType": "org.apache.camel.dsl.jbang.core.common.RuntimeType", "type": "object" }, { "names": "--sort", "description": "Sort by (version, date, or days)", "defaultValue": "version", "javaType": "java.lang.String", "type": "string" }, { "names": "--tail", "description": "The number of lines from the end of the table to show.", "javaType": "int", "type": "integer" }, { "names": "--to-date", "description": "Filter by release date (exclusive)", "javaType": "java.lang.String", "type": "string" }, { "names": "--to-version", "description": "Filter by Camel version (exclusive)", "javaType": "java.lang.String", "type": "string" }, { "names": "--vendor", "description": "Vendor of Apache Camel distribution to use when filtering versions", "javaType": "java.lang.String", "type": "string" }, { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ] }, { "name": "set", "fullName": "version set", "description": "Set\/change current Camel version", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.version.VersionSet", "options": [ { "names": "--global", "description": "Use global or local configuration", "javaType": "boolean", "type": "boolean" }, { "names": "--repo,--repos", "description": "Maven repository for downloading the dependencies (Use commas to separate multiple repositories)", "javaType": "java.lang.String", "type": "string" }, { "names": "--reset", "description": "Reset by removing any custom version settings", "javaType": "boolean", "type": "boolean" }, { "names": "--runtime", "description": "Runtime (camel-main, spring-boot, quarkus)", "javaType": "org.apache.camel.dsl.jbang.core.common.RuntimeType", "type": "object" }, { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ] } ] },
35-
{ "name": "wrapper", "fullName": "wrapper", "description": "Install Camel wrapper scripts for version pinning", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.WrapperCommand", "options": [ { "names": "--camel-version", "description": "Camel version to pin (defaults to current version)", "javaType": "java.lang.String", "type": "string" }, { "names": "--dir,--directory", "description": "Directory where wrapper files will be created", "defaultValue": ".", "javaType": "java.lang.String", "type": "string" }, { "names": "--repo-url", "description": "Maven repository URL for downloading the launcher", "defaultValue": "DEFAULT_REPO_URL", "javaType": "java.lang.String", "type": "string" }, { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ] }
35+
{ "name": "wrapper", "fullName": "wrapper", "description": "Install Camel wrapper scripts for version pinning", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.WrapperCommand", "options": [ { "names": "--camel-version", "description": "Camel version to pin (defaults to current version)", "javaType": "java.lang.String", "type": "string" }, { "names": "--command-name", "description": "The name of the command to use (camel or camelw)", "defaultValue": "camel", "javaType": "java.lang.String", "type": "string" }, { "names": "--dir,--directory", "description": "Directory where wrapper files will be created", "defaultValue": ".", "javaType": "java.lang.String", "type": "string" }, { "names": "--repo-url", "description": "Maven repository URL for downloading the launcher", "defaultValue": "DEFAULT_REPO_URL", "javaType": "java.lang.String", "type": "string" }, { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ] }
3636
]
3737
}

dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/WrapperCommand.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
footer = {
3636
"%nExamples:",
3737
" camel wrapper",
38-
" camel wrapper --camel-version=4.10.0" })
38+
" camel wrapper --camel-version=4.18.2" })
3939
public class WrapperCommand extends CamelCommand {
4040

4141
private static final String DEFAULT_REPO_URL = "https://repo1.maven.org/maven2";
@@ -56,6 +56,10 @@ public class WrapperCommand extends CamelCommand {
5656
defaultValue = ".")
5757
String directory = ".";
5858

59+
@CommandLine.Option(names = { "--command-name" },
60+
description = "The name of the command to use (camel or camelw)", defaultValue = "camel")
61+
String commandName = "camel";
62+
5963
public WrapperCommand(CamelJBangMain main) {
6064
super(main);
6165
}
@@ -77,18 +81,18 @@ public Integer doCall() throws Exception {
7781
writeProperties(camelDir);
7882

7983
// Write camelw script
80-
writeScript(baseDir, "camelw");
84+
writeScript(baseDir, "camelw", commandName);
8185

8286
// Write camelw.cmd script
83-
writeScript(baseDir, "camelw.cmd");
87+
writeScript(baseDir, "camelw.cmd", commandName + ".cmd");
8488

8589
printer().println("Apache Camel wrapper installed successfully.");
8690
printer().println(" Camel version: " + camelVersion);
8791
printer().println(" Properties: " + camelDir.resolve(WRAPPER_PROPERTIES_FILE));
88-
printer().println(" Unix script: " + baseDir.resolve("camelw"));
89-
printer().println(" Windows script: " + baseDir.resolve("camelw.cmd"));
92+
printer().println(" Unix script: " + baseDir.resolve(commandName));
93+
printer().println(" Windows script: " + baseDir.resolve(commandName + ".cmd"));
9094
printer().println();
91-
printer().println("You can now use ./camelw instead of camel to run with the pinned version.");
95+
printer().println("You can now use ./" + commandName + " instead of camel to run with the pinned version.");
9296

9397
return 0;
9498
}
@@ -128,18 +132,18 @@ String buildDistributionUrl() {
128132
+ ".jar";
129133
}
130134

131-
void writeScript(Path baseDir, String scriptName) throws IOException {
132-
String resourcePath = "camel-wrapper/" + scriptName;
135+
void writeScript(Path baseDir, String source, String commandName) throws IOException {
136+
String resourcePath = "camel-wrapper/" + source;
133137
try (InputStream is = WrapperCommand.class.getClassLoader().getResourceAsStream(resourcePath)) {
134138
if (is == null) {
135139
throw new IOException("Resource not found: " + resourcePath);
136140
}
137141
String content = IOHelper.loadText(is);
138-
Path scriptPath = baseDir.resolve(scriptName);
142+
Path scriptPath = baseDir.resolve(commandName);
139143
Files.writeString(scriptPath, content);
140144

141145
// Make Unix script executable
142-
if (!scriptName.endsWith(".cmd")) {
146+
if (!commandName.endsWith(".cmd")) {
143147
makeExecutable(scriptPath);
144148
}
145149
}

0 commit comments

Comments
 (0)