Search in sources :

Example 71 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode 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 72 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode 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 73 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode 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 74 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project quarkus by quarkusio.

the class DeploymentInjectingDependencyVisitor method replaceDirectDepBranch.

private boolean replaceDirectDepBranch(ExtensionDependency extDep, List<DependencyNode> deploymentDeps) throws BootstrapDependencyProcessingException {
    int i = 0;
    DependencyNode inserted = null;
    while (i < deploymentDeps.size()) {
        final Artifact a = deploymentDeps.get(i).getArtifact();
        if (a == null) {
            continue;
        }
        if (isSameKey(extDep.info.runtimeArtifact, a)) {
            // we are not comparing the version in the above condition because the runtime version
            // may appear to be different then the deployment one and that's ok
            // e.g. the version of the runtime artifact could be managed by a BOM
            // but overridden by the user in the project config. The way the deployment deps
            // are resolved here, the deployment version of the runtime artifact will be the one from the BOM.
            inserted = new DefaultDependencyNode(extDep.runtimeNode);
            inserted.setChildren(extDep.runtimeNode.getChildren());
            deploymentDeps.set(i, inserted);
            break;
        }
        ++i;
    }
    if (inserted == null) {
        return false;
    }
    if (extDep.runtimeExtensionDeps != null) {
        for (ExtensionDependency dep : extDep.runtimeExtensionDeps) {
            for (DependencyNode deploymentDep : deploymentDeps) {
                if (deploymentDep == inserted) {
                    continue;
                }
                if (replaceRuntimeBranch(dep, deploymentDep.getChildren())) {
                    break;
                }
            }
        }
    }
    return true;
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) Artifact(org.eclipse.aether.artifact.Artifact)

Example 75 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project quarkus by quarkusio.

the class GoOfflineMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final Artifact pom = new DefaultArtifact(project.getArtifact().getGroupId(), project.getArtifactId(), ArtifactCoords.TYPE_POM, project.getVersion());
    final MavenArtifactResolver resolver = getResolver();
    final DependencyNode root;
    try {
        root = resolver.collectDependencies(pom, Collections.emptyList()).getRoot();
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to collect dependencies of " + pom, e);
    }
    final List<Path> createdDirs = new ArrayList<>();
    try {
        ensureResolvableModule(root, resolver.getMavenContext().getWorkspace(), createdDirs);
        final ArtifactCoords appArtifact = new GACTV(pom.getGroupId(), pom.getArtifactId(), pom.getClassifier(), pom.getExtension(), pom.getVersion());
        resolveAppModel(resolver, appArtifact, LaunchMode.NORMAL);
        resolveAppModel(resolver, appArtifact, LaunchMode.DEVELOPMENT);
        resolveAppModel(resolver, appArtifact, LaunchMode.TEST);
    } finally {
        for (Path d : createdDirs) {
            IoUtils.recursiveDelete(d);
        }
    }
}
Also used : Path(java.nio.file.Path) ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyNode(org.eclipse.aether.graph.DependencyNode) ArrayList(java.util.ArrayList) MavenArtifactResolver(io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver) GACTV(io.quarkus.maven.dependency.GACTV) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) BootstrapMavenException(io.quarkus.bootstrap.resolver.maven.BootstrapMavenException) AppModelResolverException(io.quarkus.bootstrap.resolver.AppModelResolverException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

DependencyNode (org.eclipse.aether.graph.DependencyNode)267 Test (org.junit.Test)107 Artifact (org.eclipse.aether.artifact.Artifact)63 Dependency (org.eclipse.aether.graph.Dependency)59 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)53 CollectRequest (org.eclipse.aether.collection.CollectRequest)53 DefaultDependencyNode (org.eclipse.aether.graph.DefaultDependencyNode)53 ArrayList (java.util.ArrayList)39 IOException (java.io.IOException)28 List (java.util.List)26 CollectResult (org.eclipse.aether.collection.CollectResult)24 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)24 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)22 PreorderNodeListGenerator (org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator)21 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)19 File (java.io.File)17 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)17 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)17 Path (java.nio.file.Path)16 NodeBuilder (org.eclipse.aether.internal.test.util.NodeBuilder)16