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:10 UTC

[camel] branch main 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 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 3f6d9eb89d7 CAMEL-19940: camel-jbang - Create working directory on init (#11634)
3f6d9eb89d7 is described below

commit 3f6d9eb89d7bf4bb25a6d9f5ca014acc816dc719
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 47230fd0433..dee1858505c 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/")) {
@@ -158,6 +169,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(",");