use of io.quarkus.maven.dependency.ArtifactCoords in project quarkus by quarkusio.
the class InfoCommandHandler method resolveProjectState.
protected static ProjectState resolveProjectState(ApplicationModel appModel, ExtensionCatalog currentCatalog) {
final ProjectState.Builder projectBuilder = ProjectState.builder();
final Collection<ArtifactCoords> importedPlatformBoms = appModel.getPlatforms().getImportedPlatformBoms();
if (importedPlatformBoms.isEmpty()) {
return projectBuilder.build();
}
final Map<String, ExtensionProvider.Builder> extProviderBuilders = new LinkedHashMap<>(importedPlatformBoms.size());
importedPlatformBoms.forEach(bom -> {
projectBuilder.addPlatformBom(bom);
extProviderBuilders.put(ExtensionProvider.key(bom, true), ExtensionProvider.builder().setArtifact(bom).setPlatform(true));
});
final Map<WorkspaceModuleId, ModuleState.Builder> projectModuleBuilders = new HashMap<>();
final Map<ArtifactKey, List<ModuleState.Builder>> directModuleDeps = new HashMap<>();
final WorkspaceModule appModule = appModel.getAppArtifact().getWorkspaceModule();
if (appModule != null) {
final ModuleState.Builder module = ModuleState.builder().setWorkspaceModule(appModule).setMainModule(true);
projectModuleBuilders.put(appModule.getId(), module);
appModule.getDirectDependencies().forEach(d -> directModuleDeps.computeIfAbsent(d.getKey(), dk -> new ArrayList<>()).add(module));
for (Dependency constraint : appModule.getDirectDependencyConstraints()) {
if (extProviderBuilders.containsKey(constraint.toCompactCoords())) {
module.addPlatformBom(constraint);
}
}
}
for (ResolvedDependency dep : appModel.getDependencies()) {
if (dep.getWorkspaceModule() != null) {
projectModuleBuilders.computeIfAbsent(dep.getWorkspaceModule().getId(), k -> {
final ModuleState.Builder module = ModuleState.builder().setWorkspaceModule(dep.getWorkspaceModule());
dep.getWorkspaceModule().getDirectDependencies().forEach(d -> directModuleDeps.computeIfAbsent(d.getKey(), dk -> new ArrayList<>()).add(module));
return module;
});
}
}
final Map<ArtifactKey, TopExtensionDependency.Builder> directExtDeps = new HashMap<>();
for (ResolvedDependency dep : appModel.getDependencies()) {
if (dep.isFlagSet(DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT)) {
directExtDeps.put(dep.getKey(), TopExtensionDependency.builder().setResolvedDependency(dep).setTransitive(!directModuleDeps.containsKey(dep.getKey())));
} else if (dep.isRuntimeExtensionArtifact() && directModuleDeps.containsKey(dep.getKey())) {
directExtDeps.put(dep.getKey(), TopExtensionDependency.builder().setResolvedDependency(dep));
}
}
if (directExtDeps.isEmpty()) {
return projectBuilder.build();
}
currentCatalog.getExtensions().forEach(e -> {
final ArtifactKey key = e.getArtifact().getKey();
final TopExtensionDependency.Builder dep = directExtDeps.get(key);
if (dep != null) {
dep.setCatalogMetadata(e);
}
});
for (TopExtensionDependency.Builder extBuilder : directExtDeps.values()) {
final List<ModuleState.Builder> modules = directModuleDeps.getOrDefault(extBuilder.getKey(), Collections.emptyList());
final TopExtensionDependency dep = extBuilder.setTransitive(modules.isEmpty()).build();
projectBuilder.addExtensionDependency(dep);
for (ModuleState.Builder module : modules) {
module.addExtensionDependency(dep);
}
final ExtensionProvider.Builder provider = extProviderBuilders.computeIfAbsent(dep.getProviderKey(), k -> ExtensionProvider.builder().setOrigin(dep.getOrigin()));
provider.addExtension(dep);
}
for (ExtensionProvider.Builder builder : extProviderBuilders.values()) {
projectBuilder.addExtensionProvider(builder.build());
}
for (ModuleState.Builder builder : projectModuleBuilders.values()) {
projectBuilder.addModule(builder.build());
}
return projectBuilder.build();
}
use of io.quarkus.maven.dependency.ArtifactCoords in project quarkus by quarkusio.
the class PlatformStreamInfo method getPossibleAlignemnts.
List<List<String>> getPossibleAlignemnts(Collection<ArtifactCoords> importedPlatformBoms) {
final Map<ArtifactKey, String> importedKeys = new HashMap<>(importedPlatformBoms.size());
for (ArtifactCoords bom : importedPlatformBoms) {
importedKeys.put(bom.getKey(), bom.getVersion());
}
final List<List<String>> suggestions = new ArrayList<>();
for (PlatformReleaseInfo release : releases.values()) {
final Map<ArtifactKey, ArtifactCoords> stackBoms = new HashMap<>(release.getBoms().size());
for (ArtifactCoords bom : release.getBoms()) {
stackBoms.put(bom.getKey(), bom);
}
if (stackBoms.keySet().containsAll(importedKeys.keySet())) {
final List<String> suggestion = new ArrayList<>(importedPlatformBoms.size());
suggestions.add(suggestion);
for (Map.Entry<ArtifactKey, String> bomKey : importedKeys.entrySet()) {
final ArtifactCoords stackBom = stackBoms.get(bomKey.getKey());
if (!bomKey.getValue().equals(stackBom.getVersion())) {
suggestion.add(bomKey.getKey().getGroupId() + ":" + bomKey.getKey().getArtifactId() + ":" + bomKey.getValue() + " -> " + stackBom.getVersion());
} else {
suggestion.add(stackBom.getGroupId() + ":" + stackBom.getArtifactId() + ":" + stackBom.getVersion());
}
}
}
}
return suggestions;
}
use of io.quarkus.maven.dependency.ArtifactCoords in project quarkus by quarkusio.
the class PlatformImportsImpl method getMisalignmentReport.
@Override
public String getMisalignmentReport() {
StringWriter error = null;
for (Map.Entry<ArtifactCoords, PlatformImport> pi : platformImports.entrySet()) {
if (!pi.getValue().descriptorFound) {
if (error == null) {
error = new StringWriter();
error.append("The Quarkus platform properties applied to the project are missing the corresponding Quarkus platform BOM imports: ");
} else {
error.append(", ");
}
error.append(pi.getKey().toString());
}
}
if (error != null) {
return error.getBuffer().toString();
}
final Map<String, List<List<String>>> possibleAlignments = getPossibleAlignemnts(importedPlatformBoms);
if (possibleAlignments.isEmpty()) {
return null;
}
error = new StringWriter();
try (BufferedWriter writer = new BufferedWriter(error)) {
writer.append("Some of the imported Quarkus platform BOMs belong to different platform releases. To properly align the platform BOM imports, please, consider one of the following combinations:");
writer.newLine();
for (Map.Entry<String, List<List<String>>> entry : possibleAlignments.entrySet()) {
writer.append("For platform ").append(entry.getKey()).append(':');
writer.newLine();
int i = 1;
for (List<String> boms : entry.getValue()) {
writer.append(" ").append(String.valueOf(i++)).append(") ");
writer.newLine();
for (String bom : boms) {
writer.append(" - ").append(bom);
writer.newLine();
}
}
}
} catch (IOException e) {
// ignore
}
return error.toString();
}
use of io.quarkus.maven.dependency.ArtifactCoords in project quarkus by quarkusio.
the class ExtensionDescriptorMojo method completeCodestartArtifact.
private void completeCodestartArtifact(ObjectMapper mapper, ObjectNode extObject) throws MojoExecutionException {
JsonNode mvalue = getJsonElement(extObject, METADATA, "codestart");
if (mvalue == null || !mvalue.isObject()) {
return;
}
final ObjectNode codestartObject = (ObjectNode) mvalue;
mvalue = mvalue.get("artifact");
if (mvalue == null) {
if (!skipCodestartValidation) {
throw new MojoExecutionException("Codestart artifact is missing from the " + extensionFile);
}
return;
}
String codestartArtifact = getCodestartArtifact(mvalue.asText(), project.getVersion());
final ArtifactCoords codestartArtifactCoords = GACTV.fromString(codestartArtifact);
codestartObject.put("artifact", codestartArtifactCoords.toString());
if (!skipCodestartValidation) {
// first we look for it in the workspace, if it's in there we don't need to actually resolve the artifact, because it might not have been built yet
if (workspaceProvider.getProject(codestartArtifactCoords.getGroupId(), codestartArtifactCoords.getArtifactId()) != null) {
return;
}
for (Artifact attached : project.getAttachedArtifacts()) {
if (codestartArtifactCoords.getArtifactId().equals(attached.getArtifactId()) && codestartArtifactCoords.getClassifier().equals(attached.getClassifier()) && codestartArtifactCoords.getType().equals(attached.getType()) && codestartArtifactCoords.getVersion().equals(attached.getVersion()) && codestartArtifactCoords.getGroupId().equals(attached.getGroupId())) {
return;
}
}
try {
resolve(new DefaultArtifact(codestartArtifact));
} catch (MojoExecutionException e) {
throw new MojoExecutionException("Failed to resolve codestart artifact " + codestartArtifactCoords, e);
}
}
}
use of io.quarkus.maven.dependency.ArtifactCoords in project quarkus by quarkusio.
the class DependencyUtils method loadExtensionInfo.
private static ExtensionDependency loadExtensionInfo(Project project, Path descriptorPath, ModuleVersionIdentifier exentionId, Project extensionProject) {
final Properties extensionProperties = new Properties();
try (BufferedReader reader = Files.newBufferedReader(descriptorPath)) {
extensionProperties.load(reader);
} catch (IOException e) {
throw new GradleException("Failed to load " + descriptorPath, e);
}
ArtifactCoords deploymentModule = GACTV.fromString(extensionProperties.getProperty(BootstrapConstants.PROP_DEPLOYMENT_ARTIFACT));
final List<Dependency> conditionalDependencies;
if (extensionProperties.containsKey(BootstrapConstants.CONDITIONAL_DEPENDENCIES)) {
final String[] deps = BootstrapUtils.splitByWhitespace(extensionProperties.getProperty(BootstrapConstants.CONDITIONAL_DEPENDENCIES));
conditionalDependencies = new ArrayList<>(deps.length);
for (String conditionalDep : deps) {
conditionalDependencies.add(create(project.getDependencies(), conditionalDep));
}
} else {
conditionalDependencies = Collections.emptyList();
}
final ArtifactKey[] constraints = BootstrapUtils.parseDependencyCondition(extensionProperties.getProperty(BootstrapConstants.DEPENDENCY_CONDITION));
if (extensionProject != null) {
return new LocalExtensionDependency(extensionProject, exentionId, deploymentModule, conditionalDependencies, constraints == null ? Collections.emptyList() : Arrays.asList(constraints));
}
return new ExtensionDependency(exentionId, deploymentModule, conditionalDependencies, constraints == null ? Collections.emptyList() : Arrays.asList(constraints));
}
Aggregations