Merge branch 'master' into 2.0.x

This commit is contained in:
Marcin Grzejszczak
2017-11-23 17:47:40 +01:00
6 changed files with 81 additions and 19 deletions

View File

@@ -79,7 +79,7 @@ effect on the stubs loaded explicitly from the `stubs` attribute.
For a more conventional WireMock experience, you can use JUnit `@Rules` to start and stop
the server. To do so, use the `WireMockSpring` convenience class to obtain an `Options`
instance, as shown in the followin example:
instance, as shown in the following example:
[source,java,indent=0]
----

View File

@@ -582,17 +582,12 @@ the following options:
Defaults to `groupid/artifactid` where `gropuid` is slash separated.
* *contractsWorkOffline*: Dictates whether the dependencies should be downloaded or the
local Maven artifacts should be reused.
* *contractsRepositoryUrl*: *DEPRECATED PROPERTY - please use the `contractRepository`
closure*: URL to a repo with the artifacts that have contracts. If it is not provided,
* *contractsRepositoryUrl*: URL to a repo with the artifacts that have contracts. If it is not provided,
use the current Maven ones.
* *contractRepository* - Lets you use a closure where you can define properties related
to repository with contracts.
* *username*: The user name to be used to connect to the repo.
* *password*: The password to be used to connect to the repo.
* *proxyHost*: The proxy host to be used to connect to the repo.
* *proxyPort*: The proxy port to be used to connect to the repo.
* *cacheDownloadedContracts* - Specifies whether to reuse downloaded JARs that contain
contract definitions.
* *contractsRepositoryUsername*: The user name to be used to connect to the repo with contracts.
* *contractsRepositoryPassword*: The password to be used to connect to the repo with contracts.
* *contractsRepositoryProxyHost*: The proxy host to be used to connect to the repo with contracts.
* *contractsRepositoryProxyPort*: The proxy port to be used to connect to the repo with contracts.
We cache only non-snapshot, explicitly provided versions (for example
`+` or `1.0.0.BUILD-SNAPSHOT` won't get cached). By default, this feature is turned on.

View File

@@ -1,10 +1,12 @@
package org.springframework.cloud.contract.verifier.plugin
import java.util.concurrent.ConcurrentHashMap
import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import org.gradle.api.Project
import org.gradle.api.logging.Logger
import org.springframework.cloud.contract.stubrunner.AetherStubDownloader
import org.springframework.cloud.contract.stubrunner.ContractDownloader
import org.springframework.cloud.contract.stubrunner.StubConfiguration
import org.springframework.cloud.contract.stubrunner.StubDownloader
@@ -13,8 +15,6 @@ import org.springframework.cloud.contract.stubrunner.StubRunnerOptions
import org.springframework.cloud.contract.stubrunner.StubRunnerOptionsBuilder
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
import org.springframework.util.StringUtils
import java.util.concurrent.ConcurrentHashMap
/**
* @author Marcin Grzejszczak
*/
@@ -76,6 +76,7 @@ class GradleContractsDownloader {
protected StubDownloader stubDownloader(ContractVerifierExtension extension) {
StubDownloaderBuilderProvider provider = new StubDownloaderBuilderProvider()
StubRunnerOptionsBuilder options = new StubRunnerOptionsBuilder()
.withOptions(StubRunnerOptions.fromSystemProps())
.withStubRepositoryRoot(extension.contractRepository.repositoryUrl)
.withWorkOffline(extension.contractsWorkOffline)
.withUsername(extension.contractRepository.username)

View File

@@ -116,6 +116,30 @@ public class ConvertMojo extends AbstractMojo {
@Parameter(property = "excludeBuildFolders", defaultValue = "false")
private boolean excludeBuildFolders;
/**
* The user name to be used to connect to the repo with contracts.
*/
@Parameter(property = "contractsRepositoryUsername")
private String contractsRepositoryUsername;
/**
* The password to be used to connect to the repo with contracts.
*/
@Parameter(property = "contractsRepositoryPassword")
private String contractsRepositoryPassword;
/**
* The proxy host to be used to connect to the repo with contracts.
*/
@Parameter(property = "contractsRepositoryProxyHost")
private String contractsRepositoryProxyHost;
/**
* The proxy port to be used to connect to the repo with contracts.
*/
@Parameter(property = "contractsRepositoryProxyPort")
private Integer contractsRepositoryProxyPort;
@Component(role = MavenResourcesFiltering.class, hint = "default")
private MavenResourcesFiltering mavenResourcesFiltering;
@@ -142,7 +166,8 @@ public class ConvertMojo extends AbstractMojo {
config.setExcludeBuildFolders(this.excludeBuildFolders);
File contractsDirectory = new MavenContractsDownloader(this.project, this.contractDependency,
this.contractsPath, this.contractsRepositoryUrl, this.contractsWorkOffline, getLog(),
this.aetherStubDownloaderFactory, this.repoSession).downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
this.aetherStubDownloaderFactory, this.repoSession, this.contractsRepositoryUsername,
this.contractsRepositoryPassword, this.contractsRepositoryProxyHost, this.contractsRepositoryProxyPort).downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
getLog().info("Directory with contract is present at [" + contractsDirectory + "]");
new CopyContracts(this.project, this.mavenSession, this.mavenResourcesFiltering, config)

View File

@@ -171,6 +171,30 @@ public class GenerateTestsMojo extends AbstractMojo {
@Parameter(property = "baseClassMappings")
private List<BaseClassMapping> baseClassMappings;
/**
* The user name to be used to connect to the repo with contracts.
*/
@Parameter(property = "contractsRepositoryUsername")
private String contractsRepositoryUsername;
/**
* The password to be used to connect to the repo with contracts.
*/
@Parameter(property = "contractsRepositoryPassword")
private String contractsRepositoryPassword;
/**
* The proxy host to be used to connect to the repo with contracts.
*/
@Parameter(property = "contractsRepositoryProxyHost")
private String contractsRepositoryProxyHost;
/**
* The proxy port to be used to connect to the repo with contracts.
*/
@Parameter(property = "contractsRepositoryProxyPort")
private Integer contractsRepositoryProxyPort;
private final AetherStubDownloaderFactory aetherStubDownloaderFactory;
@Inject
@@ -191,7 +215,9 @@ public class GenerateTestsMojo extends AbstractMojo {
// download contracts, unzip them and pass as output directory
File contractsDirectory = new MavenContractsDownloader(this.project, this.contractDependency,
this.contractsPath, this.contractsRepositoryUrl, this.contractsWorkOffline, getLog(),
this.aetherStubDownloaderFactory, this.repoSession).downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
this.aetherStubDownloaderFactory, this.repoSession,
this.contractsRepositoryUsername, this.contractsRepositoryPassword,
this.contractsRepositoryProxyHost, this.contractsRepositoryProxyPort).downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
getLog().info("Directory with contract is present at [" + contractsDirectory + "]");
setupConfig(config, contractsDirectory);
this.project.addTestCompileSourceRoot(this.generatedTestSourcesDir.getAbsolutePath());

View File

@@ -39,12 +39,18 @@ class MavenContractsDownloader {
private final AetherStubDownloaderFactory aetherStubDownloaderFactory;
private final RepositorySystemSession repoSession;
private final StubDownloaderBuilderProvider stubDownloaderBuilderProvider;
private final String repositoryUsername;
private final String repositoryPassword;
private final String repositoryProxyHost;
private final Integer repositoryProxyPort;
MavenContractsDownloader(MavenProject project, Dependency contractDependency,
String contractsPath, String contractsRepositoryUrl,
boolean contractsWorkOffline, Log log,
AetherStubDownloaderFactory aetherStubDownloaderFactory,
RepositorySystemSession repoSession) {
RepositorySystemSession repoSession, String repositoryUsername,
String repositoryPassword, String repositoryProxyHost,
Integer repositoryProxyPort) {
this.project = project;
this.contractDependency = contractDependency;
this.contractsPath = contractsPath;
@@ -53,6 +59,10 @@ class MavenContractsDownloader {
this.log = log;
this.aetherStubDownloaderFactory = aetherStubDownloaderFactory;
this.repoSession = repoSession;
this.repositoryUsername = repositoryUsername;
this.repositoryPassword = repositoryPassword;
this.repositoryProxyHost = repositoryProxyHost;
this.repositoryProxyPort = repositoryProxyPort;
this.stubDownloaderBuilderProvider = new StubDownloaderBuilderProvider();
}
@@ -113,11 +123,16 @@ class MavenContractsDownloader {
}
StubRunnerOptions buildOptions() {
return new StubRunnerOptionsBuilder()
StubRunnerOptionsBuilder builder = new StubRunnerOptionsBuilder()
.withOptions(StubRunnerOptions.fromSystemProps())
.withStubRepositoryRoot(this.contractsRepositoryUrl)
.withWorkOffline(this.contractsWorkOffline)
.build();
.withUsername(this.repositoryUsername)
.withPassword(this.repositoryPassword);
if (this.repositoryProxyPort != null) {
builder.withProxy(this.repositoryProxyHost, this.repositoryProxyPort);
}
return builder.build();
}
private StubConfiguration stubConfiguration() {