Locate placeholder in resource search location correctly

Fixes gh-303
This commit is contained in:
Dave Syer
2015-12-21 12:16:21 +00:00
parent a125393f27
commit 4a35526b97
4 changed files with 12 additions and 5 deletions

View File

@@ -161,7 +161,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
finally {
try {
if (git != null) {
git.getRepository().close();
git.close();
}
}
catch (Exception e) {

View File

@@ -51,7 +51,7 @@ public class GenericResourceRepository
@Override
public synchronized Resource findOne(String application, String profile, String label,
String path) {
String[] locations = this.service.getLocations(application, "default", label).getLocations();
String[] locations = this.service.getLocations(application, profile, label).getLocations();
try {
for (int i = locations.length; i-- > 0;) {
String location = locations[i];

View File

@@ -24,8 +24,6 @@ import org.junit.Test;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepositoryTests;
import org.springframework.cloud.config.server.resource.GenericResourceRepository;
import org.springframework.cloud.config.server.resource.NoSuchResourceException;
import org.springframework.context.ConfigurableApplicationContext;
/**
@@ -36,6 +34,7 @@ public class GenericResourceRepositoryTests {
private GenericResourceRepository repository;
private ConfigurableApplicationContext context;
private NativeEnvironmentRepository nativeRepository;
@After
public void close() {
@@ -48,8 +47,9 @@ public class GenericResourceRepositoryTests {
public void init() {
this.context = new SpringApplicationBuilder(
NativeEnvironmentRepositoryTests.class).web(false).run();
this.nativeRepository = new NativeEnvironmentRepository(this.context.getEnvironment());
this.repository = new GenericResourceRepository(
new NativeEnvironmentRepository(this.context.getEnvironment()));
this.nativeRepository);
this.repository.setResourceLoader(this.context);
this.context.close();
}
@@ -64,6 +64,12 @@ public class GenericResourceRepositoryTests {
assertNotNull(this.repository.findOne("blah", "local", "master", "foo.txt"));
}
@Test
public void locateProfiledResourceWithPlaceholder() {
this.nativeRepository.setSearchLocations("classpath:/test/{profile}");
assertNotNull(this.repository.findOne("blah", "local", "master", "foo.txt"));
}
@Test(expected=NoSuchResourceException.class)
public void locateMissingResource() {
assertNotNull(this.repository.findOne("blah", "default", "master", "foo.txt"));

View File

@@ -0,0 +1 @@
foo=bar