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();
}
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");
}
}
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;
}
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");
}
}
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");
}
Aggregations