Search in sources :

Example 1 with ExtensionOrigin

use of io.quarkus.registry.catalog.ExtensionOrigin in project quarkus by quarkusio.

the class UpdateCommandHandler method resolveRecommendedState.

private static ProjectState resolveRecommendedState(ProjectState currentState, ExtensionCatalog latestCatalog, MessageWriter log) {
    if (currentState.getPlatformBoms().isEmpty()) {
        return currentState;
    }
    if (currentState.getExtensions().isEmpty()) {
        return currentState;
    }
    final ExtensionMap extensionInfo = new ExtensionMap();
    for (TopExtensionDependency dep : currentState.getExtensions()) {
        extensionInfo.add(new ExtensionInfo(dep));
    }
    for (Extension e : latestCatalog.getExtensions()) {
        final ExtensionInfo candidate = extensionInfo.get(e.getArtifact().getKey());
        if (candidate != null && candidate.latestMetadata == null) {
            // if the latestMetadata has already been initialized, it's already the preferred one
            // that could happen if an artifact has relocated
            candidate.latestMetadata = e;
        }
    }
    final List<ExtensionInfo> unknownExtensions = new ArrayList<>(0);
    final List<Extension> updateCandidates = new ArrayList<>(extensionInfo.size());
    final Map<String, ExtensionMap> updateCandidatesByOrigin = new HashMap<>();
    for (ExtensionInfo i : extensionInfo.values()) {
        if (i.latestMetadata == null) {
            unknownExtensions.add(i);
        } else {
            updateCandidates.add(i.latestMetadata);
            for (ExtensionOrigin o : i.latestMetadata.getOrigins()) {
                updateCandidatesByOrigin.computeIfAbsent(o.getId(), k -> new ExtensionMap()).add(i);
            }
        }
    }
    if (extensionInfo.isEmpty()) {
        return currentState;
    }
    if (!unknownExtensions.isEmpty()) {
        log.warn("The configured Quarkus registries did not provide any compatibility information for the following extensions in the context of the currently recommended Quarkus platforms:");
        unknownExtensions.forEach(e -> log.warn(" " + e.currentDep.getArtifact().toCompactCoords()));
    }
    final List<ExtensionCatalog> recommendedOrigins;
    try {
        recommendedOrigins = getRecommendedOrigins(latestCatalog, updateCandidates);
    } catch (QuarkusCommandException e) {
        log.info("Failed to find a compatible configuration update for the project");
        return currentState;
    }
    int collectedUpdates = 0;
    for (ExtensionCatalog recommendedOrigin : recommendedOrigins) {
        final ExtensionMap candidates = updateCandidatesByOrigin.get(recommendedOrigin.getId());
        for (Extension e : recommendedOrigin.getExtensions()) {
            final ExtensionInfo info = candidates.get(e.getArtifact().getKey());
            if (info != null && info.recommendedMetadata == null) {
                info.setRecommendedMetadata(e);
                if (++collectedUpdates == updateCandidates.size()) {
                    break;
                }
            }
        }
    }
    final ProjectState.Builder stateBuilder = ProjectState.builder();
    for (ExtensionCatalog c : recommendedOrigins) {
        if (c.isPlatform()) {
            stateBuilder.addPlatformBom(c.getBom());
        }
    }
    final Map<String, ExtensionProvider.Builder> extProviders = new LinkedHashMap<>(recommendedOrigins.size());
    for (ExtensionInfo info : extensionInfo.values()) {
        final TopExtensionDependency ext = info.getRecommendedDependency();
        stateBuilder.addExtensionDependency(ext);
        extProviders.computeIfAbsent(ext.getProviderKey(), k -> ExtensionProvider.builder().setOrigin(ext.getOrigin())).addExtension(ext);
    }
    extProviders.values().forEach(b -> stateBuilder.addExtensionProvider(b.build()));
    for (ModuleState module : currentState.getModules()) {
        final ModuleState.Builder moduleBuilder = ModuleState.builder().setMainModule(module.isMain()).setWorkspaceModule(module.getWorkspaceModule());
        for (TopExtensionDependency dep : module.getExtensions()) {
            final TopExtensionDependency recommendedDep = extensionInfo.get(dep.getKey()).getRecommendedDependency();
            moduleBuilder.addExtensionDependency(recommendedDep);
            final ExtensionOrigin origin = recommendedDep.getOrigin();
            if (origin != null && origin.isPlatform()) {
                moduleBuilder.addPlatformBom(origin.getBom());
            }
        }
        stateBuilder.addModule(moduleBuilder.build());
    }
    return stateBuilder.build();
}
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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) ModuleState(io.quarkus.devtools.project.state.ModuleState) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException) LinkedHashMap(java.util.LinkedHashMap) Extension(io.quarkus.registry.catalog.Extension) ProjectState(io.quarkus.devtools.project.state.ProjectState) TopExtensionDependency(io.quarkus.devtools.project.state.TopExtensionDependency) ExtensionOrigin(io.quarkus.registry.catalog.ExtensionOrigin)

Example 2 with ExtensionOrigin

use of io.quarkus.registry.catalog.ExtensionOrigin in project quarkus by quarkusio.

the class UpdateCommandHandler method addOrigins.

private static void addOrigins(final List<ExtensionOrigins> extOrigins, Extension e) {
    ExtensionOrigins.Builder eoBuilder = null;
    for (ExtensionOrigin o : e.getOrigins()) {
        if (!(o instanceof ExtensionCatalog)) {
            continue;
        }
        final ExtensionCatalog c = (ExtensionCatalog) o;
        final OriginPreference op = (OriginPreference) c.getMetadata().get("origin-preference");
        if (op == null) {
            continue;
        }
        if (eoBuilder == null) {
            eoBuilder = ExtensionOrigins.builder(e.getArtifact().getKey());
        }
        eoBuilder.addOrigin(c, op);
    }
    if (eoBuilder != null) {
        extOrigins.add(eoBuilder.build());
    }
}
Also used : ExtensionOrigins(io.quarkus.registry.catalog.selection.ExtensionOrigins) OriginPreference(io.quarkus.registry.catalog.selection.OriginPreference) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) ExtensionOrigin(io.quarkus.registry.catalog.ExtensionOrigin)

Example 3 with ExtensionOrigin

use of io.quarkus.registry.catalog.ExtensionOrigin in project quarkus by quarkusio.

the class CreateProjectCommandHandler method addOrigins.

private static void addOrigins(final List<ExtensionOrigins> extOrigins, Extension e) {
    ExtensionOrigins.Builder eoBuilder = null;
    for (ExtensionOrigin o : e.getOrigins()) {
        if (!(o instanceof ExtensionCatalog)) {
            continue;
        }
        final ExtensionCatalog c = (ExtensionCatalog) o;
        final OriginPreference op = (OriginPreference) c.getMetadata().get("origin-preference");
        if (op == null) {
            continue;
        }
        if (eoBuilder == null) {
            eoBuilder = ExtensionOrigins.builder(e.getArtifact().getKey());
        }
        eoBuilder.addOrigin(c, op);
    }
    if (eoBuilder != null) {
        extOrigins.add(eoBuilder.build());
    }
}
Also used : ExtensionOrigins(io.quarkus.registry.catalog.selection.ExtensionOrigins) OriginPreference(io.quarkus.registry.catalog.selection.OriginPreference) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) ExtensionOrigin(io.quarkus.registry.catalog.ExtensionOrigin)

Example 4 with ExtensionOrigin

use of io.quarkus.registry.catalog.ExtensionOrigin in project quarkus by quarkusio.

the class ExtensionsAppearingInPlatformAndNonPlatformCatalogsTest method createWithPreferedCatalogs.

@Test
public void createWithPreferedCatalogs() throws Exception {
    final Path projectDir = newProjectDir("preferred-catalogs");
    final ExtensionCatalog catalog = QuarkusProjectHelper.getCatalogResolver().resolveExtensionCatalog(Arrays.asList(ArtifactCoords.fromString("org.acme.platform:quarkus-bom::pom:1.0.1"), ArtifactCoords.fromString("org.acme.platform:acme-foo-bom::pom:1.0.1"), ArtifactCoords.fromString("org.acme.platform:acme-baz-bom::pom:1.0.1")));
    final QuarkusProject project = QuarkusProjectHelper.getProject(projectDir, catalog, BuildTool.MAVEN);
    final Set<String> extensionKeys = new HashSet<>();
    final List<ArtifactCoords> expectedExtensions = new ArrayList<>();
    catalog.getExtensions().forEach(e -> {
        final ArtifactCoords coords = e.getArtifact();
        extensionKeys.add(coords.getGroupId() + ":" + coords.getArtifactId());
        boolean platform = false;
        for (ExtensionOrigin o : e.getOrigins()) {
            if (o.isPlatform()) {
                platform = true;
                break;
            }
        }
        expectedExtensions.add(platform ? new ArtifactCoords(coords.getGroupId(), coords.getArtifactId(), coords.getClassifier(), coords.getType(), null) : coords);
    });
    new CreateProject(project).extensions(extensionKeys).noCode().execute();
    assertModel(projectDir, toPlatformBomCoords("acme-foo-bom", "acme-baz-bom"), expectedExtensions, "1.0.1");
}
Also used : Path(java.nio.file.Path) ArtifactCoords(io.quarkus.maven.ArtifactCoords) ArrayList(java.util.ArrayList) QuarkusProject(io.quarkus.devtools.project.QuarkusProject) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) CreateProject(io.quarkus.devtools.commands.CreateProject) HashSet(java.util.HashSet) ExtensionOrigin(io.quarkus.registry.catalog.ExtensionOrigin) Test(org.junit.jupiter.api.Test)

Example 5 with ExtensionOrigin

use of io.quarkus.registry.catalog.ExtensionOrigin 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)

Aggregations

ExtensionOrigin (io.quarkus.registry.catalog.ExtensionOrigin)10 ExtensionCatalog (io.quarkus.registry.catalog.ExtensionCatalog)9 ArrayList (java.util.ArrayList)6 ArtifactCoords (io.quarkus.maven.ArtifactCoords)4 Extension (io.quarkus.registry.catalog.Extension)4 ExtensionOrigins (io.quarkus.registry.catalog.selection.ExtensionOrigins)3 OriginPreference (io.quarkus.registry.catalog.selection.OriginPreference)3 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 CreateProject (io.quarkus.devtools.commands.CreateProject)2 QuarkusCommandException (io.quarkus.devtools.commands.data.QuarkusCommandException)2 QuarkusCommandInvocation (io.quarkus.devtools.commands.data.QuarkusCommandInvocation)2 QuarkusCommandOutcome (io.quarkus.devtools.commands.data.QuarkusCommandOutcome)2 MessageWriter (io.quarkus.devtools.messagewriter.MessageWriter)2 QuarkusProject (io.quarkus.devtools.project.QuarkusProject)2 ArtifactKey (io.quarkus.maven.ArtifactKey)2 ApplicationModel (io.quarkus.bootstrap.model.ApplicationModel)1 CodestartProjectDefinition (io.quarkus.devtools.codestarts.CodestartProjectDefinition)1