You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "Croway (via GitHub)" <gi...@apache.org> on 2025/01/21 15:23:52 UTC

[PR] Camel cli update [camel]

Croway opened a new pull request, #16874:
URL: https://github.com/apache/camel/pull/16874

   Use openrewrite recipes via Camel JBang to update Camel, Camel Spring Boot and Camel Quarkus applications:
   
   - `update list` shows versions that can be used for upgrades
   ```
   $ camel update list
    VERSION                       RUNTIME        DESCRIPTION
    3.15                          Camel Quarkus  Migrates `camel 4.4` quarkus application to `camel 4.8`.
    3.8                           Camel Quarkus  Migrates `camel 4.0` quarkus application to `camel 4.4`.
    4.8.0                         Camel          Migrates Apache Camel 4 application to Apache Camel 4.8.0 
    ```
    - `update run $VERSION` execute the update
    ```
    $ camel update run 3.15 --runtime=quarkus
    ...
    [Logs from io.quarkus.platform:quarkus-maven-plugin]
    ...
    ```
    
    ```
    $ camel update run 4.8.0
    ...
    [Logs from openrewrite]
    ...
    ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Camel cli update [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #16874:
URL: https://github.com/apache/camel/pull/16874#discussion_r1926611962


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/update/UpdateRun.java:
##########
@@ -68,7 +73,7 @@ public class UpdateRun extends CamelCommand {
     boolean debug;
 
     @CommandLine.Option(names = { "--quarkusMavenPluginVersion" },
-                        defaultValue = "3.15.2")
+                        defaultValue = "3.17.7")

Review Comment:
   There is a constant for that in `RuntimeType`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Camel JBang Update [camel]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on PR #16874:
URL: https://github.com/apache/camel/pull/16874#issuecomment-2630596667

   Documentation added


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Camel JBang Update [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #16874:
URL: https://github.com/apache/camel/pull/16874#issuecomment-2630287807

   It would be good to add docs into docs/user-manual/modules/ROOT/pages/camel-jbang.adoc


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Camel cli update [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #16874:
URL: https://github.com/apache/camel/pull/16874#issuecomment-2606686995

   It is a bit confusing with CEQ vs Camel versions. I wonder if the CLI can show Camel and Runtime columns with version numbers.
   
   We ought to have the info, ala what you can do with
   
   ```
   camel version list --runtime=quarkus
   camel version list --runtime=spring-boot
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Camel cli update [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #16874:
URL: https://github.com/apache/camel/pull/16874#discussion_r1926613181


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/update/UpdateRun.java:
##########
@@ -110,94 +123,161 @@ public Integer doCall() throws Exception {
             mvnProgramCall = "mvn";
         }
         String command = "";
-        if (runtime == RuntimeType.quarkus) {
-            command = mvnProgramCall + " --no-transfer-progress io.quarkus.platform:quarkus-maven-plugin:"
-                      + quarkusMavenPluginVersion + ":update" +
-                      " -Dstream=" + version;
-        } else {
-            MavenDependencyDownloader downloader = new MavenDependencyDownloader();
+
+        try (MavenDependencyDownloader downloader = new MavenDependencyDownloader();) {
             downloader.setRepositories(repos);
             downloader.start();
 
-            String recipesArtifactId = "camel-upgrade-recipes";
-            if (runtime == RuntimeType.springBoot) {
-                recipesArtifactId = "camel-spring-boot-upgrade-recipes";
-            }
+            if (runtime == RuntimeType.quarkus) {
+                // Assume that the quarkus updates are in the form 3.8, 3.15, 3.16...
+                List<String[]> qVersions
+                        = downloader.resolveAvailableVersions("org.apache.camel.quarkus", "camel-quarkus-catalog", version,
+                                repos);
+                String streamVersion = null;
+                for (String[] qVersion : qVersions) {
+                    if (qVersion[0].equals(version)) {
+                        streamVersion = qVersion[1].substring(0, qVersion[1].lastIndexOf('.'));
+                    }
+                }
 
-            List<Recipe> recipes;
-            try {
-                MavenArtifact mavenArtifact
-                        = downloader.downloadArtifact("org.apache.camel.upgrade", recipesArtifactId, version);
+                command = mvnProgramCall + " --no-transfer-progress io.quarkus.platform:quarkus-maven-plugin:"
+                          + quarkusMavenPluginVersion + ":update" +
+                          " -Dstream=" + streamVersion;
+            } else {
+                String recipesArtifactId = "camel-upgrade-recipes";
+                if (runtime == RuntimeType.springBoot) {
+                    recipesArtifactId = "camel-spring-boot-upgrade-recipes";
+                }
 
-                recipes = getRecipesInJar(mavenArtifact.getFile());
-            } catch (DownloadException ex) {
-                printer().println(String.format("Cannot find Camel Upgrade Recipes %s:%s:%s",
-                        "org.apache.camel.upgrade", recipesArtifactId, version));
+                List<Recipe> recipes;
+                try {
+                    MavenArtifact mavenArtifact
+                            = downloader.downloadArtifact("org.apache.camel.upgrade", recipesArtifactId, version);
 
-                return -1;
-            }
+                    recipes = getRecipesInJar(mavenArtifact.getFile());
+                } catch (DownloadException ex) {
+                    printer().println(String.format("Cannot find Camel Upgrade Recipes %s:%s:%s",
+                            "org.apache.camel.upgrade", recipesArtifactId, version));
 
-            List<String> activeRecipes = new ArrayList<>();
-            recipes.forEach(r -> r.recipeName().ifPresent(name -> activeRecipes.add(name)));
+                    return -1;
+                }
 
-            String task = dryRun ? "dryRun" : "run";
+                List<String> activeRecipes = new ArrayList<>();
+                for (Recipe recipe : recipes) {
+                    // The recipe named latest.yaml contains all the recipe for the update up to the selected version
+                    if (recipe.name().contains("latest")) {
+                        activeRecipes.clear();
+                        recipe.recipeName().ifPresent(name -> activeRecipes.add(name));
+                        break;
+                    }
 
-            String extraOptions = "";
-            if (!debug) {
-                extraOptions += "--no-transfer-progress";
-            }
+                    recipe.recipeName().ifPresent(name -> activeRecipes.add(name));
+                }
+
+                String task = dryRun ? "dryRun" : "run";
 
-            mvnProgramCall = mvnProgramCall + " " + extraOptions;
+                String extraOptions = "";
+                if (!debug) {
+                    extraOptions += "--no-transfer-progress";
+                }
+
+                mvnProgramCall = mvnProgramCall + " " + extraOptions;
 
-            command = mvnProgramCall + " org.openrewrite.maven:rewrite-maven-plugin:" + openRewriteVersion + ":" + task +
-                      " -Drewrite.recipeArtifactCoordinates=" + camelArtifactCoordinates + ":" + camelArtifactVersion +
-                      " -DactiveRecipes=" + activeRecipes.stream().collect(Collectors.joining(","));
+                command = mvnProgramCall + " org.openrewrite.maven:rewrite-maven-plugin:" + openRewriteVersion + ":" + task +
+                          " -Drewrite.recipeArtifactCoordinates=" + camelArtifactCoordinates + ":" + camelArtifactVersion +
+                          " -Drewrite.activeRecipes=" + activeRecipes.stream().collect(Collectors.joining(","));
+            }
         }
 
+        executeCommand(command);
+
         Process p = Runtime.getRuntime()
                 .exec(command);
 
         printMavenUpdateOutput(p);
 
-        boolean done = p.waitFor(240, TimeUnit.SECONDS);
+        return 0;
+    }
 
-        if (!done) {
-            return -1;
-        }
+    /**
+     * Executes a shell command and prints its output.
+     *
+     * @param  command              the command to execute
+     * @return                      the exit code of the command execution
+     * @throws IOException          if an I/O error occurs
+     * @throws InterruptedException if the command execution is interrupted
+     */
+    private int executeCommand(String command) throws IOException, InterruptedException {
+        Process p = new ProcessBuilder()
+                .command(command.split("\\s+"))
+                .redirectErrorStream(true)
+                .start();
+
+        try (BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
+             BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()))) {
+
+            String line;
+            while ((line = stdInput.readLine()) != null || (line = stdError.readLine()) != null) {
+                printer().println(line);
+            }
 
-        return 0;
+            if (!p.waitFor(240, TimeUnit.SECONDS)) {

Review Comment:
   Is this 240 seconds an option we should make configurable ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Camel JBang Update [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #16874:
URL: https://github.com/apache/camel/pull/16874#issuecomment-2630679324

   LGTM


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Camel JBang Update [camel]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on PR #16874:
URL: https://github.com/apache/camel/pull/16874#issuecomment-2621360979

   It is possible to define extra recipes and artifacts like
   `camel update run 4.9.0 --runtime=camel-main --extraRecipeArtifactCoordinates=org.openrewrite.recipe:rewrite-third-party:0.15.0 --extraActiveRecipes=io.quarkus.updates.core.quarkus30.JavaxActivationMigrationToJakartaActivatio`
   
   Considering this example, the applied recipes are the following:
   `[INFO] Using active recipe(s) [org.apache.camel.upgrade.CamelMigrationRecipe, io.quarkus.updates.core.quarkus30.JavaxActivationMigrationToJakartaActivation]`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Camel cli update [camel]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on PR #16874:
URL: https://github.com/apache/camel/pull/16874#issuecomment-2606828567

   > It is a bit confusing with CEQ vs Camel versions. I wonder if the CLI can show Camel and Runtime columns with version numbers.
   > 
   > We ought to have the info, ala what you can do with
   > 
   > ```
   > camel version list --runtime=quarkus
   > camel version list --runtime=spring-boot
   > ```
   
   Good point, I expected this kind of comment, I added the runtime version information in the list like this
   ```
    VERSION                       RUNTIME        RUNTIME VERSION  DESCRIPTION
    4.4.3                         Camel Quarkus  3.8.x            Migrates `camel 4.0` quarkus application to `camel 4.4`.
    4.8.0                         Camel                           Migrates Apache Camel 4 application to Apache Camel 4.8.0
    4.8.0                         Camel Quarkus  3.15.x           Migrates `camel 4.4` quarkus application to `camel 4.8`.
    ```
    
    And the run can be executed with the Camel version:
    ```
    camel update run 4.4.3 --runtime=quarkus
    ```
    
    I had to make some assumptions... but it is working, and I can translate Quarkus/Camel versions


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Camel JBang Update [camel]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway merged PR #16874:
URL: https://github.com/apache/camel/pull/16874


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Camel cli update [camel]

Posted by "mcarlett (via GitHub)" <gi...@apache.org>.
mcarlett commented on code in PR #16874:
URL: https://github.com/apache/camel/pull/16874#discussion_r1927166674


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/update/UpdateRun.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.update;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+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.RuntimeCompletionCandidates;
+import org.apache.camel.dsl.jbang.core.common.RuntimeType;
+import org.apache.camel.dsl.jbang.core.common.RuntimeTypeConverter;
+import org.apache.camel.main.download.DownloadException;
+import org.apache.camel.main.download.MavenDependencyDownloader;
+import org.apache.camel.util.FileUtil;
+import picocli.CommandLine;
+
+/**
+ * Command to update a Camel project to a specified version. This command supports updating projects for different
+ * runtimes such as Camel Main, Spring Boot, and Quarkus. It uses Maven and OpenRewrite to apply the necessary updates.
+ */
+@CommandLine.Command(name = "run",
+                     description = "Update Camel project")
+public class UpdateRun extends CamelCommand {
+
+    @CommandLine.Parameters(description = "Update version", arity = "1")
+    private String version;
+
+    @CommandLine.Option(names = { "--openRewriteVersion" },
+                        defaultValue = "6.0.4")
+    String openRewriteVersion;
+
+    @CommandLine.Option(names = { "--camelArtifact" },
+                        defaultValue = "camel-upgrade-recipes")
+    String camelArtifactCoordinates;
+
+    @CommandLine.Option(names = { "--camelSpringBootArtifact" },
+                        defaultValue = "camel-spring-boot-upgrade-recipes")
+    String camelSpringBootArtifactCoordinates;
+
+    @CommandLine.Option(names = { "--camelArtifactVersion" },
+                        defaultValue = "4.8.0")
+    String camelArtifactVersion;
+
+    @CommandLine.Option(names = { "--debug" },
+                        defaultValue = "false")
+    boolean debug;
+
+    @CommandLine.Option(names = { "--quarkusMavenPluginVersion" },
+                        defaultValue = RuntimeType.QUARKUS_VERSION)
+    String quarkusMavenPluginVersion;
+
+    @CommandLine.Option(names = { "--quarkusMavenPluginGroupId" },
+                        defaultValue = "io.quarkus")
+    String quarkusMavenPluginGroupId;
+
+    @CommandLine.Option(names = { "--dryRun" },
+                        defaultValue = "false")
+    boolean dryRun;
+
+    @CommandLine.Option(names = { "--runtime" },
+                        completionCandidates = RuntimeCompletionCandidates.class,
+                        defaultValue = "camel-main",
+                        converter = RuntimeTypeConverter.class,
+                        description = "Runtime (${COMPLETION-CANDIDATES})")
+    RuntimeType runtime = RuntimeType.main;
+
+    @CommandLine.Option(names = { "--repos" },
+                        description = "Additional maven repositories for download on-demand (Use commas to separate multiple repositories)")
+    String repos;
+
+    @CommandLine.Option(names = { "--upgradeTimeout" },
+                        description = "Time to wait, in seconds, before shutting down the upgrade process",
+                        defaultValue = "240")
+    int upgradeTimeout;
+
+    public UpdateRun(CamelJBangMain main) {
+        super(main);
+    }
+
+    /**
+     * Executes the update command for a Camel project. This method determines the appropriate Maven command based on
+     * the runtime type (Camel Main, Spring Boot, or Quarkus) and executes it to update the project to the specified
+     * version.
+     *
+     * @return           the exit code of the update process (0 for success, -1 for failure)
+     * @throws Exception if an error occurs during the update process
+     */
+    @Override
+    public Integer doCall() throws Exception {
+        // Check if the current directory contains a Maven project (i.e., a pom.xml file)
+        if (Files.list(Path.of("."))
+                .filter(f -> f.getFileName().toString().equals("pom.xml"))
+                .count()
+            == 0) {

Review Comment:
   maybe you can refactor as Path.of(".")).noneMatch(f -> f.getFileName().toString().equals("pom.xml"))



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Camel JBang Update [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #16874:
URL: https://github.com/apache/camel/pull/16874#issuecomment-2626450021

   @Croway it would be good to have this ready mon/tue next week


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Camel JBang Update [camel]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on PR #16874:
URL: https://github.com/apache/camel/pull/16874#issuecomment-2626653854

   > @Croway it would be good to have this ready mon/tue next week
   
   sure thing, I'll do another round of test today and set it to ready for review. Thanks for the heads up


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org