This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.20.x by this push:
new 9e38d380393 CAMEL-19128: camel-jbang - Set version command
9e38d380393 is described below
commit 9e38d380393423ba2d6caaffc81210c85f758c93
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Mar 14 04:50:55 2023 +0100
CAMEL-19128: camel-jbang - Set version command
---
.../dsl/jbang/core/commands/CamelJBangMain.java | 2 +
.../jbang/core/commands/version/VersionSet.java | 71 ++++++++++++++++++++++
2 files changed, 73 insertions(+)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
index fd129df2e6f..c9d088bfc72 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
@@ -69,6 +69,7 @@ import
org.apache.camel.dsl.jbang.core.commands.process.StopProcess;
import org.apache.camel.dsl.jbang.core.commands.version.VersionCommand;
import org.apache.camel.dsl.jbang.core.commands.version.VersionGet;
import org.apache.camel.dsl.jbang.core.commands.version.VersionList;
+import org.apache.camel.dsl.jbang.core.commands.version.VersionSet;
import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
import picocli.CommandLine;
import picocli.CommandLine.Command;
@@ -140,6 +141,7 @@ public class CamelJBangMain implements Callable<Integer> {
.addSubcommand("set", new CommandLine(new
ConfigSet(main))))
.addSubcommand("version", new CommandLine(new
VersionCommand(main))
.addSubcommand("get", new CommandLine(new
VersionGet(main)))
+ .addSubcommand("set", new CommandLine(new
VersionSet(main)))
.addSubcommand("list", new CommandLine(new
VersionList(main))));
commandLine.getCommandSpec().versionProvider(() -> {
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSet.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSet.java
new file mode 100644
index 00000000000..6713e97c636
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSet.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.version;
+
+import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
+import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
+import org.apache.camel.dsl.jbang.core.common.RuntimeCompletionCandidates;
+import picocli.CommandLine;
+
[email protected](name = "set", description = "Set/change current Camel
version")
+public class VersionSet extends CamelCommand {
+
+ @CommandLine.Parameters(description = "Camel version", arity = "0..1")
+ String version;
+
+ @CommandLine.Option(names = { "--runtime" }, completionCandidates =
RuntimeCompletionCandidates.class,
+ description = "Runtime (spring-boot, quarkus, or
camel-main)")
+ String runtime;
+
+ @CommandLine.Option(names = { "--repo", "--repos" }, description = "Maven
repository for downloading the dependencies")
+ String repo;
+
+ @CommandLine.Option(names = { "--reset" }, description = "Reset by
removing any custom version settings")
+ boolean reset;
+
+ public VersionSet(CamelJBangMain main) {
+ super(main);
+ }
+
+ @Override
+ public Integer call() throws Exception {
+ CommandLineHelper.createPropertyFile();
+
+ CommandLineHelper.loadProperties(properties -> {
+ if (reset) {
+ properties.remove("camel-version");
+ properties.remove("repos");
+ properties.remove("runtime");
+ } else {
+ if (version != null) {
+ properties.put("camel-version", version);
+ }
+ if (repo != null) {
+ properties.put("repos", repo);
+ }
+ if (runtime != null) {
+ properties.put("runtime", runtime);
+ }
+ }
+ CommandLineHelper.storeProperties(properties);
+ });
+
+ return 0;
+ }
+
+}