Search in sources :

Example 1 with ExtensionOrigins

use of io.quarkus.registry.catalog.selection.ExtensionOrigins 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 2 with ExtensionOrigins

use of io.quarkus.registry.catalog.selection.ExtensionOrigins 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 3 with ExtensionOrigins

use of io.quarkus.registry.catalog.selection.ExtensionOrigins in project quarkus by quarkusio.

the class UpdateCommandHandler method getRecommendedOrigins.

private static List<ExtensionCatalog> getRecommendedOrigins(ExtensionCatalog extensionCatalog, List<Extension> extensions) throws QuarkusCommandException {
    final List<ExtensionOrigins> extOrigins = new ArrayList<>(extensions.size());
    for (Extension e : extensions) {
        addOrigins(extOrigins, e);
    }
    final OriginCombination recommendedCombination = OriginSelector.of(extOrigins).calculateRecommendedCombination();
    if (recommendedCombination == null) {
        final StringBuilder buf = new StringBuilder();
        buf.append("Failed to determine a compatible Quarkus version for the requested extensions: ");
        buf.append(extensions.get(0).getArtifact().getKey().toGacString());
        for (int i = 1; i < extensions.size(); ++i) {
            buf.append(", ").append(extensions.get(i).getArtifact().getKey().toGacString());
        }
        throw new QuarkusCommandException(buf.toString());
    }
    return recommendedCombination.getUniqueSortedOrigins().stream().map(o -> o.getCatalog()).collect(Collectors.toList());
}
Also used : Extension(io.quarkus.registry.catalog.Extension) 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) ExtensionOrigins(io.quarkus.registry.catalog.selection.ExtensionOrigins) ArrayList(java.util.ArrayList) OriginCombination(io.quarkus.registry.catalog.selection.OriginCombination) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException)

Example 4 with ExtensionOrigins

use of io.quarkus.registry.catalog.selection.ExtensionOrigins in project quarkus by quarkusio.

the class CreateProjectCommandHandler method execute.

@Override
public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws QuarkusCommandException {
    final Set<String> extensionsQuery = invocation.getValue(ProjectGenerator.EXTENSIONS, Collections.emptySet());
    // Default to cleaned groupId if packageName not set
    final String className = invocation.getStringValue(CLASS_NAME);
    final String pkgName = invocation.getStringValue(PACKAGE_NAME);
    final String groupId = invocation.getStringValue(PROJECT_GROUP_ID);
    if (pkgName == null) {
        if (className != null && className.contains(".")) {
            final int idx = className.lastIndexOf('.');
            invocation.setValue(PACKAGE_NAME, className.substring(0, idx));
            invocation.setValue(CLASS_NAME, className.substring(idx + 1));
        } else if (groupId != null) {
            invocation.setValue(PACKAGE_NAME, groupId.replace('-', '.').replace('_', '.'));
        }
    }
    List<Extension> extensionsToAdd = computeRequiredExtensions(invocation.getExtensionsCatalog(), extensionsQuery, invocation.log());
    // legacy platform initialization
    ExtensionCatalog mainCatalog = invocation.getExtensionsCatalog();
    final List<ExtensionCatalog> extensionOrigins;
    try {
        extensionOrigins = getExtensionOrigins(mainCatalog, extensionsToAdd);
    } catch (QuarkusCommandException e) {
        final StringBuilder buf = new StringBuilder();
        buf.append(ERROR_ICON).append(' ').append(e.getLocalizedMessage());
        invocation.log().info(buf.toString());
        return QuarkusCommandOutcome.failure();
    }
    final List<ArtifactCoords> platformBoms = new ArrayList<>(Math.max(extensionOrigins.size(), 1));
    if (extensionOrigins.size() > 0) {
        // necessary to set the versions from the selected origins
        extensionsToAdd = computeRequiredExtensions(CatalogMergeUtility.merge(extensionOrigins), extensionsQuery, invocation.log());
        // collect platform BOMs to import
        boolean sawFirstPlatform = false;
        for (ExtensionCatalog c : extensionOrigins) {
            if (!c.isPlatform()) {
                continue;
            }
            if (c.getBom().getArtifactId().equals("quarkus-bom") || !sawFirstPlatform) {
                mainCatalog = c;
                sawFirstPlatform = true;
            }
            platformBoms.add(c.getBom());
        }
    } else {
        platformBoms.add(mainCatalog.getBom());
    }
    final List<ArtifactCoords> extensionCoords = new ArrayList<>(extensionsToAdd.size());
    for (Extension e : extensionsToAdd) {
        ArtifactCoords coords = e.getArtifact();
        for (ExtensionOrigin origin : e.getOrigins()) {
            if (origin.isPlatform() && origin.getBom() != null && platformBoms.contains(origin.getBom())) {
                coords = Extensions.stripVersion(coords);
                break;
            }
        }
        extensionCoords.add(coords);
    }
    invocation.setValue(BOM_GROUP_ID, mainCatalog.getBom().getGroupId());
    invocation.setValue(BOM_ARTIFACT_ID, mainCatalog.getBom().getArtifactId());
    invocation.setValue(BOM_VERSION, mainCatalog.getBom().getVersion());
    invocation.setValue(QUARKUS_VERSION, mainCatalog.getQuarkusCoreVersion());
    final Properties quarkusProps = ToolsUtils.readQuarkusProperties(mainCatalog);
    quarkusProps.forEach((k, v) -> {
        final String name = k.toString().replace('-', '_');
        if (!invocation.hasValue(name)) {
            invocation.setValue(name, v.toString());
        }
    });
    try {
        Map<String, Object> platformData = new HashMap<>();
        if (mainCatalog.getMetadata().get("maven") != null) {
            platformData.put("maven", mainCatalog.getMetadata().get("maven"));
        }
        if (mainCatalog.getMetadata().get("gradle") != null) {
            platformData.put("gradle", mainCatalog.getMetadata().get("gradle"));
        }
        final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder().addPlatforms(platformBoms).addExtensions(extensionCoords).buildTool(invocation.getQuarkusProject().getBuildTool()).example(invocation.getValue(EXAMPLE)).noCode(invocation.getValue(NO_CODE, false)).addCodestarts(invocation.getValue(EXTRA_CODESTARTS, Collections.emptySet())).noBuildToolWrapper(invocation.getValue(NO_BUILDTOOL_WRAPPER, false)).noDockerfiles(invocation.getValue(NO_DOCKERFILES, false)).addData(platformData).addData(LegacySupport.convertFromLegacy(invocation.getValues())).putData(APP_CONFIG, invocation.getValue(APP_CONFIG, Collections.emptyMap())).messageWriter(invocation.log()).build();
        invocation.log().info("-----------");
        if (!extensionsToAdd.isEmpty()) {
            invocation.log().info("selected extensions: \n" + extensionsToAdd.stream().map(e -> "- " + e.getArtifact().getGroupId() + ":" + e.getArtifact().getArtifactId() + "\n").collect(Collectors.joining()));
        }
        final QuarkusCodestartCatalog catalog = QuarkusCodestartCatalog.fromExtensionsCatalog(invocation.getQuarkusProject().getExtensionsCatalog(), invocation.getQuarkusProject().getCodestartResourceLoaders());
        final CodestartProjectDefinition projectDefinition = catalog.createProject(input);
        projectDefinition.generate(invocation.getQuarkusProject().getProjectDirPath());
        invocation.log().info("\n-----------\n" + MessageIcons.OK_ICON + " " + projectDefinition.getRequiredCodestart(CodestartType.PROJECT).getName() + " project has been successfully generated in:\n--> " + invocation.getQuarkusProject().getProjectDirPath().toString() + "\n-----------");
    } catch (IOException e) {
        throw new QuarkusCommandException("Failed to create project: " + e.getMessage(), e);
    }
    return QuarkusCommandOutcome.success();
}
Also used : BOM_GROUP_ID(io.quarkus.devtools.project.codegen.ProjectGenerator.BOM_GROUP_ID) Extensions(io.quarkus.devtools.project.extensions.Extensions) PACKAGE_NAME(io.quarkus.devtools.project.codegen.ProjectGenerator.PACKAGE_NAME) OriginPreference(io.quarkus.registry.catalog.selection.OriginPreference) ExtensionOrigins(io.quarkus.registry.catalog.selection.ExtensionOrigins) HashMap(java.util.HashMap) CodestartType(io.quarkus.devtools.codestarts.CodestartType) ToolsUtils(io.quarkus.platform.tools.ToolsUtils) ArrayList(java.util.ArrayList) QuarkusCodestartCatalog(io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog) QuarkusCommandInvocation(io.quarkus.devtools.commands.data.QuarkusCommandInvocation) ERROR_ICON(io.quarkus.devtools.messagewriter.MessageIcons.ERROR_ICON) ArtifactCoords(io.quarkus.maven.ArtifactCoords) MessageIcons(io.quarkus.devtools.messagewriter.MessageIcons) Map(java.util.Map) NO_CODE(io.quarkus.devtools.commands.CreateProject.NO_CODE) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) EXAMPLE(io.quarkus.devtools.commands.CreateProject.EXAMPLE) NO_BUILDTOOL_WRAPPER(io.quarkus.devtools.commands.CreateProject.NO_BUILDTOOL_WRAPPER) APP_CONFIG(io.quarkus.devtools.project.codegen.ProjectGenerator.APP_CONFIG) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) CatalogMergeUtility(io.quarkus.registry.CatalogMergeUtility) QuarkusCommandHandlers.computeExtensionsFromQuery(io.quarkus.devtools.commands.handlers.QuarkusCommandHandlers.computeExtensionsFromQuery) BOM_ARTIFACT_ID(io.quarkus.devtools.project.codegen.ProjectGenerator.BOM_ARTIFACT_ID) Properties(java.util.Properties) QuarkusCodestartProjectInput(io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartProjectInput) CLASS_NAME(io.quarkus.devtools.project.codegen.ProjectGenerator.CLASS_NAME) CodestartProjectDefinition(io.quarkus.devtools.codestarts.CodestartProjectDefinition) Set(java.util.Set) IOException(java.io.IOException) LegacySupport(io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.LegacySupport) EXTRA_CODESTARTS(io.quarkus.devtools.commands.CreateProject.EXTRA_CODESTARTS) PROJECT_GROUP_ID(io.quarkus.devtools.project.codegen.ProjectGenerator.PROJECT_GROUP_ID) Collectors(java.util.stream.Collectors) OriginSelector(io.quarkus.registry.catalog.selection.OriginSelector) ExtensionOrigin(io.quarkus.registry.catalog.ExtensionOrigin) List(java.util.List) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException) QUARKUS_VERSION(io.quarkus.devtools.project.codegen.ProjectGenerator.QUARKUS_VERSION) Optional(java.util.Optional) MessageWriter(io.quarkus.devtools.messagewriter.MessageWriter) ProjectGenerator(io.quarkus.devtools.project.codegen.ProjectGenerator) Extension(io.quarkus.registry.catalog.Extension) OriginCombination(io.quarkus.registry.catalog.selection.OriginCombination) Collections(java.util.Collections) NO_DOCKERFILES(io.quarkus.devtools.commands.CreateProject.NO_DOCKERFILES) BOM_VERSION(io.quarkus.devtools.project.codegen.ProjectGenerator.BOM_VERSION) ArtifactCoords(io.quarkus.maven.ArtifactCoords) HashMap(java.util.HashMap) CodestartProjectDefinition(io.quarkus.devtools.codestarts.CodestartProjectDefinition) ArrayList(java.util.ArrayList) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) IOException(java.io.IOException) Properties(java.util.Properties) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException) Extension(io.quarkus.registry.catalog.Extension) QuarkusCodestartCatalog(io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog) QuarkusCodestartProjectInput(io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartProjectInput) ExtensionOrigin(io.quarkus.registry.catalog.ExtensionOrigin)

Example 5 with ExtensionOrigins

use of io.quarkus.registry.catalog.selection.ExtensionOrigins in project quarkus by quarkusio.

the class CreateProjectCommandHandler method getExtensionOrigins.

private static List<ExtensionCatalog> getExtensionOrigins(ExtensionCatalog extensionCatalog, List<Extension> extensionsToAdd) throws QuarkusCommandException {
    final List<ExtensionOrigins> extOrigins = new ArrayList<>(extensionsToAdd.size());
    for (Extension e : extensionsToAdd) {
        addOrigins(extOrigins, e);
    }
    if (extOrigins.isEmpty()) {
        // legacy 1.x or universe platform
        return Collections.emptyList();
    }
    // we add quarkus-core as a selected extension here only to include the quarkus-bom
    // in the list of platforms. quarkus-core won't be added to the generated POM though.
    final Optional<Extension> quarkusCore = extensionCatalog.getExtensions().stream().filter(e -> e.getArtifact().getArtifactId().equals("quarkus-core")).findFirst();
    if (!quarkusCore.isPresent()) {
        throw new QuarkusCommandException("Failed to locate quarkus-core in the extension catalog");
    }
    addOrigins(extOrigins, quarkusCore.get());
    final OriginCombination recommendedCombination = OriginSelector.of(extOrigins).calculateRecommendedCombination();
    if (recommendedCombination == null) {
        final StringBuilder buf = new StringBuilder();
        buf.append("Failed to determine a compatible Quarkus version for the requested extensions: ");
        buf.append(extensionsToAdd.get(0).getArtifact().getKey().toGacString());
        for (int i = 1; i < extensionsToAdd.size(); ++i) {
            buf.append(", ").append(extensionsToAdd.get(i).getArtifact().getKey().toGacString());
        }
        throw new QuarkusCommandException(buf.toString());
    }
    return recommendedCombination.getUniqueSortedOrigins().stream().map(o -> o.getCatalog()).collect(Collectors.toList());
}
Also used : Extension(io.quarkus.registry.catalog.Extension) BOM_GROUP_ID(io.quarkus.devtools.project.codegen.ProjectGenerator.BOM_GROUP_ID) Extensions(io.quarkus.devtools.project.extensions.Extensions) PACKAGE_NAME(io.quarkus.devtools.project.codegen.ProjectGenerator.PACKAGE_NAME) OriginPreference(io.quarkus.registry.catalog.selection.OriginPreference) ExtensionOrigins(io.quarkus.registry.catalog.selection.ExtensionOrigins) HashMap(java.util.HashMap) CodestartType(io.quarkus.devtools.codestarts.CodestartType) ToolsUtils(io.quarkus.platform.tools.ToolsUtils) ArrayList(java.util.ArrayList) QuarkusCodestartCatalog(io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog) QuarkusCommandInvocation(io.quarkus.devtools.commands.data.QuarkusCommandInvocation) ERROR_ICON(io.quarkus.devtools.messagewriter.MessageIcons.ERROR_ICON) ArtifactCoords(io.quarkus.maven.ArtifactCoords) MessageIcons(io.quarkus.devtools.messagewriter.MessageIcons) Map(java.util.Map) NO_CODE(io.quarkus.devtools.commands.CreateProject.NO_CODE) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) EXAMPLE(io.quarkus.devtools.commands.CreateProject.EXAMPLE) NO_BUILDTOOL_WRAPPER(io.quarkus.devtools.commands.CreateProject.NO_BUILDTOOL_WRAPPER) APP_CONFIG(io.quarkus.devtools.project.codegen.ProjectGenerator.APP_CONFIG) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) CatalogMergeUtility(io.quarkus.registry.CatalogMergeUtility) QuarkusCommandHandlers.computeExtensionsFromQuery(io.quarkus.devtools.commands.handlers.QuarkusCommandHandlers.computeExtensionsFromQuery) BOM_ARTIFACT_ID(io.quarkus.devtools.project.codegen.ProjectGenerator.BOM_ARTIFACT_ID) Properties(java.util.Properties) QuarkusCodestartProjectInput(io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartProjectInput) CLASS_NAME(io.quarkus.devtools.project.codegen.ProjectGenerator.CLASS_NAME) CodestartProjectDefinition(io.quarkus.devtools.codestarts.CodestartProjectDefinition) Set(java.util.Set) IOException(java.io.IOException) LegacySupport(io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.LegacySupport) EXTRA_CODESTARTS(io.quarkus.devtools.commands.CreateProject.EXTRA_CODESTARTS) PROJECT_GROUP_ID(io.quarkus.devtools.project.codegen.ProjectGenerator.PROJECT_GROUP_ID) Collectors(java.util.stream.Collectors) OriginSelector(io.quarkus.registry.catalog.selection.OriginSelector) ExtensionOrigin(io.quarkus.registry.catalog.ExtensionOrigin) List(java.util.List) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException) QUARKUS_VERSION(io.quarkus.devtools.project.codegen.ProjectGenerator.QUARKUS_VERSION) Optional(java.util.Optional) MessageWriter(io.quarkus.devtools.messagewriter.MessageWriter) ProjectGenerator(io.quarkus.devtools.project.codegen.ProjectGenerator) Extension(io.quarkus.registry.catalog.Extension) OriginCombination(io.quarkus.registry.catalog.selection.OriginCombination) Collections(java.util.Collections) NO_DOCKERFILES(io.quarkus.devtools.commands.CreateProject.NO_DOCKERFILES) BOM_VERSION(io.quarkus.devtools.project.codegen.ProjectGenerator.BOM_VERSION) ExtensionOrigins(io.quarkus.registry.catalog.selection.ExtensionOrigins) ArrayList(java.util.ArrayList) OriginCombination(io.quarkus.registry.catalog.selection.OriginCombination) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException)

Aggregations

ExtensionCatalog (io.quarkus.registry.catalog.ExtensionCatalog)5 ExtensionOrigin (io.quarkus.registry.catalog.ExtensionOrigin)5 ExtensionOrigins (io.quarkus.registry.catalog.selection.ExtensionOrigins)5 OriginPreference (io.quarkus.registry.catalog.selection.OriginPreference)5 QuarkusCommandException (io.quarkus.devtools.commands.data.QuarkusCommandException)3 QuarkusCommandInvocation (io.quarkus.devtools.commands.data.QuarkusCommandInvocation)3 QuarkusCommandOutcome (io.quarkus.devtools.commands.data.QuarkusCommandOutcome)3 MessageWriter (io.quarkus.devtools.messagewriter.MessageWriter)3 Extension (io.quarkus.registry.catalog.Extension)3 OriginCombination (io.quarkus.registry.catalog.selection.OriginCombination)3 OriginSelector (io.quarkus.registry.catalog.selection.OriginSelector)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 CodestartProjectDefinition (io.quarkus.devtools.codestarts.CodestartProjectDefinition)2 CodestartType (io.quarkus.devtools.codestarts.CodestartType)2 QuarkusCodestartCatalog (io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog)2