From b71f07932eeb4d4df40cb8aac86b7496ab7eafda Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Sat, 29 Mar 2014 19:18:40 +0000 Subject: [PATCH] Support for explicit module path in dependency Instead of *always* needing to pull auto-import dependencies from the master parent pom, we now allow normal @Grab-style module specifications, e.g. "io.ratpack:ratpack-groovy:0.9.2" --- .../cli/compiler/DependencyCustomizer.java | 3 ++- .../ArtifactCoordinatesResolver.java | 26 ++++++++++++------- ...pendenciesArtifactCoordinatesResolver.java | 11 ++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyCustomizer.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyCustomizer.java index 188ad47141a..ecefc7c9865 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyCustomizer.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyCustomizer.java @@ -205,7 +205,8 @@ public class DependencyCustomizer { ArtifactCoordinatesResolver artifactCoordinatesResolver = this.dependencyResolutionContext .getArtifactCoordinatesResolver(); this.classNode.addAnnotation(createGrabAnnotation( - artifactCoordinatesResolver.getGroupId(module), module, + artifactCoordinatesResolver.getGroupId(module), + artifactCoordinatesResolver.getArtifactId(module), artifactCoordinatesResolver.getVersion(module), transitive)); } return this; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/ArtifactCoordinatesResolver.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/ArtifactCoordinatesResolver.java index aae720725f5..49b17b39b60 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/ArtifactCoordinatesResolver.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/ArtifactCoordinatesResolver.java @@ -25,18 +25,26 @@ package org.springframework.boot.cli.compiler.dependencies; public interface ArtifactCoordinatesResolver { /** - * Gets the group id of the artifact identified by the given {@code artifactId}. - * Returns {@code null} if the artifact is unknown to the resolver. - * @param artifactId The id of the artifact - * @return The group id of the artifact + * Gets the group id of the artifact identified by the given {@code module}. Returns + * {@code null} if the artifact is unknown to the resolver. + * @param module The id of the module + * @return The group id of the module */ - String getGroupId(String artifactId); + String getGroupId(String module); /** - * Gets the version of the artifact identified by the given {@code artifactId}. + * Gets the artifact id of the artifact identified by the given {@code module}. * Returns {@code null} if the artifact is unknown to the resolver. - * @param artifactId The id of the artifact - * @return The version of the artifact + * @param module The id of the module + * @return The group id of the module */ - String getVersion(String artifactId); + String getArtifactId(String module); + + /** + * Gets the version of the artifact identified by the given {@code module}. Returns + * {@code null} if the artifact is unknown to the resolver. + * @param module The id of the module + * @return The version of the module + */ + String getVersion(String module); } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/ManagedDependenciesArtifactCoordinatesResolver.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/ManagedDependenciesArtifactCoordinatesResolver.java index c88fa234aa3..a864829d095 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/ManagedDependenciesArtifactCoordinatesResolver.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/ManagedDependenciesArtifactCoordinatesResolver.java @@ -19,6 +19,7 @@ package org.springframework.boot.cli.compiler.dependencies; import org.springframework.boot.dependency.tools.Dependency; import org.springframework.boot.dependency.tools.ManagedDependencies; import org.springframework.boot.dependency.tools.VersionManagedDependencies; +import org.springframework.util.StringUtils; /** * {@link ArtifactCoordinatesResolver} backed by {@link ManagedDependencies}. @@ -50,7 +51,17 @@ public class ManagedDependenciesArtifactCoordinatesResolver implements return (dependency == null ? null : dependency.getVersion()); } + @Override + public String getArtifactId(String artifactId) { + Dependency dependency = find(artifactId); + return (dependency == null ? null : dependency.getArtifactId()); + } + private Dependency find(String artifactId) { + if (StringUtils.countOccurrencesOf(artifactId, ":") == 2) { + String[] tokens = artifactId.split(":"); + return new Dependency(tokens[0], tokens[1], tokens[2]); + } if (artifactId != null) { if (artifactId.startsWith("spring-boot")) { return new Dependency("org.springframework.boot", artifactId,