Search in sources :

Example 1 with ArtifactCoords

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();
}
Also used : ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ExtensionProvider(io.quarkus.devtools.project.state.ExtensionProvider) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) WorkspaceModuleId(io.quarkus.bootstrap.workspace.WorkspaceModuleId) Dependency(io.quarkus.maven.dependency.Dependency) TopExtensionDependency(io.quarkus.devtools.project.state.TopExtensionDependency) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ModuleState(io.quarkus.devtools.project.state.ModuleState) ProjectState(io.quarkus.devtools.project.state.ProjectState) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) TopExtensionDependency(io.quarkus.devtools.project.state.TopExtensionDependency)

Example 2 with ArtifactCoords

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;
}
Also used : ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with ArtifactCoords

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();
}
Also used : ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ArtifactCoords

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);
        }
    }
}
Also used : ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) AppArtifactCoords(io.quarkus.bootstrap.model.AppArtifactCoords) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JsonNode(com.fasterxml.jackson.databind.JsonNode) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 5 with ArtifactCoords

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));
}
Also used : ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) IOException(java.io.IOException) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) Dependency(org.gradle.api.artifacts.Dependency) Properties(java.util.Properties) GradleException(org.gradle.api.GradleException) BufferedReader(java.io.BufferedReader)

Aggregations

ArtifactCoords (io.quarkus.maven.dependency.ArtifactCoords)17 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 ArtifactKey (io.quarkus.maven.dependency.ArtifactKey)7 BufferedWriter (java.io.BufferedWriter)6 StringWriter (java.io.StringWriter)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Path (java.nio.file.Path)5 Map (java.util.Map)5 ExtensionProvider (io.quarkus.devtools.project.state.ExtensionProvider)4 ModuleState (io.quarkus.devtools.project.state.ModuleState)4 TopExtensionDependency (io.quarkus.devtools.project.state.TopExtensionDependency)4 GACTV (io.quarkus.maven.dependency.GACTV)4 LinkedHashMap (java.util.LinkedHashMap)4 AppModelResolverException (io.quarkus.bootstrap.resolver.AppModelResolverException)3 WorkspaceModule (io.quarkus.bootstrap.workspace.WorkspaceModule)3 ProjectState (io.quarkus.devtools.project.state.ProjectState)3 ExtensionOrigin (io.quarkus.registry.catalog.ExtensionOrigin)3 Collection (java.util.Collection)3