Honour ext and classifier on @Grabbed dependencies

We currently honour type, but ignore ext. Aether doesn't make a
distinction between the two so a Grab that specifies both type and ext
but with different values is considered to be an error.

Fixes #995
This commit is contained in:
Andy Wilkinson
2014-05-30 15:12:09 +01:00
parent 2025dbad61
commit 8f7c96e8f0
2 changed files with 73 additions and 3 deletions

View File

@@ -19,17 +19,20 @@ package org.springframework.boot.cli.compiler.grape;
import groovy.lang.GroovyClassLoader;
import java.net.URI;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link AetherGrapeEngine}.
*
*
* @author Andy Wilkinson
*/
public class AetherGrapeEngineTests {
@@ -99,6 +102,53 @@ public class AetherGrapeEngineTests {
assertEquals(1, this.groovyClassLoader.getURLs().length);
}
@Test(expected = IllegalArgumentException.class)
public void differingTypeAndExt() {
Map<String, Object> dependency = createDependency("org.grails",
"grails-dependencies", "2.4.0");
dependency.put("type", "foo");
dependency.put("ext", "bar");
this.grapeEngine.grab(Collections.emptyMap(), dependency);
}
@Test
public void pomDependencyResolutionViaType() {
Map<String, Object> args = new HashMap<String, Object>();
Map<String, Object> dependency = createDependency("org.springframework",
"spring-framework-bom", "4.0.5.RELEASE");
dependency.put("type", "pom");
this.grapeEngine.grab(args, dependency);
URL[] urls = this.groovyClassLoader.getURLs();
assertEquals(1, urls.length);
assertTrue(urls[0].toExternalForm().endsWith(".pom"));
}
@Test
public void pomDependencyResolutionViaExt() {
Map<String, Object> args = new HashMap<String, Object>();
Map<String, Object> dependency = createDependency("org.springframework",
"spring-framework-bom", "4.0.5.RELEASE");
dependency.put("ext", "pom");
this.grapeEngine.grab(args, dependency);
URL[] urls = this.groovyClassLoader.getURLs();
assertEquals(1, urls.length);
assertTrue(urls[0].toExternalForm().endsWith(".pom"));
}
@Test
public void resolutionWithClassifier() {
Map<String, Object> args = new HashMap<String, Object>();
Map<String, Object> dependency = createDependency("org.springframework",
"spring-jdbc", "3.2.4.RELEASE", false);
dependency.put("classifier", "sources");
this.grapeEngine.grab(args, dependency);
URL[] urls = this.groovyClassLoader.getURLs();
assertEquals(1, urls.length);
assertTrue(urls[0].toExternalForm().endsWith("-sources.jar"));
}
private Map<String, Object> createDependency(String group, String module,
String version) {
Map<String, Object> dependency = new HashMap<String, Object>();