mirror of https://github.com/apache/maven.git
Rewrite deps if needed
This commit is contained in:
parent
02c8fb186c
commit
f469391ee2
|
@ -24,11 +24,12 @@ import javax.inject.Singleton;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
@ -220,15 +221,28 @@ public class DefaultPluginDependenciesResolver implements PluginDependenciesReso
|
||||||
request.setRequestContext(REPOSITORY_CONTEXT);
|
request.setRequestContext(REPOSITORY_CONTEXT);
|
||||||
request.setRepositories(repositories);
|
request.setRepositories(repositories);
|
||||||
request.setRoot(new org.eclipse.aether.graph.Dependency(pluginArtifact, null));
|
request.setRoot(new org.eclipse.aether.graph.Dependency(pluginArtifact, null));
|
||||||
|
Map<String, org.eclipse.aether.graph.Dependency> core = getCoreExportsAsDependencies(session);
|
||||||
|
request.setManagedDependencies(core.values().stream().toList());
|
||||||
for (Dependency dependency : plugin.getDependencies()) {
|
for (Dependency dependency : plugin.getDependencies()) {
|
||||||
org.eclipse.aether.graph.Dependency pluginDep =
|
org.eclipse.aether.graph.Dependency pluginDep =
|
||||||
RepositoryUtils.toDependency(dependency, session.getArtifactTypeRegistry());
|
RepositoryUtils.toDependency(dependency, session.getArtifactTypeRegistry());
|
||||||
if (!DependencyScope.SYSTEM.is(pluginDep.getScope())) {
|
if (!DependencyScope.SYSTEM.is(pluginDep.getScope())) {
|
||||||
pluginDep = pluginDep.setScope(DependencyScope.RUNTIME.id());
|
pluginDep = pluginDep.setScope(DependencyScope.RUNTIME.id());
|
||||||
}
|
}
|
||||||
|
org.eclipse.aether.graph.Dependency managedDep =
|
||||||
|
core.get(pluginDep.getArtifact().getGroupId() + ":"
|
||||||
|
+ pluginDep.getArtifact().getArtifactId());
|
||||||
|
if (managedDep != null
|
||||||
|
&& !Objects.equals(
|
||||||
|
pluginDep.getArtifact().getVersion(),
|
||||||
|
managedDep.getArtifact().getVersion())) {
|
||||||
|
pluginDep = pluginDep.setArtifact(pluginDep
|
||||||
|
.getArtifact()
|
||||||
|
.setVersion(managedDep.getArtifact().getVersion()));
|
||||||
|
pluginDep = pluginDep.setScope(DependencyScope.PROVIDED.id());
|
||||||
|
}
|
||||||
request.addDependency(pluginDep);
|
request.addDependency(pluginDep);
|
||||||
}
|
}
|
||||||
request.setManagedDependencies(getCoreExportsAsDependencies(session));
|
|
||||||
|
|
||||||
DependencyRequest depRequest = new DependencyRequest(request, resolutionFilter);
|
DependencyRequest depRequest = new DependencyRequest(request, resolutionFilter);
|
||||||
depRequest.setTrace(trace);
|
depRequest.setTrace(trace);
|
||||||
|
@ -260,25 +274,29 @@ public class DefaultPluginDependenciesResolver implements PluginDependenciesReso
|
||||||
DefaultPluginDependenciesResolver.class.getName() + "#getCoreExportsAsDependencies";
|
DefaultPluginDependenciesResolver.class.getName() + "#getCoreExportsAsDependencies";
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private List<org.eclipse.aether.graph.Dependency> getCoreExportsAsDependencies(RepositorySystemSession session) {
|
private Map<String, org.eclipse.aether.graph.Dependency> getCoreExportsAsDependencies(
|
||||||
return (List<org.eclipse.aether.graph.Dependency>) session.getData().computeIfAbsent(CACHE_KEY, () -> {
|
RepositorySystemSession session) {
|
||||||
ArrayList<org.eclipse.aether.graph.Dependency> core = new ArrayList<>();
|
return (Map<String, org.eclipse.aether.graph.Dependency>)
|
||||||
ClassLoader classLoader = coreExports.getExportedPackages().get("org.apache.maven.*");
|
session.getData().computeIfAbsent(CACHE_KEY, () -> {
|
||||||
for (String coreArtifact : coreExports.getExportedArtifacts()) {
|
HashMap<String, org.eclipse.aether.graph.Dependency> core = new HashMap<>();
|
||||||
String[] split = coreArtifact.split(":");
|
ClassLoader classLoader = coreExports.getExportedPackages().get("org.apache.maven.*");
|
||||||
if (split.length == 2) {
|
for (String coreArtifact : coreExports.getExportedArtifacts()) {
|
||||||
String groupId = split[0];
|
String[] split = coreArtifact.split(":");
|
||||||
String artifactId = split[1];
|
if (split.length == 2) {
|
||||||
String version = discoverArtifactVersion(classLoader, groupId, artifactId, null);
|
String groupId = split[0];
|
||||||
if (version != null) {
|
String artifactId = split[1];
|
||||||
core.add(new org.eclipse.aether.graph.Dependency(
|
String version = discoverArtifactVersion(classLoader, groupId, artifactId, null);
|
||||||
new DefaultArtifact(groupId + ":" + artifactId + ":" + version),
|
if (version != null) {
|
||||||
DependencyScope.PROVIDED.id()));
|
core.put(
|
||||||
|
groupId + ":" + artifactId,
|
||||||
|
new org.eclipse.aether.graph.Dependency(
|
||||||
|
new DefaultArtifact(groupId + ":" + artifactId + ":" + version),
|
||||||
|
DependencyScope.PROVIDED.id()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return Collections.unmodifiableMap(core);
|
||||||
}
|
});
|
||||||
return Collections.unmodifiableList(core);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String discoverArtifactVersion(
|
private static String discoverArtifactVersion(
|
||||||
|
|
Loading…
Reference in New Issue