Search in sources :

Example 1 with PlatformInfo

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("");
        }
    }
}
Also used : OriginPreference(io.quarkus.registry.catalog.selection.OriginPreference) ExtensionOrigins(io.quarkus.registry.catalog.selection.ExtensionOrigins) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) QuarkusCommandInvocation(io.quarkus.devtools.commands.data.QuarkusCommandInvocation) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) Map(java.util.Map) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) ModuleState(io.quarkus.devtools.project.state.ModuleState) PlatformInfo(io.quarkus.devtools.commands.handlers.InfoCommandHandler.PlatformInfo) ExtensionProvider(io.quarkus.devtools.project.state.ExtensionProvider) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) OriginSelector(io.quarkus.registry.catalog.selection.OriginSelector) ExtensionOrigin(io.quarkus.registry.catalog.ExtensionOrigin) List(java.util.List) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) TopExtensionDependency(io.quarkus.devtools.project.state.TopExtensionDependency) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException) MessageWriter(io.quarkus.devtools.messagewriter.MessageWriter) Extension(io.quarkus.registry.catalog.Extension) OriginCombination(io.quarkus.registry.catalog.selection.OriginCombination) Collections(java.util.Collections) ProjectState(io.quarkus.devtools.project.state.ProjectState) ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) ArrayList(java.util.ArrayList) PlatformInfo(io.quarkus.devtools.commands.handlers.InfoCommandHandler.PlatformInfo) LinkedHashMap(java.util.LinkedHashMap) ProjectState(io.quarkus.devtools.project.state.ProjectState) ArrayList(java.util.ArrayList) List(java.util.List) TopExtensionDependency(io.quarkus.devtools.project.state.TopExtensionDependency) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ApplicationModel (io.quarkus.bootstrap.model.ApplicationModel)1 QuarkusCommandException (io.quarkus.devtools.commands.data.QuarkusCommandException)1 QuarkusCommandInvocation (io.quarkus.devtools.commands.data.QuarkusCommandInvocation)1 QuarkusCommandOutcome (io.quarkus.devtools.commands.data.QuarkusCommandOutcome)1 PlatformInfo (io.quarkus.devtools.commands.handlers.InfoCommandHandler.PlatformInfo)1 MessageWriter (io.quarkus.devtools.messagewriter.MessageWriter)1 ExtensionProvider (io.quarkus.devtools.project.state.ExtensionProvider)1 ModuleState (io.quarkus.devtools.project.state.ModuleState)1 ProjectState (io.quarkus.devtools.project.state.ProjectState)1 TopExtensionDependency (io.quarkus.devtools.project.state.TopExtensionDependency)1 ArtifactCoords (io.quarkus.maven.dependency.ArtifactCoords)1 ArtifactKey (io.quarkus.maven.dependency.ArtifactKey)1 Extension (io.quarkus.registry.catalog.Extension)1 ExtensionCatalog (io.quarkus.registry.catalog.ExtensionCatalog)1 ExtensionOrigin (io.quarkus.registry.catalog.ExtensionOrigin)1 ExtensionOrigins (io.quarkus.registry.catalog.selection.ExtensionOrigins)1 OriginCombination (io.quarkus.registry.catalog.selection.OriginCombination)1 OriginPreference (io.quarkus.registry.catalog.selection.OriginPreference)1 OriginSelector (io.quarkus.registry.catalog.selection.OriginSelector)1 ArrayList (java.util.ArrayList)1