Add a switch to fail on no stubs (#1153)

* Add a switch to fail on no stubs

without this change we throw an exception if no stubs / contracts were found
with this change we catch exceptions from aether stub downloader and if there are no stubs found whatsover, and a switch is set to fail in that case, then we do throw an exception that no stubs / contracts were found

fixes gh-895
This commit is contained in:
Marcin Grzejszczak
2019-08-06 11:54:52 +02:00
committed by GitHub
parent 4f652ad1e6
commit 4ae133a0f8
20 changed files with 182 additions and 41 deletions

View File

@@ -267,7 +267,8 @@ class ContractVerifierExtension {
password: this.contractRepository.password,
proxyPort: this.contractRepository.proxyPort,
proxyHost: this.contractRepository.proxyHost,
cacheDownloadedContracts: this.contractRepository.cacheDownloadedContracts
cacheDownloadedContracts: this.contractRepository.cacheDownloadedContracts,
failOnNoStubs: this.contractRepository.failOnNoStubs
),
contractDependency: new Dependency(
groupId: this.contractDependency.groupId,
@@ -366,6 +367,12 @@ class ContractVerifierExtension {
*/
boolean cacheDownloadedContracts = true
/**
* When enabled, this flag will tell stub runner to throw an exception when no stubs /
* contracts were found.
*/
boolean failOnNoStubs = true
void repositoryUrl(String repositoryUrl) {
this.repositoryUrl = repositoryUrl
}
@@ -389,5 +396,9 @@ class ContractVerifierExtension {
void cacheDownloadedContracts(boolean cacheDownloadedContracts) {
this.cacheDownloadedContracts = cacheDownloadedContracts
}
void failOnNoStubs(boolean failOnNoStubs) {
this.failOnNoStubs = failOnNoStubs
}
}
}

View File

@@ -91,6 +91,7 @@ class GradleContractsDownloader {
if (extension.contractRepository.proxyPort) {
options = options.withProxy(extension.contractRepository.proxyHost, extension.contractRepository.proxyPort)
}
options = options.withFailOnNoStubs(extension.contractRepository.failOnNoStubs)
return options.build()
}

View File

@@ -181,6 +181,13 @@ public class ConvertMojo extends AbstractMojo {
@Component(role = MavenResourcesFiltering.class, hint = "default")
private MavenResourcesFiltering mavenResourcesFiltering;
/**
* When enabled, this flag will tell stub runner to throw an exception when no stubs /
* contracts were found.
*/
@Parameter(property = "failOnNoStubs", defaultValue = "true")
private boolean failOnNoStubs;
@Override
public void execute() throws MojoExecutionException {
if (this.skip) {
@@ -271,8 +278,9 @@ public class ConvertMojo extends AbstractMojo {
getLog(), this.contractsRepositoryUsername,
this.contractsRepositoryPassword, this.contractsRepositoryProxyHost,
this.contractsRepositoryProxyPort, this.deleteStubsAfterTest,
this.contractsProperties).downloadAndUnpackContractsIfRequired(config,
this.contractsDirectory);
this.contractsProperties, this.failOnNoStubs)
.downloadAndUnpackContractsIfRequired(config,
this.contractsDirectory);
}
private File stubsOutputDir(String rootPath) {

View File

@@ -229,6 +229,13 @@ public class GenerateTestsMojo extends AbstractMojo {
@Parameter(property = "contractsProperties")
private Map<String, String> contractsProperties = new HashMap<>();
/**
* When enabled, this flag will tell stub runner to throw an exception when no stubs /
* contracts were found.
*/
@Parameter(property = "failOnNoStubs", defaultValue = "true")
private boolean failOnNoStubs;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (this.skip || this.mavenTestSkip || this.skipTests) {
@@ -258,8 +265,9 @@ public class GenerateTestsMojo extends AbstractMojo {
this.contractsMode, getLog(), this.contractsRepositoryUsername,
this.contractsRepositoryPassword, this.contractsRepositoryProxyHost,
this.contractsRepositoryProxyPort, this.deleteStubsAfterTest,
this.contractsProperties).downloadAndUnpackContractsIfRequired(config,
this.contractsDirectory);
this.contractsProperties, this.failOnNoStubs)
.downloadAndUnpackContractsIfRequired(config,
this.contractsDirectory);
getLog().info(
"Directory with contract is present at [" + contractsDirectory + "]");
setupConfig(config, contractsDirectory);

View File

@@ -71,12 +71,14 @@ class MavenContractsDownloader {
private final Map<String, String> contractsProperties;
private final boolean failOnNoStubs;
MavenContractsDownloader(MavenProject project, Dependency contractDependency,
String contractsPath, String contractsRepositoryUrl,
StubRunnerProperties.StubsMode stubsMode, Log log, String repositoryUsername,
String repositoryPassword, String repositoryProxyHost,
Integer repositoryProxyPort, boolean deleteStubsAfterTest,
Map<String, String> contractsProperties) {
Map<String, String> contractsProperties, boolean failOnNoStubs) {
this.project = project;
this.contractDependency = contractDependency;
this.contractsPath = contractsPath;
@@ -90,6 +92,7 @@ class MavenContractsDownloader {
this.stubDownloaderBuilderProvider = new StubDownloaderBuilderProvider();
this.deleteStubsAfterTest = deleteStubsAfterTest;
this.contractsProperties = contractsProperties;
this.failOnNoStubs = failOnNoStubs;
}
File downloadAndUnpackContractsIfRequired(ContractVerifierConfigProperties config,
@@ -144,7 +147,8 @@ class MavenContractsDownloader {
.withStubsMode(this.stubsMode).withUsername(this.repositoryUsername)
.withPassword(this.repositoryPassword)
.withDeleteStubsAfterTest(this.deleteStubsAfterTest)
.withProperties(this.contractsProperties);
.withProperties(this.contractsProperties)
.withFailOnNoStubs(this.failOnNoStubs);
if (StringUtils.hasText(this.contractsRepositoryUrl)) {
builder.withStubRepositoryRoot(this.contractsRepositoryUrl);
}