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