Search in sources :

Example 1 with WorkspaceModuleId

use of io.quarkus.bootstrap.workspace.WorkspaceModuleId in project quarkus by quarkusio.

the class InfoCommandHandler method resolveProjectState.

protected static ProjectState resolveProjectState(ApplicationModel appModel, ExtensionCatalog currentCatalog) {
    final ProjectState.Builder projectBuilder = ProjectState.builder();
    final Collection<ArtifactCoords> importedPlatformBoms = appModel.getPlatforms().getImportedPlatformBoms();
    if (importedPlatformBoms.isEmpty()) {
        return projectBuilder.build();
    }
    final Map<String, ExtensionProvider.Builder> extProviderBuilders = new LinkedHashMap<>(importedPlatformBoms.size());
    importedPlatformBoms.forEach(bom -> {
        projectBuilder.addPlatformBom(bom);
        extProviderBuilders.put(ExtensionProvider.key(bom, true), ExtensionProvider.builder().setArtifact(bom).setPlatform(true));
    });
    final Map<WorkspaceModuleId, ModuleState.Builder> projectModuleBuilders = new HashMap<>();
    final Map<ArtifactKey, List<ModuleState.Builder>> directModuleDeps = new HashMap<>();
    final WorkspaceModule appModule = appModel.getAppArtifact().getWorkspaceModule();
    if (appModule != null) {
        final ModuleState.Builder module = ModuleState.builder().setWorkspaceModule(appModule).setMainModule(true);
        projectModuleBuilders.put(appModule.getId(), module);
        appModule.getDirectDependencies().forEach(d -> directModuleDeps.computeIfAbsent(d.getKey(), dk -> new ArrayList<>()).add(module));
        for (Dependency constraint : appModule.getDirectDependencyConstraints()) {
            if (extProviderBuilders.containsKey(constraint.toCompactCoords())) {
                module.addPlatformBom(constraint);
            }
        }
    }
    for (ResolvedDependency dep : appModel.getDependencies()) {
        if (dep.getWorkspaceModule() != null) {
            projectModuleBuilders.computeIfAbsent(dep.getWorkspaceModule().getId(), k -> {
                final ModuleState.Builder module = ModuleState.builder().setWorkspaceModule(dep.getWorkspaceModule());
                dep.getWorkspaceModule().getDirectDependencies().forEach(d -> directModuleDeps.computeIfAbsent(d.getKey(), dk -> new ArrayList<>()).add(module));
                return module;
            });
        }
    }
    final Map<ArtifactKey, TopExtensionDependency.Builder> directExtDeps = new HashMap<>();
    for (ResolvedDependency dep : appModel.getDependencies()) {
        if (dep.isFlagSet(DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT)) {
            directExtDeps.put(dep.getKey(), TopExtensionDependency.builder().setResolvedDependency(dep).setTransitive(!directModuleDeps.containsKey(dep.getKey())));
        } else if (dep.isRuntimeExtensionArtifact() && directModuleDeps.containsKey(dep.getKey())) {
            directExtDeps.put(dep.getKey(), TopExtensionDependency.builder().setResolvedDependency(dep));
        }
    }
    if (directExtDeps.isEmpty()) {
        return projectBuilder.build();
    }
    currentCatalog.getExtensions().forEach(e -> {
        final ArtifactKey key = e.getArtifact().getKey();
        final TopExtensionDependency.Builder dep = directExtDeps.get(key);
        if (dep != null) {
            dep.setCatalogMetadata(e);
        }
    });
    for (TopExtensionDependency.Builder extBuilder : directExtDeps.values()) {
        final List<ModuleState.Builder> modules = directModuleDeps.getOrDefault(extBuilder.getKey(), Collections.emptyList());
        final TopExtensionDependency dep = extBuilder.setTransitive(modules.isEmpty()).build();
        projectBuilder.addExtensionDependency(dep);
        for (ModuleState.Builder module : modules) {
            module.addExtensionDependency(dep);
        }
        final ExtensionProvider.Builder provider = extProviderBuilders.computeIfAbsent(dep.getProviderKey(), k -> ExtensionProvider.builder().setOrigin(dep.getOrigin()));
        provider.addExtension(dep);
    }
    for (ExtensionProvider.Builder builder : extProviderBuilders.values()) {
        projectBuilder.addExtensionProvider(builder.build());
    }
    for (ModuleState.Builder builder : projectModuleBuilders.values()) {
        projectBuilder.addModule(builder.build());
    }
    return projectBuilder.build();
}
Also used : ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ExtensionProvider(io.quarkus.devtools.project.state.ExtensionProvider) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) WorkspaceModuleId(io.quarkus.bootstrap.workspace.WorkspaceModuleId) Dependency(io.quarkus.maven.dependency.Dependency) TopExtensionDependency(io.quarkus.devtools.project.state.TopExtensionDependency) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ModuleState(io.quarkus.devtools.project.state.ModuleState) ProjectState(io.quarkus.devtools.project.state.ProjectState) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) TopExtensionDependency(io.quarkus.devtools.project.state.TopExtensionDependency)

Aggregations

WorkspaceModule (io.quarkus.bootstrap.workspace.WorkspaceModule)1 WorkspaceModuleId (io.quarkus.bootstrap.workspace.WorkspaceModuleId)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 Dependency (io.quarkus.maven.dependency.Dependency)1 ResolvedDependency (io.quarkus.maven.dependency.ResolvedDependency)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1