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