Merge branch '1.0.x'

This commit is contained in:
Marcin Grzejszczak
2017-02-28 13:12:27 +01:00
7 changed files with 89 additions and 8 deletions

View File

@@ -4,7 +4,7 @@
= Spring Cloud Contract
_Documentation Authors: Adam Dudczak, Mathias Düsterhöft, Marcin Grzejszczak, Jakub Kubryński, Karol Lassak,
_Documentation Authors: Adam Dudczak, Mathias Düsterhöft, Marcin Grzejszczak, Dennis Kieselhorst, Jakub Kubryński, Karol Lassak,
Olga Maciaszek-Sharma, Mariusz Smykuła, Dave Syer_
{spring-cloud-version}

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-build</artifactId>
<version>1.2.2.BUILD-SNAPSHOT</version>
<version>1.2.3.BUILD-SNAPSHOT</version>
<relativePath/>
</parent>

View File

@@ -168,6 +168,11 @@
<artifactId>maven-aether-provider</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings-builder</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<profiles>

View File

@@ -127,6 +127,11 @@ include::src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/Stu
Check the *Common properties for JUnit and Spring* for more information on how to apply global configuration of Stub Runner.
==== Maven settings
The stub downloader honors Maven settings for a different local repository folder.
Authentication details for repositories and profiles are currently not taken into account, so you need to specify it using the properties mentioned above.
==== Providing fixed ports
You can also run your stubs on fixed ports. You can do it in two different ways. One is to pass it in the properties, and the other via fluent API of
@@ -306,4 +311,4 @@ include::src/test/groovy/org/springframework/cloud/contract/stubrunner/serverexa
That way your deployed application can send requests to started WireMock servers via the service
discovery. Most likely points 1-3 could be set by default in `application.yml` cause they are not
likely to change. That way you can provide only the list of stubs to download whenever you start
the Stub Runner Boot.
the Stub Runner Boot.

View File

@@ -90,6 +90,10 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings-builder</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@@ -16,7 +16,16 @@
package org.springframework.cloud.contract.stubrunner;
import java.io.File;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.building.DefaultSettingsBuilderFactory;
import org.apache.maven.settings.building.DefaultSettingsBuildingRequest;
import org.apache.maven.settings.building.SettingsBuilder;
import org.apache.maven.settings.building.SettingsBuildingException;
import org.apache.maven.settings.building.SettingsBuildingRequest;
import org.apache.maven.settings.building.SettingsBuildingResult;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
@@ -32,6 +41,8 @@ import org.eclipse.aether.transport.http.HttpTransporterFactory;
class AetherFactories {
private static final String MAVEN_LOCAL_REPOSITORY_LOCATION = "maven.repo.local";
private static final String MAVEN_USER_SETTINGS_LOCATION = "org.apache.maven.user-settings";
private static final String MAVEN_GLOBAL_SETTINGS_LOCATION = "org.apache.maven.global-settings";
public static RepositorySystem newRepositorySystem() {
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
@@ -54,7 +65,33 @@ class AetherFactories {
}
private static String localRepositoryDirectory() {
return System.getProperty(MAVEN_LOCAL_REPOSITORY_LOCATION, System.getProperty("user.home") + "/.m2/repository");
String localRepoLocationFromSettings = settings().getLocalRepository();
return System.getProperty(MAVEN_LOCAL_REPOSITORY_LOCATION, localRepoLocationFromSettings != null
? localRepoLocationFromSettings
: System.getProperty("user.home") + File.separator + ".m2" + File.separator + "repository");
}
private static Settings settings() {
SettingsBuilder builder = new DefaultSettingsBuilderFactory().newInstance();
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
String user = System.getProperty(MAVEN_USER_SETTINGS_LOCATION);
if (user == null) {
request.setUserSettingsFile(new File(new File(System.getProperty("user.home")).getAbsoluteFile(),
File.separator + ".m2" + File.separator + "settings.xml"));
} else {
request.setUserSettingsFile(new File(user));
}
String global = System.getProperty(MAVEN_GLOBAL_SETTINGS_LOCATION);
if (global != null) {
request.setGlobalSettingsFile(new File(global));
}
SettingsBuildingResult result;
try {
result = builder.build(request);
} catch (SettingsBuildingException ex) {
throw new IllegalStateException(ex);
}
return result.getEffectiveSettings();
}
}

View File

@@ -1,9 +1,12 @@
package org.springframework.cloud.contract.stubrunner
import io.specto.hoverfly.junit.HoverflyRule
import org.eclipse.aether.RepositorySystemSession;
import org.junit.Rule
import org.springframework.util.ResourceUtils
import spock.lang.Specification
import spock.util.environment.RestoreSystemProperties
class AetherStubDownloaderSpec extends Specification {
@@ -12,19 +15,46 @@ class AetherStubDownloaderSpec extends Specification {
def 'Should be able to download from a repository using username and password authentication'() {
given:
final StubRunnerOptions stubRunnerOptions = new StubRunnerOptionsBuilder()
StubRunnerOptions stubRunnerOptions = new StubRunnerOptionsBuilder()
.withUsername("andrew.morgan")
.withPassword("k+hbZp8rpolRucXB09dGE/CxPXxidQryQUYSGbeo6JE=")
.withProxy("localhost", hoverflyRule.proxyPort)
.withStubRepositoryRoot("https://test.jfrog.io/test/libs-snapshot-local")
.build()
final AetherStubDownloader aetherStubDownloader = new AetherStubDownloader(stubRunnerOptions)
AetherStubDownloader aetherStubDownloader = new AetherStubDownloader(stubRunnerOptions)
when:
final def jar = aetherStubDownloader.downloadAndUnpackStubJar(new StubConfiguration("io.test", "test-simulations-svc", "1.0-SNAPSHOT"))
def jar = aetherStubDownloader.downloadAndUnpackStubJar(new StubConfiguration("io.test", "test-simulations-svc", "1.0-SNAPSHOT"))
then:
jar != null
}
@RestoreSystemProperties
def 'Should use local repository from settings.xml'() {
given:
File tempSettings = File.createTempFile("settings", ".xml")
def m2repoFolder = 'm2repo' + File.separator + 'repository'
tempSettings.text = '<settings><localRepository>' +
ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + m2repoFolder).getAbsolutePath() + '</localRepository></settings>'
System.setProperty("org.apache.maven.user-settings", tempSettings.getAbsolutePath())
RepositorySystemSession repositorySystemSession =
AetherFactories.newSession(AetherFactories.newRepositorySystem(), true);
and:
StubRunnerOptions stubRunnerOptions = new StubRunnerOptionsBuilder()
.withWorkOffline(true)
.build()
AetherStubDownloader aetherStubDownloader = new AetherStubDownloader(stubRunnerOptions)
when:
def jar = aetherStubDownloader.downloadAndUnpackStubJar(
new StubConfiguration("org.springframework.cloud.contract.verifier.stubs",
"bootService", "0.0.1-SNAPSHOT"))
then:
jar != null
repositorySystemSession.getLocalRepository().getBasedir().getAbsolutePath().endsWith(m2repoFolder)
}
}