diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java index 567207f9e9f..f11eee20e57 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java @@ -48,7 +48,7 @@ import org.eclipse.aether.util.filter.DependencyFilterUtils; * A {@link GrapeEngine} implementation that uses Aether, the dependency resolution system used by * Maven. - * + * * @author Andy Wilkinson * @author Phillip Webb */ @@ -168,7 +168,27 @@ public class AetherGrapeEngine implements GrapeEngine { String group = (String) dependencyMap.get("group"); String module = (String) dependencyMap.get("module"); String version = (String) dependencyMap.get("version"); - return new DefaultArtifact(group, module, "jar", version); + String classifier = (String) dependencyMap.get("classifier"); + String type = determineType(dependencyMap); + + return new DefaultArtifact(group, module, classifier, type, version); + } + + private String determineType(Map dependencyMap) { + String type = (String) dependencyMap.get("type"); + String ext = (String) dependencyMap.get("ext"); + + if (type == null) { + type = ext; + if (type == null) { + type = "jar"; + } + } + else if (ext != null && !type.equals(ext)) { + throw new IllegalArgumentException( + "If both type and ext are specified they must have the same value"); + } + return type; } private boolean isTransitive(Map dependencyMap) { diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java index 9e811081318..be9aac2641b 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java @@ -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 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 args = new HashMap(); + Map 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 args = new HashMap(); + Map 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 args = new HashMap(); + + Map 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 createDependency(String group, String module, String version) { Map dependency = new HashMap();