This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7d3e0924f0844b5cb64bd04f622e91658fb896a2 Author: Claus Ibsen <[email protected]> AuthorDate: Fri Jun 17 14:33:29 2022 +0200 CAMEL-18151: camel-jbang - Export read from application.properties runtime/gav to use --- .../modules/ROOT/pages/camel-jbang.adoc | 24 ++++++++++---------- .../camel/dsl/jbang/core/commands/Export.java | 26 ++++++++++++++++++++++ .../dsl/jbang/core/commands/ExportBaseCommand.java | 4 ++-- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc index 5d10e16088f..876f4ae3b88 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc @@ -611,7 +611,7 @@ runtimes of Spring Boot, Quarkus or vanilla Camel Main. === Exporting to Camel Spring Boot -The command `export spring-boot` will export your current Camel JBang file(s) to a Maven based +The command `export --runtime=spring-boot` will export your current Camel JBang file(s) to a Maven based Spring Boot project with files organized in `src/main/` folder structure. For example to export to Spring Boot using the Maven groupId _com.foo_ and the artifactId _acme_ @@ -619,7 +619,7 @@ and with version _1.0-SNAPSHOT_ you simply execute: [source,bash] ---- -camel export spring-boot --gav=com.foo:acme:1.0-SNAPSHOT +camel export --runtime=spring-boot --gav=com.foo:acme:1.0-SNAPSHOT ---- NOTE: This will export to the _current_ directory, meaning that files are moved into the needed folder structure. @@ -628,14 +628,14 @@ To export to another directly (copies the files) you execute: [source,bash] ---- -camel export spring-boot --gav=com.foo:acme:1.0-SNAPSHOT --dir=../myproject +camel export --runtime=spring-boot --gav=com.foo:acme:1.0-SNAPSHOT --dir=../myproject ---- -TIP: See the possible options by running: `camel export spring-boot --help` for more details. +TIP: See the possible options by running: `camel export --help` for more details. === Exporting to Camel Quarkus -The command `export quarkus` will export your current Camel JBang file(s) to a Maven based +The command `export --runtime=quarkus` will export your current Camel JBang file(s) to a Maven based Quarkus project with files organized in `src/main/` folder structure. For example to export to Quarkus using the Maven groupId _com.foo_ and the artifactId _acme_ @@ -643,7 +643,7 @@ and with version _1.0-SNAPSHOT_ you simply execute: [source,bash] ---- -camel export quarkus --gav=com.foo:acme:1.0-SNAPSHOT +camel export --runtime=quarkus --gav=com.foo:acme:1.0-SNAPSHOT ---- NOTE: This will export to the _current_ directory, meaning that files are moved into the needed folder structure. @@ -652,14 +652,14 @@ To export to another directly (copies the files) you execute: [source,bash] ---- -camel export quarkus --gav=com.foo:acme:1.0-SNAPSHOT --dir=../myproject +camel export --runtime=quarkus --gav=com.foo:acme:1.0-SNAPSHOT --dir=../myproject ---- -TIP: See the possible options by running: `camel export quarkus --help` for more details. +TIP: See the possible options by running: `camel export --help` for more details. === Exporting to Camel Main -The command `export camel-main` will export your current Camel JBang file(s) to a Maven based +The command `export --runtime=camel-main` will export your current Camel JBang file(s) to a Maven based vanilla Camel Main project with files organized in `src/main/` folder structure. For example to export to Camel Main using the Maven groupId _com.foo_ and the artifactId _acme_ @@ -667,7 +667,7 @@ and with version _1.0-SNAPSHOT_ you simply execute: [source,bash] ---- -camel export camel-main --gav=com.foo:acme:1.0-SNAPSHOT +camel export --runtime=camel-main --gav=com.foo:acme:1.0-SNAPSHOT ---- NOTE: This will export to the _current_ directory, meaning that files are moved into the needed folder structure. @@ -676,10 +676,10 @@ To export to another directly (copies the files) you execute: [source,bash] ---- -camel export camel-main --gav=com.foo:acme:1.0-SNAPSHOT --dir=../myproject +camel export --runtime=camel-main --gav=com.foo:acme:1.0-SNAPSHOT --dir=../myproject ---- -TIP: See the possible options by running: `camel export camel-main --help` for more details. +TIP: See the possible options by running: `camel export --help` for more details. == Troubleshooting diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java index b627ea208e6..0a6ae68b4fb 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java @@ -16,8 +16,12 @@ */ package org.apache.camel.dsl.jbang.core.commands; +import org.apache.camel.util.OrderedProperties; import picocli.CommandLine.Command; +import java.io.File; +import java.io.FileInputStream; + @Command(name = "export", description = "Export to other runtimes such as Spring Boot or Quarkus") class Export extends ExportBaseCommand { @@ -28,6 +32,28 @@ class Export extends ExportBaseCommand { @Override protected Integer export() throws Exception { + // read runtime and gav from profile if not configured + File profile = new File(getProfile() + ".properties"); + if (profile.exists()) { + OrderedProperties prop = new OrderedProperties(); + prop.load(new FileInputStream(profile)); + if (this.runtime == null) { + this.runtime = prop.getProperty("camel.jbang.runtime"); + } + if (this.gav == null) { + this.gav = prop.getProperty("camel.jbang.gav"); + } + } + + if (runtime == null) { + System.err.println("The runtime option must be specified"); + return 1; + } + if (gav == null) { + System.err.println("The gav option must be specified"); + return 1; + } + if ("spring-boot".equals(runtime)) { return export(new ExportSpringBoot(getMain())); } else if ("quarkus".equals(runtime)) { diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java index 94a9d1a0718..b84181d6295 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java @@ -56,10 +56,10 @@ abstract class ExportBaseCommand extends CamelCommand { "camel.jbang.classpathFiles" }; - @CommandLine.Option(names = { "--runtime" }, description = "Runtime (spring-boot, quarkus, or camel-main)", required = true) + @CommandLine.Option(names = { "--runtime" }, description = "Runtime (spring-boot, quarkus, or camel-main)") protected String runtime; - @CommandLine.Option(names = { "--gav" }, description = "The Maven group:artifact:version", required = true) + @CommandLine.Option(names = { "--gav" }, description = "The Maven group:artifact:version") protected String gav; @CommandLine.Option(names = { "--main-classname" },
