Skip to content

Commit

Permalink
Print command
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Feb 13, 2023
1 parent 216eb0d commit 65c0ff2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ protected static boolean logState(ProjectState projectState, boolean perModule,
} else {
if (rectify) {
sb.append(String.format(UpdateProjectCommandHandler.PLATFORM_RECTIFY_FORMAT, "",
platform.imported.toCompactCoords()));
platform.imported.toCompactCoords())).append(" ✔");
} else {
sb.append(" ").append(platform.imported.toCompactCoords());
sb.append(" ").append(platform.imported.toCompactCoords()).append(" | up-to-date");
}
}
log.info(sb.toString());
Expand Down Expand Up @@ -193,6 +193,12 @@ private static boolean logExtensionInfo(TopExtensionDependency dep, boolean rect
sb.append(" -> remove version (managed)");
}
recommendationsAvailable = true;
} else {
if (rectify) {
sb.append(" ✔");
} else {
sb.append(" | up-to-date");
}
}
} else {
sb.append(" ").append(dep.getArtifact().getGroupId()).append(':')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.devtools.commands.handlers;

import static io.quarkus.devtools.project.update.QuarkusUpdateRecipe.RECIPE_IO_QUARKUS_OPENREWRITE_QUARKUS;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -66,18 +68,25 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
invocation.log().info("Instructions to update this project from '%s' to '%s':",
projectQuarkusPlatformBom.getVersion(), targetPlatformVersion);
logUpdates(currentState, latestCatalog, false, perModule, invocation.getQuarkusProject().log());
}

if (generateRewriteConfig) {
QuarkusUpdates.ProjectUpdateRequest request = new QuarkusUpdates.ProjectUpdateRequest(
projectQuarkusPlatformBom.getVersion(), targetPlatformVersion);
try {
final Path tempFile = Files.createTempFile("quarkus-project-recipe-", ".yaml");
QuarkusUpdates.createRecipe(tempFile,
QuarkusProjectHelper.artifactResolver(), request);
invocation.log().info("Project update recipe has been created: %s", tempFile.toString());
} catch (IOException e) {
throw new QuarkusCommandException("Failed to create project update recipe", e);
if (generateRewriteConfig) {
QuarkusUpdates.ProjectUpdateRequest request = new QuarkusUpdates.ProjectUpdateRequest(
projectQuarkusPlatformBom.getVersion(), targetPlatformVersion);
try {
final Path tempFile = Files.createTempFile("quarkus-project-recipe-", ".yaml");
QuarkusUpdates.createRecipe(tempFile,
QuarkusProjectHelper.artifactResolver(), request);
invocation.log().info("Project update recipe has been created:\n%s", tempFile.toString());

invocation.log().info("The command to update this project: \n" +
"mvn org.openrewrite.maven:rewrite-maven-plugin:4.39.0:run quarkus-update \\\n" +
" -Drewrite.configLocation=%s \\\n" +
" -DactiveRecipes=%s -e",
tempFile.toString(), RECIPE_IO_QUARKUS_OPENREWRITE_QUARKUS);

} catch (IOException e) {
throw new QuarkusCommandException("Failed to create project update recipe", e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

public class QuarkusUpdateRecipe {

public static final String RECIPE_IO_QUARKUS_OPENREWRITE_QUARKUS = "io.quarkus.openrewrite.Quarkus";
public static final Map<String, Object> QUARKUS_RECIPE = Map.of(
"type", "specs.openrewrite.org/v1beta/recipe",
"name", "io.quarkus.openrewrite.Quarkus",
"name", RECIPE_IO_QUARKUS_OPENREWRITE_QUARKUS,
"displayName", "Migrate quarkus project to a new version",
"description", "Update Quarkus version and refactor imports and resources if needed.",
"tags", List.of("quarkus"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ public static List<String> fetchLatestRecipes(MavenArtifactResolver artifactReso
try {
final ResourceLoader resourceLoader = ResourceLoaders.resolveFileResourceLoader(
artifactResolver.resolve(DependencyUtils.toArtifact(QUARKUS_RECIPE_GAV)).getArtifact().getFile());

return resourceLoader.loadResourceAsPath("quarkus-updates/core",
path -> {
try (final Stream<Path> pathStream = Files.walk(path)) {
return pathStream
.filter(p -> p.getFileName().toString().matches("^\\d\\.\\d(\\.\\d)?\\.ya?ml$"))
.filter(p -> p.getFileName().toString().matches("^\\d\\.\\H+.ya?ml$"))
.filter(p -> shouldApplyRecipe(p.getFileName().toString(), currentVersion, targetVersion))
.map(p -> {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.devtools.project.update;

import static io.quarkus.devtools.project.update.QuarkusUpdatesRepository.shouldApplyRecipe;
import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;

class QuarkusUpdatesRepositoryTest {

@ParameterizedTest
@CsvFileSource(resources = "/should_apply_recipe_test_cases.csv", numLinesToSkip = 1)
void testShouldApplyRecipeWithCSV(String recipeVersion, String currentVersion, String targetVersion,
boolean expectedResult) {
boolean result = shouldApplyRecipe(recipeVersion, currentVersion, targetVersion);
assertEquals(expectedResult, result);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
recipeFileName,currentVersion,targetVersion,expectedResult
3alpha.yaml,2.0.0.Final,3.0.0.Alpha4,true
3.0.yaml,2.0.0.Final,3.0.0.Final,true
2.9.yaml,2.0.0.Final,3.0.0.Final,true
2.7.yaml,2.0.0.Final,3.0.0.Final,true
Expand Down

0 comments on commit 65c0ff2

Please sign in to comment.