Add support for @GrabExclude to AetherGrapeEngine
@GrabExclude can now be used to exclude certain transitive dependencies. In Aether (Maven), exclusions are applied to an individual dependency rather than being global. In Grape, exclusions are global. AetherGrapeEngine adheres to the Grape convention by applying every exclusion create by @GrabExclude to every dependency, effectively making them global.
This commit is contained in:
@@ -139,8 +139,9 @@ public class AetherGrapeEngine implements GrapeEngine {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object grab(Map args, Map... dependencyMaps) {
|
public Object grab(Map args, Map... dependencyMaps) {
|
||||||
|
List<Exclusion> exclusions = createExclusions(args);
|
||||||
|
List<Dependency> dependencies = createDependencies(dependencyMaps, exclusions);
|
||||||
try {
|
try {
|
||||||
List<Dependency> dependencies = createDependencies(dependencyMaps);
|
|
||||||
List<File> files = resolve(dependencies);
|
List<File> files = resolve(dependencies);
|
||||||
GroovyClassLoader classLoader = getClassLoader(args);
|
GroovyClassLoader classLoader = getClassLoader(args);
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
@@ -156,25 +157,43 @@ public class AetherGrapeEngine implements GrapeEngine {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GroovyClassLoader getClassLoader(Map args) {
|
@SuppressWarnings("unchecked")
|
||||||
GroovyClassLoader classLoader = (GroovyClassLoader) args.get("classLoader");
|
private List<Exclusion> createExclusions(Map<?, ?> args) {
|
||||||
return (classLoader == null ? this.classLoader : classLoader);
|
List<Exclusion> exclusions = new ArrayList<Exclusion>();
|
||||||
|
List<Map<String, Object>> exclusionMaps = (List<Map<String, Object>>) args
|
||||||
|
.get("excludes");
|
||||||
|
if (exclusionMaps != null) {
|
||||||
|
for (Map<String, Object> exclusionMap : exclusionMaps) {
|
||||||
|
exclusions.add(createExclusion(exclusionMap));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return exclusions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Dependency> createDependencies(Map<?, ?>... dependencyMaps) {
|
private Exclusion createExclusion(Map<String, Object> exclusionMap) {
|
||||||
|
String group = (String) exclusionMap.get("group");
|
||||||
|
String module = (String) exclusionMap.get("module");
|
||||||
|
return new Exclusion(group, module, "*", "*");
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Dependency> createDependencies(Map<?, ?>[] dependencyMaps,
|
||||||
|
List<Exclusion> exclusions) {
|
||||||
List<Dependency> dependencies = new ArrayList<Dependency>(dependencyMaps.length);
|
List<Dependency> dependencies = new ArrayList<Dependency>(dependencyMaps.length);
|
||||||
for (Map<?, ?> dependencyMap : dependencyMaps) {
|
for (Map<?, ?> dependencyMap : dependencyMaps) {
|
||||||
dependencies.add(createDependency(dependencyMap));
|
dependencies.add(createDependency(dependencyMap, exclusions));
|
||||||
}
|
}
|
||||||
return dependencies;
|
return dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dependency createDependency(Map<?, ?> dependencyMap) {
|
private Dependency createDependency(Map<?, ?> dependencyMap,
|
||||||
|
List<Exclusion> exclusions) {
|
||||||
Artifact artifact = createArtifact(dependencyMap);
|
Artifact artifact = createArtifact(dependencyMap);
|
||||||
if (isTransitive(dependencyMap)) {
|
if (isTransitive(dependencyMap)) {
|
||||||
return new Dependency(artifact, JavaScopes.COMPILE);
|
return new Dependency(artifact, JavaScopes.COMPILE, false, exclusions);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return new Dependency(artifact, JavaScopes.COMPILE, null, WILDCARD_EXCLUSION);
|
||||||
}
|
}
|
||||||
return new Dependency(artifact, JavaScopes.COMPILE, null, WILDCARD_EXCLUSION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Artifact createArtifact(Map<?, ?> dependencyMap) {
|
private Artifact createArtifact(Map<?, ?> dependencyMap) {
|
||||||
@@ -216,6 +235,11 @@ public class AetherGrapeEngine implements GrapeEngine {
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private GroovyClassLoader getClassLoader(Map args) {
|
||||||
|
GroovyClassLoader classLoader = (GroovyClassLoader) args.get("classLoader");
|
||||||
|
return (classLoader == null ? this.classLoader : classLoader);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addResolver(Map<String, Object> args) {
|
public void addResolver(Map<String, Object> args) {
|
||||||
String name = (String) args.get("name");
|
String name = (String) args.get("name");
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.springframework.boot.cli.compiler.grape;
|
|||||||
|
|
||||||
import groovy.lang.GroovyClassLoader;
|
import groovy.lang.GroovyClassLoader;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -47,6 +48,20 @@ public class AetherGrapeEngineTests {
|
|||||||
assertEquals(6, this.groovyClassLoader.getURLs().length);
|
assertEquals(6, this.groovyClassLoader.getURLs().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void dependencyResolutionWithExclusions() {
|
||||||
|
Map<String, Object> args = new HashMap<String, Object>();
|
||||||
|
args.put("excludes",
|
||||||
|
Arrays.asList(createExclusion("org.springframework", "spring-core")));
|
||||||
|
|
||||||
|
this.grapeEngine.grab(args,
|
||||||
|
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"),
|
||||||
|
createDependency("org.springframework", "spring-beans", "3.2.4.RELEASE"));
|
||||||
|
|
||||||
|
assertEquals(4, this.groovyClassLoader.getURLs().length);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nonTransitiveDependencyResolution() {
|
public void nonTransitiveDependencyResolution() {
|
||||||
Map<String, Object> args = new HashMap<String, Object>();
|
Map<String, Object> args = new HashMap<String, Object>();
|
||||||
@@ -117,4 +132,11 @@ public class AetherGrapeEngineTests {
|
|||||||
resolver.put("root", url);
|
resolver.put("root", url);
|
||||||
return resolver;
|
return resolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> createExclusion(String group, String module) {
|
||||||
|
Map<String, Object> exclusion = new HashMap<String, Object>();
|
||||||
|
exclusion.put("group", group);
|
||||||
|
exclusion.put("module", module);
|
||||||
|
return exclusion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user