Search in sources :

Example 1 with ExtensionProvider

use of io.quarkus.devtools.project.state.ExtensionProvider in project quarkus by quarkusio.

the class InfoCommandHandler method logState.

// TODO: instead of returning a boolean, the info about available
// recommendations should be reflected in ProjectState
protected static boolean logState(ProjectState projectState, boolean perModule, boolean rectify, MessageWriter log) {
    boolean recommendationsAvailable = false;
    final Map<ArtifactKey, PlatformInfo> providerInfo = new LinkedHashMap<>();
    for (ArtifactCoords bom : projectState.getPlatformBoms()) {
        providerInfo.computeIfAbsent(bom.getKey(), k -> new PlatformInfo()).imported = bom;
    }
    for (TopExtensionDependency dep : projectState.getExtensions()) {
        final ExtensionOrigin origin = dep.getOrigin();
        if (origin != null && origin.isPlatform()) {
            providerInfo.computeIfAbsent(origin.getBom().getKey(), k -> new PlatformInfo()).recommended = origin.getBom();
        }
    }
    if (providerInfo.isEmpty()) {
        log.info("No Quarkus platform BOMs found");
    } else {
        log.info("Quarkus platform BOMs:");
        boolean recommendExtraImports = false;
        for (PlatformInfo platform : providerInfo.values()) {
            if (platform.imported == null) {
                recommendExtraImports = true;
                continue;
            }
            final StringBuilder sb = new StringBuilder();
            if (platform.recommended == null) {
                if (rectify) {
                    sb.append(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, UpdateCommandHandler.REMOVE, platform.imported.toCompactCoords()));
                    recommendationsAvailable = true;
                } else {
                    sb.append("  ");
                    sb.append(platform.imported.toCompactCoords());
                    if (!projectState.getExtensions().isEmpty()) {
                        // The extension check is for modules that are aggregating modules (e.g. parent POMs)
                        // that import common BOMs. It's however not how it should be done.
                        sb.append(" | unnecessary");
                        recommendationsAvailable = true;
                    }
                }
            } else if (platform.isVersionUpdateRecommended()) {
                if (rectify) {
                    sb.append(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, UpdateCommandHandler.UPDATE, platform.imported.toCompactCoords()));
                    sb.append(platform.imported.toCompactCoords()).append(" -> ").append(platform.getRecommendedVersion());
                } else {
                    sb.append("  ");
                    sb.append(platform.imported.toCompactCoords()).append(" | misaligned");
                }
                recommendationsAvailable = true;
            } else {
                if (rectify) {
                    sb.append(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, "", platform.imported.toCompactCoords()));
                } else {
                    sb.append("  ").append(platform.imported.toCompactCoords());
                }
            }
            log.info(sb.toString());
        }
        if (rectify && recommendExtraImports) {
            for (PlatformInfo platform : providerInfo.values()) {
                if (platform.imported == null) {
                    log.info(String.format(UpdateCommandHandler.PLATFORM_RECTIFY_FORMAT, UpdateCommandHandler.ADD, platform.recommended.toCompactCoords()));
                }
            }
            recommendationsAvailable = true;
        }
    }
    if (projectState.getExtensions().isEmpty()) {
        log.info("");
        log.info("No Quarkus extensions found among the project dependencies");
        return recommendationsAvailable;
    }
    log.info("");
    if (perModule) {
        final ModuleState mainModule = projectState.getMainModule();
        final Path baseDir = mainModule.getModuleDir();
        recommendationsAvailable |= logModuleInfo(projectState, mainModule, baseDir, log, rectify);
        for (ModuleState module : projectState.getModules()) {
            if (!module.isMain()) {
                recommendationsAvailable |= logModuleInfo(projectState, module, baseDir, log, rectify);
            }
        }
    } else {
        for (ExtensionProvider provider : projectState.getExtensionProviders()) {
            if (provider.isPlatform()) {
                recommendationsAvailable = logProvidedExtensions(provider, rectify, log, recommendationsAvailable);
            }
        }
        for (ExtensionProvider provider : projectState.getExtensionProviders()) {
            if (!provider.isPlatform()) {
                recommendationsAvailable = logProvidedExtensions(provider, rectify, log, recommendationsAvailable);
            }
        }
    }
    return recommendationsAvailable;
}
Also used : Path(java.nio.file.Path) ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) ExtensionProvider(io.quarkus.devtools.project.state.ExtensionProvider) TopExtensionDependency(io.quarkus.devtools.project.state.TopExtensionDependency) ModuleState(io.quarkus.devtools.project.state.ModuleState) LinkedHashMap(java.util.LinkedHashMap) ExtensionOrigin(io.quarkus.registry.catalog.ExtensionOrigin)

Example 2 with ExtensionProvider

use of io.quarkus.devtools.project.state.ExtensionProvider in project quarkus by quarkusio.

the class InfoCommandHandler method logModuleInfo.

private static boolean logModuleInfo(ProjectState project, ModuleState module, Path baseDir, MessageWriter log, boolean rectify) {
    if (module.getExtensions().isEmpty() && module.getPlatformBoms().isEmpty() && !module.isMain()) {
        return false;
    }
    boolean recommendationsAvailable = false;
    final StringBuilder sb = new StringBuilder();
    if (module.isMain()) {
        sb.append("Main application module ");
    } else {
        sb.append("Module ");
    }
    sb.append(module.getId().getGroupId()).append(':').append(module.getId().getArtifactId()).append(':');
    log.info(sb.toString());
    final Iterator<Path> i = module.getWorkspaceModule().getBuildFiles().iterator();
    if (i.hasNext()) {
        sb.setLength(0);
        sb.append("  Build file: ");
        sb.append(baseDir.relativize(i.next()));
        while (i.hasNext()) {
            sb.append(", ").append(baseDir.relativize(i.next()));
        }
        log.info(sb.toString());
    }
    if (!module.getPlatformBoms().isEmpty()) {
        log.info("  Platform BOMs:");
        for (ArtifactCoords bom : module.getPlatformBoms()) {
            log.info("    " + bom.toCompactCoords());
        }
    }
    if (!module.getExtensions().isEmpty()) {
        final Map<String, List<TopExtensionDependency>> extDepsByProvider = new LinkedHashMap<>();
        for (TopExtensionDependency dep : module.getExtensions()) {
            extDepsByProvider.computeIfAbsent(dep.getProviderKey(), k -> new ArrayList<>()).add(dep);
        }
        for (ExtensionProvider provider : project.getExtensionProviders()) {
            if (!provider.isPlatform()) {
                continue;
            }
            final List<TopExtensionDependency> extList = extDepsByProvider.getOrDefault(provider.getKey(), Collections.emptyList());
            if (!extList.isEmpty()) {
                log.info("  Extensions from " + provider.getKey() + ":");
                for (TopExtensionDependency dep : extList) {
                    sb.setLength(0);
                    sb.append("  ");
                    recommendationsAvailable = logExtensionInfo(dep, rectify, sb, recommendationsAvailable);
                    log.info(sb.toString());
                }
                log.info("");
            }
        }
        for (ExtensionProvider provider : project.getExtensionProviders()) {
            if (provider.isPlatform()) {
                continue;
            }
            final List<TopExtensionDependency> extList = extDepsByProvider.getOrDefault(provider.getKey(), Collections.emptyList());
            if (!extList.isEmpty()) {
                log.info("  Extensions from " + provider.getKey() + ":");
                for (TopExtensionDependency dep : extList) {
                    sb.setLength(0);
                    sb.append("  ");
                    recommendationsAvailable = logExtensionInfo(dep, rectify, sb, recommendationsAvailable);
                    log.info(sb.toString());
                }
                log.info("");
            }
        }
    }
    return recommendationsAvailable;
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) QuarkusCommandInvocation(io.quarkus.devtools.commands.data.QuarkusCommandInvocation) DependencyFlags(io.quarkus.maven.dependency.DependencyFlags) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) Map(java.util.Map) Dependency(io.quarkus.maven.dependency.Dependency) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) Path(java.nio.file.Path) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) ModuleState(io.quarkus.devtools.project.state.ModuleState) Iterator(java.util.Iterator) ExtensionProvider(io.quarkus.devtools.project.state.ExtensionProvider) Collection(java.util.Collection) WorkspaceModuleId(io.quarkus.bootstrap.workspace.WorkspaceModuleId) 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) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) MessageWriter(io.quarkus.devtools.messagewriter.MessageWriter) Collections(java.util.Collections) ProjectState(io.quarkus.devtools.project.state.ProjectState) ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) ArrayList(java.util.ArrayList) ExtensionProvider(io.quarkus.devtools.project.state.ExtensionProvider) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) TopExtensionDependency(io.quarkus.devtools.project.state.TopExtensionDependency)

Aggregations

ExtensionProvider (io.quarkus.devtools.project.state.ExtensionProvider)2 ModuleState (io.quarkus.devtools.project.state.ModuleState)2 TopExtensionDependency (io.quarkus.devtools.project.state.TopExtensionDependency)2 ArtifactCoords (io.quarkus.maven.dependency.ArtifactCoords)2 ArtifactKey (io.quarkus.maven.dependency.ArtifactKey)2 ExtensionOrigin (io.quarkus.registry.catalog.ExtensionOrigin)2 Path (java.nio.file.Path)2 LinkedHashMap (java.util.LinkedHashMap)2 ApplicationModel (io.quarkus.bootstrap.model.ApplicationModel)1 WorkspaceModule (io.quarkus.bootstrap.workspace.WorkspaceModule)1 WorkspaceModuleId (io.quarkus.bootstrap.workspace.WorkspaceModuleId)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 MessageWriter (io.quarkus.devtools.messagewriter.MessageWriter)1 ProjectState (io.quarkus.devtools.project.state.ProjectState)1 Dependency (io.quarkus.maven.dependency.Dependency)1 DependencyFlags (io.quarkus.maven.dependency.DependencyFlags)1 ResolvedDependency (io.quarkus.maven.dependency.ResolvedDependency)1 ExtensionCatalog (io.quarkus.registry.catalog.ExtensionCatalog)1