Search in sources :

Example 1 with AppArtifactKey

use of io.quarkus.bootstrap.model.AppArtifactKey in project quarkus by quarkusio.

the class ExtensionDescriptorMojo method highlightInTree.

private void highlightInTree(int depth, DependencyNode node, Collection<AppArtifactKey> keysToHighlight, Set<AppArtifactKey> visited, StringBuilder buf, List<String> branch) {
    final AppArtifactKey key = toKey(node.getArtifact());
    if (!visited.add(key)) {
        return;
    }
    buf.setLength(0);
    final boolean highlighted = keysToHighlight.contains(key);
    if (highlighted) {
        buf.append('*');
    } else {
        buf.append(' ');
    }
    for (int i = 0; i < depth; ++i) {
        buf.append("  ");
    }
    buf.append(node.getArtifact());
    branch.add(buf.toString());
    if (!highlighted) {
        for (DependencyNode child : node.getChildren()) {
            highlightInTree(depth + 1, child, keysToHighlight, visited, buf, branch);
        }
    } else {
        for (String line : branch) {
            getLog().error(line);
        }
    }
    branch.remove(branch.size() - 1);
}
Also used : AppArtifactKey(io.quarkus.bootstrap.model.AppArtifactKey) DependencyNode(org.eclipse.aether.graph.DependencyNode)

Example 2 with AppArtifactKey

use of io.quarkus.bootstrap.model.AppArtifactKey in project quarkus by quarkusio.

the class ExtensionDescriptorMojo method validateExtensionDeps.

private void validateExtensionDeps() throws MojoExecutionException {
    final AppArtifactKey rootDeploymentGact = getDeploymentCoords().getKey();
    final RootNode rootDeployment = new RootNode(rootDeploymentGact, 2);
    final Artifact artifact = project.getArtifact();
    final Node rootRuntime = rootDeployment.newChild(new AppArtifactKey(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType()), 1);
    rootDeployment.expectedDeploymentNodes.put(rootDeployment.gact, rootDeployment);
    rootDeployment.expectedDeploymentNodes.put(rootRuntime.gact, rootRuntime);
    // collect transitive extension deps
    final DependencyResult resolvedDeps;
    resolvedDeps = resolveRuntimeDeps();
    for (DependencyNode node : resolvedDeps.getRoot().getChildren()) {
        rootDeployment.directRuntimeDeps.add(toKey(node.getArtifact()));
    }
    visitRuntimeDeps(rootDeployment, rootDeployment, rootDeployment.id, resolvedDeps.getRoot());
    final DependencyNode deploymentNode = collectDeploymentDeps().getRoot();
    visitDeploymentDeps(rootDeployment, deploymentNode);
    if (rootDeployment.hasErrors()) {
        final Log log = getLog();
        log.error("Quarkus Extension Dependency Verification Error");
        final StringBuilder buf = new StringBuilder();
        if (rootDeployment.deploymentDepsTotal != 0) {
            log.error("Deployment artifact " + getDeploymentCoords() + " was found to be missing dependencies on the Quarkus extension artifacts marked with '-' below:");
            final List<AppArtifactKey> missing = rootDeployment.collectMissingDeploymentDeps(log);
            buf.append("Deployment artifact ");
            buf.append(getDeploymentCoords());
            buf.append(" is missing the following dependencies from its configuration: ");
            final Iterator<AppArtifactKey> i = missing.iterator();
            buf.append(i.next());
            while (i.hasNext()) {
                buf.append(", ").append(i.next());
            }
        }
        if (!rootDeployment.deploymentsOnRtCp.isEmpty()) {
            if (rootDeployment.runtimeCp > 0) {
                log.error("The following deployment artifact(s) appear on the runtime classpath: ");
                rootDeployment.collectDeploymentsOnRtCp(log);
            }
            if (buf.length() > 0) {
                buf.append(System.lineSeparator());
            }
            buf.append("The following deployment artifact(s) appear on the runtime classpath: ");
            final Iterator<AppArtifactKey> i = rootDeployment.deploymentsOnRtCp.iterator();
            buf.append(i.next());
            while (i.hasNext()) {
                buf.append(", ").append(i.next());
            }
        }
        if (!rootDeployment.unexpectedDeploymentDeps.isEmpty()) {
            final List<AppArtifactKey> unexpectedRtDeps = new ArrayList<>(0);
            final List<AppArtifactKey> unexpectedDeploymentDeps = new ArrayList<>(0);
            for (Map.Entry<AppArtifactKey, org.eclipse.aether.artifact.Artifact> e : rootDeployment.unexpectedDeploymentDeps.entrySet()) {
                if (rootDeployment.allDeploymentDeps.contains(e.getKey())) {
                    unexpectedDeploymentDeps.add(e.getKey());
                } else {
                    unexpectedRtDeps.add(toKey(e.getValue()));
                }
            }
            if (!unexpectedRtDeps.isEmpty()) {
                if (buf.length() > 0) {
                    buf.append(System.lineSeparator());
                }
                buf.append("The deployment artifact " + rootDeploymentGact + " depends on the following Quarkus extension runtime artifacts that weren't found among the dependencies of " + project.getArtifact() + ":");
                for (AppArtifactKey a : unexpectedRtDeps) {
                    buf.append(' ').append(a);
                }
                log.error("The deployment artifact " + rootDeploymentGact + " depends on the following Quarkus extension runtime artifacts that weren't found among the dependencies of " + project.getArtifact() + ":");
                highlightInTree(deploymentNode, unexpectedRtDeps);
            }
            if (!unexpectedDeploymentDeps.isEmpty()) {
                if (buf.length() > 0) {
                    buf.append(System.lineSeparator());
                }
                buf.append("The deployment artifact " + rootDeploymentGact + " depends on the following Quarkus extension deployment artifacts whose corresponding runtime artifacts were not found among the dependencies of " + project.getArtifact() + ":");
                for (AppArtifactKey a : unexpectedDeploymentDeps) {
                    buf.append(' ').append(a);
                }
                log.error("The deployment artifact " + rootDeploymentGact + " depends on the following Quarkus extension deployment artifacts whose corresponding runtime artifacts were not found among the dependencies of " + project.getArtifact() + ":");
                highlightInTree(deploymentNode, unexpectedDeploymentDeps);
            }
        }
        throw new MojoExecutionException(buf.toString());
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AppArtifactKey(io.quarkus.bootstrap.model.AppArtifactKey) Log(org.apache.maven.plugin.logging.Log) DependencyResult(org.eclipse.aether.resolution.DependencyResult) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DependencyNode(org.eclipse.aether.graph.DependencyNode) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) DependencyNode(org.eclipse.aether.graph.DependencyNode) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with AppArtifactKey

use of io.quarkus.bootstrap.model.AppArtifactKey in project quarkus by quarkusio.

the class ExtensionDescriptorMojo method visitDeploymentDep.

private void visitDeploymentDep(RootNode rootDeployment, DependencyNode dep) throws MojoExecutionException {
    org.eclipse.aether.artifact.Artifact artifact = dep.getArtifact();
    if (artifact == null) {
        return;
    }
    final AppArtifactKey key = toKey(artifact);
    if (!rootDeployment.allDeploymentDeps.add(key)) {
        return;
    }
    final Node node = rootDeployment.expectedDeploymentNodes.get(key);
    if (node != null) {
        if (!node.present) {
            node.present = true;
            --rootDeployment.deploymentDepsTotal;
            if (rootDeployment.allRtDeps.contains(key)) {
                rootDeployment.deploymentsOnRtCp.add(key);
            }
        }
    } else if (!rootDeployment.allRtDeps.contains(key)) {
        final AppArtifactKey deployment = getDeploymentKey(artifact);
        if (deployment != null) {
            rootDeployment.unexpectedDeploymentDeps.put(deployment, artifact);
        }
    }
    visitDeploymentDeps(rootDeployment, dep);
}
Also used : AppArtifactKey(io.quarkus.bootstrap.model.AppArtifactKey) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DependencyNode(org.eclipse.aether.graph.DependencyNode)

Example 4 with AppArtifactKey

use of io.quarkus.bootstrap.model.AppArtifactKey in project quarkus by quarkusio.

the class MavenArtifactResolver method newCollectManagedRequest.

private CollectRequest newCollectManagedRequest(Artifact artifact, List<Dependency> deps, List<Dependency> managedDeps, List<RemoteRepository> mainRepos, Collection<Exclusion> exclusions, String... excludedScopes) throws BootstrapMavenException {
    final List<RemoteRepository> aggregatedRepos = aggregateRepositories(mainRepos, remoteRepos);
    final ArtifactDescriptorResult descr = resolveDescriptorInternal(artifact, aggregatedRepos);
    Collection<String> excluded;
    if (excludedScopes.length == 0) {
        excluded = Collections.emptyList();
    } else if (excludedScopes.length == 1) {
        excluded = Collections.singleton(excludedScopes[0]);
    } else {
        excluded = Arrays.asList(excludedScopes);
        if (excludedScopes.length > 3) {
            excluded = new HashSet<>(Arrays.asList(excludedScopes));
        }
    }
    final List<Dependency> originalDeps = new ArrayList<>(descr.getDependencies().size());
    for (Dependency dep : descr.getDependencies()) {
        if (excluded.contains(dep.getScope())) {
            continue;
        }
        originalDeps.add(dep);
    }
    final List<Dependency> mergedManagedDeps = new ArrayList<Dependency>(managedDeps.size() + descr.getManagedDependencies().size());
    Map<AppArtifactKey, String> managedVersions = Collections.emptyMap();
    if (!managedDeps.isEmpty()) {
        managedVersions = new HashMap<>(managedDeps.size());
        for (Dependency dep : managedDeps) {
            managedVersions.put(getId(dep.getArtifact()), dep.getArtifact().getVersion());
            mergedManagedDeps.add(dep);
        }
    }
    if (!descr.getManagedDependencies().isEmpty()) {
        for (Dependency dep : descr.getManagedDependencies()) {
            final AppArtifactKey key = getId(dep.getArtifact());
            if (!managedVersions.containsKey(key)) {
                mergedManagedDeps.add(dep);
            }
        }
    }
    final CollectRequest request = new CollectRequest().setDependencies(mergeDeps(deps, originalDeps, managedVersions)).setManagedDependencies(mergedManagedDeps).setRepositories(aggregateRepositories(aggregatedRepos, newResolutionRepositories(descr.getRepositories())));
    if (exclusions.isEmpty()) {
        request.setRootArtifact(artifact);
    } else {
        request.setRoot(new Dependency(artifact, JavaScopes.COMPILE, false, exclusions));
    }
    return request;
}
Also used : AppArtifactKey(io.quarkus.bootstrap.model.AppArtifactKey) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) HashSet(java.util.HashSet)

Example 5 with AppArtifactKey

use of io.quarkus.bootstrap.model.AppArtifactKey in project quarkus by quarkusio.

the class MavenArtifactResolver method mergeDeps.

private List<Dependency> mergeDeps(List<Dependency> dominant, List<Dependency> recessive, Map<AppArtifactKey, String> managedVersions) {
    final int initialCapacity = dominant.size() + recessive.size();
    if (initialCapacity == 0) {
        return Collections.emptyList();
    }
    final List<Dependency> result = new ArrayList<Dependency>(initialCapacity);
    final Set<AppArtifactKey> ids = new HashSet<AppArtifactKey>(initialCapacity, 1.0f);
    for (Dependency dependency : dominant) {
        final AppArtifactKey id = getId(dependency.getArtifact());
        ids.add(id);
        final String managedVersion = managedVersions.get(id);
        if (managedVersion != null) {
            dependency = dependency.setArtifact(dependency.getArtifact().setVersion(managedVersion));
        }
        result.add(dependency);
    }
    for (Dependency dependency : recessive) {
        final AppArtifactKey id = getId(dependency.getArtifact());
        if (!ids.contains(id)) {
            final String managedVersion = managedVersions.get(id);
            if (managedVersion != null) {
                dependency = dependency.setArtifact(dependency.getArtifact().setVersion(managedVersion));
            }
            result.add(dependency);
        }
    }
    return result;
}
Also used : AppArtifactKey(io.quarkus.bootstrap.model.AppArtifactKey) ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency) HashSet(java.util.HashSet)

Aggregations

AppArtifactKey (io.quarkus.bootstrap.model.AppArtifactKey)11 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ArrayList (java.util.ArrayList)5 DependencyNode (org.eclipse.aether.graph.DependencyNode)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 HashSet (java.util.HashSet)3 AppArtifact (io.quarkus.bootstrap.model.AppArtifact)2 AppDependency (io.quarkus.bootstrap.model.AppDependency)2 IOException (java.io.IOException)2 FileSystem (java.nio.file.FileSystem)2 Path (java.nio.file.Path)2 Dependency (org.eclipse.aether.graph.Dependency)2 AppModel (io.quarkus.bootstrap.model.AppModel)1 CapabilityContract (io.quarkus.bootstrap.model.CapabilityContract)1 ResolvedDependency (io.quarkus.maven.dependency.ResolvedDependency)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1