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 6685b9632f8 CAMEL-18151: camel-jbang - Export command for camel-main
6685b9632f8 is described below

commit 6685b9632f833a341fec99e7f8a5d78b59067e38
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Jun 2 13:08:15 2022 +0200

    CAMEL-18151: camel-jbang - Export command for camel-main
---
 .../dsl/jbang/core/commands/ExportCamelMain.java   | 10 +++++-
 .../src/main/resources/assembly/runner.xml         | 34 ++++++++++++++++++
 .../src/main/resources/templates/main-pom.tmpl     | 41 +++++++++++++++++++---
 3 files changed, 80 insertions(+), 5 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
index 7a8fbc135b0..2b8167acbca 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
@@ -160,7 +160,7 @@ class ExportCamelMain extends CamelCommand {
         context = context.replaceFirst("\\{\\{ \\.Version }}", ids[2]);
         context = context.replaceFirst("\\{\\{ \\.JavaVersion }}", 
javaVersion);
         context = context.replaceAll("\\{\\{ \\.CamelVersion }}", 
camelVersion);
-        context = context.replaceFirst("\\{\\{ \\.MainClassname }}", 
packageName + "." + mainClassname);
+        context = context.replaceAll("\\{\\{ \\.MainClassname }}", packageName 
+ "." + mainClassname);
 
         StringBuilder sb = new StringBuilder();
         for (String dep : deps) {
@@ -263,6 +263,9 @@ class ExportCamelMain extends CamelCommand {
         safeCopy(is, new File(srcResourcesDir, "log4j2.properties"));
         is = 
ExportCamelMain.class.getResourceAsStream("/log4j2.component.properties");
         safeCopy(is, new File(srcResourcesDir, "log4j2.component.properties"));
+        // assembly for runner jar
+        is = ExportCamelMain.class.getResourceAsStream("/assembly/runner.xml");
+        safeCopy(is, new File(srcResourcesDir, "assembly/runner.xml"));
     }
 
     private void copySettingsAndProfile(File settings, File profile, File 
targetDir, String packageName) throws Exception {
@@ -312,6 +315,11 @@ class ExportCamelMain extends CamelCommand {
             return;
         }
 
+        File dir = target.getParentFile();
+        if (!dir.exists()) {
+            dir.mkdirs();
+        }
+
         if (!target.exists()) {
             Files.copy(source, target.toPath());
         }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/assembly/runner.xml 
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/assembly/runner.xml
new file mode 100644
index 00000000000..9aba8dd0baf
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/assembly/runner.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<assembly>
+    <id>runner</id>
+    <formats>
+        <format>jar</format>
+    </formats>
+    <includeBaseDirectory>false</includeBaseDirectory>
+    <dependencySets>
+        <dependencySet>
+            <outputDirectory>/</outputDirectory>
+            <useProjectArtifact>true</useProjectArtifact>
+            <unpack>true</unpack>
+            <scope>runtime</scope>
+        </dependencySet>
+    </dependencySets>
+</assembly>
\ No newline at end of file
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-pom.tmpl 
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-pom.tmpl
index d4e4b7044a8..0c08bbbb124 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-pom.tmpl
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-pom.tmpl
@@ -71,6 +71,16 @@
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.10.1</version>
+                <configuration>
+                    <source>${java.version}</source>
+                    <target>${java.version}</target>
+                </configuration>
+            </plugin>
+            <!-- mvn camel:run or mvn camel:dev -->
             <plugin>
                 <groupId>org.apache.camel</groupId>
                 <artifactId>camel-maven-plugin</artifactId>
@@ -78,15 +88,38 @@
                 <configuration>
                     <mainClass>{{ .MainClassname }}</mainClass>
                 </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>prepare-fatjar</goal>
+                        </goals>
+                    </execution>
+                </executions>
             </plugin>
+            <!-- package as runner jar -->
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <version>3.10.1</version>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <version>3.3.0</version>
                 <configuration>
-                    <source>${java.version}</source>
-                    <target>${java.version}</target>
+                    <descriptors>
+                        
<descriptor>src/main/resources/assembly/runner.xml</descriptor>
+                    </descriptors>
+                    <archive>
+                        <manifest>
+                            <mainClass>{{ .MainClassname }}</mainClass>
+                        </manifest>
+                    </archive>
                 </configuration>
+                <executions>
+                    <execution>
+                        <id>make-assembly</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                    </execution>
+                </executions>
             </plugin>
         </plugins>
     </build>

Reply via email to