Skip to content

Commit

Permalink
CAMEL-19940: camel-jbang - Create working directory on init (#11634)
Browse files Browse the repository at this point in the history
  • Loading branch information
essobedo authored Oct 3, 2023
1 parent 56bea65 commit 3f6d9eb
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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;
Expand Down Expand Up @@ -74,6 +75,16 @@ public Init(CamelJBangMain main) {

@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/")) {
Expand Down Expand Up @@ -158,6 +169,13 @@ public Integer doCall() throws Exception {
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(",");

Expand Down

0 comments on commit 3f6d9eb

Please sign in to comment.