Search in sources :

Example 1 with MessageWriter

use of io.quarkus.devtools.messagewriter.MessageWriter 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 MessageWriter

use of io.quarkus.devtools.messagewriter.MessageWriter in project quarkus by quarkusio.

the class CreateJBangMojo method execute.

@Override
public void execute() throws MojoExecutionException {
    try {
        Files.createDirectories(outputDirectory.toPath());
    } catch (IOException e) {
        throw new MojoExecutionException("Could not create directory " + outputDirectory, e);
    }
    File projectRoot = outputDirectory;
    final Path projectDirPath = projectRoot.toPath();
    final MavenArtifactResolver mvn;
    try {
        mvn = MavenArtifactResolver.builder().setRepositorySystem(repoSystem).setRepositorySystemSession(getLog().isDebugEnabled() ? repoSession : MojoUtils.muteTransferListener(repoSession)).setRemoteRepositories(repos).setRemoteRepositoryManager(remoteRepoManager).build();
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to initialize Maven artifact resolver", e);
    }
    final MessageWriter log = new MojoMessageWriter(getLog());
    ExtensionCatalog catalog;
    try {
        catalog = CreateProjectMojo.resolveExtensionsCatalog(this, bomGroupId, bomArtifactId, bomVersion, QuarkusProjectHelper.getCatalogResolver(mvn, log), mvn, log);
    } catch (RegistryResolutionException e) {
        throw new MojoExecutionException("Failed to resolve Quarkus extension catalog", e);
    }
    final List<ResourceLoader> codestartsResourceLoader = codestartLoadersBuilder().catalog(catalog).artifactResolver(mvn).build();
    final CreateJBangProject createJBangProject = new CreateJBangProject(QuarkusProject.of(projectDirPath, catalog, codestartsResourceLoader, log, BuildTool.MAVEN)).extensions(extensions).javaTarget(javaVersion).setValue("noJBangWrapper", noJBangWrapper);
    boolean success;
    try {
        success = createJBangProject.execute().isSuccess();
    } catch (QuarkusCommandException e) {
        throw new MojoExecutionException("Failed to generate JBang Quarkus project", e);
    }
    if (success) {
        getLog().info("");
        getLog().info("========================================================================");
        getLog().warn(ansi().a("Quarkus JBang project is an experimental feature.").toString());
        getLog().info("========================================================================");
        getLog().info("");
    } else {
        throw new MojoExecutionException("Failed to generate JBang Quarkus project");
    }
}
Also used : Path(java.nio.file.Path) ResourceLoader(io.quarkus.platform.descriptor.loader.json.ResourceLoader) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) MojoMessageWriter(io.quarkus.platform.tools.maven.MojoMessageWriter) RegistryResolutionException(io.quarkus.registry.RegistryResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException) RegistryResolutionException(io.quarkus.registry.RegistryResolutionException) CreateJBangProject(io.quarkus.devtools.commands.CreateJBangProject) MojoMessageWriter(io.quarkus.platform.tools.maven.MojoMessageWriter) MessageWriter(io.quarkus.devtools.messagewriter.MessageWriter) MavenArtifactResolver(io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver) File(java.io.File)

Example 3 with MessageWriter

use of io.quarkus.devtools.messagewriter.MessageWriter in project quarkus-platform by quarkusio.

the class QuarkusProjectMojoBase method collectImportedPlatforms.

private List<ArtifactCoords> collectImportedPlatforms() throws MojoExecutionException {
    final List<ArtifactCoords> descriptors = new ArrayList<>(4);
    final List<Dependency> constraints = project.getDependencyManagement() == null ? Collections.emptyList() : project.getDependencyManagement().getDependencies();
    if (!constraints.isEmpty()) {
        final MessageWriter log = getMessageWriter();
        for (Dependency d : constraints) {
            if (!("json".equals(d.getType()) && d.getArtifactId().endsWith(BootstrapConstants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX))) {
                continue;
            }
            final ArtifactCoords a = new ArtifactCoords(d.getGroupId(), d.getArtifactId(), d.getClassifier(), d.getType(), d.getVersion());
            descriptors.add(a);
            log.debug("Found platform descriptor %s", a);
        }
    }
    return descriptors;
}
Also used : ArrayList(java.util.ArrayList) MojoMessageWriter(io.quarkus.platform.tools.maven.MojoMessageWriter) MessageWriter(io.quarkus.devtools.messagewriter.MessageWriter) Dependency(org.apache.maven.model.Dependency)

Example 4 with MessageWriter

use of io.quarkus.devtools.messagewriter.MessageWriter in project quarkus-platform by quarkusio.

the class CreateJBangMojo method execute.

@Override
public void execute() throws MojoExecutionException {
    try {
        Files.createDirectories(outputDirectory.toPath());
    } catch (IOException e) {
        throw new MojoExecutionException("Could not create directory " + outputDirectory, e);
    }
    File projectRoot = outputDirectory;
    final Path projectDirPath = projectRoot.toPath();
    final MavenArtifactResolver mvn;
    try {
        mvn = MavenArtifactResolver.builder().setRepositorySystem(repoSystem).setRepositorySystemSession(getLog().isDebugEnabled() ? repoSession : MojoUtils.muteTransferListener(repoSession)).setRemoteRepositories(repos).setRemoteRepositoryManager(remoteRepoManager).build();
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to initialize Maven artifact resolver", e);
    }
    final MessageWriter log = new MojoMessageWriter(getLog());
    ExtensionCatalog catalog;
    try {
        catalog = CreateProjectMojo.resolveExtensionsCatalog(this, bomGroupId, bomArtifactId, bomVersion, QuarkusProjectHelper.getCatalogResolver(mvn, log), mvn, log);
    } catch (RegistryResolutionException e) {
        throw new MojoExecutionException("Failed to resolve Quarkus extension catalog", e);
    }
    final List<ResourceLoader> codestartsResourceLoader = codestartLoadersBuilder().catalog(catalog).artifactResolver(mvn).build();
    final CreateJBangProject createJBangProject = new CreateJBangProject(QuarkusProject.of(projectDirPath, catalog, codestartsResourceLoader, log, BuildTool.MAVEN)).extensions(extensions).javaTarget(javaVersion).setValue("noJBangWrapper", noJBangWrapper);
    boolean success;
    try {
        success = createJBangProject.execute().isSuccess();
    } catch (QuarkusCommandException e) {
        throw new MojoExecutionException("Failed to generate JBang Quarkus project", e);
    }
    if (success) {
        getLog().info("");
        getLog().info("========================================================================");
        getLog().warn(ansi().a("Quarkus JBang project is an experimental feature.").toString());
        getLog().info("========================================================================");
        getLog().info("");
    } else {
        throw new MojoExecutionException("Failed to generate JBang Quarkus project");
    }
}
Also used : Path(java.nio.file.Path) ResourceLoader(io.quarkus.platform.descriptor.loader.json.ResourceLoader) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) MojoMessageWriter(io.quarkus.platform.tools.maven.MojoMessageWriter) RegistryResolutionException(io.quarkus.registry.RegistryResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException) RegistryResolutionException(io.quarkus.registry.RegistryResolutionException) CreateJBangProject(io.quarkus.devtools.commands.CreateJBangProject) MojoMessageWriter(io.quarkus.platform.tools.maven.MojoMessageWriter) MessageWriter(io.quarkus.devtools.messagewriter.MessageWriter) MavenArtifactResolver(io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver) File(java.io.File)

Example 5 with MessageWriter

use of io.quarkus.devtools.messagewriter.MessageWriter in project quarkus by quarkusio.

the class CliHelpTest method testMessageFlags.

@Test
@Order(80)
public void testMessageFlags() throws Exception {
    MessageWriter writer = MessageWriter.debug();
    // has emoji
    writer.error("error");
    // has emoji
    writer.warn("warn");
    writer.info(MessageIcons.NOOP_ICON + " info");
    writer.info(MessageIcons.OK_ICON + " info");
    writer.info(MessageIcons.NOK_ICON + " info");
    writer.debug("debug");
}
Also used : MessageWriter(io.quarkus.devtools.messagewriter.MessageWriter) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Aggregations

MessageWriter (io.quarkus.devtools.messagewriter.MessageWriter)12 QuarkusCommandException (io.quarkus.devtools.commands.data.QuarkusCommandException)7 ArrayList (java.util.ArrayList)7 ExtensionCatalog (io.quarkus.registry.catalog.ExtensionCatalog)6 QuarkusCommandInvocation (io.quarkus.devtools.commands.data.QuarkusCommandInvocation)5 QuarkusCommandOutcome (io.quarkus.devtools.commands.data.QuarkusCommandOutcome)5 ExtensionOrigin (io.quarkus.registry.catalog.ExtensionOrigin)5 List (java.util.List)5 Map (java.util.Map)5 Extension (io.quarkus.registry.catalog.Extension)4 IOException (java.io.IOException)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 ApplicationModel (io.quarkus.bootstrap.model.ApplicationModel)3 ExtensionProvider (io.quarkus.devtools.project.state.ExtensionProvider)3 ModuleState (io.quarkus.devtools.project.state.ModuleState)3 ProjectState (io.quarkus.devtools.project.state.ProjectState)3 TopExtensionDependency (io.quarkus.devtools.project.state.TopExtensionDependency)3