Changed module resolver to single method

This commit is contained in:
David Turanski
2015-07-29 11:05:10 -04:00
parent ffc57e0c04
commit 5a145eacfe
3 changed files with 19 additions and 42 deletions

View File

@@ -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<RemoteRepository> 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());

View File

@@ -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);
}

View File

@@ -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<String, String> 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");
}