Skip to content

Commit 24ab56b

Browse files
aloubyanskygsmet
authored andcommitted
Use the version of Quarkus platform recommended for the current project for recipe filtering instead of the latest version recommended by the registry
(cherry picked from commit e064d4d)
1 parent faa1a74 commit 24ab56b

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/UpdateProject.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ public UpdateProject rewriteDryRun(boolean rewriteDryRun) {
7474
return this;
7575
}
7676

77+
/**
78+
* This method is not used since currently the version passed in here might not be the final target platform version
79+
* but the latest recommended w/o taking into account extensions found in the current project.
80+
*
81+
* @param targetPlatformVersion latest recommended Quarkus platform version
82+
* @return this instance
83+
*/
7784
public UpdateProject targetPlatformVersion(String targetPlatformVersion) {
7885
invocation.setValue(TARGET_PLATFORM_VERSION, targetPlatformVersion);
7986
return this;

independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/UpdateProjectCommandHandler.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,37 +71,41 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
7171
}
7272
final ApplicationModel appModel = invocation.getValue(UpdateProject.APP_MODEL);
7373
final ExtensionCatalog targetCatalog = invocation.getValue(UpdateProject.TARGET_CATALOG);
74-
final String targetPlatformVersion = invocation.getValue(UpdateProject.TARGET_PLATFORM_VERSION);
7574
final ProjectState currentState = resolveProjectState(appModel,
7675
invocation.getQuarkusProject().getExtensionsCatalog());
77-
final ArtifactCoords projectQuarkusPlatformBom = getProjectQuarkusPlatformBOM(currentState);
78-
if (projectQuarkusPlatformBom == null) {
79-
String error = "The project does not import any Quarkus platform BOM";
80-
81-
invocation.log().error(error);
82-
return QuarkusCommandOutcome.failure(error);
76+
final ArtifactCoords currentQuarkusPlatformBom = getProjectQuarkusPlatformBOM(currentState);
77+
var failure = ensureQuarkusBomVersionIsNotNull(currentQuarkusPlatformBom, invocation.log());
78+
if (failure != null) {
79+
return failure;
8380
}
84-
final QuarkusProject quarkusProject = invocation.getQuarkusProject();
8581
final ProjectState recommendedState = resolveRecommendedState(currentState, targetCatalog,
8682
invocation.log());
83+
final ArtifactCoords recommendedQuarkusPlatformBom = getProjectQuarkusPlatformBOM(recommendedState);
84+
failure = ensureQuarkusBomVersionIsNotNull(recommendedQuarkusPlatformBom, invocation.log());
85+
if (failure != null) {
86+
return failure;
87+
}
88+
8789
final ProjectPlatformUpdateInfo platformUpdateInfo = resolvePlatformUpdateInfo(currentState,
8890
recommendedState);
8991
final ProjectExtensionsUpdateInfo extensionsUpdateInfo = ProjectUpdateInfos.resolveExtensionsUpdateInfo(
9092
currentState,
9193
recommendedState);
9294
boolean shouldUpdate = logUpdates(invocation.getQuarkusProject(), currentState, recommendedState, platformUpdateInfo,
9395
extensionsUpdateInfo,
94-
quarkusProject.log());
96+
invocation.log());
9597
Boolean rewrite = invocation.getValue(UpdateProject.REWRITE, null);
9698
boolean rewriteDryRun = invocation.getValue(UpdateProject.REWRITE_DRY_RUN, false);
9799
if (shouldUpdate) {
100+
final QuarkusProject quarkusProject = invocation.getQuarkusProject();
98101
final BuildTool buildTool = quarkusProject.getExtensionManager().getBuildTool();
102+
// TODO targetCatalog shouldn't be used here, since it might not be the recommended one according to the calculated recommended state
99103
String kotlinVersion = getMetadata(targetCatalog, "project", "properties", "kotlin-version");
100104
final Optional<Integer> updateJavaVersion = resolveUpdateJavaVersion(extensionsUpdateInfo, projectJavaVersion);
101105
QuarkusUpdates.ProjectUpdateRequest request = new QuarkusUpdates.ProjectUpdateRequest(
102106
buildTool,
103-
projectQuarkusPlatformBom.getVersion(),
104-
targetPlatformVersion,
107+
currentQuarkusPlatformBom.getVersion(),
108+
recommendedQuarkusPlatformBom.getVersion(),
105109
kotlinVersion,
106110
updateJavaVersion,
107111
extensionsUpdateInfo);
@@ -239,6 +243,15 @@ private static ArtifactCoords getProjectQuarkusPlatformBOM(ProjectState currentS
239243
return null;
240244
}
241245

246+
private static QuarkusCommandOutcome<Void> ensureQuarkusBomVersionIsNotNull(ArtifactCoords bomCoords, MessageWriter log) {
247+
if (bomCoords == null) {
248+
String error = "The project state is missing the Quarkus platform BOM";
249+
log.error(error);
250+
return QuarkusCommandOutcome.failure(error);
251+
}
252+
return null;
253+
}
254+
242255
private static boolean logUpdates(QuarkusProject project, ProjectState currentState, ProjectState recommendedState,
243256
ProjectPlatformUpdateInfo platformUpdateInfo,
244257
ProjectExtensionsUpdateInfo extensionsUpdateInfo,

independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ProjectUpdateInfos.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,16 @@ private static List<ExtensionCatalog> getRecommendedOrigins(List<Extension> exte
214214
private static void addOrigins(final List<ExtensionOrigins> extOrigins, Extension e) {
215215
ExtensionOrigins.Builder eoBuilder = null;
216216
for (ExtensionOrigin o : e.getOrigins()) {
217-
if (!(o instanceof ExtensionCatalog)) {
218-
continue;
219-
}
220-
final ExtensionCatalog c = (ExtensionCatalog) o;
221-
final OriginPreference op = (OriginPreference) c.getMetadata().get("origin-preference");
222-
if (op == null) {
223-
continue;
224-
}
225-
if (eoBuilder == null) {
226-
eoBuilder = ExtensionOrigins.builder(e.getArtifact().getKey());
217+
if (o instanceof ExtensionCatalog c) {
218+
final OriginPreference op = (OriginPreference) c.getMetadata().get("origin-preference");
219+
if (op == null) {
220+
continue;
221+
}
222+
if (eoBuilder == null) {
223+
eoBuilder = ExtensionOrigins.builder(e.getArtifact().getKey());
224+
}
225+
eoBuilder.addOrigin(c, op);
227226
}
228-
eoBuilder.addOrigin(c, op);
229227
}
230228
if (eoBuilder != null) {
231229
extOrigins.add(eoBuilder.build());

0 commit comments

Comments
 (0)