Search in sources :

Example 1 with QuarkusCommandInvocation

use of io.quarkus.devtools.commands.data.QuarkusCommandInvocation in project quarkus by quarkusio.

the class AddExtensionsCommandHandler method execute.

@Override
public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws QuarkusCommandException {
    final Set<String> extensionsQuery = invocation.getValue(AddExtensions.EXTENSIONS, Collections.emptySet());
    if (extensionsQuery.isEmpty()) {
        return QuarkusCommandOutcome.success().setValue(AddExtensions.OUTCOME_UPDATED, false);
    }
    final ExtensionManager extensionManager = invocation.getValue(EXTENSION_MANAGER, invocation.getQuarkusProject().getExtensionManager());
    try {
        ExtensionInstallPlan extensionInstallPlan = planInstallation(invocation, extensionsQuery);
        if (extensionInstallPlan.isInstallable()) {
            final InstallResult result = extensionManager.install(extensionInstallPlan);
            result.getInstalledPlatforms().forEach(a -> invocation.log().info(MessageIcons.OK_ICON + " Platform " + a.getGroupId() + ":" + a.getArtifactId() + " has been installed"));
            result.getInstalledManagedExtensions().forEach(a -> invocation.log().info(MessageIcons.OK_ICON + " Extension " + a.getGroupId() + ":" + a.getArtifactId() + " has been installed"));
            result.getInstalledIndependentExtensions().forEach(a -> invocation.log().info(MessageIcons.OK_ICON + " Extension " + a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion() + " has been installed"));
            result.getAlreadyInstalled().forEach(a -> invocation.log().info(MessageIcons.NOOP_ICON + " Extension " + a.getGroupId() + ":" + a.getArtifactId() + " was already installed"));
            return new QuarkusCommandOutcome(true).setValue(AddExtensions.OUTCOME_UPDATED, result.isSourceUpdated());
        } else if (!extensionInstallPlan.getUnmatchedKeywords().isEmpty()) {
            invocation.log().info(ERROR_ICON + " Nothing installed because keyword(s) '" + String.join("', '", extensionInstallPlan.getUnmatchedKeywords()) + "' were not matched in the catalog.");
        } else {
            invocation.log().info(NOK_ICON + " The provided keyword(s) did not match any extension from the catalog.");
        }
    } catch (MultipleExtensionsFoundException m) {
        StringBuilder sb = new StringBuilder();
        sb.append(ERROR_ICON + " Multiple extensions matching '").append(m.getKeyword()).append("'");
        m.getExtensions().forEach(extension -> sb.append(System.lineSeparator()).append("     - ").append(extension.managementKey()));
        sb.append(System.lineSeparator()).append("     Be more specific e.g using the exact name or the full GAV.");
        invocation.log().info(sb.toString());
    } catch (IOException e) {
        throw new QuarkusCommandException("Failed to add extensions", e);
    }
    return new QuarkusCommandOutcome(false).setValue(AddExtensions.OUTCOME_UPDATED, false);
}
Also used : Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ArtifactKey(io.quarkus.maven.ArtifactKey) QuarkusCommandInvocation(io.quarkus.devtools.commands.data.QuarkusCommandInvocation) ERROR_ICON(io.quarkus.devtools.messagewriter.MessageIcons.ERROR_ICON) ArtifactCoords(io.quarkus.maven.ArtifactCoords) ExtensionOrigin(io.quarkus.registry.catalog.ExtensionOrigin) List(java.util.List) NOK_ICON(io.quarkus.devtools.messagewriter.MessageIcons.NOK_ICON) ExtensionInstallPlan(io.quarkus.devtools.project.extensions.ExtensionInstallPlan) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException) MessageIcons(io.quarkus.devtools.messagewriter.MessageIcons) InstallResult(io.quarkus.devtools.project.extensions.ExtensionManager.InstallResult) ExtensionPredicate(io.quarkus.platform.catalog.predicate.ExtensionPredicate) EXTENSION_MANAGER(io.quarkus.devtools.commands.AddExtensions.EXTENSION_MANAGER) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) Extension(io.quarkus.registry.catalog.Extension) Collections(java.util.Collections) AddExtensions(io.quarkus.devtools.commands.AddExtensions) ExtensionManager(io.quarkus.devtools.project.extensions.ExtensionManager) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) ExtensionInstallPlan(io.quarkus.devtools.project.extensions.ExtensionInstallPlan) ExtensionManager(io.quarkus.devtools.project.extensions.ExtensionManager) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) IOException(java.io.IOException) InstallResult(io.quarkus.devtools.project.extensions.ExtensionManager.InstallResult) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException)

Example 2 with QuarkusCommandInvocation

use of io.quarkus.devtools.commands.data.QuarkusCommandInvocation in project quarkus by quarkusio.

the class CreateApp method call.

@Override
public Integer call() throws Exception {
    try {
        output.debug("Creating a new project with initial parameters: %s", this);
        output.throwIfUnmatchedArguments(spec.commandLine());
        setSingleProjectGAV(gav);
        setTestOutputDirectory(output.getTestDirectory());
        if (checkProjectRootAlreadyExists(runMode.isDryRun())) {
            return CommandLine.ExitCode.USAGE;
        }
        BuildTool buildTool = targetBuildTool.getBuildTool(BuildTool.MAVEN);
        SourceType sourceType = targetLanguage.getSourceType(spec, buildTool, extensions, output);
        setJavaVersion(targetLanguage.getJavaVersion());
        setSourceTypeExtensions(extensions, sourceType);
        setCodegenOptions(codeGeneration);
        QuarkusCommandInvocation invocation = build(buildTool, targetQuarkusVersion, propertiesOptions.properties, extensions);
        boolean success = true;
        if (runMode.isDryRun()) {
            dryRun(buildTool, invocation, output);
        } else if (buildTool == BuildTool.JBANG) {
            success = new CreateJBangProjectCommandHandler().execute(invocation).isSuccess();
        } else {
            // maven or gradle
            success = new CreateProjectCommandHandler().execute(invocation).isSuccess();
        }
        if (success) {
            if (!runMode.isDryRun()) {
                output.info("Navigate into this directory and get started: " + spec.root().qualifiedName() + " dev");
            }
            return CommandLine.ExitCode.OK;
        }
        return CommandLine.ExitCode.SOFTWARE;
    } catch (Exception e) {
        return output.handleCommandException(e, "Unable to create project: " + e.getMessage());
    }
}
Also used : CreateJBangProjectCommandHandler(io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler) QuarkusCommandInvocation(io.quarkus.devtools.commands.data.QuarkusCommandInvocation) BuildTool(io.quarkus.devtools.project.BuildTool) SourceType(io.quarkus.devtools.project.codegen.SourceType) CreateProjectCommandHandler(io.quarkus.devtools.commands.handlers.CreateProjectCommandHandler)

Example 3 with QuarkusCommandInvocation

use of io.quarkus.devtools.commands.data.QuarkusCommandInvocation in project quarkus by quarkusio.

the class InfoMojo method processProjectState.

@Override
protected void processProjectState(QuarkusProject quarkusProject) throws MojoExecutionException {
    final Map<String, Object> params = new HashMap<>();
    params.put(UpdateCommandHandler.APP_MODEL, resolveApplicationModel());
    params.put(UpdateCommandHandler.LOG_STATE_PER_MODULE, perModule);
    final QuarkusCommandInvocation invocation = new QuarkusCommandInvocation(quarkusProject, params);
    QuarkusCommandOutcome outcome;
    try {
        outcome = new InfoCommandHandler().execute(invocation);
    } catch (QuarkusCommandException e) {
        throw new MojoExecutionException("Failed to resolve the available updates", e);
    }
    if (outcome.getValue(InfoCommandHandler.RECOMMENDATIONS_AVAILABLE, false)) {
        getLog().warn("Non-recommended Quarkus platform BOM and/or extension versions were found. For more details, please, execute 'mvn quarkus:update -Drectify'");
    }
}
Also used : InfoCommandHandler(io.quarkus.devtools.commands.handlers.InfoCommandHandler) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) QuarkusCommandInvocation(io.quarkus.devtools.commands.data.QuarkusCommandInvocation) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException)

Example 4 with QuarkusCommandInvocation

use of io.quarkus.devtools.commands.data.QuarkusCommandInvocation in project quarkus by quarkusio.

the class UpdateMojo method processProjectState.

@Override
protected void processProjectState(QuarkusProject quarkusProject) throws MojoExecutionException {
    final Map<String, Object> params = new HashMap<>();
    try {
        params.put(UpdateCommandHandler.LATEST_CATALOG, getExtensionCatalogResolver().resolveExtensionCatalog());
    } catch (RegistryResolutionException e) {
        throw new MojoExecutionException("Failed to resolve the latest Quarkus extension catalog from the configured extension registries", e);
    }
    params.put(UpdateCommandHandler.APP_MODEL, resolveApplicationModel());
    params.put(UpdateCommandHandler.LOG_RECOMMENDED_STATE, recommendedState);
    params.put(UpdateCommandHandler.LOG_STATE_PER_MODULE, perModule);
    params.put(UpdateCommandHandler.RECTIFY, rectify);
    final QuarkusCommandInvocation invocation = new QuarkusCommandInvocation(quarkusProject, params);
    try {
        new UpdateCommandHandler().execute(invocation);
    } catch (QuarkusCommandException e) {
        throw new MojoExecutionException("Failed to resolve the available updates", e);
    }
}
Also used : RegistryResolutionException(io.quarkus.registry.RegistryResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) QuarkusCommandInvocation(io.quarkus.devtools.commands.data.QuarkusCommandInvocation) UpdateCommandHandler(io.quarkus.devtools.commands.handlers.UpdateCommandHandler) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException)

Example 5 with QuarkusCommandInvocation

use of io.quarkus.devtools.commands.data.QuarkusCommandInvocation in project quarkus-platform by quarkusio.

the class UpdateMojo method processProjectState.

@Override
protected void processProjectState(QuarkusProject quarkusProject) throws MojoExecutionException {
    final Map<String, Object> params = new HashMap<>();
    try {
        params.put(UpdateCommandHandler.LATEST_CATALOG, getExtensionCatalogResolver().resolveExtensionCatalog());
    } catch (RegistryResolutionException e) {
        throw new MojoExecutionException("Failed to resolve the latest Quarkus extension catalog from the configured extension registries", e);
    }
    params.put(UpdateCommandHandler.APP_MODEL, resolveApplicationModel());
    params.put(UpdateCommandHandler.LOG_RECOMMENDED_STATE, recommendedState);
    params.put(UpdateCommandHandler.LOG_STATE_PER_MODULE, perModule);
    params.put(UpdateCommandHandler.RECTIFY, rectify);
    final QuarkusCommandInvocation invocation = new QuarkusCommandInvocation(quarkusProject, params);
    try {
        new UpdateCommandHandler().execute(invocation);
    } catch (QuarkusCommandException e) {
        throw new MojoExecutionException("Failed to resolve the available updates", e);
    }
}
Also used : RegistryResolutionException(io.quarkus.registry.RegistryResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) QuarkusCommandInvocation(io.quarkus.devtools.commands.data.QuarkusCommandInvocation) UpdateCommandHandler(io.quarkus.devtools.commands.handlers.UpdateCommandHandler) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException)

Aggregations

QuarkusCommandInvocation (io.quarkus.devtools.commands.data.QuarkusCommandInvocation)15 QuarkusCommandException (io.quarkus.devtools.commands.data.QuarkusCommandException)8 QuarkusCommandOutcome (io.quarkus.devtools.commands.data.QuarkusCommandOutcome)7 HashMap (java.util.HashMap)7 QuarkusProject (io.quarkus.devtools.project.QuarkusProject)4 ArtifactCoords (io.quarkus.maven.ArtifactCoords)4 IOException (java.io.IOException)4 List (java.util.List)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 CreateJBangProjectCommandHandler (io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler)3 CreateProjectCommandHandler (io.quarkus.devtools.commands.handlers.CreateProjectCommandHandler)3 InfoCommandHandler (io.quarkus.devtools.commands.handlers.InfoCommandHandler)3 MessageIcons (io.quarkus.devtools.messagewriter.MessageIcons)3 Extension (io.quarkus.registry.catalog.Extension)3 ExtensionCatalog (io.quarkus.registry.catalog.ExtensionCatalog)3 ExtensionOrigin (io.quarkus.registry.catalog.ExtensionOrigin)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3