use of io.quarkus.devtools.commands.handlers.InfoCommandHandler.PlatformInfo in project quarkus by quarkusio.
the class UpdateCommandHandler method logUpdates.
private static void logUpdates(ProjectState currentState, ExtensionCatalog recommendedCatalog, boolean recommendState, boolean perModule, MessageWriter log) {
if (currentState.getPlatformBoms().isEmpty()) {
log.info("The project does not import any Quarkus platform BOM");
return;
}
if (currentState.getExtensions().isEmpty()) {
log.info("Quarkus extension were not found among the project dependencies");
return;
}
final ProjectState recommendedState = resolveRecommendedState(currentState, recommendedCatalog, log);
if (currentState == recommendedState) {
log.info("The project is up-to-date");
return;
}
if (recommendState) {
InfoCommandHandler.logState(recommendedState, perModule, false, log);
return;
}
// log instructions
final Map<ArtifactKey, PlatformInfo> platformImports = new LinkedHashMap<>();
for (ArtifactCoords c : currentState.getPlatformBoms()) {
final PlatformInfo info = new PlatformInfo();
info.imported = c;
platformImports.put(c.getKey(), info);
}
List<PlatformInfo> importVersionUpdates = new ArrayList<>();
List<PlatformInfo> newImports = new ArrayList<>(0);
for (ArtifactCoords c : recommendedState.getPlatformBoms()) {
final PlatformInfo importInfo = platformImports.computeIfAbsent(c.getKey(), k -> new PlatformInfo());
importInfo.recommended = c;
if (importInfo.isToBeImported()) {
newImports.add(importInfo);
} else if (importInfo.isVersionUpdateRecommended()) {
importVersionUpdates.add(importInfo);
}
}
log.info("");
final boolean importsToBeRemoved = platformImports.values().stream().filter(p -> p.recommended == null).findFirst().isPresent();
final boolean platformUpdatesAvailable = !importVersionUpdates.isEmpty() || !newImports.isEmpty() || importsToBeRemoved;
if (platformUpdatesAvailable) {
log.info("Recommended Quarkus platform BOM updates:");
if (!importVersionUpdates.isEmpty()) {
for (PlatformInfo importInfo : importVersionUpdates) {
log.info(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, UpdateCommandHandler.UPDATE, importInfo.imported.toCompactCoords()) + " -> " + importInfo.getRecommendedVersion());
}
}
if (!newImports.isEmpty()) {
for (PlatformInfo importInfo : newImports) {
log.info(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, UpdateCommandHandler.ADD, importInfo.recommended.toCompactCoords()));
}
}
if (importsToBeRemoved) {
for (PlatformInfo importInfo : platformImports.values()) {
if (importInfo.recommended == null) {
log.info(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, UpdateCommandHandler.REMOVE, importInfo.imported.toCompactCoords()));
}
}
}
log.info("");
}
final ExtensionMap extensionInfo = new ExtensionMap(currentState.getExtensions().size());
for (TopExtensionDependency dep : currentState.getExtensions()) {
extensionInfo.add(new ExtensionInfo(dep));
}
for (TopExtensionDependency dep : recommendedState.getExtensions()) {
final ExtensionInfo info = extensionInfo.get(dep.getKey());
if (info != null) {
info.recommendedDep = dep;
}
}
final Map<String, List<ExtensionInfo>> versionedManagedExtensions = new LinkedHashMap<>(0);
final Map<String, List<ArtifactCoords>> removedExtensions = new LinkedHashMap<>(0);
final Map<String, List<ArtifactCoords>> addedExtensions = new LinkedHashMap<>(0);
final Map<String, List<ExtensionInfo>> nonPlatformExtensionUpdates = new LinkedHashMap<>();
for (ExtensionInfo info : extensionInfo.values()) {
if (!info.isUpdateRecommended()) {
continue;
}
if (!info.currentDep.getKey().equals(info.getRecommendedDependency().getKey())) {
if (info.currentDep.isPlatformExtension()) {
removedExtensions.computeIfAbsent(info.currentDep.getProviderKey(), k -> new ArrayList<>()).add(info.currentDep.getArtifact());
} else {
nonPlatformExtensionUpdates.computeIfAbsent(info.currentDep.getProviderKey(), k -> new ArrayList<>()).add(info);
}
if (info.getRecommendedDependency().isPlatformExtension()) {
addedExtensions.computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>()).add(info.getRecommendedDependency().getArtifact());
} else {
nonPlatformExtensionUpdates.computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>()).add(info);
}
} else if (info.getRecommendedDependency().isPlatformExtension()) {
if (info.currentDep.isNonRecommendedVersion()) {
versionedManagedExtensions.computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>()).add(info);
}
} else if (!info.currentDep.getVersion().equals(info.getRecommendedDependency().getVersion())) {
nonPlatformExtensionUpdates.computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>()).add(info);
}
}
if (versionedManagedExtensions.isEmpty() && removedExtensions.isEmpty() && addedExtensions.isEmpty() && nonPlatformExtensionUpdates.isEmpty()) {
if (!platformUpdatesAvailable) {
log.info("The project is up-to-date");
}
return;
}
for (PlatformInfo platform : platformImports.values()) {
final String provider = platform.getRecommendedProviderKey();
if (!versionedManagedExtensions.containsKey(provider) && !removedExtensions.containsKey(provider) && !addedExtensions.containsKey(provider)) {
continue;
}
log.info("Extensions from " + platform.getRecommendedProviderKey() + ":");
for (ExtensionInfo e : versionedManagedExtensions.getOrDefault(provider, Collections.emptyList())) {
final StringBuilder sb = new StringBuilder();
sb.append(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, UpdateCommandHandler.UPDATE, e.currentDep.getArtifact().toCompactCoords()));
sb.append(" -> remove version (managed)");
log.info(sb.toString());
}
for (ArtifactCoords e : addedExtensions.getOrDefault(provider, Collections.emptyList())) {
log.info(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, UpdateCommandHandler.ADD, e.getKey().toGacString()));
}
for (ArtifactCoords e : removedExtensions.getOrDefault(provider, Collections.emptyList())) {
log.info(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, UpdateCommandHandler.REMOVE, e.getKey().toGacString()));
}
log.info("");
}
if (!nonPlatformExtensionUpdates.isEmpty()) {
for (Map.Entry<String, List<ExtensionInfo>> provider : nonPlatformExtensionUpdates.entrySet()) {
log.info("Extensions from " + provider.getKey() + ":");
for (ExtensionInfo info : provider.getValue()) {
if (info.currentDep.isPlatformExtension()) {
log.info(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, UpdateCommandHandler.ADD, info.getRecommendedDependency().getArtifact().toCompactCoords()));
} else if (info.getRecommendedDependency().isPlatformExtension()) {
log.info(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, UpdateCommandHandler.REMOVE, info.currentDep.getArtifact().toCompactCoords()));
} else {
log.info(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, UpdateCommandHandler.UPDATE, info.currentDep.getArtifact().toCompactCoords() + " -> " + info.getRecommendedDependency().getVersion()));
}
}
log.info("");
}
}
}
Aggregations