From fcfa22a06354c5a1246ba63d310e00e7fdbbe3f7 Mon Sep 17 00:00:00 2001 From: David Turanski Date: Tue, 28 Jul 2015 17:18:33 -0400 Subject: [PATCH] added support for classifier and extension --- .../module/resolver/AetherModuleResolver.java | 30 +++++++++++++++++-- .../module/resolver/ModuleResolver.java | 12 ++++++++ .../resolver/AetherModuleResolverTests.java | 9 ++---- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/resolver/AetherModuleResolver.java b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/resolver/AetherModuleResolver.java index f35fe6ea6..1c3876dfe 100644 --- a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/resolver/AetherModuleResolver.java +++ b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/resolver/AetherModuleResolver.java @@ -64,7 +64,6 @@ public class AetherModuleResolver implements ModuleResolver { /** * Create an instance specifying the locations of the local and remote repositories. - * * @param localRepository the root path of the local maven repository * @param remoteRepositories a Map containing pairs of (repository ID,repository URL). This * may be null or empty if the local repository is off line. @@ -90,11 +89,36 @@ public class AetherModuleResolver implements ModuleResolver { * @param artifactId the artifactId * @param version the version * @return a {@ link FileSystemResource} representing the resolved artifact in the local repository. - * @throws a RuntimeException if the artifact does not exist or the resolution fails. + * @throws a RuntimeException if the artifact does not exist or the resolution fails. */ @Override public Resource resolve(String groupId, String artifactId, String version) { - Artifact artifact = new DefaultArtifact(groupId, artifactId, DEFAULT_CLASSIFIER, DEFAULT_EXTENSION, version); + return resolve(groupId, artifactId, version, DEFAULT_CLASSIFIER, DEFAULT_EXTENSION); + } + + /** + * Resolve an artifact and return its location in the local repository. Aether performs the normal + * Maven resolution process ensuring that the latest update is cached to the local repository. + * @param groupId the groupId + * @param artifactId the artifactId + * @param version the version + * @param classifer classifier can be null if none + * @param extension the file extension + * @return a {@ link FileSystemResource} representing the resolved artifact in the local repository. + * @throws a RuntimeException if the artifact does not exist or the resolution fails. + */ + @Override + public Resource resolve(String groupId, String artifactId, String version, String classifer, String extension) { + Assert.hasText(groupId, "'groupId' cannot be blank."); + Assert.hasText(artifactId, "'artifactId' cannot be blank."); + Assert.hasText(version, "'version' cannot be blank."); + if (classifer == null) { + classifer = ""; + } + + Assert.hasText(extension, "'extension' cannot be blank."); + + Artifact artifact = new DefaultArtifact(groupId, artifactId, classifer, extension, version); RepositorySystemSession session = newRepositorySystemSession(repositorySystem, localRepository.getAbsolutePath()); ArtifactResult result; diff --git a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/resolver/ModuleResolver.java b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/resolver/ModuleResolver.java index 7925473fa..0299009fb 100644 --- a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/resolver/ModuleResolver.java +++ b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/resolver/ModuleResolver.java @@ -35,4 +35,16 @@ public interface ModuleResolver { */ public Resource resolve(String groupId, String artifactId, String version); + /** + * Retrieve a resource given its coordinates. + * + * @param groupId the groupId + * @param artifactId the artifactId + * @param version the version + * @param classifer classifier + * @param extension the file extension + * @return the resource + */ + public Resource resolve(String groupId, String artifactId, String version, String classifer, String extension); + } diff --git a/spring-cloud-stream-module-launcher/src/test/java/org/springframework/cloud/stream/module/resolver/AetherModuleResolverTests.java b/spring-cloud-stream-module-launcher/src/test/java/org/springframework/cloud/stream/module/resolver/AetherModuleResolverTests.java index 20a2044eb..db4329b36 100644 --- a/spring-cloud-stream-module-launcher/src/test/java/org/springframework/cloud/stream/module/resolver/AetherModuleResolverTests.java +++ b/spring-cloud-stream-module-launcher/src/test/java/org/springframework/cloud/stream/module/resolver/AetherModuleResolverTests.java @@ -71,14 +71,11 @@ public class AetherModuleResolverTests { Map remoteRepos = new HashMap<>(); - remoteRepos.put("spring", "http://repo.spring.io/release"); - remoteRepos.put("spring-snap", "http://repo.spring.io/snapshot"); - remoteRepos.put("spring-ms", "http://repo.spring.io/milestone"); - + remoteRepos.put("modules", "http://repo.spring.io/spring-cloud-stream-modules"); AetherModuleResolver defaultModuleResolver = new AetherModuleResolver(localRepository, remoteRepos); - Resource resource = defaultModuleResolver.resolve("org.springframework", "spring-core", "4.1.6.RELEASE"); + Resource resource = defaultModuleResolver.resolve("org.springframework.cloud.stream.module", "time-source", "1.0.0.BUILD-SNAPSHOT","exec", "jar"); assertTrue(resource.exists()); - assertEquals(resource.getFile().getName(), "spring-core-4.1.6.RELEASE.jar"); + assertEquals(resource.getFile().getName(), "time-source-1.0.0.BUILD-SNAPSHOT-exec.jar"); } @Test