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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]