From 5a145eacfe4ff57508d2897c39155d0d771c959b Mon Sep 17 00:00:00 2001 From: David Turanski Date: Wed, 29 Jul 2015 11:05:10 -0400 Subject: [PATCH] Changed module resolver to single method --- .../module/resolver/AetherModuleResolver.java | 36 ++++++------------- .../module/resolver/ModuleResolver.java | 16 ++------- .../resolver/AetherModuleResolverTests.java | 9 ++--- 3 files changed, 19 insertions(+), 42 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 d5fe37b88..788f81d23 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 @@ -54,10 +54,6 @@ public class AetherModuleResolver implements ModuleResolver { private static final String DEFAULT_CONTENT_TYPE = "default"; - private static final String DEFAULT_CLASSIFIER = ""; - - private static final String DEFAULT_EXTENSION = "jar"; - private final File localRepository; private final List remoteRepositories; @@ -89,35 +85,25 @@ public class AetherModuleResolver implements ModuleResolver { * 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 - * @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) { - 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. + * @param classifer classifier can be null if none + * @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 */ @Override - public Resource resolve(String groupId, String artifactId, String version, String classifer, String extension) { + public Resource resolve(String groupId, String artifactId, String extension, String classifer, String version) { Assert.hasText(groupId, "'groupId' cannot be blank."); Assert.hasText(artifactId, "'artifactId' cannot be blank."); - Assert.hasText(version, "'version' cannot be blank."); + + Assert.hasText(extension, "'extension' cannot be blank."); + if (classifer == null) { classifer = ""; } - Assert.hasText(extension, "'extension' cannot be blank."); + + Assert.hasText(version, "'version' cannot be blank."); + Artifact artifact = new DefaultArtifact(groupId, artifactId, classifer, extension, version); RepositorySystemSession session = newRepositorySystemSession(repositorySystem, localRepository.getAbsolutePath()); 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 0299009fb..333483a51 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 @@ -30,21 +30,11 @@ public interface ModuleResolver { * * @param groupId the groupId * @param artifactId the artifactId - * @param version the version - * @return the resource - */ - 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 + * @param classifer classifier + * @param version the version * @return the resource */ - public Resource resolve(String groupId, String artifactId, String version, String classifer, String extension); + public Resource resolve(String groupId, String artifactId, String extension, String classifer, String version); } 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 f30ce7026..a8e8da558 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 @@ -51,7 +51,7 @@ public class AetherModuleResolverTests { ClassPathResource cpr = new ClassPathResource("local-repo"); File localRepository = cpr.getFile(); AetherModuleResolver defaultModuleResolver = new AetherModuleResolver(localRepository, null); - Resource resource = defaultModuleResolver.resolve("foo.bar", "foo-bar", "1.0.0"); + Resource resource = defaultModuleResolver.resolve("foo.bar", "foo-bar", "jar","","1.0.0"); assertTrue(resource.exists()); assertEquals(resource.getFile().getName(), "foo-bar-1.0.0.jar"); } @@ -61,7 +61,7 @@ public class AetherModuleResolverTests { ClassPathResource cpr = new ClassPathResource("local-repo"); File localRepository = cpr.getFile(); AetherModuleResolver defaultModuleResolver = new AetherModuleResolver(localRepository, null); - defaultModuleResolver.resolve("niente", "nada", "zilch"); + defaultModuleResolver.resolve("niente", "nada", "jar","", "zilch"); } @Test @@ -72,7 +72,8 @@ public class AetherModuleResolverTests { Map remoteRepos = new HashMap<>(); remoteRepos.put("modules", "http://repo.spring.io/spring-cloud-stream-modules"); AetherModuleResolver defaultModuleResolver = new AetherModuleResolver(localRepository, remoteRepos); - Resource resource = defaultModuleResolver.resolve("org.springframework.cloud.stream.module", "time-source", "1.0.0.BUILD-SNAPSHOT", "exec", "jar"); + 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(), "time-source-1.0.0.BUILD-SNAPSHOT-exec.jar"); } @@ -91,7 +92,7 @@ public class AetherModuleResolverTests { .withStatus(200) .withBodyFile(stubFileName))); AetherModuleResolver defaultModuleResolver = new AetherModuleResolver(localRepository, remoteRepos); - Resource resource = defaultModuleResolver.resolve("org.bar", "foo", "1.0.0"); + Resource resource = defaultModuleResolver.resolve("org.bar", "foo","jar", "", "1.0.0"); assertTrue(resource.exists()); assertEquals(resource.getFile().getName(), "foo-1.0.0.jar"); }