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


The following commit(s) were added to refs/heads/main by this push:
     new c9018877654 CAMEL-18823: camel-jbang - Add dependency copy command.
c9018877654 is described below

commit c90188776544cb30730f50da9ff8e440e7e0e303
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon Dec 19 08:25:57 2022 +0100

    CAMEL-18823: camel-jbang - Add dependency copy command.
---
 .../ROOT/pages/camel-3x-upgrade-guide-3_21.adoc    |  12 +++
 .../modules/ROOT/pages/camel-3x-upgrade-guide.adoc |   1 +
 .../modules/ROOT/pages/camel-jbang.adoc            |  30 +++++-
 .../dsl/jbang/core/commands/CamelJBangMain.java    |   5 +-
 .../dsl/jbang/core/commands/DependencyCommand.java |  36 +++++++
 .../dsl/jbang/core/commands/DependencyCopy.java    | 107 +++++++++++++++++++++
 .../{DependencyTree.java => DependencyList.java}   |   6 +-
 7 files changed, 189 insertions(+), 8 deletions(-)

diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc
new file mode 100644
index 00000000000..c2dd69ba82c
--- /dev/null
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc
@@ -0,0 +1,12 @@
+= Apache Camel 3.x Upgrade Guide
+
+This document is for helping you upgrade your Apache Camel application
+from Camel 3.x to 3.y. For example if you are upgrading Camel 3.0 to 3.2, then 
you should follow the guides
+from both 3.0 to 3.1 and 3.1 to 3.2.
+
+== Upgrading Camel 3.20 to 3.21
+
+=== camel-jbang
+
+The command `camel dependencies` has been renamed to `camel dependency`.
+
diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc
index 0cc3616710d..4d7726ae722 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc
@@ -29,3 +29,4 @@ You can find upgrade guide for each release in the following 
pages:
 - xref:camel-3x-upgrade-guide-3_18.adoc[Upgrade guide 3.17 -> 3.18]
 - xref:camel-3x-upgrade-guide-3_19.adoc[Upgrade guide 3.18 -> 3.19]
 - xref:camel-3x-upgrade-guide-3_20.adoc[Upgrade guide 3.19 -> 3.20]
+- xref:camel-3x-upgrade-guide-3_21.adoc[Upgrade guide 3.20 -> 3.21]
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index 0ce9a508fae..7dc872dd7ab 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -1354,7 +1354,7 @@ you do not have to use a build system like Maven or 
Gradle to add every Camel co
 as a dependency.
 
 However, you may want to know what dependencies are required to run the Camel 
integration.
-To see this, you can use the `dependencies` command. The command output does 
not output a detailed
+To see this, you can use the `dependency` command. The command output does not 
output a detailed
 tree, such as `mvn dependencies:tree`, as the output is intended to list which 
Camel components,
 and other JARs needed (when using Kamelets).
 
@@ -1362,7 +1362,7 @@ The dependency output by default is _vanilla_ Apache 
Camel with the camel-main a
 
 [source,bash]
 ----
-camel dependencies
+camel dependency
 org.apache.camel:camel-dsl-modeline:3.20.0
 org.apache.camel:camel-health:3.20.0
 org.apache.camel:camel-kamelet:3.20.0
@@ -1381,7 +1381,7 @@ You can also specify the output should be in _Maven 
format_ as shown:
 
 [source,bash]
 ----
-camel dependencies --output=maven
+camel dependency --output=maven
 <dependency>
     <groupId>org.apache.camel</groupId>
     <artifactId>camel-main</artifactId>
@@ -1443,7 +1443,7 @@ You can also choose the target runtime as either 
_quarkus_ or _spring-boot_ as s
 
 [source,bash]
 ----
-camel dependencies --runtime=spring-boot
+camel dependency --runtime=spring-boot
 org.springframework.boot:spring-boot-starter-actuator:2.7.5
 org.springframework.boot:spring-boot-starter-web:2.7.5
 org.apache.camel.springboot:camel-spring-boot-engine-starter:3.20.0
@@ -1458,6 +1458,28 @@ org.apache.camel.kamelets:camel-kamelets-utils:0.9.3
 org.apache.camel.kamelets:camel-kamelets:0.9.3
 ----
 
+=== Copying dependency JARs to a specific directory
+
+You can use the `camel dependency copy` command to copy the required JARs to a 
specific folder.
+This command reuses Maven by invoking the `mvn dependency:copy-dependencies` 
command.
+
+By default, the JARs are copied to `lib` folder:
+
+[source,bash]
+----
+camel dependency copy
+ls lib
+camel-api-3.21.0.jar                    camel-health-3.21.0.jar                
 camel-yaml-dsl-3.21.0.jar
+camel-base-3.21.0.jar                   camel-main-3.21.0.jar                  
 camel-yaml-dsl-common-3.21.0.jar
+camel-base-engine-3.21.0.jar            camel-management-api-3.21.0.jar        
 camel-yaml-dsl-deserializers-3.21.0.jar
+camel-core-engine-3.21.0.jar            camel-rest-3.21.0.jar                  
 jakarta.activation-api-1.2.2.jar
+camel-core-languages-3.21.0.jar         camel-support-3.21.0.jar               
 jakarta.xml.bind-api-2.3.3.jar
+camel-core-model-3.21.0.jar             camel-timer-3.21.0.jar                 
 slf4j-api-1.7.36.jar
+camel-core-processor-3.21.0.jar         camel-tooling-model-3.21.0.jar         
 snakeyaml-engine-2.3.jar
+camel-core-reifier-3.21.0.jar           camel-util-3.21.0.jar
+camel-dsl-support-3.21.0.jar            camel-util-json-3.21.0.jar
+----
+
 == Creating Projects
 
 You can _export_ your Camel JBang integration to a traditional Java based 
project such as Spring Boot or Quarkus.
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
index 49ed050991b..9c487c6800c 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
@@ -103,6 +103,9 @@ public class CamelJBangMain implements Callable<Integer> {
                         .addSubcommand("thread-dump", new CommandLine(new 
CamelThreadDump(main)))
                         .addSubcommand("logger", new CommandLine(new 
LoggerAction(main)))
                         .addSubcommand("gc", new CommandLine(new 
CamelGCAction(main))))
+                .addSubcommand("dependency", new CommandLine(new 
DependencyCommand(main))
+                        .addSubcommand("list", new CommandLine(new 
DependencyList(main)))
+                        .addSubcommand("copy", new CommandLine(new 
DependencyCopy(main))))
                 .addSubcommand("generate", new CommandLine(new 
CodeGenerator(main))
                         .addSubcommand("rest", new CommandLine(new 
CodeRestGenerator(main))))
                 .addSubcommand("catalog", new CommandLine(new 
CatalogCommand(main))
@@ -116,7 +119,7 @@ public class CamelJBangMain implements Callable<Integer> {
                 .addSubcommand("hawtio", new CommandLine(new Hawtio(main)))
                 .addSubcommand("bind", new CommandLine(new Bind(main)))
                 .addSubcommand("pipe", new CommandLine(new Pipe(main)))
-                .addSubcommand("dependencies", new CommandLine(new 
DependencyTree(main)))
+                .addSubcommand("dependencies", new CommandLine(new 
DependencyList(main)))
                 .addSubcommand("export", new CommandLine(new Export(main)))
                 .addSubcommand("completion", new CommandLine(new 
Complete(main)));
 
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyCommand.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyCommand.java
new file mode 100644
index 00000000000..e34619741ec
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyCommand.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+import picocli.CommandLine;
+
+@CommandLine.Command(name = "dependency",
+                     description = "Displays all Camel dependencies required 
to run (use dependency --help to see sub commands)")
+public class DependencyCommand extends CamelCommand {
+
+    public DependencyCommand(CamelJBangMain main) {
+        super(main);
+    }
+
+    @Override
+    public Integer call() throws Exception {
+        // default to list
+        new CommandLine(new DependencyList(getMain())).execute();
+        return 0;
+    }
+
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyCopy.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyCopy.java
new file mode 100644
index 00000000000..bd033fa954f
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyCopy.java
@@ -0,0 +1,107 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.dsl.jbang.core.common.RuntimeUtil;
+import org.apache.camel.util.CamelCaseOrderedProperties;
+import org.apache.camel.util.FileUtil;
+import picocli.CommandLine;
+
+@CommandLine.Command(name = "copy",
+                     description = "Copies all Camel dependencies required to 
run to a specific directory")
+public class DependencyCopy extends Export {
+
+    protected static final String EXPORT_DIR = ".camel-jbang/export";
+
+    @CommandLine.Option(names = { "--output-directory" }, description = 
"Directory where dependencies should be copied",
+                        defaultValue = "lib", required = true)
+    protected String outputDirectory;
+
+    public DependencyCopy(CamelJBangMain main) {
+        super(main);
+    }
+
+    @Override
+    protected Integer export() throws Exception {
+        this.quiet = true; // be quiet and generate from fresh data to ensure 
the output is up-to-date
+
+        Integer answer = doExport();
+        if (answer == 0) {
+            File buildDir = new File(EXPORT_DIR);
+            Process p = Runtime.getRuntime()
+                    .exec("mvn dependency:copy-dependencies 
-DincludeScope=compile 
-DexcludeGroupIds=org.fusesource.jansi,org.apache.logging.log4j 
-DoutputDirectory=../../"
+                          + outputDirectory,
+                            null,
+                            buildDir);
+            boolean done = p.waitFor(30, TimeUnit.SECONDS);
+            if (!done) {
+                answer = 1;
+            }
+            // cleanup dir after complete
+            FileUtil.removeDir(buildDir);
+        }
+        return answer;
+    }
+
+    protected Integer doExport() throws Exception {
+        // read runtime and gav from profile if not configured
+        File profile = new File(getProfile() + ".properties");
+        if (profile.exists()) {
+            Properties prop = new CamelCaseOrderedProperties();
+            RuntimeUtil.loadProperties(prop, profile);
+            if (this.runtime == null) {
+                this.runtime = prop.getProperty("camel.jbang.runtime");
+            }
+            if (this.gav == null) {
+                this.gav = prop.getProperty("camel.jbang.gav");
+            }
+            // allow configuring versions from profile
+            this.javaVersion = prop.getProperty("camel.jbang.javaVersion", 
this.javaVersion);
+            this.kameletsVersion = 
prop.getProperty("camel.jbang.kameletsVersion", this.kameletsVersion);
+            this.localKameletDir = 
prop.getProperty("camel.jbang.localKameletDir", this.localKameletDir);
+            this.quarkusGroupId = 
prop.getProperty("camel.jbang.quarkusGroupId", this.quarkusGroupId);
+            this.quarkusArtifactId = 
prop.getProperty("camel.jbang.quarkusArtifactId", this.quarkusArtifactId);
+            this.quarkusVersion = 
prop.getProperty("camel.jbang.quarkusVersion", this.quarkusVersion);
+            this.springBootVersion = 
prop.getProperty("camel.jbang.springBootVersion", this.springBootVersion);
+        }
+
+        // use temporary export dir
+        exportDir = EXPORT_DIR;
+        if (gav == null) {
+            gav = "org.apache.camel:camel-jbang-dummy:1.0";
+        }
+        if (runtime == null) {
+            runtime = "camel-main";
+        }
+
+        if ("spring-boot".equals(runtime) || 
"camel-spring-boot".equals(runtime)) {
+            return export(new ExportSpringBoot(getMain()));
+        } else if ("quarkus".equals(runtime) || 
"camel-quarkus".equals(runtime)) {
+            return export(new ExportQuarkus(getMain()));
+        } else if ("main".equals(runtime) || "camel-main".equals(runtime)) {
+            return export(new ExportCamelMain(getMain()));
+        } else {
+            System.err.println("Unknown runtime: " + runtime);
+            return 1;
+        }
+    }
+
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyTree.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyList.java
similarity index 98%
rename from 
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyTree.java
rename to 
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyList.java
index 040150d1123..3dc475b2cad 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyTree.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyList.java
@@ -35,16 +35,16 @@ import org.apache.camel.util.CamelCaseOrderedProperties;
 import org.apache.camel.util.FileUtil;
 import picocli.CommandLine;
 
-@CommandLine.Command(name = "dependencies",
+@CommandLine.Command(name = "list",
                      description = "Displays all Camel dependencies required 
to run")
-public class DependencyTree extends Export {
+public class DependencyList extends Export {
 
     protected static final String EXPORT_DIR = ".camel-jbang/export";
 
     @CommandLine.Option(names = { "--output" }, description = "Output format 
(gav or maven)", defaultValue = "gav")
     protected String output;
 
-    public DependencyTree(CamelJBangMain main) {
+    public DependencyList(CamelJBangMain main) {
         super(main);
     }
 

Reply via email to