Extend NoSuchLabelException to SVN repository

See gh-153
This commit is contained in:
Dave Syer
2015-05-19 11:58:53 +01:00
parent c685931308
commit 891e928890
3 changed files with 18 additions and 6 deletions

View File

@@ -26,13 +26,12 @@ import org.tmatesoft.svn.core.wc2.SvnCheckout;
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
import org.tmatesoft.svn.core.wc2.SvnTarget;
import org.tmatesoft.svn.core.wc2.SvnUpdate;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import static org.springframework.util.StringUtils.hasText;
/**
@@ -81,8 +80,21 @@ public class SvnKitEnvironmentRepository extends AbstractScmEnvironmentRepositor
private synchronized Environment loadEnvironment(String application, String profile, String label) {
final NativeEnvironmentRepository environmentRepository = new NativeEnvironmentRepository(
getEnvironment());
environmentRepository.setSearchLocations(getSearchLocations(getSvnPath(
getWorkingDirectory(), label)));
String[] locations = getSearchLocations(getSvnPath(
getWorkingDirectory(), label));
boolean exists = false;
for (String location : locations) {
location = location.startsWith("file:") ? location.substring("file:".length()) : location;
location = StringUtils.cleanPath(location);
if (new File(location).exists()) {
exists = true;
break;
}
}
if (!exists) {
throw new NoSuchLabelException("No label found for: " + label);
}
environmentRepository.setSearchLocations(locations);
return environmentRepository.findOne(application, profile, label);
}

View File

@@ -129,7 +129,7 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
assertEquals("trunk", repository.getDefaultLabel());
}
@Test
@Test(expected=NoSuchLabelException.class)
public void invalidLabel() throws Exception {
String uri = ConfigServerTestUtils.prepareLocalSvnRepo(
"src/test/resources/svn-config-repo", "target/config");

View File

@@ -91,7 +91,7 @@ public class SVNKitEnvironmentRepositoryTests {
.contains("application.yml"));
}
@Test
@Test(expected=NoSuchLabelException.class)
public void invalidLabel() {
Environment environment = repository.findOne("bar", "staging", "unknownlabel");
assertEquals(0, environment.getPropertySources().size());