Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure our recipes are visible as a dependency when updating #33983

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
buildTool,
quarkusProject.getProjectDirPath(),
rewritePluginVersion,
fetchResult.getRecipesGAV(),
recipe,
rewriteDryRun);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ public static String goal(boolean dryRun) {
}

public static void handle(MessageWriter log, BuildTool buildTool, Path baseDir,
String rewritePluginVersion, Path recipe, boolean dryRun) throws QuarkusUpdateException {
String rewritePluginVersion, String recipesGAV, Path recipe, boolean dryRun) throws QuarkusUpdateException {
switch (buildTool) {
case MAVEN:
runMavenUpdate(log, baseDir, rewritePluginVersion, recipe, dryRun);
runMavenUpdate(log, baseDir, rewritePluginVersion, recipesGAV, recipe, dryRun);
break;
case GRADLE:
runGradleUpdate(log, baseDir, rewritePluginVersion, recipe, dryRun);
runGradleUpdate(log, baseDir, rewritePluginVersion, recipesGAV, recipe, dryRun);
break;
default:
throw new QuarkusUpdateException(buildTool.getKey() + " is not supported yet");
}
}

private static void runGradleUpdate(MessageWriter log, Path baseDir, String rewritePluginVersion, Path recipe,
boolean dryRun) throws QuarkusUpdateException {
private static void runGradleUpdate(MessageWriter log, Path baseDir, String rewritePluginVersion, String recipesGAV,
Path recipe, boolean dryRun) throws QuarkusUpdateException {
Path tempInit = null;
try {
tempInit = Files.createTempFile("openrewrite-init", "gradle");
Expand All @@ -66,6 +66,7 @@ private static void runGradleUpdate(MessageWriter log, Path baseDir, String rewr
Qute.fmt(template, Map.of(
"rewriteFile", recipe.toAbsolutePath().toString(),
"pluginVersion", rewritePluginVersion,
"recipesGAV", recipesGAV,
"activeRecipe", RECIPE_IO_QUARKUS_OPENREWRITE_QUARKUS,
"plainTextMask", ADDITIONAL_SOURCE_FILES_SET.stream()
.map(s -> "\"" + s + "\"")
Expand All @@ -90,21 +91,11 @@ private static void runGradleUpdate(MessageWriter log, Path baseDir, String rewr
}
}

private static void printMavenUpdateCommand(MessageWriter log, Path baseDir, String rewritePluginVersion, Path recipe)
throws QuarkusUpdateException {
final String mvnBinary = findMvnBinary(baseDir);
final String[] mavenUpdateCommand = getMavenUpdateCommand(mvnBinary, rewritePluginVersion, recipe, false);
final String[] mavenProcessSourcesCommand = getMavenProcessSourcesCommand(mvnBinary);

log.info(String.join(" ", mavenUpdateCommand).replace(" -D", "\\n-D"));
log.info(String.join(" ", mavenProcessSourcesCommand));
}

private static void runMavenUpdate(MessageWriter log, Path baseDir, String rewritePluginVersion, Path recipe,
boolean dryRun)
throws QuarkusUpdateException {
private static void runMavenUpdate(MessageWriter log, Path baseDir, String rewritePluginVersion, String recipesGAV,
Path recipe,
boolean dryRun) throws QuarkusUpdateException {
final String mvnBinary = findMvnBinary(baseDir);
executeCommand(baseDir, getMavenUpdateCommand(mvnBinary, rewritePluginVersion, recipe, dryRun), log);
executeCommand(baseDir, getMavenUpdateCommand(mvnBinary, rewritePluginVersion, recipesGAV, recipe, dryRun), log);

// format the sources
executeCommand(baseDir, getMavenProcessSourcesCommand(mvnBinary), log);
Expand All @@ -114,13 +105,15 @@ private static String[] getMavenProcessSourcesCommand(String mvnBinary) {
return new String[] { mvnBinary, "process-sources" };
}

private static String[] getMavenUpdateCommand(String mvnBinary, String rewritePluginVersion, Path recipe, boolean dryRun) {
private static String[] getMavenUpdateCommand(String mvnBinary, String rewritePluginVersion, String recipesGAV, Path recipe,
boolean dryRun) {
return new String[] { mvnBinary,
"-e",
String.format("%s:%s:%s:%s", MAVEN_REWRITE_PLUGIN_GROUP, MAVEN_REWRITE_PLUGIN_ARTIFACT, rewritePluginVersion,
dryRun ? "dryRun" : "run"),
String.format("-D\"plainTextMasks=%s\"", ADDITIONAL_SOURCE_FILES),
String.format("-D\"rewrite.configLocation=%s\"", recipe.toAbsolutePath()),
String.format("-D\"rewrite.recipeArtifactCoordinates=%s\"", recipesGAV),
String.format("-D\"activeRecipes=%s\"", RECIPE_IO_QUARKUS_OPENREWRITE_QUARKUS),
"-D\"rewrite.pomCacheEnabled=false\"" };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public static FetchResult fetchRecipes(MessageWriter log, MavenArtifactResolver
targetVersion,
buildTool,
propRewritePluginVersion));
return new FetchResult(recipes, propRewritePluginVersion);
return new FetchResult(artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(),
recipes, propRewritePluginVersion);
} catch (BootstrapMavenException e) {
throw new RuntimeException("Failed to resolve artifact: " + gav, e);
} catch (IOException e) {
Expand All @@ -101,14 +102,20 @@ private static String getPropRewritePluginVersion(Properties props, BuildTool bu

public static class FetchResult {

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

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

public String getRecipesGAV() {
return recipesGAV;
}

public List<String> getRecipes() {
return recipes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ allprojects {
}
dependencies {
rewrite("org.openrewrite:rewrite-java")
rewrite("{recipesGAV}");
}
rewrite {
configFile = project.getRootProject().file("{rewriteFile}")
Expand Down