maven now fails when no contracts present in the contracts folder; fixes 1846
This commit is contained in:
@@ -41,6 +41,7 @@ import org.springframework.cloud.contract.verifier.TestGenerator;
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties;
|
||||
import org.springframework.cloud.contract.verifier.config.TestFramework;
|
||||
import org.springframework.cloud.contract.verifier.config.TestMode;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* From the provided directory with contracts generates the acceptance tests on the
|
||||
@@ -274,6 +275,7 @@ public class GenerateTestsMojo extends AbstractMojo {
|
||||
this.contractsRepositoryProxyPort, this.deleteStubsAfterTest, this.contractsProperties,
|
||||
this.failOnNoContracts).downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
|
||||
getLog().info("Directory with contract is present at [" + contractsDirectory + "]");
|
||||
throwExceptionWhenFailOnNoContracts(contractsDirectory, this.contractsRepositoryUrl);
|
||||
|
||||
if (this.incrementalContractTests
|
||||
&& !ChangeDetector.inputFilesChangeDetected(contractsDirectory, mojoExecution, session)) {
|
||||
@@ -307,6 +309,22 @@ public class GenerateTestsMojo extends AbstractMojo {
|
||||
}
|
||||
}
|
||||
|
||||
private void throwExceptionWhenFailOnNoContracts(File file, String contractsRepository)
|
||||
throws MojoExecutionException {
|
||||
if (StringUtils.hasText(contractsRepository)) {
|
||||
if (getLog().isDebugEnabled()) {
|
||||
getLog().debug(
|
||||
"Contracts repository is set, will not throw an exception that the contracts are not found");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (this.failOnNoContracts && (!file.exists() || file.listFiles().length == 0)) {
|
||||
String path = file.getAbsolutePath();
|
||||
throw new MojoExecutionException("Contracts could not be found: [" + path
|
||||
+ "]\nPlease make sure that the contracts were defined, or set the [failOnNoContracts] property to [false]");
|
||||
}
|
||||
}
|
||||
|
||||
private void setupConfig(ContractVerifierConfigProperties config, File contractsDirectory) {
|
||||
config.setContractsDslDir(contractsDirectory);
|
||||
config.setGeneratedTestSourcesDir(this.generatedTestSourcesDir);
|
||||
|
||||
Reference in New Issue
Block a user