Checking the path for classpath resource; related to gh-1045

This commit is contained in:
Marcin Grzejszczak
2019-04-17 08:19:58 +04:00
parent 46f3dabf3b
commit 1e71a32d21

View File

@@ -35,6 +35,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
@@ -207,17 +208,20 @@ public class ClasspathStubProvider implements StubDownloaderBuilder {
private List<RepoRoot> repoRoot(StubRunnerOptions stubRunnerOptions,
StubConfiguration configuration) {
if (StringUtils.hasText(stubRunnerOptions.getStubRepositoryRootAsString())) {
return Collections.singletonList(
new RepoRoot(stubRunnerOptions.getStubRepositoryRootAsString()));
}
else {
String path = "/**/" + configuration.getGroupId() + "/"
+ configuration.getArtifactId();
return Arrays.asList(new RepoRoot("classpath*:/META-INF" + path, "/**/*.*"),
new RepoRoot("classpath*:/contracts" + path, "/**/*.*"),
new RepoRoot("classpath*:/mappings" + path, "/**/*.*"));
Resource repositoryRoot = stubRunnerOptions.getStubRepositoryRoot();
if (repositoryRoot instanceof ClassPathResource) {
ClassPathResource classPathResource = (ClassPathResource) repositoryRoot;
String path = classPathResource.getPath();
if (StringUtils.hasText(path)) {
return Collections.singletonList(
new RepoRoot(stubRunnerOptions.getStubRepositoryRootAsString()));
}
}
String path = "/**/" + configuration.getGroupId() + "/"
+ configuration.getArtifactId();
return Arrays.asList(new RepoRoot("classpath*:/META-INF" + path, "/**/*.*"),
new RepoRoot("classpath*:/contracts" + path, "/**/*.*"),
new RepoRoot("classpath*:/mappings" + path, "/**/*.*"));
}
// Taken from Guava