Skip to content

Commit

Permalink
Use plugin versions from the quarkus-updates-recipes repo props
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Apr 11, 2023
1 parent ae5e4fb commit b4bd1a1
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import io.quarkus.devtools.commands.UpdateProject;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.devtools.project.update.QuarkusUpdateCommand;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.registry.RegistryResolutionException;
import io.quarkus.registry.catalog.ExtensionCatalog;
Expand All @@ -27,7 +26,7 @@ public abstract class QuarkusUpdate extends QuarkusPlatformTask {
private String targetStreamId;
private String targetPlatformVersion;

private String rewritePluginVersion = QuarkusUpdateCommand.DEFAULT_GRADLE_REWRITE_PLUGIN_VERSION;
private String rewritePluginVersion = null;

private String rewriteUpdateRecipesVersion = null;

Expand Down Expand Up @@ -66,6 +65,7 @@ public void setPerModule(boolean perModule) {
}

@Input
@Optional
public String getRewritePluginVersion() {
return rewritePluginVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import io.quarkus.devtools.commands.data.QuarkusCommandOutcome;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.devtools.project.update.QuarkusUpdateCommand;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.registry.RegistryResolutionException;
import io.quarkus.registry.catalog.ExtensionCatalog;
Expand Down Expand Up @@ -50,7 +49,7 @@ public class UpdateMojo extends QuarkusProjectStateMojoBase {
/**
* The OpenRewrite plugin version
*/
@Parameter(property = "rewritePluginVersion", required = true, defaultValue = QuarkusUpdateCommand.DEFAULT_MAVEN_REWRITE_PLUGIN_VERSION)
@Parameter(property = "rewritePluginVersion", required = false)
private String rewritePluginVersion;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.quarkus.devtools.commands.data.QuarkusCommandOutcome;
import io.quarkus.devtools.commands.handlers.ProjectInfoCommandHandler.PlatformInfo;
import io.quarkus.devtools.messagewriter.MessageWriter;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.devtools.project.state.ExtensionProvider;
Expand Down Expand Up @@ -71,23 +72,26 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
final boolean noRewrite = invocation.getValue(UpdateProject.NO_REWRITE, false);

if (!noRewrite) {
final BuildTool buildTool = quarkusProject.getExtensionManager().getBuildTool();
QuarkusUpdates.ProjectUpdateRequest request = new QuarkusUpdates.ProjectUpdateRequest(
quarkusProject.getExtensionManager().getBuildTool(),
buildTool,
projectQuarkusPlatformBom.getVersion(), targetPlatformVersion);
Path recipe = null;
try {
recipe = Files.createTempFile("quarkus-project-recipe-", ".yaml");
final String updateRecipesVersion = invocation.getValue(UpdateProject.REWRITE_UPDATE_RECIPES_VERSION,
QuarkusUpdatesRepository.DEFAULT_UPDATE_RECIPES_VERSION);
QuarkusUpdates.createRecipe(recipe,
QuarkusProjectHelper.artifactResolver(), updateRecipesVersion, request);
final String rewritePluginVersion = invocation.getValue(UpdateProject.REWRITE_PLUGIN_VERSION);
final QuarkusUpdatesRepository.FetchResult fetchResult = QuarkusUpdates.createRecipe(invocation.log(),
recipe,
QuarkusProjectHelper.artifactResolver(), buildTool, updateRecipesVersion, request);
final String rewritePluginVersion = invocation.getValue(UpdateProject.REWRITE_PLUGIN_VERSION,
fetchResult.getRewritePluginVersion());
final boolean rewriteDryRun = invocation.getValue(UpdateProject.REWRITE_DRY_RUN, false);
invocation.log().warn(
"The update feature does not yet handle updates of the extension versions. If needed, update your extensions manually.");
QuarkusUpdateCommand.handle(
invocation.log(),
quarkusProject.getExtensionManager().getBuildTool(),
buildTool,
quarkusProject.getProjectDirPath(),
rewritePluginVersion,
recipe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public class QuarkusUpdateCommand {

public static final String MAVEN_REWRITE_PLUGIN_GROUP = "org.openrewrite.maven";
public static final String MAVEN_REWRITE_PLUGIN_ARTIFACT = "rewrite-maven-plugin";
public static final String DEFAULT_MAVEN_REWRITE_PLUGIN_VERSION = "4.41.0";
public static final String DEFAULT_GRADLE_REWRITE_PLUGIN_VERSION = "5.38.0";

public static Set<String> ADDITIONAL_SOURCE_FILES_SET = Set.of("**/META-INF/services/**",
"**/*.txt",
"**/*.adoc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;

import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.devtools.messagewriter.MessageWriter;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.update.QuarkusUpdatesRepository.FetchResult;
import io.quarkus.devtools.project.update.operations.UpdatePropertyOperation;

public final class QuarkusUpdates {

private QuarkusUpdates() {
}

public static void createRecipe(Path target, MavenArtifactResolver artifactResolver, String updateRecipesVersion,
public static FetchResult createRecipe(MessageWriter log, Path target, MavenArtifactResolver artifactResolver,
BuildTool buildTool, String updateRecipesVersion,
ProjectUpdateRequest request)
throws IOException {
final List<String> recipes = QuarkusUpdatesRepository.fetchRecipes(artifactResolver, updateRecipesVersion,
final FetchResult result = QuarkusUpdatesRepository.fetchRecipes(log, artifactResolver, buildTool, updateRecipesVersion,
request.currentVersion,
request.targetVersion);
QuarkusUpdateRecipe recipe = new QuarkusUpdateRecipe()
Expand All @@ -34,10 +36,11 @@ public static void createRecipe(Path target, MavenArtifactResolver artifactResol
break;
}

for (String s : recipes) {
for (String s : result.getRecipes()) {
recipe.addRecipes(QuarkusUpdateRecipeIO.readRecipesYaml(s));
}
QuarkusUpdateRecipeIO.write(target, recipe);
return result;
}

public static class ProjectUpdateRequest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package io.quarkus.devtools.project.update;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.eclipse.aether.artifact.Artifact;

import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.bootstrap.util.DependencyUtils;
import io.quarkus.devtools.messagewriter.MessageWriter;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.platform.descriptor.loader.json.ResourceLoader;
import io.quarkus.platform.descriptor.loader.json.ResourceLoaders;

Expand All @@ -23,14 +29,20 @@ private QuarkusUpdatesRepository() {
private static final String QUARKUS_RECIPE_GA = "io.quarkus:quarkus-update-recipes";
public static final String DEFAULT_UPDATE_RECIPES_VERSION = "LATEST";

public static List<String> fetchRecipes(MavenArtifactResolver artifactResolver, String recipeVersion, String currentVersion,
public static final String DEFAULT_MAVEN_REWRITE_PLUGIN_VERSION = "4.41.0";
public static final String DEFAULT_GRADLE_REWRITE_PLUGIN_VERSION = "5.38.0";
public static final String PROP_REWRITE_MAVEN_PLUGIN_VERSION = "rewrite-maven-plugin-version";
public static final String PROP_REWRITE_GRADLE_PLUGIN_VERSION = "rewrite-gradle-plugin-version";

public static FetchResult fetchRecipes(MessageWriter log, MavenArtifactResolver artifactResolver, BuildTool buildTool,
String recipeVersion, String currentVersion,
String targetVersion) {
final String gav = QUARKUS_RECIPE_GA + ":" + recipeVersion;
try {
final Artifact artifact = artifactResolver.resolve(DependencyUtils.toArtifact(gav)).getArtifact();
final ResourceLoader resourceLoader = ResourceLoaders.resolveFileResourceLoader(
artifactResolver.resolve(DependencyUtils.toArtifact(gav)).getArtifact().getFile());

return resourceLoader.loadResourceAsPath("quarkus-updates/core",
artifact.getFile());
final List<String> recipes = resourceLoader.loadResourceAsPath("quarkus-updates/core",
path -> {
try (final Stream<Path> pathStream = Files.walk(path)) {
return pathStream
Expand All @@ -45,13 +57,67 @@ public static List<String> fetchRecipes(MavenArtifactResolver artifactResolver,
}).collect(Collectors.toList());
}
});
final Properties props = resourceLoader.loadResourceAsPath("quarkus-updates/", p -> {
final Properties properties = new Properties();
final Path propPath = p.resolve("recipes.properties");
if (Files.isRegularFile(propPath)) {
try (final InputStream inStream = Files.newInputStream(propPath)) {
properties.load(inStream);
}
}
return properties;
});
final String propRewritePluginVersion = getPropRewritePluginVersion(props, buildTool);

log.info(String.format(
"Resolved io.quarkus:quarkus-updates-recipes:%s with %s recipe(s) to update from %s to %s (initially made for OpenRewrite %s plugin version: %s) ",
artifact.getVersion(),
recipes.size(),
currentVersion,
targetVersion,
buildTool,
propRewritePluginVersion));
return new FetchResult(recipes, propRewritePluginVersion);
} catch (BootstrapMavenException e) {
throw new RuntimeException("Failed to resolve artifact: " + gav, e);
} catch (IOException e) {
throw new RuntimeException("Failed to load recipes in artifact: " + gav, e);
}
}

private static String getPropRewritePluginVersion(Properties props, BuildTool buildTool) {
switch (buildTool) {
case MAVEN:
return Optional.ofNullable(props.getProperty(PROP_REWRITE_MAVEN_PLUGIN_VERSION))
.orElse(DEFAULT_MAVEN_REWRITE_PLUGIN_VERSION);
case GRADLE:
case GRADLE_KOTLIN_DSL:
return Optional.ofNullable(props.getProperty(PROP_REWRITE_GRADLE_PLUGIN_VERSION))
.orElse(DEFAULT_GRADLE_REWRITE_PLUGIN_VERSION);
default:
throw new IllegalStateException("This build tool does not support update " + buildTool);
}
}

public static class FetchResult {

private final List<String> recipes;
private final String rewritePluginVersion;

public FetchResult(List<String> recipes, String rewritePluginVersion) {
this.rewritePluginVersion = rewritePluginVersion;
this.recipes = recipes;
}

public List<String> getRecipes() {
return recipes;
}

public String getRewritePluginVersion() {
return rewritePluginVersion;
}
}

static boolean shouldApplyRecipe(String recipeFileName, String currentVersion, String targetVersion) {
String recipeVersion = recipeFileName.replaceFirst("[.][^.]+$", "");
final DefaultArtifactVersion recipeAVersion = new DefaultArtifactVersion(recipeVersion);
Expand Down

0 comments on commit b4bd1a1

Please sign in to comment.