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 2023/10/03 16:40:33 UTC

[camel] branch camel-4.0.x updated: CAMEL-19940: camel-jbang - Create working directory on init (#11634)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-4.0.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.0.x by this push:
     new 60eeb915aae CAMEL-19940: camel-jbang - Create working directory on init (#11634)
60eeb915aae is described below

commit 60eeb915aaedadeb8a62b7f015ec89f29c94ec19
Author: Nicolas Filotto <es...@users.noreply.github.com>
AuthorDate: Tue Oct 3 18:40:02 2023 +0200

    CAMEL-19940: camel-jbang - Create working directory on init (#11634)
---
 .../org/apache/camel/dsl/jbang/core/commands/Init.java | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java
index 2264980c80c..70abdec1c25 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java
@@ -38,6 +38,7 @@ import picocli.CommandLine.Command;
 import picocli.CommandLine.Option;
 import picocli.CommandLine.Parameters;
 
+import static org.apache.camel.dsl.jbang.core.commands.Run.WORK_DIR;
 import static org.apache.camel.dsl.jbang.core.common.GistHelper.fetchGistUrls;
 import static org.apache.camel.dsl.jbang.core.common.GitHubHelper.asGithubSingleUrl;
 import static org.apache.camel.dsl.jbang.core.common.GitHubHelper.fetchGithubUrls;
@@ -74,6 +75,16 @@ public class Init extends CamelCommand {
 
     @Override
     public Integer doCall() throws Exception {
+        int code = execute();
+        if (code == 0) {
+            // In case of successful execution, we create the working directory if it does not exist to help the tooling
+            // know that it is a Camel JBang project
+            createWorkingDirectoryIfAbsent();
+        }
+        return code;
+    }
+
+    private int execute() throws Exception {
         // is the file referring to an existing file on github/gist
         // then we should download the file to local for use
         if (file.startsWith("https://github.com/")) {
@@ -159,6 +170,13 @@ public class Init extends CamelCommand {
         return 0;
     }
 
+    private void createWorkingDirectoryIfAbsent() {
+        File work = new File(WORK_DIR);
+        if (!work.exists()) {
+            work.mkdirs();
+        }
+    }
+
     private int downloadFromGithub() throws Exception {
         StringJoiner all = new StringJoiner(",");