You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/04/26 08:02:40 UTC

[camel] branch main updated: CAMEL-17998: camel-jbang - fat-jar command

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 361b0897e57 CAMEL-17998: camel-jbang - fat-jar command
361b0897e57 is described below

commit 361b0897e57d9803f7781a9090b8cd3d7e313f83
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Apr 26 10:02:24 2022 +0200

    CAMEL-17998: camel-jbang - fat-jar command
---
 .../camel/dsl/jbang/core/commands/FatJar.java      | 29 ++++++++++++++++++----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/FatJar.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/FatJar.java
index 7172a94d96a..9a5093cc240 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/FatJar.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/FatJar.java
@@ -22,6 +22,7 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.net.URI;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.StandardCopyOption;
 import java.util.HashMap;
@@ -76,9 +77,8 @@ class FatJar implements Callable<Integer> {
         target = new File("target/camel-app/classes");
         target.mkdirs();
         copyFiles(settings, target);
-        // the settings file itself
-        target = new File("target/camel-app/classes", Run.RUN_SETTINGS_FILE.substring(1));
-        safeCopy(settings, target, true);
+        // settings
+        copySettings(settings);
         // log4j configuration
         InputStream is = FatJar.class.getResourceAsStream("/log4j2.properties");
         safeCopy(is, new File("target/camel-app/classes", "log4j2.properties"), false);
@@ -138,11 +138,30 @@ class FatJar implements Callable<Integer> {
         boostrapClassLoader();
 
         // and build target jar
-        archiveFatJar(version);
+        archiveFatJar();
 
         return 0;
     }
 
+    private void copySettings(File settings) throws Exception {
+        // the settings file itself
+        File target = new File("target/camel-app/classes", Run.RUN_SETTINGS_FILE.substring(1));
+
+        // need to adjust file: scheme to classpath as the files are now embedded in the fat-jar directly
+        List<String> lines = Files.readAllLines(settings.toPath());
+        FileOutputStream fos = new FileOutputStream(target, false);
+        for (String line : lines) {
+            String value = StringHelper.after(line, "camel.main.routesIncludePattern=");
+            if (value != null) {
+                value = value.replaceAll("file:", "classpath:");
+                line = "camel.main.routesIncludePattern=" + value;
+            }
+            fos.write(line.getBytes(StandardCharsets.UTF_8));
+            fos.write("\n".getBytes(StandardCharsets.UTF_8));
+        }
+        IOHelper.close(fos);
+    }
+
     private void boostrapClassLoader() throws Exception {
         File target = new File("target/camel-app/bootstrap");
         target.mkdirs();
@@ -201,7 +220,7 @@ class FatJar implements Callable<Integer> {
         IOHelper.writeText(context, new FileOutputStream(f + "/MANIFEST.MF", false));
     }
 
-    private void archiveFatJar(String version) throws Exception {
+    private void archiveFatJar() throws Exception {
         // package all inside target/camel-app as a jar-file in target folder
         JarOutputStream jos = new JarOutputStream(new FileOutputStream(jar, false));