From 100be641928d4df126c23973846037a526aa9bf5 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Tue, 14 Feb 2017 13:40:15 -0700 Subject: [PATCH 01/26] Ensures health indicator uses configured label. fixes gh-638 (cherry picked from commit 30a1f81) --- .../config/ConfigServerHealthIndicator.java | 2 +- .../ConfigServerHealthIndicatorTests.java | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicator.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicator.java index 9c3590d3..416cf3b8 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicator.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicator.java @@ -48,7 +48,7 @@ public class ConfigServerHealthIndicator extends AbstractHealthIndicator { String profiles = repository.getProfiles(); try { - Environment environment = this.environmentRepository.findOne(application, profiles, null); + Environment environment = this.environmentRepository.findOne(application, profiles, repository.getLabel()); HashMap detail = new HashMap<>(); detail.put("name", environment.getName()); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicatorTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicatorTests.java index 58ce602c..c08d3bdc 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicatorTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicatorTests.java @@ -1,8 +1,6 @@ package org.springframework.cloud.config.server.config; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; +import java.util.Collections; import org.junit.Before; import org.junit.Test; @@ -10,9 +8,14 @@ import org.mockito.Answers; import org.mockito.Mock; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.config.environment.Environment; -import org.springframework.cloud.config.server.config.ConfigServerHealthIndicator; +import org.springframework.cloud.config.server.config.ConfigServerHealthIndicator.Repository; import org.springframework.cloud.config.server.environment.EnvironmentRepository; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + /** * @author Spencer Gibb */ @@ -44,4 +47,15 @@ public class ConfigServerHealthIndicatorTests { when(repository.findOne(anyString(), anyString(), anyString())).thenThrow(new RuntimeException()); assertEquals("wrong exception status", Status.DOWN, indicator.health().getStatus()); } + + @Test + public void customLabelWorks() { + Repository repo = new Repository(); + repo.setName("myname"); + repo.setProfiles("myprofile"); + repo.setLabel("mylabel"); + this.indicator.setRepositories(Collections.singletonMap("myname", repo)); + when(repository.findOne("myname", "myprofile", "mylabel")).thenReturn(environment); + assertEquals("wrong default status", Status.UP, indicator.health().getStatus()); + } } From cd09c75ef0fa9fc2e85cfb7079470cbf572785c9 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Tue, 7 Mar 2017 19:59:10 -0500 Subject: [PATCH 02/26] Version changes for 1.2.3.RELEASE --- docs/pom.xml | 2 +- pom.xml | 6 +++--- spring-cloud-config-client/pom.xml | 2 +- spring-cloud-config-dependencies/pom.xml | 4 ++-- spring-cloud-config-monitor/pom.xml | 4 ++-- spring-cloud-config-sample/pom.xml | 2 +- spring-cloud-config-server/pom.xml | 2 +- spring-cloud-starter-config/pom.xml | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index ff6fb294..01c6ab5c 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.3.RELEASE pom Spring Cloud Config Docs diff --git a/pom.xml b/pom.xml index 70351dea..5c57e426 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.3.RELEASE pom Spring Cloud Config Spring Cloud Config @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-build - 1.2.2.BUILD-SNAPSHOT + 1.2.2.RELEASE @@ -22,7 +22,7 @@ config - 1.1.6.BUILD-SNAPSHOT + 1.1.8.RELEASE spring-cloud-config-dependencies diff --git a/spring-cloud-config-client/pom.xml b/spring-cloud-config-client/pom.xml index f27b03be..40702f96 100644 --- a/spring-cloud-config-client/pom.xml +++ b/spring-cloud-config-client/pom.xml @@ -10,7 +10,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.3.RELEASE .. diff --git a/spring-cloud-config-dependencies/pom.xml b/spring-cloud-config-dependencies/pom.xml index b479ae7b..2f9c2702 100644 --- a/spring-cloud-config-dependencies/pom.xml +++ b/spring-cloud-config-dependencies/pom.xml @@ -5,11 +5,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 1.2.2.BUILD-SNAPSHOT + 1.2.2.RELEASE spring-cloud-config-dependencies - 1.2.3.BUILD-SNAPSHOT + 1.2.3.RELEASE pom spring-cloud-config-dependencies Spring Cloud Config Dependencies diff --git a/spring-cloud-config-monitor/pom.xml b/spring-cloud-config-monitor/pom.xml index e9b6dc67..fc18da5f 100644 --- a/spring-cloud-config-monitor/pom.xml +++ b/spring-cloud-config-monitor/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.3.RELEASE .. spring-cloud-config-monitor @@ -13,7 +13,7 @@ Spring Cloud Config Monitor ${basedir}/../.. - 1.2.2.BUILD-SNAPSHOT + 1.2.2.RELEASE diff --git a/spring-cloud-config-sample/pom.xml b/spring-cloud-config-sample/pom.xml index 5514e1bc..58c7a5e8 100644 --- a/spring-cloud-config-sample/pom.xml +++ b/spring-cloud-config-sample/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.3.RELEASE .. diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index 5b8752ed..8e4ad434 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.3.RELEASE .. diff --git a/spring-cloud-starter-config/pom.xml b/spring-cloud-starter-config/pom.xml index 9760a1c1..b2c4e93a 100644 --- a/spring-cloud-starter-config/pom.xml +++ b/spring-cloud-starter-config/pom.xml @@ -5,10 +5,10 @@ org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.3.RELEASE spring-cloud-starter-config - 1.2.3.BUILD-SNAPSHOT + 1.2.3.RELEASE spring-cloud-starter-config Spring Cloud Starter https://projects.spring.io/spring-cloud From b705ed87090093de05b42ed7dcb160e2a7874e06 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Tue, 7 Mar 2017 20:06:48 -0500 Subject: [PATCH 03/26] Revert "Version changes for 1.2.3.RELEASE" This reverts commit cd09c75ef0fa9fc2e85cfb7079470cbf572785c9. --- docs/pom.xml | 2 +- pom.xml | 6 +++--- spring-cloud-config-client/pom.xml | 2 +- spring-cloud-config-dependencies/pom.xml | 4 ++-- spring-cloud-config-monitor/pom.xml | 4 ++-- spring-cloud-config-sample/pom.xml | 2 +- spring-cloud-config-server/pom.xml | 2 +- spring-cloud-starter-config/pom.xml | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 01c6ab5c..ff6fb294 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.RELEASE + 1.2.3.BUILD-SNAPSHOT pom Spring Cloud Config Docs diff --git a/pom.xml b/pom.xml index 5c57e426..70351dea 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.cloud spring-cloud-config - 1.2.3.RELEASE + 1.2.3.BUILD-SNAPSHOT pom Spring Cloud Config Spring Cloud Config @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-build - 1.2.2.RELEASE + 1.2.2.BUILD-SNAPSHOT @@ -22,7 +22,7 @@ config - 1.1.8.RELEASE + 1.1.6.BUILD-SNAPSHOT spring-cloud-config-dependencies diff --git a/spring-cloud-config-client/pom.xml b/spring-cloud-config-client/pom.xml index 40702f96..f27b03be 100644 --- a/spring-cloud-config-client/pom.xml +++ b/spring-cloud-config-client/pom.xml @@ -10,7 +10,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.RELEASE + 1.2.3.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-dependencies/pom.xml b/spring-cloud-config-dependencies/pom.xml index 2f9c2702..b479ae7b 100644 --- a/spring-cloud-config-dependencies/pom.xml +++ b/spring-cloud-config-dependencies/pom.xml @@ -5,11 +5,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 1.2.2.RELEASE + 1.2.2.BUILD-SNAPSHOT spring-cloud-config-dependencies - 1.2.3.RELEASE + 1.2.3.BUILD-SNAPSHOT pom spring-cloud-config-dependencies Spring Cloud Config Dependencies diff --git a/spring-cloud-config-monitor/pom.xml b/spring-cloud-config-monitor/pom.xml index fc18da5f..e9b6dc67 100644 --- a/spring-cloud-config-monitor/pom.xml +++ b/spring-cloud-config-monitor/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.RELEASE + 1.2.3.BUILD-SNAPSHOT .. spring-cloud-config-monitor @@ -13,7 +13,7 @@ Spring Cloud Config Monitor ${basedir}/../.. - 1.2.2.RELEASE + 1.2.2.BUILD-SNAPSHOT diff --git a/spring-cloud-config-sample/pom.xml b/spring-cloud-config-sample/pom.xml index 58c7a5e8..5514e1bc 100644 --- a/spring-cloud-config-sample/pom.xml +++ b/spring-cloud-config-sample/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.RELEASE + 1.2.3.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index 8e4ad434..5b8752ed 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.RELEASE + 1.2.3.BUILD-SNAPSHOT .. diff --git a/spring-cloud-starter-config/pom.xml b/spring-cloud-starter-config/pom.xml index b2c4e93a..9760a1c1 100644 --- a/spring-cloud-starter-config/pom.xml +++ b/spring-cloud-starter-config/pom.xml @@ -5,10 +5,10 @@ org.springframework.cloud spring-cloud-config - 1.2.3.RELEASE + 1.2.3.BUILD-SNAPSHOT spring-cloud-starter-config - 1.2.3.RELEASE + 1.2.3.BUILD-SNAPSHOT spring-cloud-starter-config Spring Cloud Starter https://projects.spring.io/spring-cloud From e5e575370e0ea733aa65ac8c54d1bac412738f50 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Wed, 8 Mar 2017 10:56:04 -0500 Subject: [PATCH 04/26] Bumping versions for next release --- docs/pom.xml | 2 +- pom.xml | 6 +++--- spring-cloud-config-client/pom.xml | 2 +- spring-cloud-config-dependencies/pom.xml | 4 ++-- spring-cloud-config-monitor/pom.xml | 4 ++-- spring-cloud-config-sample/pom.xml | 2 +- spring-cloud-config-server/pom.xml | 2 +- spring-cloud-starter-config/pom.xml | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index ff6fb294..88d04627 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.4.BUILD-SNAPSHOT pom Spring Cloud Config Docs diff --git a/pom.xml b/pom.xml index 70351dea..3fbc12d9 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.4.BUILD-SNAPSHOT pom Spring Cloud Config Spring Cloud Config @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-build - 1.2.2.BUILD-SNAPSHOT + 1.2.3.BUILD-SNAPSHOT @@ -22,7 +22,7 @@ config - 1.1.6.BUILD-SNAPSHOT + 1.1.7.BUILD-SNAPSHOT spring-cloud-config-dependencies diff --git a/spring-cloud-config-client/pom.xml b/spring-cloud-config-client/pom.xml index f27b03be..c4c43dd5 100644 --- a/spring-cloud-config-client/pom.xml +++ b/spring-cloud-config-client/pom.xml @@ -10,7 +10,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.4.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-dependencies/pom.xml b/spring-cloud-config-dependencies/pom.xml index b479ae7b..653bbe52 100644 --- a/spring-cloud-config-dependencies/pom.xml +++ b/spring-cloud-config-dependencies/pom.xml @@ -5,11 +5,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 1.2.2.BUILD-SNAPSHOT + 1.2.3.BUILD-SNAPSHOT spring-cloud-config-dependencies - 1.2.3.BUILD-SNAPSHOT + 1.2.4.BUILD-SNAPSHOT pom spring-cloud-config-dependencies Spring Cloud Config Dependencies diff --git a/spring-cloud-config-monitor/pom.xml b/spring-cloud-config-monitor/pom.xml index e9b6dc67..560950a3 100644 --- a/spring-cloud-config-monitor/pom.xml +++ b/spring-cloud-config-monitor/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.4.BUILD-SNAPSHOT .. spring-cloud-config-monitor @@ -13,7 +13,7 @@ Spring Cloud Config Monitor ${basedir}/../.. - 1.2.2.BUILD-SNAPSHOT + 1.2.3.BUILD-SNAPSHOT diff --git a/spring-cloud-config-sample/pom.xml b/spring-cloud-config-sample/pom.xml index 5514e1bc..9988c485 100644 --- a/spring-cloud-config-sample/pom.xml +++ b/spring-cloud-config-sample/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.4.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index 5b8752ed..23e89b4d 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.4.BUILD-SNAPSHOT .. diff --git a/spring-cloud-starter-config/pom.xml b/spring-cloud-starter-config/pom.xml index 9760a1c1..e64d574e 100644 --- a/spring-cloud-starter-config/pom.xml +++ b/spring-cloud-starter-config/pom.xml @@ -5,10 +5,10 @@ org.springframework.cloud spring-cloud-config - 1.2.3.BUILD-SNAPSHOT + 1.2.4.BUILD-SNAPSHOT spring-cloud-starter-config - 1.2.3.BUILD-SNAPSHOT + 1.2.4.BUILD-SNAPSHOT spring-cloud-starter-config Spring Cloud Starter https://projects.spring.io/spring-cloud From f67bdba5ed418f9bc9c5f3c21107e7aab8d24954 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 8 May 2017 16:45:11 +0100 Subject: [PATCH 05/26] Derive base dir of new pattern matching repositories from the parent Before this change when a repository is created to support a pattern match in the URL, the basedir for cloning the scm repository is a new temp dir. So if user configures the basedir to be something other than temp then he loses the benefit once patterns are used in the URL matchers. The basedir still has to be unique, so we now use the same parent directory as the parent repo, and add the temp file name as a directory name. I.e. if basedir=/foo/bar the pattern matched basedir will be something like /foo/config-repo-23874691. You need the directory to have a parent that is writable by the config server JVM. Fixes gh-451 --- .../MultipleJGitEnvironmentRepository.java | 25 ++++--- ...mentProfilePlaceholderRepositoryTests.java | 31 ++++++--- ...EnvironmentRepositoryIntegrationTests.java | 65 ++++++++++++++----- ...ultipleJGitEnvironmentRepositoryTests.java | 53 ++++++++++----- 4 files changed, 124 insertions(+), 50 deletions(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepository.java index 1d278f3f..a63b8a29 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepository.java @@ -76,6 +76,11 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository } repo.afterPropertiesSet(); } + if (!getBasedir().getParentFile().canWrite()) { + throw new IllegalStateException( + "Cannot write parent of basedir (please configure a writable location): " + + getBasedir()); + } } public void setRepos(Map repos) { @@ -103,7 +108,8 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository if (logger.isDebugEnabled()) { this.logger.debug("Cannot retrieve resource locations from " + candidate.getUri() + ", cause: (" - + e.getClass().getSimpleName() + ") " + e.getMessage()); + + e.getClass().getSimpleName() + ") " + + e.getMessage()); } continue; } @@ -125,7 +131,7 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository for (JGitEnvironmentRepository candidate : getRepositories(repository, application, profile, label)) { try { - if (label==null) { + if (label == null) { label = candidate.getDefaultLabel(); } Environment source = candidate.findOne(application, profile, @@ -136,9 +142,10 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository } catch (Exception e) { if (logger.isDebugEnabled()) { - this.logger.debug("Cannot load configuration from " - + candidate.getUri() + ", cause: (" - + e.getClass().getSimpleName() + ") " + e.getMessage()); + this.logger.debug( + "Cannot load configuration from " + candidate.getUri() + + ", cause: (" + e.getClass().getSimpleName() + + ") " + e.getMessage()); } continue; } @@ -147,7 +154,7 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository } JGitEnvironmentRepository candidate = getRepository(this, application, profile, label); - if (label==null) { + if (label == null) { label = candidate.getDefaultLabel(); } if (candidate == this) { @@ -175,7 +182,8 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository } String key = repository.getUri(); - // cover the case where label is in the uri, but no label was sent with the request + // cover the case where label is in the uri, but no label was sent with the + // request if (key.contains("{label}") && label == null) { label = repository.getDefaultLabel(); } @@ -200,7 +208,8 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository File basedir = repository.getBasedir(); BeanUtils.copyProperties(source, repository); repository.setUri(uri); - repository.setBasedir(basedir); + repository.setBasedir( + new File(source.getBasedir().getParentFile(), basedir.getName())); return repository; } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentProfilePlaceholderRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentProfilePlaceholderRepositoryTests.java index 732ed9f3..1a5d3106 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentProfilePlaceholderRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentProfilePlaceholderRepositoryTests.java @@ -15,22 +15,27 @@ */ package org.springframework.cloud.config.server.environment; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - import java.io.File; import java.util.HashMap; import java.util.Map; import org.junit.Before; import org.junit.Test; + import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository; import org.springframework.cloud.config.server.environment.SearchPathLocator.Locations; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.core.env.StandardEnvironment; +import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.util.StringUtils; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; /** * @author Dave Syer @@ -46,6 +51,7 @@ public class MultipleJGitEnvironmentProfilePlaceholderRepositoryTests { public void init() throws Exception { String defaultUri = ConfigServerTestUtils.prepareLocalRepo("config-repo"); this.repository.setUri(defaultUri); + this.repository.setBasedir(new File("target/repos/parent_repo")); this.repository.setRepos(createRepositories()); } @@ -67,6 +73,7 @@ public class MultipleJGitEnvironmentProfilePlaceholderRepositoryTests { repo.setName(name); repo.setPattern(new String[] { pattern }); repo.setUri(uri); + repo.setBasedir(new File("target/repos/pattern_repos", name)); return repo; } @@ -84,11 +91,12 @@ public class MultipleJGitEnvironmentProfilePlaceholderRepositoryTests { Environment environment = this.repository.findOne("application", "test1-config-repo", "master"); assertEquals(1, environment.getPropertySources().size()); - assertEquals( - getUri("*").replace("{profile}", "test1-config-repo") - + "/application.yml", + String uri = getUri("*").replace("{profile}", "test1-config-repo"); + assertEquals(uri + "/application.yml", environment.getPropertySources().get(0).getName()); assertVersion(environment); + assertThat(StringUtils.cleanPath(getRepository(uri).getBasedir().toString()), + containsString("target/repos")); } @Test @@ -141,6 +149,13 @@ public class MultipleJGitEnvironmentProfilePlaceholderRepositoryTests { "test2-config-repo", "missing-config-repo" }); } + @SuppressWarnings("unchecked") + private JGitEnvironmentRepository getRepository(String uri) { + Map repos = (Map) ReflectionTestUtils + .getField(repository, "placeholders"); + return repos.get(uri); + } + private void assertVersion(Environment environment) { String version = environment.getVersion(); assertNotNull("version was null", version); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryIntegrationTests.java index 3e20e33f..da7d953d 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryIntegrationTests.java @@ -16,8 +16,6 @@ package org.springframework.cloud.config.server.environment; -import static org.junit.Assert.assertEquals; - import java.io.File; import java.io.IOException; import java.util.LinkedHashMap; @@ -26,7 +24,11 @@ import java.util.Map; import org.eclipse.jgit.util.FileUtils; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.rules.ExpectedException; + import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -38,6 +40,9 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertEquals; + /** * @author Andy Chan (iceycake) * @author Dave Syer @@ -49,6 +54,9 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests { private File basedir = new File("target/config"); + @Rule + public ExpectedException expected = ExpectedException.none(); + @Before public void init() throws Exception { if (this.basedir.exists()) { @@ -69,7 +77,8 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests { String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo"); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri).run(); - EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context + .getBean(EnvironmentRepository.class); repository.findOne("bar", "staging", "master"); Environment environment = repository.findOne("bar", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); @@ -86,7 +95,8 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri) .properties(repoMapping).run(); - EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context + .getBean(EnvironmentRepository.class); repository.findOne("test1-svc", "staging", "master"); Environment environment = repository.findOne("test1-svc", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); @@ -98,12 +108,14 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests { String test1RepoUri = ConfigServerTestUtils.prepareLocalRepo("test1-config-repo"); Map repoMapping = new LinkedHashMap(); - repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern", "*/staging"); + repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern", + "*/staging"); repoMapping.put("spring.cloud.config.server.git.repos[test1].uri", test1RepoUri); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri) .properties(repoMapping).run(); - EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context + .getBean(EnvironmentRepository.class); repository.findOne("test1-svc", "staging", "master"); Environment environment = repository.findOne("test1-svc", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); @@ -115,14 +127,17 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests { String test1RepoUri = ConfigServerTestUtils.prepareLocalRepo("test1-config-repo"); Map repoMapping = new LinkedHashMap(); - repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern", "*/staging"); + repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern", + "*/staging"); repoMapping.put("spring.cloud.config.server.git.repos[test1].uri", test1RepoUri); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri) .properties(repoMapping).run(); - EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context + .getBean(EnvironmentRepository.class); repository.findOne("test1-svc", "staging", "master"); - Environment environment = repository.findOne("test1-svc", "staging,cloud", "master"); + Environment environment = repository.findOne("test1-svc", "staging,cloud", + "master"); assertEquals(2, environment.getPropertySources().size()); } @@ -132,16 +147,21 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests { String test1RepoUri = ConfigServerTestUtils.prepareLocalRepo("test1-config-repo"); Map repoMapping = new LinkedHashMap(); - repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern[0]", "*/staging,*"); - repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern[1]", "*/*,staging"); - repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern[2]", "*/staging"); + repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern[0]", + "*/staging,*"); + repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern[1]", + "*/*,staging"); + repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern[2]", + "*/staging"); repoMapping.put("spring.cloud.config.server.git.repos[test1].uri", test1RepoUri); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri) .properties(repoMapping).run(); - EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context + .getBean(EnvironmentRepository.class); repository.findOne("test1-svc", "staging", "master"); - Environment environment = repository.findOne("test1-svc", "cloud,staging", "master"); + Environment environment = repository.findOne("test1-svc", "cloud,staging", + "master"); assertEquals(2, environment.getPropertySources().size()); environment = repository.findOne("test1-svc", "staging,cloud", "master"); assertEquals(2, environment.getPropertySources().size()); @@ -157,15 +177,28 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri) .properties(repoMapping).run(); - EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context + .getBean(EnvironmentRepository.class); repository.findOne("test1-svc", "staging", "master"); Environment environment = repository.findOne("test1-svc", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); } + @Test + public void nonWritableBasedir() throws IOException { + String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo"); + expected.expectCause(ThrowableMessageMatcher + .hasMessage(containsString("Cannot write parent"))); + this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) + .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri, + "spring.cloud.config.server.git.basedir:/tmp") + .run(); + } + @Configuration @EnableConfigurationProperties(ConfigServerProperties.class) - @Import({ PropertyPlaceholderAutoConfiguration.class, EnvironmentRepositoryConfiguration.class }) + @Import({ PropertyPlaceholderAutoConfiguration.class, + EnvironmentRepositoryConfiguration.class }) protected static class TestConfiguration { } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java index 5a38a50c..9fd7d902 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java @@ -15,22 +15,25 @@ */ package org.springframework.cloud.config.server.environment; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - +import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.junit.Before; import org.junit.Test; + import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.core.env.StandardEnvironment; +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + /** * @author Andy Chan (iceycake) * @author Dave Syer @@ -40,7 +43,8 @@ import org.springframework.core.env.StandardEnvironment; public class MultipleJGitEnvironmentRepositoryTests { private StandardEnvironment environment = new StandardEnvironment(); - private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(this.environment); + private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository( + this.environment); @Before public void init() throws Exception { @@ -49,7 +53,8 @@ public class MultipleJGitEnvironmentRepositoryTests { this.repository.setRepos(createRepositories()); } - private Map createRepositories() throws Exception { + private Map createRepositories() + throws Exception { String test1Uri = ConfigServerTestUtils.prepareLocalRepo("test1-config-repo"); Map repos = new HashMap<>(); @@ -57,12 +62,14 @@ public class MultipleJGitEnvironmentRepositoryTests { return repos; } - private PatternMatchingJGitEnvironmentRepository createRepository(String name, String pattern, String uri) { + private PatternMatchingJGitEnvironmentRepository createRepository(String name, + String pattern, String uri) { PatternMatchingJGitEnvironmentRepository repo = new PatternMatchingJGitEnvironmentRepository(); repo.setEnvironment(this.environment); repo.setName(name); - repo.setPattern(new String[] {pattern}); + repo.setPattern(new String[] { pattern }); repo.setUri(uri); + repo.setBasedir(new File(this.repository.getBasedir().getParentFile(), name)); return repo; } @@ -78,14 +85,15 @@ public class MultipleJGitEnvironmentRepositoryTests { private void assertVersion(Environment environment) { String version = environment.getVersion(); assertNotNull("version was null", version); - assertTrue("version length was wrong", version.length() >= 40 && version.length() <= 64); + assertTrue("version length was wrong", + version.length() >= 40 && version.length() <= 64); } @Test public void defaultRepoNested() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo"); this.repository.setUri(uri); - this.repository.setSearchPaths(new String[] {"sub"}); + this.repository.setSearchPaths(new String[] { "sub" }); this.repository.findOne("bar", "staging", "master"); Environment environment = this.repository.findOne("bar", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); @@ -107,13 +115,13 @@ public class MultipleJGitEnvironmentRepositoryTests { public void defaultRepoTag() { Environment environment = this.repository.findOne("bar", "staging", "foo"); assertEquals(2, environment.getPropertySources().size()); - assertEquals(this.repository.getUri() + "/bar.properties", environment - .getPropertySources().get(0).getName()); + assertEquals(this.repository.getUri() + "/bar.properties", + environment.getPropertySources().get(0).getName()); assertVersion(environment); } @Test - public void defaultRepoBasedir() { + public void defaultRepoTwice() { this.repository.findOne("bar", "staging", "master"); Environment environment = this.repository.findOne("bar", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); @@ -122,9 +130,18 @@ public class MultipleJGitEnvironmentRepositoryTests { assertVersion(environment); } + @Test + public void defaultRepoBasedir() { + repository.setBasedir(new File("target/testBase")); + assertThat(repository.getBasedir().toString(), containsString("target/testBase")); + assertThat(repository.getRepos().get("test1").getBasedir().toString(), + containsString("tmp/test1")); + } + @Test public void mappingRepo() { - Environment environment = this.repository.findOne("test1-svc", "staging", "master"); + Environment environment = this.repository.findOne("test1-svc", "staging", + "master"); assertEquals(2, environment.getPropertySources().size()); assertEquals(getUri("*test1*") + "/test1-svc.properties", environment.getPropertySources().get(0).getName()); @@ -152,15 +169,15 @@ public class MultipleJGitEnvironmentRepositoryTests { assertVersion(environment); } - private String getUri(String pattern) { String uri = null; - Map repoMappings = this.repository.getRepos(); + Map repoMappings = this.repository + .getRepos(); for (PatternMatchingJGitEnvironmentRepository repo : repoMappings.values()) { String[] mappingPattern = repo.getPattern(); - if (mappingPattern != null && mappingPattern.length!=0) { + if (mappingPattern != null && mappingPattern.length != 0) { uri = repo.getUri(); break; } From e69354269336784ff0d05ce35d26e3772f59d8d0 Mon Sep 17 00:00:00 2001 From: Roman Terentiev Date: Mon, 8 May 2017 17:15:59 +0300 Subject: [PATCH 06/26] Add ability to set JGit TransportConfigCallback --- .../EnvironmentRepositoryConfiguration.java | 5 ++ .../JGitEnvironmentRepository.java | 54 ++++++++++++------- .../MultipleJGitEnvironmentRepository.java | 3 ++ ...EnvironmentRepositoryIntegrationTests.java | 28 ++++++++++ .../JGitEnvironmentRepositoryTests.java | 26 +++++++++ ...ultipleJGitEnvironmentRepositoryTests.java | 24 +++++++++ 6 files changed, 122 insertions(+), 18 deletions(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java index 6714c352..d982064a 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java @@ -17,6 +17,7 @@ package org.springframework.cloud.config.server.config; import javax.servlet.http.HttpServletRequest; +import org.eclipse.jgit.api.TransportConfigCallback; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -57,9 +58,13 @@ public class EnvironmentRepositoryConfiguration { @Autowired private ConfigServerProperties server; + @Autowired(required = false) + private TransportConfigCallback transportConfigCallback; + @Bean public MultipleJGitEnvironmentRepository defaultEnvironmentRepository() { MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(this.environment); + repository.setTransportConfigCallback(this.transportConfigCallback); if (this.server.getDefaultLabel()!=null) { repository.setDefaultLabel(this.server.getDefaultLabel()); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java index 45b460b2..50db97f3 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java @@ -36,6 +36,7 @@ import org.eclipse.jgit.api.ResetCommand.ResetType; import org.eclipse.jgit.api.Status; import org.eclipse.jgit.api.StatusCommand; import org.eclipse.jgit.api.TransportCommand; +import org.eclipse.jgit.api.TransportConfigCallback; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.RefNotFoundException; import org.eclipse.jgit.lib.Ref; @@ -96,6 +97,11 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository */ private CredentialsProvider gitCredentialsProvider; + /** + * Transport configuration callback for JGit commands. + */ + private TransportConfigCallback transportConfigCallback; + /** * Flag to indicate that the repository should force pull. If true discard any local * changes and take from remote repository. @@ -122,6 +128,14 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository this.timeout = timeout; } + public TransportConfigCallback getTransportConfigCallback() { + return transportConfigCallback; + } + + public void setTransportConfigCallback(TransportConfigCallback transportConfigCallback) { + this.transportConfigCallback = transportConfigCallback; + } + public JGitFactory getGitFactory() { return this.gitFactory; } @@ -250,7 +264,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository } - public /*public for testing*/ boolean shouldPull(Git git) throws GitAPIException { + protected boolean shouldPull(Git git) throws GitAPIException { boolean shouldPull; Status gitStatus = git.status().call(); boolean isWorkingTreeClean = gitStatus.isClean(); @@ -292,14 +306,13 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository return isBranch(git, label) && !isLocalBranch(git, label); } - private FetchResult fetch(Git git, String label) { + protected FetchResult fetch(Git git, String label) { FetchCommand fetch = git.fetch(); fetch.setRemote("origin"); fetch.setTagOpt(TagOpt.FETCH_TAGS); - setTimeout(fetch); + configureCommand(fetch); try { - setCredentialsProvider(fetch); FetchResult result = fetch.call(); if(result.getTrackingRefUpdates() != null && result.getTrackingRefUpdates().size() > 0) { logger.info("Fetched for remote " + label + " and found " + result.getTrackingRefUpdates().size() @@ -396,8 +409,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository private Git cloneToBasedir() throws GitAPIException { CloneCommand clone = this.gitFactory.getCloneCommandByCloneRepository() .setURI(getUri()).setDirectory(getBasedir()); - setTimeout(clone); - setCredentialsProvider(clone); + configureCommand(clone); try { return clone.call(); } @@ -430,20 +442,26 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository } } - private void setCredentialsProvider(TransportCommand cmd) { - if (gitCredentialsProvider != null) { - cmd.setCredentialsProvider(gitCredentialsProvider); - } else if (hasText(getUsername())) { - cmd.setCredentialsProvider( - new UsernamePasswordCredentialsProvider(getUsername(), getPassword())); - } else if (hasText(getPassphrase())) { - cmd.setCredentialsProvider( - new PassphraseCredentialsProvider(getPassphrase())); - } + private void configureCommand(TransportCommand command) { + command.setTimeout(this.timeout); + command.setTransportConfigCallback(this.transportConfigCallback); + command.setCredentialsProvider(getCredentialsProvider()); } - private void setTimeout(TransportCommand pull) { - pull.setTimeout(this.timeout); + private CredentialsProvider getCredentialsProvider() { + if (this.gitCredentialsProvider != null) { + return this.gitCredentialsProvider; + } + + if (hasText(getUsername()) && hasText(getPassword())) { + return new UsernamePasswordCredentialsProvider(getUsername(), getPassword()); + } + + if (hasText(getPassphrase())) { + return new PassphraseCredentialsProvider(getPassphrase()); + } + + return null; } private boolean isClean(Git git) { diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepository.java index da55aec1..15fb3111 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepository.java @@ -75,6 +75,9 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository if (repo.getPattern() == null || repo.getPattern().length == 0) { repo.setPattern(new String[] { name }); } + if (repo.getTransportConfigCallback() == null) { + repo.setTransportConfigCallback(getTransportConfigCallback()); + } if (getTimeout() != 0 && repo.getTimeout() == 0) { repo.setTimeout(getTimeout()); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java index 09d9dcf3..6f3d2653 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java @@ -30,6 +30,7 @@ import java.util.Arrays; import org.eclipse.jgit.api.CheckoutCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.ResetCommand.ResetType; +import org.eclipse.jgit.api.TransportConfigCallback; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; @@ -39,6 +40,7 @@ import org.hamcrest.Matchers; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -47,6 +49,7 @@ import org.springframework.cloud.config.server.config.ConfigServerProperties; import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.util.ResourceUtils; @@ -56,6 +59,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -504,6 +508,18 @@ public class JGitEnvironmentRepositoryIntegrationTests { assertEquals(repository.isStrictHostKeyChecking(), strictHostKeyChecking); } + @Test + public void shouldSetTransportConfigCallback() throws IOException { + String uri = ConfigServerTestUtils.prepareLocalRepo(); + this.context = new SpringApplicationBuilder(TestConfigurationWithTransportConfigCallback.class) + .web(false) + .properties("spring.cloud.config.server.git.uri:" + uri) + .run(); + + JGitEnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class); + assertNotNull(repository.getTransportConfigCallback()); + } + @Configuration @EnableConfigurationProperties(ConfigServerProperties.class) @Import({ PropertyPlaceholderAutoConfiguration.class, @@ -511,4 +527,16 @@ public class JGitEnvironmentRepositoryIntegrationTests { protected static class TestConfiguration { } + @Configuration + @EnableConfigurationProperties(ConfigServerProperties.class) + @Import({ PropertyPlaceholderAutoConfiguration.class, + EnvironmentRepositoryConfiguration.class }) + protected static class TestConfigurationWithTransportConfigCallback { + + @Bean + public TransportConfigCallback transportConfigCallback() { + return Mockito.mock(TransportConfigCallback.class); + } + } + } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java index 6e6e6914..f8b430cd 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java @@ -33,6 +33,7 @@ import org.eclipse.jgit.api.MergeCommand; import org.eclipse.jgit.api.ResetCommand; import org.eclipse.jgit.api.Status; import org.eclipse.jgit.api.StatusCommand; +import org.eclipse.jgit.api.TransportConfigCallback; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.NotMergedException; @@ -727,6 +728,31 @@ public class JGitEnvironmentRepositoryTests { assertEquals("should call isDebugEnabled warn and debug", 3, numberOfInvocations); } + @Test + public void shouldSetTransportConfigCallbackOnCloneAndFetch() throws Exception { + Git mockGit = mock(Git.class); + FetchCommand fetchCommand = mock(FetchCommand.class); + when(mockGit.fetch()).thenReturn(fetchCommand); + when(fetchCommand.call()).thenReturn(mock(FetchResult.class)); + + CloneCommand mockCloneCommand = mock(CloneCommand.class); + when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand); + when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand); + + TransportConfigCallback configCallback = mock(TransportConfigCallback.class); + JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment); + envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand)); + envRepository.setUri("http://somegitserver/somegitrepo"); + envRepository.setTransportConfigCallback(configCallback); + envRepository.setCloneOnStart(true); + + envRepository.afterPropertiesSet(); + verify(mockCloneCommand, times(1)).setTransportConfigCallback(configCallback); + + envRepository.fetch(mockGit, "master"); + verify(fetchCommand, times(1)).setTransportConfigCallback(configCallback); + } + class MockCloneCommand extends CloneCommand { private Git mockGit; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java index 9fd7d902..002fc235 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import org.eclipse.jgit.api.TransportConfigCallback; import org.junit.Before; import org.junit.Test; @@ -33,6 +34,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; /** * @author Andy Chan (iceycake) @@ -169,6 +171,28 @@ public class MultipleJGitEnvironmentRepositoryTests { assertVersion(environment); } + @Test + public void shouldSetTransportConfigCallback() throws Exception { + TransportConfigCallback mockCallback1 = mock(TransportConfigCallback.class); + TransportConfigCallback mockCallback2 = mock(TransportConfigCallback.class); + + PatternMatchingJGitEnvironmentRepository repo1 = createRepository("test1", "*test1*", "test1Uri"); + + PatternMatchingJGitEnvironmentRepository repo2 = createRepository("test2", "*test2*", "test2Uri"); + repo2.setTransportConfigCallback(mockCallback2); + + Map repos = new HashMap<>(); + repos.put("test1", repo1); + repos.put("test2", repo2); + + this.repository.setRepos(repos); + this.repository.setTransportConfigCallback(mockCallback1); + this.repository.afterPropertiesSet(); + + assertEquals(repo1.getTransportConfigCallback(), mockCallback1); + assertEquals(repo2.getTransportConfigCallback(), mockCallback2); + } + private String getUri(String pattern) { String uri = null; From 7ee15a4f2a3b13353e264c4ba04bbb2087ce489a Mon Sep 17 00:00:00 2001 From: Roman Terentiev Date: Tue, 16 May 2017 12:27:57 +0300 Subject: [PATCH 07/26] Add null checks --- .../server/environment/JGitEnvironmentRepository.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java index 50db97f3..1da9c00a 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java @@ -444,8 +444,13 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository private void configureCommand(TransportCommand command) { command.setTimeout(this.timeout); - command.setTransportConfigCallback(this.transportConfigCallback); - command.setCredentialsProvider(getCredentialsProvider()); + if (this.transportConfigCallback != null) { + command.setTransportConfigCallback(this.transportConfigCallback); + } + CredentialsProvider credentialsProvider = getCredentialsProvider(); + if (credentialsProvider != null) { + command.setCredentialsProvider(credentialsProvider); + } } private CredentialsProvider getCredentialsProvider() { From 0d4a48444bebc8b5d327b6b41990fc6c8402750b Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Thu, 18 May 2017 15:02:44 -0600 Subject: [PATCH 08/26] Try and create the basedir if it doesn't exists. fixes gh-700 --- .../MultipleJGitEnvironmentRepository.java | 5 ++ ...ultipleJGitEnvironmentRepositoryTests.java | 52 +++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepository.java index da55aec1..7b78b060 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepository.java @@ -92,6 +92,11 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository credentialFactory.createFor(repo.getUri(), user, pass, passphrase)); repo.afterPropertiesSet(); } + if (!getBasedir().exists() && + !getBasedir().mkdirs()) { + throw new IllegalStateException( + "Basedir does not exist and can not be created: " + getBasedir()); + } if (!getBasedir().getParentFile().canWrite()) { throw new IllegalStateException( "Cannot write parent of basedir (please configure a writable location): " diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java index 9fd7d902..29d431fa 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java @@ -17,22 +17,31 @@ package org.springframework.cloud.config.server.environment; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashMap; import java.util.Map; +import org.assertj.core.api.Assertions; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mockito; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.core.env.StandardEnvironment; +import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * @author Andy Chan (iceycake) @@ -42,13 +51,17 @@ import static org.junit.Assert.assertTrue; */ public class MultipleJGitEnvironmentRepositoryTests { + @Rule + public ExpectedException exception = ExpectedException.none(); + private StandardEnvironment environment = new StandardEnvironment(); - private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository( - this.environment); + private MultipleJGitEnvironmentRepository repository; + @Before public void init() throws Exception { String defaultUri = ConfigServerTestUtils.prepareLocalRepo("config-repo"); + this.repository = new MultipleJGitEnvironmentRepository(this.environment); this.repository.setUri(defaultUri); this.repository.setRepos(createRepositories()); } @@ -135,7 +148,7 @@ public class MultipleJGitEnvironmentRepositoryTests { repository.setBasedir(new File("target/testBase")); assertThat(repository.getBasedir().toString(), containsString("target/testBase")); assertThat(repository.getRepos().get("test1").getBasedir().toString(), - containsString("tmp/test1")); + containsString("/test1")); } @Test @@ -169,6 +182,39 @@ public class MultipleJGitEnvironmentRepositoryTests { assertVersion(environment); } + @Test + // test for gh-700 + public void basedirCreatedIfNotExists() throws Exception { + Path tempDir = Files.createTempDirectory("basedirCreatedTest"); + File parent = new File(tempDir.toFile(), "parent"); + File basedir = new File(parent, "basedir"); + this.repository.setBasedir(basedir); + + assertThat(basedir).doesNotExist(); + + this.repository.afterPropertiesSet(); + + assertThat(basedir).exists(); + } + + @Test + // test for gh-700 + public void exceptionThrownIfBasedirDoesnotExistAndCannotBeCreated() throws Exception { + File basedir = mock(File.class); + File absoluteBasedir = mock(File.class); + when(basedir.getAbsoluteFile()).thenReturn(absoluteBasedir); + + when(absoluteBasedir.exists()).thenReturn(false); + when(absoluteBasedir.mkdir()).thenReturn(false); + + this.repository.setBasedir(basedir); + + this.exception.expect(IllegalStateException.class); + this.exception.expectMessage("Basedir does not exist and can not be created:"); + + this.repository.afterPropertiesSet(); + } + private String getUri(String pattern) { String uri = null; From d9113a417dccff271744be3a4039e270b0cebd76 Mon Sep 17 00:00:00 2001 From: Venil Noronha Date: Fri, 19 May 2017 15:13:02 -0700 Subject: [PATCH 09/26] Adds addLabelLocations option to ConfigServerProperties (#681) Adds addLabelLocations option to server properties. Also eliminates any duplicate locations. Fixes gh-676 --- .../main/asciidoc/spring-cloud-config.adoc | 5 +-- .../NativeEnvironmentRepository.java | 32 +++++++++++++++---- .../NativeEnvironmentRepositoryTests.java | 29 +++++++++++++++-- .../test/dev/ignore/application.properties | 1 + 4 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 spring-cloud-config-server/src/test/resources/test/dev/ignore/application.properties diff --git a/docs/src/main/asciidoc/spring-cloud-config.adoc b/docs/src/main/asciidoc/spring-cloud-config.adoc index d2bd9dd7..57673154 100644 --- a/docs/src/main/asciidoc/spring-cloud-config.adoc +++ b/docs/src/main/asciidoc/spring-cloud-config.adoc @@ -479,8 +479,9 @@ on the search path, so properties files are loaded from each search location *and* a subdirectory with the same name as the label (the labelled properties take precedence in the Spring Environment). Thus the default behaviour with no placeholders is the same as adding a -search location ending with `/{label}/. For example `file:/tmp/config` -is the same as `file:/tmp/config,file:/tmp/config/{label}` +search location ending with `/{label}/`. For example `file:/tmp/config` +is the same as `file:/tmp/config,file:/tmp/config/{label}`. This behavior can be +disabled by setting `spring.cloud.config.server.native.addLabelLocations=false`. ==== Vault Backend diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java index cf435669..c316b636 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,9 @@ package org.springframework.cloud.config.server.environment; import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; import org.apache.commons.logging.Log; @@ -46,6 +48,7 @@ import org.springframework.util.StringUtils; * * @author Dave Syer * @author Roy Clarkson + * @author Venil Noronha */ @ConfigurationProperties("spring.cloud.config.server.native") public class NativeEnvironmentRepository implements EnvironmentRepository, SearchPathLocator, Ordered { @@ -65,6 +68,11 @@ public class NativeEnvironmentRepository implements EnvironmentRepository, Searc */ private boolean failOnError = false; + /** + * Flag to determine whether label locations should be added. + */ + private boolean addLabelLocations = true; + /** * Version string to be reported for native repository */ @@ -89,6 +97,14 @@ public class NativeEnvironmentRepository implements EnvironmentRepository, Searc return this.failOnError; } + public void setAddLabelLocations(boolean addLabelLocations) { + this.addLabelLocations = addLabelLocations; + } + + public boolean isAddLabelLocations() { + return this.addLabelLocations; + } + public String getDefaultLabel() { return DEFAULT_LABEL; } @@ -126,7 +142,7 @@ public class NativeEnvironmentRepository implements EnvironmentRepository, Searc if (this.searchLocations == null || this.searchLocations.length == 0) { locations = DEFAULT_LOCATIONS; } - List output = new ArrayList(); + Collection output = new LinkedHashSet(); for (String location : locations) { String[] profiles = new String[] { profile }; if (profile != null) { @@ -157,11 +173,13 @@ public class NativeEnvironmentRepository implements EnvironmentRepository, Searc } } } - for (String location : locations) { - if (StringUtils.hasText(label)) { - String labelled = location + label.trim() + "/"; - if (isDirectory(labelled)) { - output.add(labelled); + if (this.addLabelLocations) { + for (String location : locations) { + if (StringUtils.hasText(label)) { + String labelled = location + label.trim() + "/"; + if (isDirectory(labelled)) { + output.add(labelled); + } } } } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java index f43a5eec..354ccfb0 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.cloud.config.server.environment; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import org.junit.Before; import org.junit.Test; @@ -27,7 +28,7 @@ import org.springframework.context.ConfigurableApplicationContext; /** * @author Dave Syer * @author Spencer Gibb - * + * @author Venil Noronha */ public class NativeEnvironmentRepositoryTests { @@ -163,4 +164,28 @@ public class NativeEnvironmentRepositoryTests { environment.getPropertySources().get(0).getSource().get("foo")); } + @Test + public void locationAddLabelLocations() { + this.repository.setSearchLocations("classpath:/test/dev/"); + Environment environment = this.repository.findOne("foo", "development", "ignore"); + assertEquals(2, environment.getPropertySources().size()); + assertNotEquals("dev_bar", environment.getPropertySources().get(0).getSource().get("foo")); + } + + @Test + public void locationDontAddLabelLocations() { + this.repository.setSearchLocations("classpath:/test/dev/"); + this.repository.setAddLabelLocations(false); + Environment environment = this.repository.findOne("foo", "development", "ignore"); + assertEquals(1, environment.getPropertySources().size()); + assertEquals("dev_bar", environment.getPropertySources().get(0).getSource().get("foo")); + } + + @Test + public void locationNoDuplicates() { + this.repository.setSearchLocations("classpath:/test/{profile}", "classpath:/test/dev"); + Locations locations = this.repository.getLocations("foo", "dev", null); + assertEquals(1, locations.getLocations().length); + } + } diff --git a/spring-cloud-config-server/src/test/resources/test/dev/ignore/application.properties b/spring-cloud-config-server/src/test/resources/test/dev/ignore/application.properties new file mode 100644 index 00000000..e9e0aaf5 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/test/dev/ignore/application.properties @@ -0,0 +1 @@ +foo: app \ No newline at end of file From 566cb39428588e88b1052e3e504cbb245d475bfe Mon Sep 17 00:00:00 2001 From: "Hanson, Tristan" Date: Tue, 23 May 2017 14:04:26 -0500 Subject: [PATCH 10/26] Updating auto configuration to allow for overriding the `ConfigServicePropertySourceLocator` bean Allow override of `ConfigServicePropertySourceLocator` bean to support the setting of a custom `RestTemplate` instance without the need to set `spring.cloud.config.enabled=false` Fixes gh-699 Fixes gh-613 --- .../main/asciidoc/spring-cloud-config.adoc | 16 +--- .../ConfigServiceBootstrapConfiguration.java | 4 +- ...nfigServiceBootstrapConfigurationTest.java | 87 +++++++++++++++++++ 3 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfigurationTest.java diff --git a/docs/src/main/asciidoc/spring-cloud-config.adoc b/docs/src/main/asciidoc/spring-cloud-config.adoc index 57673154..2f3ef071 100644 --- a/docs/src/main/asciidoc/spring-cloud-config.adoc +++ b/docs/src/main/asciidoc/spring-cloud-config.adoc @@ -1309,23 +1309,13 @@ the client. Typically this involves passing special `Authorization` headers to authenticate requests to the server. To provide a custom `RestTemplate` follow the steps below. -1. Set `spring.cloud.config.enabled=false` to disable the existing config server -property source. - -2. Create a new configuration bean with an implementation of `PropertySourceLocator`. +1. Create a new configuration bean with an implementation of `PropertySourceLocator`. .CustomConfigServiceBootstrapConfiguration.java [source,java] ---- @Configuration public class CustomConfigServiceBootstrapConfiguration { - @Bean - public ConfigClientProperties configClientProperties() { - ConfigClientProperties client = new ConfigClientProperties(this.environment); - client.setEnabled(false); - return client; - } - @Bean public ConfigServicePropertySourceLocator configServicePropertySourceLocator() { ConfigClientProperties clientProperties = configClientProperties(); @@ -1336,10 +1326,10 @@ public class CustomConfigServiceBootstrapConfiguration { } ---- -3. In `resources/META-INF` create a file called +2. In `resources/META-INF` create a file called `spring.factories` and specify your custom configuration. -.spring.factorties +.spring.factories [source,properties] ---- org.springframework.cloud.bootstrap.BootstrapConfiguration = com.my.config.client.CustomConfigServiceBootstrapConfiguration diff --git a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfiguration.java b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfiguration.java index 909d4070..7b60a21c 100644 --- a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfiguration.java +++ b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ import org.springframework.retry.interceptor.RetryOperationsInterceptor; /** * @author Dave Syer + * @author Tristan Hanson * */ @Configuration @@ -50,6 +51,7 @@ public class ConfigServiceBootstrapConfiguration { } @Bean + @ConditionalOnMissingBean(ConfigServicePropertySourceLocator.class) @ConditionalOnProperty(value = "spring.cloud.config.enabled", matchIfMissing = true) public ConfigServicePropertySourceLocator configServicePropertySource(ConfigClientProperties properties) { ConfigServicePropertySourceLocator locator = new ConfigServicePropertySourceLocator( diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfigurationTest.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfigurationTest.java new file mode 100644 index 00000000..fa9edb7b --- /dev/null +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfigurationTest.java @@ -0,0 +1,87 @@ +/* + * Copyright 2013-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.config.client; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.util.ReflectionUtils; +import org.springframework.web.client.RestTemplate; + +import java.lang.reflect.Field; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Tristan Hanson + * + */ +public class ConfigServiceBootstrapConfigurationTest { + + private AnnotationConfigApplicationContext context; + + @Before + public void setUp() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + } + + @After + public void tearDown() throws Exception { + if (this.context != null) { + this.context.close(); + } + } + + @Test + public void overrideConfigServicePropertySourceLocatorWhenBeanIsProvided() { + EnvironmentTestUtils.addEnvironment(this.context, "spring.cloud.config.enabled=true"); + this.context.register(ConfigServicePropertySourceLocatorOverrideConfig.class); + this.context.register(ConfigServiceBootstrapConfiguration.class); + this.context.refresh(); + + ConfigServicePropertySourceLocator locator = this.context.getBean(ConfigServicePropertySourceLocator.class); + + Field restTemplateField = ReflectionUtils.findField(ConfigServicePropertySourceLocator.class, "restTemplate"); + restTemplateField.setAccessible(true); + + RestTemplate restTemplate = (RestTemplate) ReflectionUtils.getField(restTemplateField, locator); + + assertThat(restTemplate).isNotNull(); + } + + @Configuration + protected static class ConfigServicePropertySourceLocatorOverrideConfig { + + @Autowired + private Environment environment; + + @Bean + public ConfigServicePropertySourceLocator locator() { + ConfigServicePropertySourceLocator locator = new ConfigServicePropertySourceLocator(new ConfigClientProperties(environment)); + locator.setRestTemplate(new RestTemplate()); + return locator; + } + + } + +} \ No newline at end of file From 63e6a0ebd3335e46ac4c8e5fd6de1d9f652ebd0f Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Fri, 19 May 2017 16:34:26 -0600 Subject: [PATCH 11/26] Update SNAPSHOT to 1.3.1.RELEASE --- docs/pom.xml | 2 +- mvnw.cmd | 286 +++++++++++------------ pom.xml | 4 +- spring-cloud-config-client/pom.xml | 2 +- spring-cloud-config-dependencies/pom.xml | 2 +- spring-cloud-config-monitor/pom.xml | 4 +- spring-cloud-config-sample/pom.xml | 2 +- spring-cloud-config-server/pom.xml | 2 +- spring-cloud-starter-config/pom.xml | 4 +- 9 files changed, 154 insertions(+), 154 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index b051940b..2f1c595f 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.1.RELEASE pom Spring Cloud Config Docs diff --git a/mvnw.cmd b/mvnw.cmd index fc830243..b0dc0e7e 100644 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -1,145 +1,145 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -set MAVEN_CMD_LINE_ARGS=%* - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +set MAVEN_CMD_LINE_ARGS=%* + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar"" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index 9a7c4809..7d139fca 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.1.RELEASE pom Spring Cloud Config Spring Cloud Config @@ -22,7 +22,7 @@ config - 1.2.1.BUILD-SNAPSHOT + 1.2.2.RELEASE spring-cloud-config-dependencies diff --git a/spring-cloud-config-client/pom.xml b/spring-cloud-config-client/pom.xml index 8ce3bbe6..d849b7a2 100644 --- a/spring-cloud-config-client/pom.xml +++ b/spring-cloud-config-client/pom.xml @@ -10,7 +10,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.1.RELEASE .. diff --git a/spring-cloud-config-dependencies/pom.xml b/spring-cloud-config-dependencies/pom.xml index a3de5ffd..2a43b4c9 100644 --- a/spring-cloud-config-dependencies/pom.xml +++ b/spring-cloud-config-dependencies/pom.xml @@ -9,7 +9,7 @@ spring-cloud-config-dependencies - 1.3.1.BUILD-SNAPSHOT + 1.3.1.RELEASE pom spring-cloud-config-dependencies Spring Cloud Config Dependencies diff --git a/spring-cloud-config-monitor/pom.xml b/spring-cloud-config-monitor/pom.xml index e1c47b6e..ceb354b6 100644 --- a/spring-cloud-config-monitor/pom.xml +++ b/spring-cloud-config-monitor/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.1.RELEASE .. spring-cloud-config-monitor @@ -13,7 +13,7 @@ Spring Cloud Config Monitor ${basedir}/../.. - 1.3.1.BUILD-SNAPSHOT + 1.3.1.RELEASE diff --git a/spring-cloud-config-sample/pom.xml b/spring-cloud-config-sample/pom.xml index 97173b2a..4d922170 100644 --- a/spring-cloud-config-sample/pom.xml +++ b/spring-cloud-config-sample/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.1.RELEASE .. diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index b9680832..4a436e98 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.1.RELEASE .. diff --git a/spring-cloud-starter-config/pom.xml b/spring-cloud-starter-config/pom.xml index b9aa7a50..8d6e3412 100644 --- a/spring-cloud-starter-config/pom.xml +++ b/spring-cloud-starter-config/pom.xml @@ -5,10 +5,10 @@ org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.1.RELEASE spring-cloud-starter-config - 1.3.1.BUILD-SNAPSHOT + 1.3.1.RELEASE spring-cloud-starter-config Spring Cloud Starter https://projects.spring.io/spring-cloud From 446a65f4e18fdd75941c79f2167bdb7392e98229 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Fri, 19 May 2017 16:36:27 -0600 Subject: [PATCH 12/26] Going back to snapshots --- docs/pom.xml | 2 +- mvnw.cmd | 286 +++++++++++------------ pom.xml | 4 +- spring-cloud-config-client/pom.xml | 2 +- spring-cloud-config-dependencies/pom.xml | 2 +- spring-cloud-config-monitor/pom.xml | 4 +- spring-cloud-config-sample/pom.xml | 2 +- spring-cloud-config-server/pom.xml | 2 +- spring-cloud-starter-config/pom.xml | 4 +- 9 files changed, 154 insertions(+), 154 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 2f1c595f..b051940b 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.RELEASE + 1.3.1.BUILD-SNAPSHOT pom Spring Cloud Config Docs diff --git a/mvnw.cmd b/mvnw.cmd index b0dc0e7e..fc830243 100644 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -1,145 +1,145 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -set MAVEN_CMD_LINE_ARGS=%* - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +set MAVEN_CMD_LINE_ARGS=%* + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar"" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index 7d139fca..9a7c4809 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.cloud spring-cloud-config - 1.3.1.RELEASE + 1.3.1.BUILD-SNAPSHOT pom Spring Cloud Config Spring Cloud Config @@ -22,7 +22,7 @@ config - 1.2.2.RELEASE + 1.2.1.BUILD-SNAPSHOT spring-cloud-config-dependencies diff --git a/spring-cloud-config-client/pom.xml b/spring-cloud-config-client/pom.xml index d849b7a2..8ce3bbe6 100644 --- a/spring-cloud-config-client/pom.xml +++ b/spring-cloud-config-client/pom.xml @@ -10,7 +10,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.RELEASE + 1.3.1.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-dependencies/pom.xml b/spring-cloud-config-dependencies/pom.xml index 2a43b4c9..a3de5ffd 100644 --- a/spring-cloud-config-dependencies/pom.xml +++ b/spring-cloud-config-dependencies/pom.xml @@ -9,7 +9,7 @@ spring-cloud-config-dependencies - 1.3.1.RELEASE + 1.3.1.BUILD-SNAPSHOT pom spring-cloud-config-dependencies Spring Cloud Config Dependencies diff --git a/spring-cloud-config-monitor/pom.xml b/spring-cloud-config-monitor/pom.xml index ceb354b6..e1c47b6e 100644 --- a/spring-cloud-config-monitor/pom.xml +++ b/spring-cloud-config-monitor/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.RELEASE + 1.3.1.BUILD-SNAPSHOT .. spring-cloud-config-monitor @@ -13,7 +13,7 @@ Spring Cloud Config Monitor ${basedir}/../.. - 1.3.1.RELEASE + 1.3.1.BUILD-SNAPSHOT diff --git a/spring-cloud-config-sample/pom.xml b/spring-cloud-config-sample/pom.xml index 4d922170..97173b2a 100644 --- a/spring-cloud-config-sample/pom.xml +++ b/spring-cloud-config-sample/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.RELEASE + 1.3.1.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index 4a436e98..b9680832 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.RELEASE + 1.3.1.BUILD-SNAPSHOT .. diff --git a/spring-cloud-starter-config/pom.xml b/spring-cloud-starter-config/pom.xml index 8d6e3412..b9aa7a50 100644 --- a/spring-cloud-starter-config/pom.xml +++ b/spring-cloud-starter-config/pom.xml @@ -5,10 +5,10 @@ org.springframework.cloud spring-cloud-config - 1.3.1.RELEASE + 1.3.1.BUILD-SNAPSHOT spring-cloud-starter-config - 1.3.1.RELEASE + 1.3.1.BUILD-SNAPSHOT spring-cloud-starter-config Spring Cloud Starter https://projects.spring.io/spring-cloud From 8ca749ff4bde8d9a0f405b85f1cdfa5cf92498e0 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Fri, 19 May 2017 16:36:27 -0600 Subject: [PATCH 13/26] Bumping versions to 1.3.2.BUILD-SNAPSHOT after release --- docs/pom.xml | 2 +- mvnw.cmd | 286 +++++++++++------------ pom.xml | 2 +- spring-cloud-config-client/pom.xml | 2 +- spring-cloud-config-dependencies/pom.xml | 2 +- spring-cloud-config-monitor/pom.xml | 2 +- spring-cloud-config-sample/pom.xml | 2 +- spring-cloud-config-server/pom.xml | 2 +- spring-cloud-starter-config/pom.xml | 4 +- 9 files changed, 152 insertions(+), 152 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index b051940b..38eabee8 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.2.BUILD-SNAPSHOT pom Spring Cloud Config Docs diff --git a/mvnw.cmd b/mvnw.cmd index fc830243..b0dc0e7e 100644 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -1,145 +1,145 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -set MAVEN_CMD_LINE_ARGS=%* - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +set MAVEN_CMD_LINE_ARGS=%* + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar"" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index 9a7c4809..bbdbc97a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.2.BUILD-SNAPSHOT pom Spring Cloud Config Spring Cloud Config diff --git a/spring-cloud-config-client/pom.xml b/spring-cloud-config-client/pom.xml index 8ce3bbe6..7151af7a 100644 --- a/spring-cloud-config-client/pom.xml +++ b/spring-cloud-config-client/pom.xml @@ -10,7 +10,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.2.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-dependencies/pom.xml b/spring-cloud-config-dependencies/pom.xml index a3de5ffd..812bba71 100644 --- a/spring-cloud-config-dependencies/pom.xml +++ b/spring-cloud-config-dependencies/pom.xml @@ -9,7 +9,7 @@ spring-cloud-config-dependencies - 1.3.1.BUILD-SNAPSHOT + 1.3.2.BUILD-SNAPSHOT pom spring-cloud-config-dependencies Spring Cloud Config Dependencies diff --git a/spring-cloud-config-monitor/pom.xml b/spring-cloud-config-monitor/pom.xml index e1c47b6e..35a06878 100644 --- a/spring-cloud-config-monitor/pom.xml +++ b/spring-cloud-config-monitor/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.2.BUILD-SNAPSHOT .. spring-cloud-config-monitor diff --git a/spring-cloud-config-sample/pom.xml b/spring-cloud-config-sample/pom.xml index 97173b2a..ca14f67b 100644 --- a/spring-cloud-config-sample/pom.xml +++ b/spring-cloud-config-sample/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.2.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index b9680832..4482de8a 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.2.BUILD-SNAPSHOT .. diff --git a/spring-cloud-starter-config/pom.xml b/spring-cloud-starter-config/pom.xml index b9aa7a50..55800605 100644 --- a/spring-cloud-starter-config/pom.xml +++ b/spring-cloud-starter-config/pom.xml @@ -5,10 +5,10 @@ org.springframework.cloud spring-cloud-config - 1.3.1.BUILD-SNAPSHOT + 1.3.2.BUILD-SNAPSHOT spring-cloud-starter-config - 1.3.1.BUILD-SNAPSHOT + 1.3.2.BUILD-SNAPSHOT spring-cloud-starter-config Spring Cloud Starter https://projects.spring.io/spring-cloud From 215eb24d0b659df4ea04fb48bbac018bc0d5b9f8 Mon Sep 17 00:00:00 2001 From: tapvirvirk Date: Thu, 25 May 2017 15:03:42 -0400 Subject: [PATCH 14/26] Update AwsCodeCommitCredentialProvider.java --- .../config/server/support/AwsCodeCommitCredentialProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AwsCodeCommitCredentialProvider.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AwsCodeCommitCredentialProvider.java index 7425067e..08236135 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AwsCodeCommitCredentialProvider.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AwsCodeCommitCredentialProvider.java @@ -326,7 +326,7 @@ public class AwsCodeCommitCredentialProvider extends CredentialsProvider { } try { - URI u = new URI(uri.toLowerCase()); + URI u = new URI(URLEncoder.encode(uri.toLowerCase(),"UTF-8")); if (u.getScheme().equals("https")) { String host = u.getHost(); if (host.endsWith(".amazonaws.com") && host.startsWith("git-codecommit.")) { From cf38dedd1479e24f49c3f5b4b2eac500797eda3a Mon Sep 17 00:00:00 2001 From: tapvirvirk Date: Fri, 26 May 2017 16:43:27 -0400 Subject: [PATCH 15/26] Update AwsCodeCommitCredentialProvider.java --- .../server/support/AwsCodeCommitCredentialProvider.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AwsCodeCommitCredentialProvider.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AwsCodeCommitCredentialProvider.java index 08236135..b1cf3dd7 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AwsCodeCommitCredentialProvider.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AwsCodeCommitCredentialProvider.java @@ -19,6 +19,7 @@ package org.springframework.cloud.config.server.support; import static org.springframework.util.StringUtils.hasText; import java.net.URI; +import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.text.SimpleDateFormat; @@ -326,7 +327,8 @@ public class AwsCodeCommitCredentialProvider extends CredentialsProvider { } try { - URI u = new URI(URLEncoder.encode(uri.toLowerCase(),"UTF-8")); + URL url = new URL(uri); + URI u = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); if (u.getScheme().equals("https")) { String host = u.getHost(); if (host.endsWith(".amazonaws.com") && host.startsWith("git-codecommit.")) { From 389da6b20ffe66e3688d5aee4915c13dc48b52cb Mon Sep 17 00:00:00 2001 From: tapvirvirk Date: Fri, 26 May 2017 16:51:14 -0400 Subject: [PATCH 16/26] Update AwsCodeCommitCredentialsProviderTests.java --- ...AwsCodeCommitCredentialsProviderTests.java | 214 +++++++++--------- 1 file changed, 112 insertions(+), 102 deletions(-) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java index 634d1bfd..d62ecd06 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java @@ -44,111 +44,121 @@ import static org.junit.Assert.fail; * */ public class AwsCodeCommitCredentialsProviderTests { - private static final String PASSWORD = "secret"; - private static final String USER = "test"; - private static final String AWS_REPO = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test"; - private static final String BAD_REPO = "https://amazonaws.com/v1/repos/test"; + private static final String PASSWORD = "secret"; + private static final String USER = "test"; + private static final String AWS_REPO = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test"; + private static final String BAD_REPO = "https://amazonaws.com/v1/repos/test"; + private static final String CURLY_BRACES_REPO = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/{application}"; - private AwsCodeCommitCredentialProvider provider; - - @Before - public void init() { - GitCredentialsProviderFactory factory = new GitCredentialsProviderFactory(); - provider = (AwsCodeCommitCredentialProvider) - factory.createFor(AWS_REPO, USER, PASSWORD, null); - } - - @Test - public void basics() { - assertNotNull(provider); - assertEquals(USER, provider.getUsername()); - assertEquals(PASSWORD, provider.getPassword()); - assertFalse(provider.isInteractive()); - } + private AwsCodeCommitCredentialProvider provider; + + @Before + public void init() { + GitCredentialsProviderFactory factory = new GitCredentialsProviderFactory(); + provider = (AwsCodeCommitCredentialProvider) + factory.createFor(AWS_REPO, USER, PASSWORD, null); + } + + @Test + public void basics() { + assertNotNull(provider); + assertEquals(USER, provider.getUsername()); + assertEquals(PASSWORD, provider.getPassword()); + assertFalse(provider.isInteractive()); + } - @Test - public void testSupportsUsernamePassword() { - assertTrue(provider.supports(new CredentialItem[] { - new CredentialItem.Username(), - new CredentialItem.Password() - })); - } + @Test + public void testSupportsUsernamePassword() { + assertTrue(provider.supports(new CredentialItem[] { + new CredentialItem.Username(), + new CredentialItem.Password() + })); + } - @Test - public void testNotSupportsOther() { - assertFalse(provider.supports(new CredentialItem[] { - new CredentialItem.YesNoType("OK To Login?") // this is not ok - })); - assertFalse(provider.supports(new CredentialItem[] { - new CredentialItem.StringType("OK To Login?", true) // this is not ok - })); - assertFalse(provider.supports(new CredentialItem[] { - new CredentialItem.Username(), // this is ok - new CredentialItem.Password(), // this is ok - new CredentialItem.StringType("OK To Login?", true) // this is not ok - })); - } - - @Test - public void testAwsCredentialsProviderIsNullInitially() { - AWSCredentialsProvider awsProvider = provider.getAwsCredentialProvider(); - assertNull(awsProvider); - } + @Test + public void testNotSupportsOther() { + assertFalse(provider.supports(new CredentialItem[] { + new CredentialItem.YesNoType("OK To Login?") // this is not ok + })); + assertFalse(provider.supports(new CredentialItem[] { + new CredentialItem.StringType("OK To Login?", true) // this is not ok + })); + assertFalse(provider.supports(new CredentialItem[] { + new CredentialItem.Username(), // this is ok + new CredentialItem.Password(), // this is ok + new CredentialItem.StringType("OK To Login?", true) // this is not ok + })); + } + + @Test + public void testAwsCredentialsProviderIsNullInitially() { + AWSCredentialsProvider awsProvider = provider.getAwsCredentialProvider(); + assertNull(awsProvider); + } - @Test - public void testAwsCredentialsProviderIsDefinedAfterGet() throws URISyntaxException { - AWSCredentialsProvider awsProvider = provider.getAwsCredentialProvider(); - assertNull(awsProvider); - assertTrue(provider.get(new URIish(AWS_REPO), makeCredentialItems())); - awsProvider = provider.getAwsCredentialProvider(); - assertNotNull(awsProvider); - assertTrue(awsProvider instanceof AwsCodeCommitCredentialProvider.AWSStaticCredentialsProvider); - } - - @Test - public void testBadUriReturnsFalse() throws UnsupportedCredentialItem, URISyntaxException { - CredentialItem[] credentialItems = makeCredentialItems(); - assertFalse(provider.get(new URIish(BAD_REPO), credentialItems)); - } - - @Test - public void testThrowsUnsupportedCredentialException() throws URISyntaxException { - CredentialItem[] goodCredentialItems = makeCredentialItems(); - CredentialItem[] badCredentialItems = new CredentialItem[] { - goodCredentialItems[0], - goodCredentialItems[1], - new CredentialItem.YesNoType("OK?") - }; - try { - provider.get(new URIish(AWS_REPO), badCredentialItems); - fail("Expected UnsupportedCredentialItem exception"); - } catch (UnsupportedCredentialItem e) { - assertNotNull(e.getMessage()); - } - } - - @Test - public void testReturnsCredentials() throws URISyntaxException { - CredentialItem[] credentialItems = makeCredentialItems(); - assertTrue(provider.get(new URIish(AWS_REPO), credentialItems)); - - String theUsername = ((CredentialItem.Username) credentialItems[0]).getValue(); - char[] thePassword = ((CredentialItem.Password) credentialItems[1]).getValue(); - - assertEquals(USER, theUsername); - assertNotNull(thePassword); - - // The password will always begin with a timestamp like - // 20161113T121314Z - assertTrue(thePassword.length > 16); - assertEquals('T', thePassword[8]); - assertEquals('Z', thePassword[15]); - } + @Test + public void testAwsCredentialsProviderIsDefinedAfterGet() throws URISyntaxException { + AWSCredentialsProvider awsProvider = provider.getAwsCredentialProvider(); + assertNull(awsProvider); + assertTrue(provider.get(new URIish(AWS_REPO), makeCredentialItems())); + awsProvider = provider.getAwsCredentialProvider(); + assertNotNull(awsProvider); + assertTrue(awsProvider instanceof AwsCodeCommitCredentialProvider.AWSStaticCredentialsProvider); + } + + @Test + public void testBadUriReturnsFalse() throws UnsupportedCredentialItem, URISyntaxException { + CredentialItem[] credentialItems = makeCredentialItems(); + assertFalse(provider.get(new URIish(BAD_REPO), credentialItems)); + } + + @Test + public void testUriWithCurlyBracesReturnsTrue() throws UnsupportedCredentialItem, URISyntaxException { + GitCredentialsProviderFactory factory = new GitCredentialsProviderFactory(); + provider = (AwsCodeCommitCredentialProvider) + factory.createFor(CURLY_BRACES_REPO, USER, PASSWORD, null); + CredentialItem[] credentialItems = makeCredentialItems(); + assertTrue(provider.get(new URIish(CURLY_BRACES_REPO), credentialItems)); + } + + @Test + public void testThrowsUnsupportedCredentialException() throws URISyntaxException { + CredentialItem[] goodCredentialItems = makeCredentialItems(); + CredentialItem[] badCredentialItems = new CredentialItem[] { + goodCredentialItems[0], + goodCredentialItems[1], + new CredentialItem.YesNoType("OK?") + }; + try { + provider.get(new URIish(AWS_REPO), badCredentialItems); + fail("Expected UnsupportedCredentialItem exception"); + } catch (UnsupportedCredentialItem e) { + assertNotNull(e.getMessage()); + } + } + + @Test + public void testReturnsCredentials() throws URISyntaxException { + CredentialItem[] credentialItems = makeCredentialItems(); + assertTrue(provider.get(new URIish(AWS_REPO), credentialItems)); + + String theUsername = ((CredentialItem.Username) credentialItems[0]).getValue(); + char[] thePassword = ((CredentialItem.Password) credentialItems[1]).getValue(); + + assertEquals(USER, theUsername); + assertNotNull(thePassword); + + // The password will always begin with a timestamp like + // 20161113T121314Z + assertTrue(thePassword.length > 16); + assertEquals('T', thePassword[8]); + assertEquals('Z', thePassword[15]); + } - private CredentialItem[] makeCredentialItems() { - CredentialItem[] credentialItems = new CredentialItem[2]; - credentialItems[0] = new CredentialItem.Username(); - credentialItems[1] = new CredentialItem.Password(); - return credentialItems; - } + private CredentialItem[] makeCredentialItems() { + CredentialItem[] credentialItems = new CredentialItem[2]; + credentialItems[0] = new CredentialItem.Username(); + credentialItems[1] = new CredentialItem.Password(); + return credentialItems; + } } From 2611b0a229a69e4ce94da022a8240de4d83cd482 Mon Sep 17 00:00:00 2001 From: tapvirvirk Date: Fri, 26 May 2017 16:53:58 -0400 Subject: [PATCH 17/26] Update AwsCodeCommitCredentialsProviderTests.java --- ...AwsCodeCommitCredentialsProviderTests.java | 204 +++++++++--------- 1 file changed, 102 insertions(+), 102 deletions(-) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java index d62ecd06..220ed439 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java @@ -44,74 +44,74 @@ import static org.junit.Assert.fail; * */ public class AwsCodeCommitCredentialsProviderTests { - private static final String PASSWORD = "secret"; - private static final String USER = "test"; - private static final String AWS_REPO = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test"; - private static final String BAD_REPO = "https://amazonaws.com/v1/repos/test"; + private static final String PASSWORD = "secret"; + private static final String USER = "test"; + private static final String AWS_REPO = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test"; + private static final String BAD_REPO = "https://amazonaws.com/v1/repos/test"; private static final String CURLY_BRACES_REPO = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/{application}"; - private AwsCodeCommitCredentialProvider provider; - - @Before - public void init() { - GitCredentialsProviderFactory factory = new GitCredentialsProviderFactory(); - provider = (AwsCodeCommitCredentialProvider) - factory.createFor(AWS_REPO, USER, PASSWORD, null); - } - - @Test - public void basics() { - assertNotNull(provider); - assertEquals(USER, provider.getUsername()); - assertEquals(PASSWORD, provider.getPassword()); - assertFalse(provider.isInteractive()); - } + private AwsCodeCommitCredentialProvider provider; + + @Before + public void init() { + GitCredentialsProviderFactory factory = new GitCredentialsProviderFactory(); + provider = (AwsCodeCommitCredentialProvider) + factory.createFor(AWS_REPO, USER, PASSWORD, null); + } + + @Test + public void basics() { + assertNotNull(provider); + assertEquals(USER, provider.getUsername()); + assertEquals(PASSWORD, provider.getPassword()); + assertFalse(provider.isInteractive()); + } - @Test - public void testSupportsUsernamePassword() { - assertTrue(provider.supports(new CredentialItem[] { - new CredentialItem.Username(), - new CredentialItem.Password() - })); - } + @Test + public void testSupportsUsernamePassword() { + assertTrue(provider.supports(new CredentialItem[] { + new CredentialItem.Username(), + new CredentialItem.Password() + })); + } - @Test - public void testNotSupportsOther() { - assertFalse(provider.supports(new CredentialItem[] { - new CredentialItem.YesNoType("OK To Login?") // this is not ok - })); - assertFalse(provider.supports(new CredentialItem[] { - new CredentialItem.StringType("OK To Login?", true) // this is not ok - })); - assertFalse(provider.supports(new CredentialItem[] { - new CredentialItem.Username(), // this is ok - new CredentialItem.Password(), // this is ok - new CredentialItem.StringType("OK To Login?", true) // this is not ok - })); - } - - @Test - public void testAwsCredentialsProviderIsNullInitially() { - AWSCredentialsProvider awsProvider = provider.getAwsCredentialProvider(); - assertNull(awsProvider); - } + @Test + public void testNotSupportsOther() { + assertFalse(provider.supports(new CredentialItem[] { + new CredentialItem.YesNoType("OK To Login?") // this is not ok + })); + assertFalse(provider.supports(new CredentialItem[] { + new CredentialItem.StringType("OK To Login?", true) // this is not ok + })); + assertFalse(provider.supports(new CredentialItem[] { + new CredentialItem.Username(), // this is ok + new CredentialItem.Password(), // this is ok + new CredentialItem.StringType("OK To Login?", true) // this is not ok + })); + } + + @Test + public void testAwsCredentialsProviderIsNullInitially() { + AWSCredentialsProvider awsProvider = provider.getAwsCredentialProvider(); + assertNull(awsProvider); + } - @Test - public void testAwsCredentialsProviderIsDefinedAfterGet() throws URISyntaxException { - AWSCredentialsProvider awsProvider = provider.getAwsCredentialProvider(); - assertNull(awsProvider); - assertTrue(provider.get(new URIish(AWS_REPO), makeCredentialItems())); - awsProvider = provider.getAwsCredentialProvider(); - assertNotNull(awsProvider); - assertTrue(awsProvider instanceof AwsCodeCommitCredentialProvider.AWSStaticCredentialsProvider); - } - - @Test - public void testBadUriReturnsFalse() throws UnsupportedCredentialItem, URISyntaxException { - CredentialItem[] credentialItems = makeCredentialItems(); - assertFalse(provider.get(new URIish(BAD_REPO), credentialItems)); - } - + @Test + public void testAwsCredentialsProviderIsDefinedAfterGet() throws URISyntaxException { + AWSCredentialsProvider awsProvider = provider.getAwsCredentialProvider(); + assertNull(awsProvider); + assertTrue(provider.get(new URIish(AWS_REPO), makeCredentialItems())); + awsProvider = provider.getAwsCredentialProvider(); + assertNotNull(awsProvider); + assertTrue(awsProvider instanceof AwsCodeCommitCredentialProvider.AWSStaticCredentialsProvider); + } + + @Test + public void testBadUriReturnsFalse() throws UnsupportedCredentialItem, URISyntaxException { + CredentialItem[] credentialItems = makeCredentialItems(); + assertFalse(provider.get(new URIish(BAD_REPO), credentialItems)); + } + @Test public void testUriWithCurlyBracesReturnsTrue() throws UnsupportedCredentialItem, URISyntaxException { GitCredentialsProviderFactory factory = new GitCredentialsProviderFactory(); @@ -121,44 +121,44 @@ public class AwsCodeCommitCredentialsProviderTests { assertTrue(provider.get(new URIish(CURLY_BRACES_REPO), credentialItems)); } - @Test - public void testThrowsUnsupportedCredentialException() throws URISyntaxException { - CredentialItem[] goodCredentialItems = makeCredentialItems(); - CredentialItem[] badCredentialItems = new CredentialItem[] { - goodCredentialItems[0], - goodCredentialItems[1], - new CredentialItem.YesNoType("OK?") - }; - try { - provider.get(new URIish(AWS_REPO), badCredentialItems); - fail("Expected UnsupportedCredentialItem exception"); - } catch (UnsupportedCredentialItem e) { - assertNotNull(e.getMessage()); - } - } - - @Test - public void testReturnsCredentials() throws URISyntaxException { - CredentialItem[] credentialItems = makeCredentialItems(); - assertTrue(provider.get(new URIish(AWS_REPO), credentialItems)); - - String theUsername = ((CredentialItem.Username) credentialItems[0]).getValue(); - char[] thePassword = ((CredentialItem.Password) credentialItems[1]).getValue(); - - assertEquals(USER, theUsername); - assertNotNull(thePassword); - - // The password will always begin with a timestamp like - // 20161113T121314Z - assertTrue(thePassword.length > 16); - assertEquals('T', thePassword[8]); - assertEquals('Z', thePassword[15]); - } + @Test + public void testThrowsUnsupportedCredentialException() throws URISyntaxException { + CredentialItem[] goodCredentialItems = makeCredentialItems(); + CredentialItem[] badCredentialItems = new CredentialItem[] { + goodCredentialItems[0], + goodCredentialItems[1], + new CredentialItem.YesNoType("OK?") + }; + try { + provider.get(new URIish(AWS_REPO), badCredentialItems); + fail("Expected UnsupportedCredentialItem exception"); + } catch (UnsupportedCredentialItem e) { + assertNotNull(e.getMessage()); + } + } + + @Test + public void testReturnsCredentials() throws URISyntaxException { + CredentialItem[] credentialItems = makeCredentialItems(); + assertTrue(provider.get(new URIish(AWS_REPO), credentialItems)); + + String theUsername = ((CredentialItem.Username) credentialItems[0]).getValue(); + char[] thePassword = ((CredentialItem.Password) credentialItems[1]).getValue(); + + assertEquals(USER, theUsername); + assertNotNull(thePassword); + + // The password will always begin with a timestamp like + // 20161113T121314Z + assertTrue(thePassword.length > 16); + assertEquals('T', thePassword[8]); + assertEquals('Z', thePassword[15]); + } - private CredentialItem[] makeCredentialItems() { - CredentialItem[] credentialItems = new CredentialItem[2]; - credentialItems[0] = new CredentialItem.Username(); - credentialItems[1] = new CredentialItem.Password(); - return credentialItems; - } + private CredentialItem[] makeCredentialItems() { + CredentialItem[] credentialItems = new CredentialItem[2]; + credentialItems[0] = new CredentialItem.Username(); + credentialItems[1] = new CredentialItem.Password(); + return credentialItems; + } } From b83572ab475c524e14c6888cf6db5f91c6f34161 Mon Sep 17 00:00:00 2001 From: tapvirvirk Date: Tue, 30 May 2017 19:04:58 -0400 Subject: [PATCH 18/26] Update AwsCodeCommitCredentialProvider.java Fixed the spaces --- .../server/support/AwsCodeCommitCredentialProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AwsCodeCommitCredentialProvider.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AwsCodeCommitCredentialProvider.java index b1cf3dd7..1653d72f 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AwsCodeCommitCredentialProvider.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AwsCodeCommitCredentialProvider.java @@ -327,8 +327,8 @@ public class AwsCodeCommitCredentialProvider extends CredentialsProvider { } try { - URL url = new URL(uri); - URI u = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); + URL url = new URL(uri); + URI u = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); if (u.getScheme().equals("https")) { String host = u.getHost(); if (host.endsWith(".amazonaws.com") && host.startsWith("git-codecommit.")) { From b7ce3185968b22bdef3f52ccf92cc0e3e6765730 Mon Sep 17 00:00:00 2001 From: tapvirvirk Date: Tue, 30 May 2017 19:05:37 -0400 Subject: [PATCH 19/26] Update AwsCodeCommitCredentialsProviderTests.java Fixed the spaces --- .../AwsCodeCommitCredentialsProviderTests.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java index 220ed439..6eb6018f 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java @@ -48,7 +48,7 @@ public class AwsCodeCommitCredentialsProviderTests { private static final String USER = "test"; private static final String AWS_REPO = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test"; private static final String BAD_REPO = "https://amazonaws.com/v1/repos/test"; - private static final String CURLY_BRACES_REPO = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/{application}"; + private static final String CURLY_BRACES_REPO = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/{application}"; private AwsCodeCommitCredentialProvider provider; @@ -112,14 +112,14 @@ public class AwsCodeCommitCredentialsProviderTests { assertFalse(provider.get(new URIish(BAD_REPO), credentialItems)); } - @Test - public void testUriWithCurlyBracesReturnsTrue() throws UnsupportedCredentialItem, URISyntaxException { - GitCredentialsProviderFactory factory = new GitCredentialsProviderFactory(); - provider = (AwsCodeCommitCredentialProvider) - factory.createFor(CURLY_BRACES_REPO, USER, PASSWORD, null); - CredentialItem[] credentialItems = makeCredentialItems(); - assertTrue(provider.get(new URIish(CURLY_BRACES_REPO), credentialItems)); - } + @Test + public void testUriWithCurlyBracesReturnsTrue() throws UnsupportedCredentialItem, URISyntaxException { + GitCredentialsProviderFactory factory = new GitCredentialsProviderFactory(); + provider = (AwsCodeCommitCredentialProvider) + factory.createFor(CURLY_BRACES_REPO, USER, PASSWORD, null); + CredentialItem[] credentialItems = makeCredentialItems(); + assertTrue(provider.get(new URIish(CURLY_BRACES_REPO), credentialItems)); + } @Test public void testThrowsUnsupportedCredentialException() throws URISyntaxException { From bb4168380435f6102c922ead68d5203fca40a077 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Wed, 14 Jun 2017 14:46:43 -0400 Subject: [PATCH 20/26] Set version when there is only a single environment repository in a composite. Fixes #718. --- .../CompositeEnvironmentRepository.java | 11 ++++-- .../CompositeEnvironmentRepositoryTests.java | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepository.java index 77d2f44f..f58509f2 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepository.java @@ -41,8 +41,15 @@ public class CompositeEnvironmentRepository implements EnvironmentRepository { @Override public Environment findOne(String application, String profile, String label) { Environment env = new Environment(application, new String[]{profile}, label, null, null); - for(EnvironmentRepository repo : environmentRepositories) { - env.addAll(repo.findOne(application, profile, label).getPropertySources()); + if(environmentRepositories.size() == 1) { + Environment envRepo = environmentRepositories.get(0).findOne(application, profile, label); + env.addAll(envRepo.getPropertySources()); + env.setVersion(envRepo.getVersion()); + env.setState(envRepo.getState()); + } else { + for (EnvironmentRepository repo : environmentRepositories) { + env.addAll(repo.findOne(application, profile, label).getPropertySources()); + } } return env; } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java index b1cc7904..138f9f56 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java @@ -110,4 +110,38 @@ public class CompositeEnvironmentRepositoryTests { assertEquals(sLoc4, locationStrings[3]); assertEquals(sLoc1, locationStrings[4]); } + + @Test + public void testVersion() { + PropertySource p1 = mock(PropertySource.class); + doReturn("p1").when(p1).getName(); + PropertySource p2 = mock(PropertySource.class); + doReturn("p2").when(p2).getName(); + String sLoc1 = "loc1"; + String sLoc2 = "loc2"; + Environment e1 = new Environment("app", "dev"); + e1.add(p1); + e1.setVersion("1"); + e1.setState("state"); + Environment e2 = new Environment("app", "dev"); + e2.add(p2); + e2.setVersion("2"); + e2.setState("state2"); + SearchPathLocator.Locations loc1 = new SearchPathLocator.Locations("app", "dev", "label", "version", new String[]{sLoc1}); + SearchPathLocator.Locations loc2 = new SearchPathLocator.Locations("app", "dev", "label", "version", new String[]{sLoc1, sLoc2}); + List repos = new ArrayList(); + repos.add(new TestOrderedEnvironmentRepository(3, e1, loc1)); + List repos2 = new ArrayList(); + repos2.add(new TestOrderedEnvironmentRepository(3, e1, loc1)); + repos2.add(new TestOrderedEnvironmentRepository(3, e2, loc2)); + SearchPathCompositeEnvironmentRepository compositeRepo = new SearchPathCompositeEnvironmentRepository(repos); + SearchPathCompositeEnvironmentRepository multiCompositeRepo = new SearchPathCompositeEnvironmentRepository(repos2); + Environment env = compositeRepo.findOne("app", "dev", "label"); + assertEquals("1", env.getVersion()); + assertEquals("state", env.getState()); + Environment multiEnv = multiCompositeRepo.findOne("app", "dev", "label"); + assertEquals(null, multiEnv.getVersion()); + assertEquals(null, multiEnv.getState()); + + } } From 7f7b1040e068fb52e8ff9ee5f965144f1127716e Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Wed, 14 Jun 2017 16:35:47 -0400 Subject: [PATCH 21/26] Bumping version to 1.4.0 --- pom.xml | 6 +++--- spring-cloud-config-client/pom.xml | 2 +- spring-cloud-config-dependencies/pom.xml | 4 ++-- spring-cloud-config-monitor/pom.xml | 4 ++-- spring-cloud-config-sample/pom.xml | 2 +- spring-cloud-config-server/pom.xml | 2 +- spring-cloud-starter-config/pom.xml | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index bbdbc97a..6ccfe87c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.cloud spring-cloud-config - 1.3.2.BUILD-SNAPSHOT + 1.4.0.BUILD-SNAPSHOT pom Spring Cloud Config Spring Cloud Config @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-build - 1.3.2.RELEASE + 1.3.3.BUILD-SNAPSHOT @@ -22,7 +22,7 @@ config - 1.2.1.BUILD-SNAPSHOT + 1.2.3.BUILD-SNAPSHOT spring-cloud-config-dependencies diff --git a/spring-cloud-config-client/pom.xml b/spring-cloud-config-client/pom.xml index 7151af7a..563183e9 100644 --- a/spring-cloud-config-client/pom.xml +++ b/spring-cloud-config-client/pom.xml @@ -10,7 +10,7 @@ org.springframework.cloud spring-cloud-config - 1.3.2.BUILD-SNAPSHOT + 1.4.0.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-dependencies/pom.xml b/spring-cloud-config-dependencies/pom.xml index 812bba71..15014984 100644 --- a/spring-cloud-config-dependencies/pom.xml +++ b/spring-cloud-config-dependencies/pom.xml @@ -5,11 +5,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 1.3.2.RELEASE + 1.3.3.BUILD-SNAPSHOT spring-cloud-config-dependencies - 1.3.2.BUILD-SNAPSHOT + 1.4.0.BUILD-SNAPSHOT pom spring-cloud-config-dependencies Spring Cloud Config Dependencies diff --git a/spring-cloud-config-monitor/pom.xml b/spring-cloud-config-monitor/pom.xml index 35a06878..607985d2 100644 --- a/spring-cloud-config-monitor/pom.xml +++ b/spring-cloud-config-monitor/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-config - 1.3.2.BUILD-SNAPSHOT + 1.4.0.BUILD-SNAPSHOT .. spring-cloud-config-monitor @@ -13,7 +13,7 @@ Spring Cloud Config Monitor ${basedir}/../.. - 1.3.1.BUILD-SNAPSHOT + 1.3.2.BUILD-SNAPSHOT diff --git a/spring-cloud-config-sample/pom.xml b/spring-cloud-config-sample/pom.xml index ca14f67b..a97d9f9e 100644 --- a/spring-cloud-config-sample/pom.xml +++ b/spring-cloud-config-sample/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.3.2.BUILD-SNAPSHOT + 1.4.0.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index 4482de8a..21237c68 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.3.2.BUILD-SNAPSHOT + 1.4.0.BUILD-SNAPSHOT .. diff --git a/spring-cloud-starter-config/pom.xml b/spring-cloud-starter-config/pom.xml index 55800605..37b081f6 100644 --- a/spring-cloud-starter-config/pom.xml +++ b/spring-cloud-starter-config/pom.xml @@ -5,10 +5,10 @@ org.springframework.cloud spring-cloud-config - 1.3.2.BUILD-SNAPSHOT + 1.4.0.BUILD-SNAPSHOT spring-cloud-starter-config - 1.3.2.BUILD-SNAPSHOT + 1.4.0.BUILD-SNAPSHOT spring-cloud-starter-config Spring Cloud Starter https://projects.spring.io/spring-cloud From c5c432e2b37db7a6d13deee42bfa0d37fbc937da Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 26 Jun 2017 08:12:55 +0100 Subject: [PATCH 22/26] Use undeprecated class --- .../config/server/environment/NativeEnvironmentRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java index c316b636..0987819f 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java @@ -27,7 +27,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.boot.Banner.Mode; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.config.ConfigFileApplicationListener; import org.springframework.boot.context.properties.ConfigurationProperties; From a64fe280f44ffc724736954cf956e3cffa93073a Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 26 Jun 2017 08:49:22 +0100 Subject: [PATCH 23/26] Update build to latest --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bbdbc97a..866033d2 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-build - 1.3.2.RELEASE + 1.3.3.RELEASE From e6a42aab95825f81942d5ca398d05a00c833a826 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 26 Jun 2017 09:20:31 +0100 Subject: [PATCH 24/26] Check for index.lock before attempting to use JGit A stale lock from a crashed JVM can prang the JGit client by preventing it from ever getting access to the working directory. This change attempts to clean the slate by removing the lock - because of the synchronization already present in the repository the only way this can go wrong is if multiple server instances are trying to share the working directory (which would be an eror for other reasons). --- .../JGitEnvironmentRepository.java | 152 +++++------ .../cloud/config/server/AdhocTestSuite.java | 25 ++ ...EnvironmentRepositoryIntegrationTests.java | 241 ++++++++---------- .../JGitEnvironmentRepositoryTests.java | 205 +++++++-------- 4 files changed, 309 insertions(+), 314 deletions(-) create mode 100644 spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/AdhocTestSuite.java diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java index 1da9c00a..f94cd97e 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java @@ -75,23 +75,23 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository private static final String FILE_URI_PREFIX = "file:"; /** - * Timeout (in seconds) for obtaining HTTP or SSH connection (if applicable). Default - * 5 seconds. + * Timeout (in seconds) for obtaining HTTP or SSH connection (if + * applicable). Default 5 seconds. */ private int timeout = 5; private boolean initialized; /** - * Flag to indicate that the repository should be cloned on startup (not on demand). - * Generally leads to slower startup but faster first query. + * Flag to indicate that the repository should be cloned on startup (not on + * demand). Generally leads to slower startup but faster first query. */ private boolean cloneOnStart = false; private JGitEnvironmentRepository.JGitFactory gitFactory = new JGitEnvironmentRepository.JGitFactory(); private String defaultLabel = DEFAULT_LABEL; - + /** * The credentials provider to use to connect to the Git repository. */ @@ -103,8 +103,8 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository private TransportConfigCallback transportConfigCallback; /** - * Flag to indicate that the repository should force pull. If true discard any local - * changes and take from remote repository. + * Flag to indicate that the repository should force pull. If true discard + * any local changes and take from remote repository. */ private boolean forcePull; @@ -161,8 +161,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository } @Override - public synchronized Locations getLocations(String application, String profile, - String label) { + public synchronized Locations getLocations(String application, String profile, String label) { if (label == null) { label = this.defaultLabel; } @@ -173,8 +172,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository @Override public void afterPropertiesSet() throws Exception { - Assert.state(getUri() != null, - "You need to configure a uri for the git repository"); + Assert.state(getUri() != null, "You need to configure a uri for the git repository"); initialize(); if (this.cloneOnStart) { initClonedRepository(); @@ -191,41 +189,35 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository git = createGitClient(); if (shouldPull(git)) { fetch(git, label); - //checkout after fetch so we can get any new branches, tags, ect. + // checkout after fetch so we can get any new branches, tags, + // ect. checkout(git, label); - if(isBranch(git, label)) { - //merge results from fetch + if (isBranch(git, label)) { + // merge results from fetch merge(git, label); if (!isClean(git)) { - logger.warn("The local repository is dirty. Resetting it to origin/" - + label + "."); + logger.warn("The local repository is dirty. Resetting it to origin/" + label + "."); resetHard(git, label, "refs/remotes/origin/" + label); } } - } - else{ - //nothing to update so just checkout + } else { + // nothing to update so just checkout checkout(git, label); } - //always return what is currently HEAD as the version - return git.getRepository().getRef("HEAD").getObjectId().getName(); - } - catch (RefNotFoundException e) { + // always return what is currently HEAD as the version + return git.getRepository().findRef("HEAD").getObjectId().getName(); + } catch (RefNotFoundException e) { throw new NoSuchLabelException("No such label: " + label, e); - } - catch (GitAPIException e) { + } catch (GitAPIException e) { throw new IllegalStateException("Cannot clone or checkout repository", e); - } - catch (Exception e) { + } catch (Exception e) { throw new IllegalStateException("Cannot load environment", e); - } - finally { + } finally { try { if (git != null) { git.close(); } - } - catch (Exception e) { + } catch (Exception e) { this.logger.warn("Could not close git repository", e); } } @@ -233,6 +225,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository /** * Clones the remote repository and then opens a connection to it. + * * @throws GitAPIException * @throws IOException */ @@ -255,41 +248,35 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository CheckoutCommand checkout = git.checkout(); if (shouldTrack(git, label)) { trackBranch(git, checkout, label); - } - else { + } else { // works for tags and local branches checkout.setName(label); } return checkout.call(); } - protected boolean shouldPull(Git git) throws GitAPIException { boolean shouldPull; Status gitStatus = git.status().call(); boolean isWorkingTreeClean = gitStatus.isClean(); - String originUrl = git.getRepository().getConfig().getString("remote", "origin", - "url"); + String originUrl = git.getRepository().getConfig().getString("remote", "origin", "url"); if (this.forcePull && !isWorkingTreeClean) { shouldPull = true; logDirty(gitStatus); - } - else { + } else { shouldPull = isWorkingTreeClean && originUrl != null; } if (!isWorkingTreeClean && !this.forcePull) { - this.logger.info("Cannot pull from remote " + originUrl - + ", the working tree is not clean."); + this.logger.info("Cannot pull from remote " + originUrl + ", the working tree is not clean."); } return shouldPull; } @SuppressWarnings("unchecked") private void logDirty(Status status) { - Set dirties = dirties(status.getAdded(), status.getChanged(), - status.getRemoved(), status.getMissing(), status.getModified(), - status.getConflicting(), status.getUntracked()); + Set dirties = dirties(status.getAdded(), status.getChanged(), status.getRemoved(), status.getMissing(), + status.getModified(), status.getConflicting(), status.getUntracked()); this.logger.warn(String.format("Dirty files found: %s", dirties)); } @@ -314,15 +301,14 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository configureCommand(fetch); try { FetchResult result = fetch.call(); - if(result.getTrackingRefUpdates() != null && result.getTrackingRefUpdates().size() > 0) { + if (result.getTrackingRefUpdates() != null && result.getTrackingRefUpdates().size() > 0) { logger.info("Fetched for remote " + label + " and found " + result.getTrackingRefUpdates().size() - + " updates"); + + " updates"); } return result; - } - catch (Exception ex) { - String message = "Could not fetch remote for " + label + " remote: " + git - .getRepository().getConfig().getString("remote", "origin", "url"); + } catch (Exception ex) { + String message = "Could not fetch remote for " + label + " remote: " + + git.getRepository().getConfig().getString("remote", "origin", "url"); warn(message, ex); return null; } @@ -331,16 +317,15 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository private MergeResult merge(Git git, String label) { try { MergeCommand merge = git.merge(); - merge.include(git.getRepository().getRef("origin/" + label)); + merge.include(git.getRepository().findRef("origin/" + label)); MergeResult result = merge.call(); - if(!result.getMergeStatus().isSuccessful()) { + if (!result.getMergeStatus().isSuccessful()) { this.logger.warn("Merged from remote " + label + " with result " + result.getMergeStatus()); } return result; - } - catch (Exception ex) { - String message = "Could not merge remote for " + label + " remote: " + git - .getRepository().getConfig().getString("remote", "origin", "url"); + } catch (Exception ex) { + String message = "Could not merge remote for " + label + " remote: " + + git.getRepository().getConfig().getString("remote", "origin", "url"); warn(message, ex); return null; } @@ -352,31 +337,38 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository reset.setMode(ResetType.HARD); try { Ref resetRef = reset.call(); - if(resetRef != null) { + if (resetRef != null) { this.logger.info("Reset label " + label + " to version " + resetRef.getObjectId()); } return resetRef; - } - catch (Exception ex) { - String message = "Could not reset to remote for " + label + " (current ref=" - + ref + "), remote: " + git.getRepository().getConfig() - .getString("remote", "origin", "url"); + } catch (Exception ex) { + String message = "Could not reset to remote for " + label + " (current ref=" + ref + "), remote: " + + git.getRepository().getConfig().getString("remote", "origin", "url"); warn(message, ex); return null; } } private Git createGitClient() throws IOException, GitAPIException { - if (new File(getBasedir(), ".git").exists()) { - return openGitRepository(); + File lock = new File(getWorkingDirectory(), ".git/index.lock"); + if (lock.exists()) { + // The only way this can happen is if another JVM (e.g. one that + // crashed earlier) created the lock. We can attempt to recover by + // wiping the slate clean. + logger.info("Deleting stale JGit lock file at " + lock); + lock.delete(); } - else { + if (new File(getWorkingDirectory(), ".git").exists()) { + return openGitRepository(); + } else { return copyRepository(); } } - // Synchronize here so that multiple requests don't all try and delete the base dir - // together (this is a once only operation, so it only holds things up on the first + // Synchronize here so that multiple requests don't all try and delete the + // base dir + // together (this is a once only operation, so it only holds things up on + // the first // request). private synchronized Git copyRepository() throws IOException, GitAPIException { deleteBaseDirIfExists(); @@ -384,8 +376,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository Assert.state(getBasedir().exists(), "Could not create basedir: " + getBasedir()); if (getUri().startsWith(FILE_URI_PREFIX)) { return copyFromLocalRepository(); - } - else { + } else { return cloneToBasedir(); } } @@ -407,13 +398,12 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository } private Git cloneToBasedir() throws GitAPIException { - CloneCommand clone = this.gitFactory.getCloneCommandByCloneRepository() - .setURI(getUri()).setDirectory(getBasedir()); + CloneCommand clone = this.gitFactory.getCloneCommandByCloneRepository().setURI(getUri()) + .setDirectory(getBasedir()); configureCommand(clone); try { return clone.call(); - } - catch (GitAPIException e) { + } catch (GitAPIException e) { deleteBaseDirIfExists(); throw e; } @@ -423,8 +413,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository if (getBasedir().exists()) { try { FileUtils.delete(getBasedir(), FileUtils.RECURSIVE); - } - catch (IOException e) { + } catch (IOException e) { throw new IllegalStateException("Failed to initialize base directory", e); } } @@ -473,8 +462,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository StatusCommand status = git.status(); try { return status.call().isClean(); - } - catch (Exception e) { + } catch (Exception e) { String message = "Could not execute status command on local repository. Cause: (" + e.getClass().getSimpleName() + ") " + e.getMessage(); warn(message, e); @@ -483,8 +471,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository } private void trackBranch(Git git, CheckoutCommand checkout, String label) { - checkout.setCreateBranch(true).setName(label) - .setUpstreamMode(SetupUpstreamMode.TRACK) + checkout.setCreateBranch(true).setName(label).setUpstreamMode(SetupUpstreamMode.TRACK) .setStartPoint("origin/" + label); } @@ -496,8 +483,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository return containsBranch(git, label, null); } - private boolean containsBranch(Git git, String label, ListMode listMode) - throws GitAPIException { + private boolean containsBranch(Git git, String label, ListMode listMode) throws GitAPIException { ListBranchCommand command = git.branchList(); if (listMode != null) { command.setListMode(listMode); @@ -520,7 +506,8 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository /** * Wraps the static method calls to {@link org.eclipse.jgit.api.Git} and - * {@link org.eclipse.jgit.api.CloneCommand} allowing for easier unit testing. + * {@link org.eclipse.jgit.api.CloneCommand} allowing for easier unit + * testing. */ static class JGitFactory { @@ -543,7 +530,8 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository } /** - * @param gitCredentialsProvider the gitCredentialsProvider to set + * @param gitCredentialsProvider + * the gitCredentialsProvider to set */ public void setGitCredentialsProvider(CredentialsProvider gitCredentialsProvider) { this.gitCredentialsProvider = gitCredentialsProvider; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/AdhocTestSuite.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/AdhocTestSuite.java new file mode 100644 index 00000000..4749750f --- /dev/null +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/AdhocTestSuite.java @@ -0,0 +1,25 @@ +package org.springframework.cloud.config.server; + +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +import org.springframework.cloud.config.server.environment.EnvironmentEncryptorEnvironmentRepositoryTests; +import org.springframework.cloud.config.server.environment.JGitEnvironmentRepositoryIntegrationTests; +import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepositoryIntegrationTests; +import org.springframework.cloud.config.server.environment.NativeEnvironmentRepositoryTests; +import org.springframework.cloud.config.server.environment.SVNKitEnvironmentRepositoryIntegrationTests; + +/** + * A test suite for probing weird ordering problems in the tests. + * + * @author Dave Syer + */ +@RunWith(Suite.class) +@SuiteClasses({ MultipleJGitEnvironmentRepositoryIntegrationTests.class, + JGitEnvironmentRepositoryIntegrationTests.class, EnvironmentEncryptorEnvironmentRepositoryTests.class, + NativeEnvironmentRepositoryTests.class, SVNKitEnvironmentRepositoryIntegrationTests.class }) +@Ignore +public class AdhocTestSuite { + +} diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java index 6f3d2653..60b38ce3 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java @@ -16,6 +16,14 @@ package org.springframework.cloud.config.server.environment; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -41,7 +49,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.config.environment.Environment; @@ -52,17 +60,10 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.util.FileSystemUtils; import org.springframework.util.ResourceUtils; import org.springframework.util.StreamUtils; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - /** * @author Dave Syer * @author Roy Clarkson @@ -95,8 +96,7 @@ public class JGitEnvironmentRepositoryIntegrationTests { String uri = ConfigServerTestUtils.prepareLocalRepo(); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .properties("spring.cloud.config.server.git.uri:" + uri).run(); - EnvironmentRepository repository = this.context - .getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); repository.findOne("bar", "staging", "master"); Environment environment = repository.findOne("bar", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); @@ -111,12 +111,10 @@ public class JGitEnvironmentRepositoryIntegrationTests { String uri = ConfigServerTestUtils.copyLocalRepo("config-copy"); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .run("--spring.cloud.config.server.git.uri=" + uri); - EnvironmentRepository repository = this.context - .getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); repository.findOne("bar", "staging", "master"); Environment environment = repository.findOne("bar", "staging", "master"); - assertEquals("bar", - environment.getPropertySources().get(0).getSource().get("foo")); + assertEquals("bar", environment.getPropertySources().get(0).getSource().get("foo")); Git git = Git.open(ResourceUtils.getFile(uri).getAbsoluteFile()); git.checkout().setName("master").call(); StreamUtils.copy("foo: foo", Charset.defaultCharset(), @@ -124,15 +122,14 @@ public class JGitEnvironmentRepositoryIntegrationTests { git.add().addFilepattern("bar.properties").call(); git.commit().setMessage("Updated for pull").call(); environment = repository.findOne("bar", "staging", "master"); - assertEquals("foo", - environment.getPropertySources().get(0).getSource().get("foo")); + assertEquals("foo", environment.getPropertySources().get(0).getSource().get("foo")); } /** - * Tests a special use case where the remote repository has been updated with a forced - * push conflicting with the local repo of the Config Server. The Config Server has to - * reset hard on the new reference because a simple pull operation could result in a - * conflicting local repository. + * Tests a special use case where the remote repository has been updated + * with a forced push conflicting with the local repo of the Config Server. + * The Config Server has to reset hard on the new reference because a simple + * pull operation could result in a conflicting local repository. */ @Test public void pullDirtyRepo() throws Exception { @@ -144,23 +141,19 @@ public class JGitEnvironmentRepositoryIntegrationTests { Git git = Git.open(ResourceUtils.getFile(uri).getAbsoluteFile()); StoredConfig config = git.getRepository().getConfig(); - config.setString("remote", "origin", "url", - remote.getDirectory().getAbsolutePath()); - config.setString("remote", "origin", "fetch", - "+refs/heads/*:refs/remotes/origin/*"); + config.setString("remote", "origin", "url", remote.getDirectory().getAbsolutePath()); + config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.save(); // Pushes the raw branch to remote repository. git.push().call(); - String commitToRevertBeforePull = git.log().setMaxCount(1).call().iterator() - .next().getName(); + String commitToRevertBeforePull = git.log().setMaxCount(1).call().iterator().next().getName(); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .run("--spring.cloud.config.server.git.uri=" + uri); - JGitEnvironmentRepository repository = this.context - .getBean(JGitEnvironmentRepository.class); + JGitEnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class); // Fetches the repository for the first time. SearchPathLocator.Locations locations = repository.getLocations("bar", "test", "raw"); @@ -170,17 +163,14 @@ public class JGitEnvironmentRepositoryIntegrationTests { git.reset().setMode(ResetType.HARD).setRef("master").call(); // Generate a conflicting commit who will be forced on the origin. - Path applicationFilePath = Paths - .get(ResourceUtils.getFile(uri).getAbsoluteFile() + "/application.yml"); + Path applicationFilePath = Paths.get(ResourceUtils.getFile(uri).getAbsoluteFile() + "/application.yml"); - Files.write(applicationFilePath, - Arrays.asList("info:", " foo: bar", "raw: false"), - StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING); + Files.write(applicationFilePath, Arrays.asList("info:", " foo: bar", "raw: false"), StandardCharsets.UTF_8, + StandardOpenOption.TRUNCATE_EXISTING); git.add().addFilepattern(".").call(); git.commit().setMessage("Conflicting commit.").call(); git.push().setForce(true).call(); - String conflictingCommit = git.log().setMaxCount(1).call().iterator() - .next().getName(); + String conflictingCommit = git.log().setMaxCount(1).call().iterator().next().getName(); // Reset to the raw branch. git.reset().setMode(ResetType.HARD).setRef(commitToRevertBeforePull).call(); @@ -189,8 +179,17 @@ public class JGitEnvironmentRepositoryIntegrationTests { locations = repository.getLocations("bar", "test", "raw"); assertEquals(locations.getVersion(), conflictingCommit); - assertTrue("Local repository is not cleaned after retrieving resources.", - git.status().call().isClean()); + assertTrue("Local repository is not cleaned after retrieving resources.", git.status().call().isClean()); + } + + @Test + public void pullMissingRepo() throws Exception { + pull(); + JGitEnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class); + new File(repository.getUri().replaceAll("file:", ""), ".git/index.lock").createNewFile(); + repository.findOne("bar", "staging", "master"); + Environment environment = repository.findOne("bar", "staging", "master"); + assertEquals("foo", environment.getPropertySources().get(0).getSource().get("foo")); } @Test @@ -198,10 +197,8 @@ public class JGitEnvironmentRepositoryIntegrationTests { String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo"); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) // TODO: why didn't .properties() work for me? - .run("--spring.cloud.config.server.git.uri=" + uri, - "--spring.cloud.config.server.git.searchPaths=sub"); - EnvironmentRepository repository = this.context - .getBean(EnvironmentRepository.class); + .run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.searchPaths=sub"); + EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); repository.findOne("bar", "staging", "master"); Environment environment = repository.findOne("bar", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); @@ -214,8 +211,7 @@ public class JGitEnvironmentRepositoryIntegrationTests { // TODO: why didn't .properties() work for me? .run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.searchPaths={application}"); - EnvironmentRepository repository = this.context - .getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); repository.findOne("foo,bar", "staging", "master"); Environment environment = repository.findOne("foo,bar", "staging", "master"); assertEquals(3, environment.getPropertySources().size()); @@ -228,8 +224,7 @@ public class JGitEnvironmentRepositoryIntegrationTests { // TODO: why didn't .properties() work for me? .run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.searchPaths={profile}"); - EnvironmentRepository repository = this.context - .getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); repository.findOne("foo,bar", "staging", "master"); Environment environment = repository.findOne("staging", "foo,bar", "master"); assertEquals(3, environment.getPropertySources().size()); @@ -238,15 +233,13 @@ public class JGitEnvironmentRepositoryIntegrationTests { @Test public void singleElementArrayIndexSearchPath() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo("nested-repo"); - this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) - .run("--spring.cloud.config.server.git.uri=" + uri, - "--spring.cloud.config.server.git.searchPaths[0]={application}"); - JGitEnvironmentRepository repository = this.context - .getBean(JGitEnvironmentRepository.class); + this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false).run( + "--spring.cloud.config.server.git.uri=" + uri, + "--spring.cloud.config.server.git.searchPaths[0]={application}"); + JGitEnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class); assertThat(repository.getSearchPaths(), Matchers.arrayContaining("{application}")); assertFalse(Arrays.equals(repository.getSearchPaths(), - new JGitEnvironmentRepository(repository.getEnvironment()) - .getSearchPaths())); + new JGitEnvironmentRepository(repository.getEnvironment()).getSearchPaths())); } @Test @@ -254,8 +247,7 @@ public class JGitEnvironmentRepositoryIntegrationTests { String uri = ConfigServerTestUtils.prepareLocalRepo(); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .properties("spring.cloud.config.server.git.uri:" + uri).run(); - JGitEnvironmentRepository repository = this.context - .getBean(JGitEnvironmentRepository.class); + JGitEnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class); assertEquals("master", repository.getDefaultLabel()); } @@ -264,8 +256,7 @@ public class JGitEnvironmentRepositoryIntegrationTests { String uri = ConfigServerTestUtils.prepareLocalRepo(); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .properties("spring.cloud.config.server.git.uri:" + uri).run(); - EnvironmentRepository repository = this.context - .getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); repository.findOne("bar", "staging", "unknownlabel"); } @@ -273,11 +264,9 @@ public class JGitEnvironmentRepositoryIntegrationTests { public void findOne_CloneOnStartTrue_FindOneSuccess() throws Exception { ConfigServerTestUtils.prepareLocalRepo(); String uri = ConfigServerTestUtils.copyLocalRepo("config-copy"); - this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) - .run("--spring.cloud.config.server.git.uri=" + uri, - "--spring.cloud.config.server.git.cloneOnStart=true"); - EnvironmentRepository repository = this.context - .getBean(JGitEnvironmentRepository.class); + this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false).run( + "--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.cloneOnStart=true"); + EnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class); assertTrue(((JGitEnvironmentRepository) repository).isCloneOnStart()); Environment environment = repository.findOne("bar", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); @@ -290,15 +279,12 @@ public class JGitEnvironmentRepositoryIntegrationTests { public void findOne_FileAddedToRepo_FindOneSuccess() throws Exception { ConfigServerTestUtils.prepareLocalRepo(); String uri = ConfigServerTestUtils.copyLocalRepo("config-copy"); - this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) - .run("--spring.cloud.config.server.git.uri=" + uri, - "--spring.cloud.config.server.git.cloneOnStart=true"); - EnvironmentRepository repository = this.context - .getBean(EnvironmentRepository.class); + this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false).run( + "--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.cloneOnStart=true"); + EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); repository.findOne("bar", "staging", "master"); Environment environment = repository.findOne("bar", "staging", "master"); - assertEquals("bar", - environment.getPropertySources().get(0).getSource().get("foo")); + assertEquals("bar", environment.getPropertySources().get(0).getSource().get("foo")); Git git = Git.open(ResourceUtils.getFile(uri).getAbsoluteFile()); git.checkout().setName("master").call(); StreamUtils.copy("foo: foo", Charset.defaultCharset(), @@ -306,8 +292,7 @@ public class JGitEnvironmentRepositoryIntegrationTests { git.add().addFilepattern("bar.properties").call(); git.commit().setMessage("Updated for pull").call(); environment = repository.findOne("bar", "staging", "master"); - assertEquals("foo", - environment.getPropertySources().get(0).getSource().get("foo")); + assertEquals("foo", environment.getPropertySources().get(0).getSource().get("foo")); } @Test @@ -315,83 +300,80 @@ public class JGitEnvironmentRepositoryIntegrationTests { String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo"); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) // TODO: why didn't .properties() work for me? - .run("--spring.cloud.config.server.git.uri=" + uri, - "--spring.cloud.config.server.git.searchPaths=sub", + .run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.searchPaths=sub", "--spring.cloud.config.server.git.cloneOnStart=true"); - EnvironmentRepository repository = this.context - .getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); repository.findOne("bar", "staging", "master"); Environment environment = repository.findOne("bar", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); } @Test(expected = NoSuchLabelException.class) - public void findOne_FindInvalidLabel_IllegalStateExceptionThrown() - throws IOException { + public void findOne_FindInvalidLabel_IllegalStateExceptionThrown() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo(); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .properties("spring.cloud.config.server.git.uri:" + uri, "--spring.cloud.config.server.git.cloneOnStart=true") .run(); - EnvironmentRepository repository = this.context - .getBean(EnvironmentRepository.class); + EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); repository.findOne("bar", "staging", "unknownlabel"); } @Test public void testVersionUpdate() throws Exception { - JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(TestConfiguration.class); + JGitConfigServerTestData testData = JGitConfigServerTestData + .prepareClonedGitRepository(TestConfiguration.class); - //get our starting versions + // get our starting versions String startingLocalVersion = getCommitID(testData.getClonedGit().getGit(), "master"); String startingRemoteVersion = getCommitID(testData.getServerGit().getGit(), "master"); - //make sure we get the right version out of the gate + // make sure we get the right version out of the gate Environment environment = testData.getRepository().findOne("bar", "staging", "master"); - //make sure the environments version is the same as the remote repo version + // make sure the environments version is the same as the remote repo + // version assertEquals(environment.getVersion(), startingRemoteVersion); - //update the remote repo - FileOutputStream out = new FileOutputStream(new File(testData.getServerGit().getGitWorkingDirectory(), "bar.properties")); + // update the remote repo + FileOutputStream out = new FileOutputStream( + new File(testData.getServerGit().getGitWorkingDirectory(), "bar.properties")); StreamUtils.copy("foo: foo", Charset.defaultCharset(), out); testData.getServerGit().getGit().add().addFilepattern("bar.properties").call(); testData.getServerGit().getGit().commit().setMessage("Updated for pull").call(); - //pull the environment again which should update the local repo from the just updated remote repo + // pull the environment again which should update the local repo from + // the just updated remote repo environment = testData.getRepository().findOne("bar", "staging", "master"); - //do some more check outs to get updated version numbers + // do some more check outs to get updated version numbers String updatedLocalVersion = getCommitID(testData.getClonedGit().getGit(), "master"); String updatedRemoteVersion = getCommitID(testData.getClonedGit().getGit(), "master"); - //make sure our versions have been updated + // make sure our versions have been updated assertEquals(updatedRemoteVersion, updatedLocalVersion); assertNotEquals(updatedRemoteVersion, startingRemoteVersion); assertNotEquals(updatedLocalVersion, startingLocalVersion); - //make sure our environment also reflects the updated version - //this used to have a bug + // make sure our environment also reflects the updated version + // this used to have a bug assertEquals(environment.getVersion(), updatedRemoteVersion); } @Test public void testNewRemoteBranch() throws Exception { - JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(TestConfiguration.class); + JGitConfigServerTestData testData = JGitConfigServerTestData + .prepareClonedGitRepository(TestConfiguration.class); Environment environment = testData.getRepository().findOne("bar", "staging", "master"); Object fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertEquals(fooProperty, "bar"); - testData.getServerGit().getGit().branchCreate() - .setName("testNewRemoteBranch") - .call(); + testData.getServerGit().getGit().branchCreate().setName("testNewRemoteBranch").call(); - testData.getServerGit().getGit().checkout() - .setName("testNewRemoteBranch") - .call(); + testData.getServerGit().getGit().checkout().setName("testNewRemoteBranch").call(); - //update the remote repo + // update the remote repo FileOutputStream out = new FileOutputStream( new File(testData.getServerGit().getGitWorkingDirectory(), "/bar.properties")); StreamUtils.copy("foo: branchBar", Charset.defaultCharset(), out); @@ -405,7 +387,8 @@ public class JGitEnvironmentRepositoryIntegrationTests { @Test public void testNewRemoteTag() throws Exception { - JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(TestConfiguration.class); + JGitConfigServerTestData testData = JGitConfigServerTestData + .prepareClonedGitRepository(TestConfiguration.class); Git serverGit = testData.getServerGit().getGit(); @@ -415,10 +398,10 @@ public class JGitEnvironmentRepositoryIntegrationTests { serverGit.checkout().setName("master").call(); - //create a new tag + // create a new tag serverGit.tag().setName("testTag").setMessage("Testing a tag").call(); - //update the remote repo + // update the remote repo FileOutputStream out = new FileOutputStream( new File(testData.getServerGit().getGitWorkingDirectory(), "/bar.properties")); StreamUtils.copy("foo: testAfterTag", Charset.defaultCharset(), out); @@ -433,50 +416,52 @@ public class JGitEnvironmentRepositoryIntegrationTests { fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertEquals(fooProperty, "bar"); - //now move the tag and test again - serverGit.tag().setName("testTag").setForceUpdate(true).setMessage("Testing a moved tag").call(); + // now move the tag and test again + serverGit.tag().setName("testTag").setForceUpdate(true).setMessage("Testing a moved tag").call(); - environment = testData.getRepository().findOne("bar", "staging", "testTag"); - fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); - assertEquals(fooProperty, "testAfterTag"); + environment = testData.getRepository().findOne("bar", "staging", "testTag"); + fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); + assertEquals(fooProperty, "testAfterTag"); } - @Test + @Test public void testNewCommitID() throws Exception { - JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(TestConfiguration.class); + JGitConfigServerTestData testData = JGitConfigServerTestData + .prepareClonedGitRepository(TestConfiguration.class); - //get our starting versions + // get our starting versions String startingRemoteVersion = getCommitID(testData.getServerGit().getGit(), "master"); - //make sure we get the right version out of the gate + // make sure we get the right version out of the gate Environment environment = testData.getRepository().findOne("bar", "staging", "master"); assertEquals(environment.getVersion(), startingRemoteVersion); - //update the remote repo - FileOutputStream out = new FileOutputStream(new File(testData.getServerGit().getGitWorkingDirectory(), "bar.properties")); + // update the remote repo + FileOutputStream out = new FileOutputStream( + new File(testData.getServerGit().getGitWorkingDirectory(), "bar.properties")); StreamUtils.copy("foo: barNewCommit", Charset.defaultCharset(), out); testData.getServerGit().getGit().add().addFilepattern("bar.properties").call(); testData.getServerGit().getGit().commit().setMessage("Updated for pull").call(); String updatedRemoteVersion = getCommitID(testData.getServerGit().getGit(), "master"); - //do a normal request and verify we get the new version + // do a normal request and verify we get the new version environment = testData.getRepository().findOne("bar", "staging", "master"); assertEquals(environment.getVersion(), updatedRemoteVersion); Object fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertEquals(fooProperty, "barNewCommit"); - //request the prior commit ID and make sure we get it + // request the prior commit ID and make sure we get it environment = testData.getRepository().findOne("bar", "staging", startingRemoteVersion); assertEquals(environment.getVersion(), startingRemoteVersion); fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertEquals(fooProperty, "bar"); } - @Test(expected = NoSuchLabelException.class) public void testUnknownLabelWithRemote() throws Exception { - JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(TestConfiguration.class); + JGitConfigServerTestData testData = JGitConfigServerTestData + .prepareClonedGitRepository(TestConfiguration.class); testData.getRepository().findOne("bar", "staging", "BADLabel"); } @@ -490,9 +475,9 @@ public class JGitEnvironmentRepositoryIntegrationTests { public void passphrase() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo("config-repo"); final String passphrase = "thisismypassphrase"; - this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) - .run("--spring.cloud.config.server.git.uri=" + uri, - "--spring.cloud.config.server.git.passphrase=" + passphrase); + this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false).run( + "--spring.cloud.config.server.git.uri=" + uri, + "--spring.cloud.config.server.git.passphrase=" + passphrase); JGitEnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class); assertThat(repository.getPassphrase(), Matchers.containsString(passphrase)); } @@ -501,9 +486,9 @@ public class JGitEnvironmentRepositoryIntegrationTests { public void strictHostKeyChecking() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo("config-repo"); final boolean strictHostKeyChecking = true; - this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) - .run("--spring.cloud.config.server.git.uri=" + uri, - "--spring.cloud.config.server.git.strict-host-key-checking=" + strictHostKeyChecking); + this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false).run( + "--spring.cloud.config.server.git.uri=" + uri, + "--spring.cloud.config.server.git.strict-host-key-checking=" + strictHostKeyChecking); JGitEnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class); assertEquals(repository.isStrictHostKeyChecking(), strictHostKeyChecking); } @@ -511,10 +496,8 @@ public class JGitEnvironmentRepositoryIntegrationTests { @Test public void shouldSetTransportConfigCallback() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo(); - this.context = new SpringApplicationBuilder(TestConfigurationWithTransportConfigCallback.class) - .web(false) - .properties("spring.cloud.config.server.git.uri:" + uri) - .run(); + this.context = new SpringApplicationBuilder(TestConfigurationWithTransportConfigCallback.class).web(false) + .properties("spring.cloud.config.server.git.uri:" + uri).run(); JGitEnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class); assertNotNull(repository.getTransportConfigCallback()); @@ -522,15 +505,13 @@ public class JGitEnvironmentRepositoryIntegrationTests { @Configuration @EnableConfigurationProperties(ConfigServerProperties.class) - @Import({ PropertyPlaceholderAutoConfiguration.class, - EnvironmentRepositoryConfiguration.class }) + @Import({ PropertyPlaceholderAutoConfiguration.class, EnvironmentRepositoryConfiguration.class }) protected static class TestConfiguration { } @Configuration @EnableConfigurationProperties(ConfigServerProperties.class) - @Import({ PropertyPlaceholderAutoConfiguration.class, - EnvironmentRepositoryConfiguration.class }) + @Import({ PropertyPlaceholderAutoConfiguration.class, EnvironmentRepositoryConfiguration.class }) protected static class TestConfigurationWithTransportConfigCallback { @Bean diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java index f8b430cd..ef105132 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java @@ -16,6 +16,21 @@ package org.springframework.cloud.config.server.environment; +import static junit.framework.TestCase.assertTrue; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockingDetails; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.io.File; import java.io.IOException; import java.lang.reflect.Method; @@ -48,6 +63,7 @@ import org.eclipse.jgit.transport.FetchResult; import org.eclipse.jgit.transport.JschConfigSessionFactory; import org.eclipse.jgit.transport.OpenSshConfig; import org.eclipse.jgit.transport.SshSessionFactory; +import org.eclipse.jgit.transport.TrackingRefUpdate; import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import org.eclipse.jgit.util.FS; @@ -66,21 +82,6 @@ import org.springframework.core.env.StandardEnvironment; import com.jcraft.jsch.Session; -import static junit.framework.TestCase.assertTrue; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockingDetails; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - /** * @author Dave Syer * @@ -88,8 +89,7 @@ import static org.mockito.Mockito.when; public class JGitEnvironmentRepositoryTests { private StandardEnvironment environment = new StandardEnvironment(); - private JGitEnvironmentRepository repository = new JGitEnvironmentRepository( - this.environment); + private JGitEnvironmentRepository repository = new JGitEnvironmentRepository(this.environment); private File basedir = new File("target/config"); @@ -110,8 +110,7 @@ public class JGitEnvironmentRepositoryTests { this.repository.findOne("bar", "staging", "master"); Environment environment = this.repository.findOne("bar", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); - assertEquals(this.repository.getUri() + "/bar.properties", - environment.getPropertySources().get(0).getName()); + assertEquals(this.repository.getUri() + "/bar.properties", environment.getPropertySources().get(0).getName()); assertVersion(environment); } @@ -119,7 +118,7 @@ public class JGitEnvironmentRepositoryTests { public void nested() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo"); this.repository.setUri(uri); - this.repository.setSearchPaths(new String[] {"sub"}); + this.repository.setSearchPaths(new String[] { "sub" }); this.repository.findOne("bar", "staging", "master"); Environment environment = this.repository.findOne("bar", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); @@ -132,7 +131,7 @@ public class JGitEnvironmentRepositoryTests { public void placeholderInSearchPath() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo"); this.repository.setUri(uri); - this.repository.setSearchPaths(new String[] {"{application}"}); + this.repository.setSearchPaths(new String[] { "{application}" }); this.repository.findOne("sub", "staging", "master"); Environment environment = this.repository.findOne("sub", "staging", "master"); assertEquals(1, environment.getPropertySources().size()); @@ -151,7 +150,7 @@ public class JGitEnvironmentRepositoryTests { public void nestedPattern() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo"); this.repository.setUri(uri); - this.repository.setSearchPaths(new String[] {"sub*"}); + this.repository.setSearchPaths(new String[] { "sub*" }); this.repository.findOne("bar", "staging", "master"); Environment environment = this.repository.findOne("bar", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); @@ -165,8 +164,7 @@ public class JGitEnvironmentRepositoryTests { this.repository.setBasedir(this.basedir); Environment environment = this.repository.findOne("bar", "staging", "raw"); assertEquals(2, environment.getPropertySources().size()); - assertEquals(this.repository.getUri() + "/bar.properties", - environment.getPropertySources().get(0).getName()); + assertEquals(this.repository.getUri() + "/bar.properties", environment.getPropertySources().get(0).getName()); assertVersion(environment); } @@ -175,8 +173,7 @@ public class JGitEnvironmentRepositoryTests { this.repository.setBasedir(this.basedir); Environment environment = this.repository.findOne("bar", "staging", "foo"); assertEquals(2, environment.getPropertySources().size()); - assertEquals(this.repository.getUri() + "/bar.properties", environment - .getPropertySources().get(0).getName()); + assertEquals(this.repository.getUri() + "/bar.properties", environment.getPropertySources().get(0).getName()); assertVersion(environment); } @@ -186,8 +183,7 @@ public class JGitEnvironmentRepositoryTests { this.repository.findOne("bar", "staging", "master"); Environment environment = this.repository.findOne("bar", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); - assertEquals(this.repository.getUri() + "/bar.properties", - environment.getPropertySources().get(0).getName()); + assertEquals(this.repository.getUri() + "/bar.properties", environment.getPropertySources().get(0).getName()); assertVersion(environment); } @@ -199,8 +195,7 @@ public class JGitEnvironmentRepositoryTests { this.repository.findOne("bar", "staging", "master"); Environment environment = this.repository.findOne("bar", "staging", "master"); assertEquals(2, environment.getPropertySources().size()); - assertEquals(this.repository.getUri() + "/bar.properties", - environment.getPropertySources().get(0).getName()); + assertEquals(this.repository.getUri() + "/bar.properties", environment.getPropertySources().get(0).getName()); assertVersion(environment); } @@ -217,16 +212,14 @@ public class JGitEnvironmentRepositoryTests { } @Test - public void afterPropertiesSet_CloneOnStartTrue_CloneAndFetchCalled() - throws Exception { + public void afterPropertiesSet_CloneOnStartTrue_CloneAndFetchCalled() throws Exception { Git mockGit = mock(Git.class); CloneCommand mockCloneCommand = mock(CloneCommand.class); when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand); when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand); - JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository( - this.environment); + JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment); envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand)); envRepository.setUri("http://somegitserver/somegitrepo"); envRepository.setCloneOnStart(true); @@ -235,16 +228,14 @@ public class JGitEnvironmentRepositoryTests { } @Test - public void afterPropertiesSet_CloneOnStartFalse_CloneAndFetchNotCalled() - throws Exception { + public void afterPropertiesSet_CloneOnStartFalse_CloneAndFetchNotCalled() throws Exception { Git mockGit = mock(Git.class); CloneCommand mockCloneCommand = mock(CloneCommand.class); when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand); when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand); - JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository( - this.environment); + JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment); envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand)); envRepository.setUri("http://somegitserver/somegitrepo"); envRepository.afterPropertiesSet(); @@ -253,16 +244,14 @@ public class JGitEnvironmentRepositoryTests { } @Test - public void afterPropertiesSet_CloneOnStartTrueWithFileURL_CloneAndFetchNotCalled() - throws Exception { + public void afterPropertiesSet_CloneOnStartTrueWithFileURL_CloneAndFetchNotCalled() throws Exception { Git mockGit = mock(Git.class); CloneCommand mockCloneCommand = mock(CloneCommand.class); when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand); when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand); - JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository( - this.environment); + JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment); envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand)); envRepository.setUri("file://somefilesystem/somegitrepo"); envRepository.setCloneOnStart(true); @@ -286,8 +275,7 @@ public class JGitEnvironmentRepositoryTests { when(statusCommand.call()).thenReturn(status); when(status.isClean()).thenReturn(false); - JGitEnvironmentRepository repo = new JGitEnvironmentRepository( - this.environment); + JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment); repo.setForcePull(true); boolean shouldPull = repo.shouldPull(git); @@ -310,8 +298,7 @@ public class JGitEnvironmentRepositoryTests { when(statusCommand.call()).thenReturn(status); when(status.isClean()).thenReturn(false); - JGitEnvironmentRepository repo = new JGitEnvironmentRepository( - this.environment); + JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment); boolean shouldPull = repo.shouldPull(git); @@ -333,8 +320,7 @@ public class JGitEnvironmentRepositoryTests { when(statusCommand.call()).thenReturn(status); when(status.isClean()).thenReturn(true); - JGitEnvironmentRepository repo = new JGitEnvironmentRepository( - this.environment); + JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment); boolean shouldPull = repo.shouldPull(git); @@ -347,11 +333,9 @@ public class JGitEnvironmentRepositoryTests { Git git = mock(Git.class); CloneCommand cloneCommand = mock(CloneCommand.class); MockGitFactory factory = new MockGitFactory(git, cloneCommand); - JGitEnvironmentRepository repo = new JGitEnvironmentRepository( - this.environment); this.repository.setGitFactory(factory); - //refresh()->shouldPull + // refresh()->shouldPull StatusCommand statusCommand = mock(StatusCommand.class); Status status = mock(Status.class); when(git.status()).thenReturn(statusCommand); @@ -363,15 +347,21 @@ public class JGitEnvironmentRepositoryTests { when(statusCommand.call()).thenReturn(status); when(status.isClean()).thenReturn(true); - //refresh()->fetch + // refresh()->fetch FetchCommand fetchCommand = mock(FetchCommand.class); when(git.fetch()).thenReturn(fetchCommand); when(fetchCommand.setRemote(anyString())).thenReturn(fetchCommand); - when(fetchCommand.call()).thenThrow(new InvalidRemoteException("invalid mock remote")); //here is our exception we are testing + when(fetchCommand.call()).thenThrow(new InvalidRemoteException("invalid mock remote")); // here + // is + // our + // exception + // we + // are + // testing - //refresh()->checkout + // refresh()->checkout CheckoutCommand checkoutCommand = mock(CheckoutCommand.class); - //refresh()->checkout->containsBranch + // refresh()->checkout->containsBranch ListBranchCommand listBranchCommand = mock(ListBranchCommand.class); when(git.checkout()).thenReturn(checkoutCommand); when(git.branchList()).thenReturn(listBranchCommand); @@ -381,20 +371,27 @@ public class JGitEnvironmentRepositoryTests { when(ref.getName()).thenReturn("/master"); when(listBranchCommand.call()).thenReturn(refs); - //refresh()->merge + // refresh()->merge MergeCommand mergeCommand = mock(MergeCommand.class); when(git.merge()).thenReturn(mergeCommand); - when(mergeCommand.call()).thenThrow(new NotMergedException()); //here is our exception we are testing + when(mergeCommand.call()).thenThrow(new NotMergedException()); // here + // is + // our + // exception + // we + // are + // testing - //refresh()->return git.getRepository().getRef("HEAD").getObjectId().getName(); + // refresh()->return + // git.getRepository().getRef("HEAD").getObjectId().getName(); Ref headRef = mock(Ref.class); - when(repository.getRef(anyString())).thenReturn(headRef); + when(repository.findRef(anyString())).thenReturn(headRef); - ObjectId newObjectId = ObjectId.fromRaw(new int[]{1,2,3,4,5}); + ObjectId newObjectId = ObjectId.fromRaw(new int[] { 1, 2, 3, 4, 5 }); when(headRef.getObjectId()).thenReturn(newObjectId); SearchPathLocator.Locations locations = this.repository.getLocations("bar", "staging", null); - assertEquals(locations.getVersion(),newObjectId.getName()); + assertEquals(locations.getVersion(), newObjectId.getName()); } @Test @@ -403,8 +400,6 @@ public class JGitEnvironmentRepositoryTests { Git git = mock(Git.class); CloneCommand cloneCommand = mock(CloneCommand.class); MockGitFactory factory = new MockGitFactory(git, cloneCommand); - JGitEnvironmentRepository repo = new JGitEnvironmentRepository( - this.environment); this.repository.setGitFactory(factory); //refresh()->shouldPull @@ -425,7 +420,7 @@ public class JGitEnvironmentRepositoryTests { when(git.fetch()).thenReturn(fetchCommand); when(fetchCommand.setRemote(anyString())).thenReturn(fetchCommand); when(fetchCommand.call()).thenReturn(fetchResult); - when(fetchResult.getTrackingRefUpdates()).thenReturn(Collections.EMPTY_LIST); + when(fetchResult.getTrackingRefUpdates()).thenReturn(Collections.emptyList()); //refresh()->checkout CheckoutCommand checkoutCommand = mock(CheckoutCommand.class); @@ -446,7 +441,7 @@ public class JGitEnvironmentRepositoryTests { //refresh()->return git.getRepository().getRef("HEAD").getObjectId().getName(); Ref headRef = mock(Ref.class); - when(repository.getRef(anyString())).thenReturn(headRef); + when(repository.findRef(anyString())).thenReturn(headRef); ObjectId newObjectId = ObjectId.fromRaw(new int[]{1,2,3,4,5}); when(headRef.getObjectId()).thenReturn(newObjectId); @@ -461,11 +456,9 @@ public class JGitEnvironmentRepositoryTests { Git git = mock(Git.class); CloneCommand cloneCommand = mock(CloneCommand.class); MockGitFactory factory = new MockGitFactory(git, cloneCommand); - JGitEnvironmentRepository repo = new JGitEnvironmentRepository( - this.environment); this.repository.setGitFactory(factory); - //refresh()->shouldPull + // refresh()->shouldPull StatusCommand statusCommand = mock(StatusCommand.class); Status status = mock(Status.class); when(git.status()).thenReturn(statusCommand); @@ -477,17 +470,17 @@ public class JGitEnvironmentRepositoryTests { when(statusCommand.call()).thenReturn(status); when(status.isClean()).thenReturn(true).thenReturn(false); - //refresh()->fetch + // refresh()->fetch FetchCommand fetchCommand = mock(FetchCommand.class); FetchResult fetchResult = mock(FetchResult.class); when(git.fetch()).thenReturn(fetchCommand); when(fetchCommand.setRemote(anyString())).thenReturn(fetchCommand); when(fetchCommand.call()).thenReturn(fetchResult); - when(fetchResult.getTrackingRefUpdates()).thenReturn(Collections.EMPTY_LIST); + when(fetchResult.getTrackingRefUpdates()).thenReturn(Collections.emptyList()); - //refresh()->checkout + // refresh()->checkout CheckoutCommand checkoutCommand = mock(CheckoutCommand.class); - //refresh()->checkout->containsBranch + // refresh()->checkout->containsBranch ListBranchCommand listBranchCommand = mock(ListBranchCommand.class); when(git.checkout()).thenReturn(checkoutCommand); when(git.branchList()).thenReturn(listBranchCommand); @@ -497,29 +490,36 @@ public class JGitEnvironmentRepositoryTests { when(ref.getName()).thenReturn("/master"); when(listBranchCommand.call()).thenReturn(refs); - //refresh()->merge + // refresh()->merge MergeCommand mergeCommand = mock(MergeCommand.class); when(git.merge()).thenReturn(mergeCommand); - when(mergeCommand.call()).thenThrow(new NotMergedException()); //here is our exception we are testing + when(mergeCommand.call()).thenThrow(new NotMergedException()); // here + // is + // our + // exception + // we + // are + // testing - //refresh()->hardReset + // refresh()->hardReset ResetCommand resetCommand = mock(ResetCommand.class); when(git.reset()).thenReturn(resetCommand); when(resetCommand.call()).thenReturn(ref); - //refresh()->return git.getRepository().getRef("HEAD").getObjectId().getName(); + // refresh()->return + // git.getRepository().getRef("HEAD").getObjectId().getName(); Ref headRef = mock(Ref.class); - when(repository.getRef(anyString())).thenReturn(headRef); + when(repository.findRef(anyString())).thenReturn(headRef); - ObjectId newObjectId = ObjectId.fromRaw(new int[]{1,2,3,4,5}); + ObjectId newObjectId = ObjectId.fromRaw(new int[] { 1, 2, 3, 4, 5 }); when(headRef.getObjectId()).thenReturn(newObjectId); SearchPathLocator.Locations locations = this.repository.getLocations("bar", "staging", "master"); - assertEquals(locations.getVersion(),newObjectId.getName()); + assertEquals(locations.getVersion(), newObjectId.getName()); } - + @Test - public void shouldDeleteBaseDirWhenCloneFails() throws Exception { + public void shouldDeleteBaseDirWhenCloneFails() throws Exception { Git mockGit = mock(Git.class); CloneCommand mockCloneCommand = mock(CloneCommand.class); @@ -527,19 +527,17 @@ public class JGitEnvironmentRepositoryTests { when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand); when(mockCloneCommand.call()).thenThrow(new TransportException("failed to clone")); - JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository( - this.environment); + JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment); envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand)); envRepository.setUri("http://somegitserver/somegitrepo"); envRepository.setBasedir(this.basedir); - + try { envRepository.findOne("bar", "staging", "master"); - } - catch (Exception ex) { + } catch (Exception ex) { // expected - ignore } - + assertFalse("baseDir should be deleted when clone fails", this.basedir.exists()); } @@ -592,13 +590,14 @@ public class JGitEnvironmentRepositoryTests { CredentialsProvider provider = mockCloneCommand.getCredentialsProvider(); assertFalse(provider.isInteractive()); - CredentialItem.StringType stringCredential = new CredentialItem.StringType(PassphraseCredentialsProvider.PROMPT, true); + CredentialItem.StringType stringCredential = new CredentialItem.StringType(PassphraseCredentialsProvider.PROMPT, + true); assertTrue(provider.supports(stringCredential)); provider.get(new URIish(), stringCredential); assertEquals(stringCredential.getValue(), passphrase); } - + @Test public void gitCredentialsProviderFactoryCreatesPassphraseProvider() throws Exception { final String passphrase = "mypassphrase"; @@ -620,7 +619,8 @@ public class JGitEnvironmentRepositoryTests { CredentialsProvider provider = mockCloneCommand.getCredentialsProvider(); assertFalse(provider.isInteractive()); - CredentialItem.StringType stringCredential = new CredentialItem.StringType(PassphraseCredentialsProvider.PROMPT, true); + CredentialItem.StringType stringCredential = new CredentialItem.StringType(PassphraseCredentialsProvider.PROMPT, + true); assertTrue(provider.supports(stringCredential)); provider.get(new URIish(), stringCredential); @@ -640,8 +640,8 @@ public class JGitEnvironmentRepositoryTests { envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand)); envRepository.setUri("git+ssh://git@somegitserver/somegitrepo"); envRepository.setBasedir(new File("./mybasedir")); - envRepository.setGitCredentialsProvider(credentialsFactory.createFor( - envRepository.getUri(), username, password, null)); + envRepository.setGitCredentialsProvider( + credentialsFactory.createFor(envRepository.getUri(), username, password, null)); envRepository.setCloneOnStart(true); envRepository.afterPropertiesSet(); @@ -665,12 +665,11 @@ public class JGitEnvironmentRepositoryTests { Git mockGit = mock(Git.class); MockCloneCommand mockCloneCommand = new MockCloneCommand(mockGit); final String awsUri = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test"; - + JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment); envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand)); envRepository.setUri(awsUri); - envRepository.setGitCredentialsProvider(credentialsFactory.createFor( - envRepository.getUri(), null, null, null)); + envRepository.setGitCredentialsProvider(credentialsFactory.createFor(envRepository.getUri(), null, null, null)); envRepository.setCloneOnStart(true); envRepository.afterPropertiesSet(); @@ -693,14 +692,17 @@ public class JGitEnvironmentRepositoryTests { } catch (Exception e) { final OpenSshConfig.Host hc = OpenSshConfig.get(FS.detect()).lookup("github.com"); JschConfigSessionFactory factory = (JschConfigSessionFactory) SshSessionFactory.getInstance(); - // There's no public method that can be used to inspect the ssh configuration, so we'll reflect - // the configure method to allow us to check that the config property is set as expected. - Method configure = factory.getClass().getDeclaredMethod("configure", OpenSshConfig.Host.class, Session.class ); + // There's no public method that can be used to inspect the ssh + // configuration, so we'll reflect + // the configure method to allow us to check that the config + // property is set as expected. + Method configure = factory.getClass().getDeclaredMethod("configure", OpenSshConfig.Host.class, + Session.class); configure.setAccessible(true); Session session = mock(Session.class); ArgumentCaptor keyCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor valueCaptor = ArgumentCaptor.forClass(String.class); - configure.invoke(factory, hc, session ); + configure.invoke(factory, hc, session); verify(session).setConfig(keyCaptor.capture(), valueCaptor.capture()); configure.setAccessible(false); assertTrue("yes".equals(valueCaptor.getValue())); @@ -710,7 +712,7 @@ public class JGitEnvironmentRepositoryTests { @Test public void shouldPrintStacktraceIfDebugEnabled() throws Exception { final Log mockLogger = mock(Log.class); - JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment){ + JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment) { @Override public void afterPropertiesSet() throws Exception { this.logger = mockLogger; @@ -774,13 +776,12 @@ public class JGitEnvironmentRepositoryTests { } } - class MockGitFactory extends JGitEnvironmentRepository.JGitFactory { private Git mockGit; private CloneCommand mockCloneCommand; - public MockGitFactory (Git mockGit, CloneCommand mockCloneCommand) { + public MockGitFactory(Git mockGit, CloneCommand mockCloneCommand) { this.mockGit = mockGit; this.mockCloneCommand = mockCloneCommand; } From 0da1397153bf3f57c64185aeead67116a344eac1 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 26 Jun 2017 16:58:25 +0100 Subject: [PATCH 25/26] Add optional decryption to bootstrap config server Fixes gh-434 --- .../ConfigServerBootstrapConfiguration.java | 27 +++++++- .../encryption/LocatorTextEncryptor.java | 61 ++++++++++++++++++ .../main/resources/META-INF/spring.factories | 4 +- ...BootstrapConfigServerIntegrationTests.java | 8 ++- .../src/test/resources/enable-bootstrap.yml | 10 ++- .../resources/encrypt-repo/application.yml | 9 +++ .../resources/encrypt-repo/bar.properties | 1 + .../resources/encrypt-repo/git/COMMIT_EDITMSG | 1 + .../resources/encrypt-repo/git/FETCH_HEAD | 2 + .../src/test/resources/encrypt-repo/git/HEAD | 1 + .../test/resources/encrypt-repo/git/config | 5 ++ .../resources/encrypt-repo/git/gitk.cache | 3 + .../src/test/resources/encrypt-repo/git/index | Bin 0 -> 225 bytes .../test/resources/encrypt-repo/git/logs/HEAD | 7 ++ .../git/logs/refs/heads/composite | 1 + .../encrypt-repo/git/logs/refs/heads/master | 2 + .../encrypt-repo/git/logs/refs/heads/raw | 1 + .../13/b76fa2acbef52a002372071d08d7967fee9146 | Bin 0 -> 419 bytes .../ad/5e0cb7036ed11ddd4b7be6ed86ad3565c8a3fc | 4 ++ .../e7/7c14ccb5f9e49c11b6d4172b76b0d3cf4cef56 | Bin 0 -> 98 bytes ...edd2290fa647beaa1255881228dc90c1d53fce.idx | Bin 0 -> 1268 bytes ...dd2290fa647beaa1255881228dc90c1d53fce.pack | Bin 0 -> 571 bytes .../encrypt-repo/git/refs/heads/composite | 1 + .../encrypt-repo/git/refs/heads/master | 1 + .../resources/encrypt-repo/git/refs/heads/raw | 1 + .../resources/encrypt-repo/git/refs/tags/foo | 1 + 26 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/encryption/LocatorTextEncryptor.java create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/application.yml create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/bar.properties create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/COMMIT_EDITMSG create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/FETCH_HEAD create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/HEAD create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/config create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/gitk.cache create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/index create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/HEAD create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/refs/heads/composite create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/refs/heads/master create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/refs/heads/raw create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/objects/13/b76fa2acbef52a002372071d08d7967fee9146 create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/objects/ad/5e0cb7036ed11ddd4b7be6ed86ad3565c8a3fc create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/objects/e7/7c14ccb5f9e49c11b6d4172b76b0d3cf4cef56 create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/objects/pack/pack-d4edd2290fa647beaa1255881228dc90c1d53fce.idx create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/objects/pack/pack-d4edd2290fa647beaa1255881228dc90c1d53fce.pack create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/heads/composite create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/heads/master create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/heads/raw create mode 100644 spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/tags/foo diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/bootstrap/ConfigServerBootstrapConfiguration.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/bootstrap/ConfigServerBootstrapConfiguration.java index 326cb108..3845f31c 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/bootstrap/ConfigServerBootstrapConfiguration.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/bootstrap/ConfigServerBootstrapConfiguration.java @@ -15,17 +15,22 @@ */ package org.springframework.cloud.config.server.bootstrap; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.config.client.ConfigClientProperties; import org.springframework.cloud.config.server.config.ConfigServerProperties; import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration; +import org.springframework.cloud.config.server.encryption.LocatorTextEncryptor; import org.springframework.cloud.config.server.environment.EnvironmentRepository; import org.springframework.cloud.config.server.environment.EnvironmentRepositoryPropertySourceLocator; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.security.crypto.encrypt.TextEncryptor; import org.springframework.util.StringUtils; /** @@ -39,9 +44,27 @@ import org.springframework.util.StringUtils; * @author Roy Clarkson */ @Configuration -public class ConfigServerBootstrapConfiguration { +@ConditionalOnProperty("spring.cloud.config.server.bootstrap") +public class ConfigServerBootstrapConfiguration implements BeanPostProcessor { + + @Autowired + private BeanFactory beanFactory; + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) + throws BeansException { + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) + throws BeansException { + if (bean instanceof TextEncryptor && !(bean instanceof LocatorTextEncryptor)) { + return new LocatorTextEncryptor(beanFactory); + } + return bean; + } - @ConditionalOnProperty("spring.cloud.config.server.bootstrap") @EnableConfigurationProperties(ConfigServerProperties.class) @Import(EnvironmentRepositoryConfiguration.class) protected static class LocalPropertySourceLocatorConfiguration { diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/encryption/LocatorTextEncryptor.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/encryption/LocatorTextEncryptor.java new file mode 100644 index 00000000..6c4b5497 --- /dev/null +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/encryption/LocatorTextEncryptor.java @@ -0,0 +1,61 @@ +/* + * Copyright 2012-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.config.server.encryption; + +import java.util.Map; + +import org.springframework.beans.factory.BeanFactory; +import org.springframework.security.crypto.encrypt.TextEncryptor; + +/** + * @author Dave Syer + * + */ +public class LocatorTextEncryptor implements TextEncryptor { + + private EnvironmentPrefixHelper helper = new EnvironmentPrefixHelper(); + + private TextEncryptorLocator locator; + + private BeanFactory beanFactory; + + public LocatorTextEncryptor(BeanFactory beanFactory) { + this.beanFactory = beanFactory; + } + + @Override + public String encrypt(String text) { + Map keys = helper.getEncryptorKeys("configserver", "default", + text); + return getLocator().locate(keys).encrypt(helper.stripPrefix(text)); + } + + private TextEncryptorLocator getLocator() { + if (locator == null) { + locator = beanFactory.getBean(TextEncryptorLocator.class); + } + return locator; + } + + @Override + public String decrypt(String encryptedText) { + Map keys = helper.getEncryptorKeys("configserver", "default", + encryptedText); + return getLocator().locate(keys).decrypt(helper.stripPrefix(encryptedText)); + } + +} \ No newline at end of file diff --git a/spring-cloud-config-server/src/main/resources/META-INF/spring.factories b/spring-cloud-config-server/src/main/resources/META-INF/spring.factories index 94a0bb01..7b893f04 100644 --- a/spring-cloud-config-server/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-config-server/src/main/resources/META-INF/spring.factories @@ -1,6 +1,8 @@ # Bootstrap components org.springframework.cloud.bootstrap.BootstrapConfiguration=\ -org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapConfiguration +org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapConfiguration,\ +org.springframework.cloud.config.server.config.EncryptionAutoConfiguration,\ +org.springframework.cloud.config.server.config.SingleEncryptorAutoConfiguration # Application listeners org.springframework.context.ApplicationListener=\ diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java index 5a215621..571a60fa 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java @@ -20,7 +20,7 @@ import static org.junit.Assert.assertFalse; @RunWith(SpringRunner.class) @SpringBootTest(classes = ConfigServerApplication.class, properties = "spring.cloud.bootstrap.name:enable-bootstrap", webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ActiveProfiles("test") +@ActiveProfiles({"test", "encrypt"}) public class BootstrapConfigServerIntegrationTests { @LocalServerPort @@ -29,9 +29,12 @@ public class BootstrapConfigServerIntegrationTests { @Value("${info.foo}") private String foo; + @Value("${config.foo}") + private String config; + @BeforeClass public static void init() throws IOException { - ConfigServerTestUtils.prepareLocalRepo(); + ConfigServerTestUtils.prepareLocalRepo("encrypt-repo"); } @Test @@ -46,6 +49,7 @@ public class BootstrapConfigServerIntegrationTests { @Test public void environmentBootstraps() throws Exception { assertEquals("bar", foo); + assertEquals("foo", config); } } diff --git a/spring-cloud-config-server/src/test/resources/enable-bootstrap.yml b/spring-cloud-config-server/src/test/resources/enable-bootstrap.yml index c780b861..f587c9bb 100644 --- a/spring-cloud-config-server/src/test/resources/enable-bootstrap.yml +++ b/spring-cloud-config-server/src/test/resources/enable-bootstrap.yml @@ -3,5 +3,11 @@ spring: config: server: git: - uri: file:./target/repos/config-repo - bootstrap: true \ No newline at end of file + uri: file:./target/repos/encrypt-repo + bootstrap: true +encrypt: + key-store: + location: classpath:server.jks + password: letmein + secret: changeme + \ No newline at end of file diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/application.yml b/spring-cloud-config-server/src/test/resources/encrypt-repo/application.yml new file mode 100644 index 00000000..13b76fa2 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/application.yml @@ -0,0 +1,9 @@ +info: + foo: bar + +--- +spring: + profiles: encrypt +config: + foo: '{cipher}{key:mytestkey}AQCohs2V6P8/UiG6a4TF/CZTCBdt5Q7wvNvcyf6vs2ByK2ZYSM77Nu0sOAduxUpMbVwJ/syecmkIXR+hU3EfT2uqPieA7/v5n33ppqIQ9JAt5JggdYIGe+wX25zU3DTXOOJdAAMzNX+zjOVyCh0QtmJf/kFslg6NqQq0E+kSg3zBi3AnkKj5BLnLIxkjxzKA4mnDXpSm7ekLZZP2iQSYSW/82AC7UOLLzTqwInMI3tJLW1e9Ne+LDsjmSxA+nkK9zhidtXPwb/SPaNF74cJCEf9mgzzKYwJlwqChLzJt8UQ1jHwRc8B6FufmizUHSp27nxdtVB4HMqh3nNsMCy137Ces58T09ZS/y/cYNRxcFbp78MHFHUqAgbC0B/p5t6h4XbQ=' + diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/bar.properties b/spring-cloud-config-server/src/test/resources/encrypt-repo/bar.properties new file mode 100644 index 00000000..7daacd5d --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/bar.properties @@ -0,0 +1 @@ +foo: bar \ No newline at end of file diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/COMMIT_EDITMSG b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/COMMIT_EDITMSG new file mode 100644 index 00000000..a6b4e397 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/COMMIT_EDITMSG @@ -0,0 +1 @@ +Add encrypted property diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/FETCH_HEAD b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/FETCH_HEAD new file mode 100644 index 00000000..527abd40 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/FETCH_HEAD @@ -0,0 +1,2 @@ +7df4a26d5437d9d4090cd5809967f870444cde8f not-for-merge branch 'raw' of dsyer@localhost:/home/dsyer/dev/platform/config/spring-platform-config-server/target/test-classes/config-repo +7df4a26d5437d9d4090cd5809967f870444cde8f not-for-merge tag 'foo' of dsyer@localhost:/home/dsyer/dev/platform/config/spring-platform-config-server/target/test-classes/config-repo diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/HEAD b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/HEAD new file mode 100644 index 00000000..cb089cd8 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/config b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/config new file mode 100644 index 00000000..9b73bf82 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/config @@ -0,0 +1,5 @@ +[core] + repositoryformatversion = 0 + filemode = true + logallrefupdates = true +[branch "raw"] diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/gitk.cache b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/gitk.cache new file mode 100644 index 00000000..b420ccba --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/gitk.cache @@ -0,0 +1,3 @@ +1 1 +7df4a26d5437d9d4090cd5809967f870444cde8f 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 +1 diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/index b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/index new file mode 100644 index 0000000000000000000000000000000000000000..e9aa8984d9074f5937eac605850199482121aaa1 GIT binary patch literal 225 zcmZ?q402{*U|<5_$UrSS;cIHnAX@P4y)6t39Lx-PZqpeU8kaCIFu#Cc#)rb&^B1kz z_f?BQxrkksOEUBG^eS_6fCfeeYAob5c3ldiA?CTJqngLS zQM>AF?2gOX$L>$lm1R6V<3^$V(<2OgNr^>z1x5J 1406860717 -0700 +7df4a26d5437d9d4090cd5809967f870444cde8f 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 Ryan Baxter 1481905383 -0500 checkout: moving from raw to master +9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 7df4a26d5437d9d4090cd5809967f870444cde8f Ryan Baxter 1481905407 -0500 checkout: moving from master to raw +7df4a26d5437d9d4090cd5809967f870444cde8f 7df4a26d5437d9d4090cd5809967f870444cde8f Ryan Baxter 1481905544 -0500 checkout: moving from raw to composite +7df4a26d5437d9d4090cd5809967f870444cde8f 7df4a26d5437d9d4090cd5809967f870444cde8f Ryan Baxter 1481905552 -0500 checkout: moving from composite to raw +7df4a26d5437d9d4090cd5809967f870444cde8f 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 Dave Syer 1498491043 +0100 checkout: moving from raw to master +9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 ad5e0cb7036ed11ddd4b7be6ed86ad3565c8a3fc Dave Syer 1498491468 +0100 commit: Add encrypted property diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/refs/heads/composite b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/refs/heads/composite new file mode 100644 index 00000000..67ab67c5 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/refs/heads/composite @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 7df4a26d5437d9d4090cd5809967f870444cde8f Ryan Baxter 1481905474 -0500 branch: Created from raw diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/refs/heads/master b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/refs/heads/master new file mode 100644 index 00000000..4310fccd --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/refs/heads/master @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 Dave Syer 1406860776 -0700 branch: Created from 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 +9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 ad5e0cb7036ed11ddd4b7be6ed86ad3565c8a3fc Dave Syer 1498491468 +0100 commit: Add encrypted property diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/refs/heads/raw b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/refs/heads/raw new file mode 100644 index 00000000..c6423ee9 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/logs/refs/heads/raw @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 7df4a26d5437d9d4090cd5809967f870444cde8f Dave Syer 1406860717 -0700 diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/objects/13/b76fa2acbef52a002372071d08d7967fee9146 b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/objects/13/b76fa2acbef52a002372071d08d7967fee9146 new file mode 100644 index 0000000000000000000000000000000000000000..c7dc2ed291e7723add5566f1f038efc55962de6f GIT binary patch literal 419 zcmV;U0bKrg0UeCXj;cTaMDLofa5oELK;D|%1)z)|pa?kVPM~>+G>zQ~^kn{h%&e+% zDyPzWm(C<@@vnwOx0*4tS<$^Sy*?ObKA$rfJ!)94-W)x;qP_#XngN(SCPbL5gGK$f z{W%}sS&b_2`1x+Yv}z{;FnPBhJutfp3n%5EadG{rT&2k3%u8e%IgtZ(c=@kvDwG!% zjADB16wT-QD7CoH|~Pm@{k0co9rYb<;(6~7O9e#16lDN>^rb=d4~ zvf)D49-G@pce>QVb%MfH1&w>T9E3Uu&*2xR3A(Aqd)K8=KiJT-MdG+$3$XM7>#p&w z4M&}QpDk%s=Oj4{DHk5DzNJc;V{VFNTT;3^56*q)&B~$(+&D&brxYx_nTK+e%h|{7Pt%oUJU!z^q5ab%00Vv` E*SY2}r~m)} literal 0 HcmV?d00001 diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/objects/pack/pack-d4edd2290fa647beaa1255881228dc90c1d53fce.idx b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/objects/pack/pack-d4edd2290fa647beaa1255881228dc90c1d53fce.idx new file mode 100644 index 0000000000000000000000000000000000000000..2a25a7b0f49bb3301f87fdd20b4f5483efb77b94 GIT binary patch literal 1268 zcmexg;-AdGz`z8=qhRQU03*=puc7<+*;Da_(wf&?^4Gd zcTa|Hzu?!fUU5(UcBxDI{{oY_ED-+zhA9uQ*y07!i-7!UAij}eze-KC`oQCBoWK7) ipY^Zw_QYqOd2MI>an7H=ylg|9Z^`1arT4GC`3e9D%Xqc` literal 0 HcmV?d00001 diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/objects/pack/pack-d4edd2290fa647beaa1255881228dc90c1d53fce.pack b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/objects/pack/pack-d4edd2290fa647beaa1255881228dc90c1d53fce.pack new file mode 100644 index 0000000000000000000000000000000000000000..a082f3c195a8a659f954b8d0d48c6eb842604f63 GIT binary patch literal 571 zcmWG=boORoU|<4b_G!EobLO7*? zfAH!c`+D;|mH zE06MQU48D@yB%|C-~2O)jXZYQI8Wr3y)6^NDOc58Jf>&Nukbh=e87KMZIF9F>ZB<;}YE6zg78P^6PoLi&B=T-ni!0YS@lxvSE-3sA9#F?^Y_2!v;LLdp7`uD0IeVdkpKVy literal 0 HcmV?d00001 diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/heads/composite b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/heads/composite new file mode 100644 index 00000000..4389eb3a --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/heads/composite @@ -0,0 +1 @@ +7df4a26d5437d9d4090cd5809967f870444cde8f diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/heads/master b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/heads/master new file mode 100644 index 00000000..ae0c4a61 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/heads/master @@ -0,0 +1 @@ +ad5e0cb7036ed11ddd4b7be6ed86ad3565c8a3fc diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/heads/raw b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/heads/raw new file mode 100644 index 00000000..4389eb3a --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/heads/raw @@ -0,0 +1 @@ +7df4a26d5437d9d4090cd5809967f870444cde8f diff --git a/spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/tags/foo b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/tags/foo new file mode 100644 index 00000000..4389eb3a --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/encrypt-repo/git/refs/tags/foo @@ -0,0 +1 @@ +7df4a26d5437d9d4090cd5809967f870444cde8f From 4db8f48233f51796474566c0e9e0c41779af9d86 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 27 Jun 2017 10:50:55 +0100 Subject: [PATCH 26/26] Send 404 if repository does not exist --- .../environment/EnvironmentController.java | 3 +- .../JGitEnvironmentRepository.java | 5 +- .../NoSuchRepositoryException.java | 34 +++++++++ ...EnvironmentControllerIntegrationTests.java | 74 +++++++++++-------- 4 files changed, 83 insertions(+), 33 deletions(-) create mode 100644 spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NoSuchRepositoryException.java diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java index b5f6e53d..f5d20db1 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java @@ -42,6 +42,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import org.yaml.snakeyaml.DumperOptions.FlowStyle; import org.yaml.snakeyaml.Yaml; @@ -223,7 +224,7 @@ public class EnvironmentController { return rootMap; } - @ExceptionHandler(NoSuchLabelException.class) + @ExceptionHandler(RepositoryException.class) public void noSuchLabel(HttpServletResponse response) throws IOException { response.sendError(HttpStatus.NOT_FOUND.value()); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java index f94cd97e..c28370de 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java @@ -39,6 +39,7 @@ import org.eclipse.jgit.api.TransportCommand; import org.eclipse.jgit.api.TransportConfigCallback; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.RefNotFoundException; +import org.eclipse.jgit.errors.NoRemoteRepositoryException; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.FetchResult; @@ -208,8 +209,10 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository return git.getRepository().findRef("HEAD").getObjectId().getName(); } catch (RefNotFoundException e) { throw new NoSuchLabelException("No such label: " + label, e); + } catch (NoRemoteRepositoryException e) { + throw new NoSuchRepositoryException("No such repository: " + getUri(), e); } catch (GitAPIException e) { - throw new IllegalStateException("Cannot clone or checkout repository", e); + throw new NoSuchRepositoryException("Cannot clone or checkout repository: " + getUri(), e); } catch (Exception e) { throw new IllegalStateException("Cannot load environment", e); } finally { diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NoSuchRepositoryException.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NoSuchRepositoryException.java new file mode 100644 index 00000000..19aad8b3 --- /dev/null +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NoSuchRepositoryException.java @@ -0,0 +1,34 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.config.server.environment; + +/** + * @author Dave Syer + * + */ +@SuppressWarnings("serial") +public class NoSuchRepositoryException extends RepositoryException { + + public NoSuchRepositoryException(String string) { + super(string); + } + + public NoSuchRepositoryException(String string, Exception e) { + super(string, e); + } + +} diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java index 6a9e373a..96001840 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.environment.EnvironmentControllerIntegrationTests.ControllerConfiguration; @@ -60,71 +60,83 @@ public class EnvironmentControllerIntegrationTests { @Test public void environmentNoLabel() throws Exception { - Mockito.when(this.repository.findOne("foo", "default", null)).thenReturn( - new Environment("foo", "default")); - this.mvc.perform(MockMvcRequestBuilders.get("/foo/default")).andExpect( - MockMvcResultMatchers.status().isOk()); + Mockito.when(this.repository.findOne("foo", "default", null)).thenReturn(new Environment("foo", "default")); + this.mvc.perform(MockMvcRequestBuilders.get("/foo/default")).andExpect(MockMvcResultMatchers.status().isOk()); Mockito.verify(this.repository).findOne("foo", "default", null); } @Test public void propertiesNoLabel() throws Exception { - Mockito.when(this.repository.findOne("foo", "default", null)).thenReturn( - new Environment("foo", "default")); - this.mvc.perform(MockMvcRequestBuilders.get("/foo-default.properties")).andExpect( - MockMvcResultMatchers.status().isOk()); + Mockito.when(this.repository.findOne("foo", "default", null)).thenReturn(new Environment("foo", "default")); + this.mvc.perform(MockMvcRequestBuilders.get("/foo-default.properties")) + .andExpect(MockMvcResultMatchers.status().isOk()); Mockito.verify(this.repository).findOne("foo", "default", null); } @Test public void propertiesLabel() throws Exception { - Mockito.when(this.repository.findOne("foo", "default", "label")).thenReturn( - new Environment("foo", "default")); - this.mvc.perform(MockMvcRequestBuilders.get("/label/foo-default.properties")).andExpect( - MockMvcResultMatchers.status().isOk()); + Mockito.when(this.repository.findOne("foo", "default", "label")).thenReturn(new Environment("foo", "default")); + this.mvc.perform(MockMvcRequestBuilders.get("/label/foo-default.properties")) + .andExpect(MockMvcResultMatchers.status().isOk()); Mockito.verify(this.repository).findOne("foo", "default", "label"); } @Test public void propertiesLabelWhenApplicationNameContainsHyphen() throws Exception { - Mockito.when(this.repository.findOne("foo-bar", "default", "label")).thenReturn(new Environment("foo-bar", "default")); - this.mvc.perform(MockMvcRequestBuilders.get("/label/foo-bar-default.properties")).andExpect( - MockMvcResultMatchers.status().isOk()); + Mockito.when(this.repository.findOne("foo-bar", "default", "label")) + .thenReturn(new Environment("foo-bar", "default")); + this.mvc.perform(MockMvcRequestBuilders.get("/label/foo-bar-default.properties")) + .andExpect(MockMvcResultMatchers.status().isOk()); Mockito.verify(this.repository).findOne("foo-bar", "default", "label"); } @Test public void propertiesLabelWithSlash() throws Exception { - Mockito.when(this.repository.findOne("foo", "default", "label/spam")).thenReturn( - new Environment("foo", "default")); - this.mvc.perform(MockMvcRequestBuilders.get("/label(_)spam/foo-default.properties")).andExpect( - MockMvcResultMatchers.status().isOk()); + Mockito.when(this.repository.findOne("foo", "default", "label/spam")) + .thenReturn(new Environment("foo", "default")); + this.mvc.perform(MockMvcRequestBuilders.get("/label(_)spam/foo-default.properties")) + .andExpect(MockMvcResultMatchers.status().isOk()); Mockito.verify(this.repository).findOne("foo", "default", "label/spam"); } @Test public void environmentWithLabel() throws Exception { - Mockito.when(this.repository.findOne("foo", "default", "awesome")).thenReturn( - new Environment("foo", "default")); - this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/awesome")).andExpect( - MockMvcResultMatchers.status().isOk()); + Mockito.when(this.repository.findOne("foo", "default", "awesome")) + .thenReturn(new Environment("foo", "default")); + this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/awesome")) + .andExpect(MockMvcResultMatchers.status().isOk()); + } + + @Test + public void environmentWithMissingLabel() throws Exception { + Mockito.when(this.repository.findOne("foo", "default", "missing")) + .thenThrow(new NoSuchLabelException("Planned")); + this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/missing")) + .andExpect(MockMvcResultMatchers.status().isNotFound()); + } + + @Test + public void environmentWithMissingRepo() throws Exception { + Mockito.when(this.repository.findOne("foo", "default", "missing")) + .thenThrow(new NoSuchRepositoryException("Planned")); + this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/missing")) + .andExpect(MockMvcResultMatchers.status().isNotFound()); } @Test public void environmentWithLabelContainingPeriod() throws Exception { - Mockito.when(this.repository.findOne("foo", "default", "1.0.0")).thenReturn( - new Environment("foo", "default")); - this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/1.0.0")).andExpect( - MockMvcResultMatchers.status().isOk()); + Mockito.when(this.repository.findOne("foo", "default", "1.0.0")).thenReturn(new Environment("foo", "default")); + this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/1.0.0")) + .andExpect(MockMvcResultMatchers.status().isOk()); } @Test public void environmentWithLabelContainingSlash() throws Exception { Mockito.when(this.repository.findOne("foo", "default", "feature/puff")) - .thenReturn(new Environment("foo", "default")); + .thenReturn(new Environment("foo", "default")); this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/feature(_)puff")) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("\"propertySources\":"))); + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("\"propertySources\":"))); } @Configuration