You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2023/10/03 14:34:11 UTC

[camel] 01/01: CAMEL-19940: camel-jbang - Create working directory on init

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

nfilotto pushed a commit to branch CAMEL-19940/create-working-directory-on-init
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 3b99222e4e9369ddb87ac0bb4c164b5b02cfe1f1
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Tue Oct 3 16:33:40 2023 +0200

    CAMEL-19940: camel-jbang - Create working directory on init
---
 .../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..afe365aa34a 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 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(",");