Bumping versions
This commit is contained in:
@@ -54,29 +54,25 @@ public class BaseClassMapping {
|
||||
return false;
|
||||
}
|
||||
BaseClassMapping that = (BaseClassMapping) o;
|
||||
if (this.contractPackageRegex != null
|
||||
? !this.contractPackageRegex.equals(that.contractPackageRegex)
|
||||
if (this.contractPackageRegex != null ? !this.contractPackageRegex.equals(that.contractPackageRegex)
|
||||
: that.contractPackageRegex != null) {
|
||||
return false;
|
||||
}
|
||||
return this.baseClassFQN != null ? this.baseClassFQN.equals(that.baseClassFQN)
|
||||
: that.baseClassFQN == null;
|
||||
return this.baseClassFQN != null ? this.baseClassFQN.equals(that.baseClassFQN) : that.baseClassFQN == null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = this.contractPackageRegex != null
|
||||
? this.contractPackageRegex.hashCode() : 0;
|
||||
result = 31 * result
|
||||
+ (this.baseClassFQN != null ? this.baseClassFQN.hashCode() : 0);
|
||||
int result = this.contractPackageRegex != null ? this.contractPackageRegex.hashCode() : 0;
|
||||
result = 31 * result + (this.baseClassFQN != null ? this.baseClassFQN.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BaseClassMapping{" + "contractPackageRegex='" + this.contractPackageRegex
|
||||
+ '\'' + ", baseClassFQN='" + this.baseClassFQN + '\'' + '}';
|
||||
return "BaseClassMapping{" + "contractPackageRegex='" + this.contractPackageRegex + '\'' + ", baseClassFQN='"
|
||||
+ this.baseClassFQN + '\'' + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,12 +29,10 @@ final class ChangeDetector {
|
||||
private ChangeDetector() {
|
||||
}
|
||||
|
||||
static boolean inputFilesChangeDetected(File contractsDirectory,
|
||||
MojoExecution mojoExecution, MavenSession session)
|
||||
static boolean inputFilesChangeDetected(File contractsDirectory, MojoExecution mojoExecution, MavenSession session)
|
||||
throws MojoExecutionException {
|
||||
|
||||
IncrementalBuildHelper incrementalBuildHelper = new IncrementalBuildHelper(
|
||||
mojoExecution, session);
|
||||
IncrementalBuildHelper incrementalBuildHelper = new IncrementalBuildHelper(mojoExecution, session);
|
||||
|
||||
DirectoryScanner scanner = incrementalBuildHelper.getDirectoryScanner();
|
||||
scanner.setBasedir(contractsDirectory);
|
||||
|
||||
@@ -48,8 +48,7 @@ import static org.springframework.cloud.contract.maven.verifier.ChangeDetector.i
|
||||
*
|
||||
* @author Mariusz Smykula
|
||||
*/
|
||||
@Mojo(name = "convert", requiresProject = false,
|
||||
defaultPhase = LifecyclePhase.PROCESS_TEST_RESOURCES)
|
||||
@Mojo(name = "convert", requiresProject = false, defaultPhase = LifecyclePhase.PROCESS_TEST_RESOURCES)
|
||||
public class ConvertMojo extends AbstractMojo {
|
||||
|
||||
static final String DEFAULT_STUBS_DIR = "${project.build.directory}/stubs/";
|
||||
@@ -222,58 +221,50 @@ public class ConvertMojo extends AbstractMojo {
|
||||
File contractsDirectory = locationOfContracts(config);
|
||||
contractsDirectory = contractSubfolderIfPresent(contractsDirectory);
|
||||
|
||||
if (this.incrementalContractStubs && !inputFilesChangeDetected(contractsDirectory,
|
||||
mojoExecution, session)) {
|
||||
if (this.incrementalContractStubs && !inputFilesChangeDetected(contractsDirectory, mojoExecution, session)) {
|
||||
getLog().info("Nothing to generate - all stubs are up to date");
|
||||
return;
|
||||
}
|
||||
|
||||
File contractsDslDir = contractsDslDir(contractsDirectory);
|
||||
LeftOverPrevention leftOverPrevention = new LeftOverPrevention(
|
||||
this.stubsDirectory, mojoExecution, session);
|
||||
LeftOverPrevention leftOverPrevention = new LeftOverPrevention(this.stubsDirectory, mojoExecution, session);
|
||||
|
||||
File copiedContracts = copyContracts(rootPath, config, contractsDirectory);
|
||||
if (this.convertToYaml) {
|
||||
contractsDslDir = copiedContracts;
|
||||
convertBackedUpDslsToYaml(rootPath, config, contractsDirectory,
|
||||
contractsDslDir);
|
||||
convertBackedUpDslsToYaml(rootPath, config, contractsDirectory, contractsDslDir);
|
||||
}
|
||||
config.setContractsDslDir(contractsDslDir);
|
||||
config.setStubsOutputDir(stubsOutputDir(rootPath));
|
||||
logSetup(config, contractsDslDir);
|
||||
RecursiveFilesConverter converter = new RecursiveFilesConverter(
|
||||
config.getStubsOutputDir(), config.getContractsDslDir(),
|
||||
config.getExcludedFiles(), config.getIncludedContracts(),
|
||||
RecursiveFilesConverter converter = new RecursiveFilesConverter(config.getStubsOutputDir(),
|
||||
config.getContractsDslDir(), config.getExcludedFiles(), config.getIncludedContracts(),
|
||||
config.isExcludeBuildFolders());
|
||||
converter.processFiles();
|
||||
leftOverPrevention.deleteLeftOvers();
|
||||
}
|
||||
|
||||
private void convertBackedUpDslsToYaml(String rootPath,
|
||||
ContractVerifierConfigProperties config, File contractsDirectory,
|
||||
File contractsDslDir) throws MojoExecutionException {
|
||||
private void convertBackedUpDslsToYaml(String rootPath, ContractVerifierConfigProperties config,
|
||||
File contractsDirectory, File contractsDslDir) throws MojoExecutionException {
|
||||
copyOriginals(rootPath, config, contractsDirectory);
|
||||
ToYamlConverter.replaceContractWithYaml(contractsDslDir);
|
||||
getLog().info("Replaced DSL files with their YAML representation at ["
|
||||
+ contractsDslDir + "]");
|
||||
getLog().info("Replaced DSL files with their YAML representation at [" + contractsDslDir + "]");
|
||||
}
|
||||
|
||||
private File copyOriginals(String rootPath, ContractVerifierConfigProperties config,
|
||||
File contractsDirectory) throws MojoExecutionException {
|
||||
File outputFolderWithOriginals = new File(this.stubsDirectory,
|
||||
rootPath + ORIGINAL_PATH);
|
||||
new CopyContracts(this.project, this.mavenSession, this.mavenResourcesFiltering,
|
||||
config).copy(contractsDirectory, outputFolderWithOriginals);
|
||||
private File copyOriginals(String rootPath, ContractVerifierConfigProperties config, File contractsDirectory)
|
||||
throws MojoExecutionException {
|
||||
File outputFolderWithOriginals = new File(this.stubsDirectory, rootPath + ORIGINAL_PATH);
|
||||
new CopyContracts(this.project, this.mavenSession, this.mavenResourcesFiltering, config)
|
||||
.copy(contractsDirectory, outputFolderWithOriginals);
|
||||
return outputFolderWithOriginals;
|
||||
}
|
||||
|
||||
private File copyContracts(String rootPath, ContractVerifierConfigProperties config,
|
||||
File contractsDirectory) throws MojoExecutionException {
|
||||
File outputFolderWithContracts = this.stubsDirectory.getPath()
|
||||
.endsWith("contracts") ? this.stubsDirectory
|
||||
: new File(this.stubsDirectory, rootPath + CONTRACTS_PATH);
|
||||
new CopyContracts(this.project, this.mavenSession, this.mavenResourcesFiltering,
|
||||
config).copy(contractsDirectory, outputFolderWithContracts);
|
||||
private File copyContracts(String rootPath, ContractVerifierConfigProperties config, File contractsDirectory)
|
||||
throws MojoExecutionException {
|
||||
File outputFolderWithContracts = this.stubsDirectory.getPath().endsWith("contracts") ? this.stubsDirectory
|
||||
: new File(this.stubsDirectory, rootPath + CONTRACTS_PATH);
|
||||
new CopyContracts(this.project, this.mavenSession, this.mavenResourcesFiltering, config)
|
||||
.copy(contractsDirectory, outputFolderWithContracts);
|
||||
return outputFolderWithContracts;
|
||||
}
|
||||
|
||||
@@ -281,21 +272,17 @@ public class ConvertMojo extends AbstractMojo {
|
||||
if (getLog().isDebugEnabled()) {
|
||||
getLog().debug("The contracts dir equals [" + contractsDslDir + "]");
|
||||
}
|
||||
getLog().info(
|
||||
"Converting from Spring Cloud Contract Verifier contracts to WireMock stubs mappings");
|
||||
getLog().info(String.format(
|
||||
" Spring Cloud Contract Verifier contracts directory: %s",
|
||||
getLog().info("Converting from Spring Cloud Contract Verifier contracts to WireMock stubs mappings");
|
||||
getLog().info(String.format(" Spring Cloud Contract Verifier contracts directory: %s",
|
||||
config.getContractsDslDir()));
|
||||
getLog().info(String.format("Stub Server stubs mappings directory: %s",
|
||||
config.getStubsOutputDir()));
|
||||
getLog().info(String.format("Stub Server stubs mappings directory: %s", config.getStubsOutputDir()));
|
||||
}
|
||||
|
||||
private File contractSubfolderIfPresent(File contractsDirectory) {
|
||||
File contractsSubFolder = new File(contractsDirectory, "contracts");
|
||||
if (contractsSubFolder.exists()) {
|
||||
if (getLog().isDebugEnabled()) {
|
||||
getLog().debug(
|
||||
"The subfolder [contracts] exists, will pick it as a source of contracts");
|
||||
getLog().debug("The subfolder [contracts] exists, will pick it as a source of contracts");
|
||||
}
|
||||
contractsDirectory = contractsSubFolder;
|
||||
}
|
||||
@@ -303,19 +290,15 @@ public class ConvertMojo extends AbstractMojo {
|
||||
}
|
||||
|
||||
private File locationOfContracts(ContractVerifierConfigProperties config) {
|
||||
return new MavenContractsDownloader(this.project, this.contractDependency,
|
||||
this.contractsPath, this.contractsRepositoryUrl, this.contractsMode,
|
||||
getLog(), this.contractsRepositoryUsername,
|
||||
this.contractsRepositoryPassword, this.contractsRepositoryProxyHost,
|
||||
this.contractsRepositoryProxyPort, this.deleteStubsAfterTest,
|
||||
this.contractsProperties, this.failOnNoContracts)
|
||||
.downloadAndUnpackContractsIfRequired(config,
|
||||
this.contractsDirectory);
|
||||
return new MavenContractsDownloader(this.project, this.contractDependency, this.contractsPath,
|
||||
this.contractsRepositoryUrl, this.contractsMode, getLog(), this.contractsRepositoryUsername,
|
||||
this.contractsRepositoryPassword, this.contractsRepositoryProxyHost, this.contractsRepositoryProxyPort,
|
||||
this.deleteStubsAfterTest, this.contractsProperties, this.failOnNoContracts)
|
||||
.downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
|
||||
}
|
||||
|
||||
private File stubsOutputDir(String rootPath) {
|
||||
return isInsideProject() ? new File(this.stubsDirectory, rootPath + MAPPINGS_PATH)
|
||||
: this.destination;
|
||||
return isInsideProject() ? new File(this.stubsDirectory, rootPath + MAPPINGS_PATH) : this.destination;
|
||||
}
|
||||
|
||||
private File contractsDslDir(File contractsDirectory) {
|
||||
|
||||
@@ -43,8 +43,7 @@ class CopyContracts {
|
||||
|
||||
private final ContractVerifierConfigProperties config;
|
||||
|
||||
CopyContracts(MavenProject project, MavenSession mavenSession,
|
||||
MavenResourcesFiltering mavenResourcesFiltering,
|
||||
CopyContracts(MavenProject project, MavenSession mavenSession, MavenResourcesFiltering mavenResourcesFiltering,
|
||||
ContractVerifierConfigProperties config) {
|
||||
this.project = project;
|
||||
this.mavenSession = mavenSession;
|
||||
@@ -52,18 +51,14 @@ class CopyContracts {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void copy(File contractsDirectory, File outputDirectory)
|
||||
throws MojoExecutionException {
|
||||
log.info("Copying Spring Cloud Contract Verifier contracts to [" + outputDirectory
|
||||
+ "]" + ". Only files matching [" + this.config.getIncludedContracts()
|
||||
+ "] pattern will end up in " + "the final JAR with stubs.");
|
||||
public void copy(File contractsDirectory, File outputDirectory) throws MojoExecutionException {
|
||||
log.info("Copying Spring Cloud Contract Verifier contracts to [" + outputDirectory + "]"
|
||||
+ ". Only files matching [" + this.config.getIncludedContracts() + "] pattern will end up in "
|
||||
+ "the final JAR with stubs.");
|
||||
Resource resource = new Resource();
|
||||
String includedRootFolderAntPattern = this.config
|
||||
.getIncludedRootFolderAntPattern() + "*.*";
|
||||
String slashSeparatedGroupIdAntPattern = slashSeparatedGroupIdAntPattern(
|
||||
includedRootFolderAntPattern);
|
||||
String dotSeparatedGroupIdAntPattern = dotSeparatedGroupIdAntPattern(
|
||||
includedRootFolderAntPattern);
|
||||
String includedRootFolderAntPattern = this.config.getIncludedRootFolderAntPattern() + "*.*";
|
||||
String slashSeparatedGroupIdAntPattern = slashSeparatedGroupIdAntPattern(includedRootFolderAntPattern);
|
||||
String dotSeparatedGroupIdAntPattern = dotSeparatedGroupIdAntPattern(includedRootFolderAntPattern);
|
||||
// by default group id is slash separated...
|
||||
resource.addInclude(slashSeparatedGroupIdAntPattern);
|
||||
if (!slashSeparatedGroupIdAntPattern.equals(dotSeparatedGroupIdAntPattern)) {
|
||||
@@ -101,8 +96,7 @@ class CopyContracts {
|
||||
return includedRootFolderAntPattern;
|
||||
}
|
||||
else if (includedRootFolderAntPattern.contains(dotSeparatedGroupId())) {
|
||||
return includedRootFolderAntPattern.replace(dotSeparatedGroupId(),
|
||||
slashSeparatedGroupId());
|
||||
return includedRootFolderAntPattern.replace(dotSeparatedGroupId(), slashSeparatedGroupId());
|
||||
}
|
||||
return includedRootFolderAntPattern;
|
||||
}
|
||||
@@ -112,8 +106,7 @@ class CopyContracts {
|
||||
return includedRootFolderAntPattern;
|
||||
}
|
||||
else if (includedRootFolderAntPattern.contains(slashSeparatedGroupId())) {
|
||||
return includedRootFolderAntPattern.replace(slashSeparatedGroupId(),
|
||||
dotSeparatedGroupId());
|
||||
return includedRootFolderAntPattern.replace(slashSeparatedGroupId(), dotSeparatedGroupId());
|
||||
}
|
||||
return includedRootFolderAntPattern;
|
||||
}
|
||||
|
||||
@@ -43,20 +43,16 @@ import static org.springframework.cloud.contract.maven.verifier.ChangeDetector.i
|
||||
*
|
||||
* @author Mariusz Smykula
|
||||
*/
|
||||
@Mojo(name = "generateStubs", defaultPhase = LifecyclePhase.PACKAGE,
|
||||
requiresProject = true)
|
||||
@Mojo(name = "generateStubs", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true)
|
||||
public class GenerateStubsMojo extends AbstractMojo {
|
||||
|
||||
@Parameter(defaultValue = "${project.build.directory}", readonly = true,
|
||||
required = true)
|
||||
@Parameter(defaultValue = "${project.build.directory}", readonly = true, required = true)
|
||||
private File projectBuildDirectory;
|
||||
|
||||
@Parameter(defaultValue = "${project.build.finalName}", readonly = true,
|
||||
required = true)
|
||||
@Parameter(defaultValue = "${project.build.finalName}", readonly = true, required = true)
|
||||
private String projectFinalName;
|
||||
|
||||
@Parameter(property = "stubsDirectory",
|
||||
defaultValue = "${project.build.directory}/stubs")
|
||||
@Parameter(property = "stubsDirectory", defaultValue = "${project.build.directory}/stubs")
|
||||
private File outputDirectory;
|
||||
|
||||
/**
|
||||
@@ -68,8 +64,7 @@ public class GenerateStubsMojo extends AbstractMojo {
|
||||
/**
|
||||
* Set this to "true" to bypass only JAR creation.
|
||||
*/
|
||||
@Parameter(property = "spring.cloud.contract.verifier.jar.skip",
|
||||
defaultValue = "false")
|
||||
@Parameter(property = "spring.cloud.contract.verifier.jar.skip", defaultValue = "false")
|
||||
private boolean jarSkip;
|
||||
|
||||
@Component
|
||||
@@ -112,10 +107,8 @@ public class GenerateStubsMojo extends AbstractMojo {
|
||||
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
if (this.skip || this.jarSkip) {
|
||||
getLog().info(
|
||||
"Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip="
|
||||
+ this.skip + ", spring.cloud.contract.verifier.jar.skip="
|
||||
+ this.jarSkip);
|
||||
getLog().info("Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip="
|
||||
+ this.skip + ", spring.cloud.contract.verifier.jar.skip=" + this.jarSkip);
|
||||
return;
|
||||
}
|
||||
else if (stubsOutputMissing(this.outputDirectory) && !this.failOnNoContracts) {
|
||||
@@ -124,44 +117,37 @@ public class GenerateStubsMojo extends AbstractMojo {
|
||||
return;
|
||||
}
|
||||
else if (stubsOutputMissing(this.outputDirectory) && this.failOnNoContracts) {
|
||||
throw new MojoExecutionException("Stubs could not be found: ["
|
||||
+ this.outputDirectory.getAbsolutePath()
|
||||
throw new MojoExecutionException("Stubs could not be found: [" + this.outputDirectory.getAbsolutePath()
|
||||
+ "] .\nPlease make sure that spring-cloud-contract:convert was invoked");
|
||||
}
|
||||
if (this.incrementalContractStubsJar
|
||||
&& !inputFilesChangeDetected(outputDirectory, mojoExecution, session)) {
|
||||
if (this.incrementalContractStubsJar && !inputFilesChangeDetected(outputDirectory, mojoExecution, session)) {
|
||||
getLog().info("Nothing to generate - stubs jar is up to date");
|
||||
return;
|
||||
}
|
||||
File stubsJarFile = createStubJar(this.outputDirectory);
|
||||
this.projectHelper.attachArtifact(this.project, "jar", this.classifier,
|
||||
stubsJarFile);
|
||||
this.projectHelper.attachArtifact(this.project, "jar", this.classifier, stubsJarFile);
|
||||
}
|
||||
|
||||
private File createStubJar(File stubsOutputDir)
|
||||
throws MojoFailureException, MojoExecutionException {
|
||||
private File createStubJar(File stubsOutputDir) throws MojoFailureException, MojoExecutionException {
|
||||
if (!stubsOutputDir.exists()) {
|
||||
throw new MojoExecutionException("Stubs could not be found: ["
|
||||
+ stubsOutputDir.getAbsolutePath()
|
||||
throw new MojoExecutionException("Stubs could not be found: [" + stubsOutputDir.getAbsolutePath()
|
||||
+ "] .\nPlease make sure that spring-cloud-contract:convert was invoked");
|
||||
}
|
||||
String stubArchiveName = this.projectFinalName + "-" + this.classifier + ".jar";
|
||||
File stubsJarFile = new File(this.projectBuildDirectory, stubArchiveName);
|
||||
String[] excludes = excludes();
|
||||
getLog().info("Files matching this pattern will be excluded from "
|
||||
+ "stubs generation " + Arrays.toString(excludes));
|
||||
getLog().info(
|
||||
"Files matching this pattern will be excluded from " + "stubs generation " + Arrays.toString(excludes));
|
||||
try {
|
||||
this.archiver.addDirectory(stubsOutputDir, new String[] { "**/*.*" },
|
||||
excludedFilesEmpty() ? new String[0] : this.excludedFiles);
|
||||
this.archiver.setCompress(true);
|
||||
this.archiver.setDestFile(stubsJarFile);
|
||||
this.archiver
|
||||
.addConfiguredManifest(ManifestCreator.createManifest(this.project));
|
||||
this.archiver.addConfiguredManifest(ManifestCreator.createManifest(this.project));
|
||||
this.archiver.createArchive();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new MojoFailureException(
|
||||
"Exception while packaging " + this.classifier + " jar.", e);
|
||||
throw new MojoFailureException("Exception while packaging " + this.classifier + " jar.", e);
|
||||
}
|
||||
return stubsJarFile;
|
||||
}
|
||||
|
||||
@@ -59,12 +59,10 @@ public class GenerateTestsMojo extends AbstractMojo {
|
||||
defaultValue = "${project.basedir}/src/test/resources/contracts")
|
||||
private File contractsDirectory;
|
||||
|
||||
@Parameter(
|
||||
defaultValue = "${project.build.directory}/generated-test-sources/contracts")
|
||||
@Parameter(defaultValue = "${project.build.directory}/generated-test-sources/contracts")
|
||||
private File generatedTestSourcesDir;
|
||||
|
||||
@Parameter(
|
||||
defaultValue = "${project.build.directory}/generated-test-resources/contracts")
|
||||
@Parameter(defaultValue = "${project.build.directory}/generated-test-resources/contracts")
|
||||
private File generatedTestResourcesDir;
|
||||
|
||||
@Parameter
|
||||
@@ -113,8 +111,7 @@ public class GenerateTestsMojo extends AbstractMojo {
|
||||
* Incubating feature. You can check the size of JSON arrays. If not turned on
|
||||
* explicitly will be disabled.
|
||||
*/
|
||||
@Parameter(property = "spring.cloud.contract.verifier.assert.size",
|
||||
defaultValue = "false")
|
||||
@Parameter(property = "spring.cloud.contract.verifier.assert.size", defaultValue = "false")
|
||||
private boolean assertJsonSize;
|
||||
|
||||
/**
|
||||
@@ -264,63 +261,50 @@ public class GenerateTestsMojo extends AbstractMojo {
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
if (this.skip || this.mavenTestSkip || this.skipTests) {
|
||||
if (this.skip) {
|
||||
getLog().info(
|
||||
"Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip="
|
||||
+ this.skip);
|
||||
getLog().info("Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip="
|
||||
+ this.skip);
|
||||
}
|
||||
if (this.mavenTestSkip) {
|
||||
getLog().info(
|
||||
"Skipping Spring Cloud Contract Verifier execution: maven.test.skip="
|
||||
+ this.mavenTestSkip);
|
||||
"Skipping Spring Cloud Contract Verifier execution: maven.test.skip=" + this.mavenTestSkip);
|
||||
}
|
||||
if (this.skipTests) {
|
||||
getLog().info(
|
||||
"Skipping Spring Cloud Contract Verifier execution: skipTests"
|
||||
+ this.skipTests);
|
||||
getLog().info("Skipping Spring Cloud Contract Verifier execution: skipTests" + this.skipTests);
|
||||
}
|
||||
return;
|
||||
}
|
||||
getLog().info(
|
||||
"Generating server tests source code for Spring Cloud Contract Verifier contract verification");
|
||||
getLog().info("Generating server tests source code for Spring Cloud Contract Verifier contract verification");
|
||||
final ContractVerifierConfigProperties config = new ContractVerifierConfigProperties();
|
||||
config.setFailOnInProgress(this.failOnInProgress);
|
||||
// download contracts, unzip them and pass as output directory
|
||||
File contractsDirectory = new MavenContractsDownloader(this.project,
|
||||
this.contractDependency, this.contractsPath, this.contractsRepositoryUrl,
|
||||
this.contractsMode, getLog(), this.contractsRepositoryUsername,
|
||||
this.contractsRepositoryPassword, this.contractsRepositoryProxyHost,
|
||||
this.contractsRepositoryProxyPort, this.deleteStubsAfterTest,
|
||||
this.contractsProperties, this.failOnNoContracts)
|
||||
.downloadAndUnpackContractsIfRequired(config,
|
||||
this.contractsDirectory);
|
||||
getLog().info(
|
||||
"Directory with contract is present at [" + contractsDirectory + "]");
|
||||
File contractsDirectory = new MavenContractsDownloader(this.project, this.contractDependency,
|
||||
this.contractsPath, this.contractsRepositoryUrl, this.contractsMode, getLog(),
|
||||
this.contractsRepositoryUsername, this.contractsRepositoryPassword, this.contractsRepositoryProxyHost,
|
||||
this.contractsRepositoryProxyPort, this.deleteStubsAfterTest, this.contractsProperties,
|
||||
this.failOnNoContracts).downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
|
||||
getLog().info("Directory with contract is present at [" + contractsDirectory + "]");
|
||||
|
||||
if (this.incrementalContractTests && !ChangeDetector
|
||||
.inputFilesChangeDetected(contractsDirectory, mojoExecution, session)) {
|
||||
if (this.incrementalContractTests
|
||||
&& !ChangeDetector.inputFilesChangeDetected(contractsDirectory, mojoExecution, session)) {
|
||||
getLog().info("Nothing to generate - all classes are up to date");
|
||||
return;
|
||||
}
|
||||
|
||||
setupConfig(config, contractsDirectory);
|
||||
this.project
|
||||
.addTestCompileSourceRoot(this.generatedTestSourcesDir.getAbsolutePath());
|
||||
this.project.addTestCompileSourceRoot(this.generatedTestSourcesDir.getAbsolutePath());
|
||||
Resource resource = new Resource();
|
||||
resource.setDirectory(this.generatedTestResourcesDir.getAbsolutePath());
|
||||
this.project.addTestResource(resource);
|
||||
if (getLog().isInfoEnabled()) {
|
||||
getLog().info("Test Source directory: "
|
||||
+ this.generatedTestSourcesDir.getAbsolutePath() + " added.");
|
||||
getLog().info("Using [" + config.getBaseClassForTests()
|
||||
+ "] as base class for test classes, ["
|
||||
+ config.getBasePackageForTests() + "] as base "
|
||||
+ "package for tests, [" + config.getPackageWithBaseClasses()
|
||||
+ "] as package with " + "base classes, base class mappings "
|
||||
getLog().info("Test Source directory: " + this.generatedTestSourcesDir.getAbsolutePath() + " added.");
|
||||
getLog().info("Using [" + config.getBaseClassForTests() + "] as base class for test classes, ["
|
||||
+ config.getBasePackageForTests() + "] as base " + "package for tests, ["
|
||||
+ config.getPackageWithBaseClasses() + "] as package with " + "base classes, base class mappings "
|
||||
+ this.baseClassMappings);
|
||||
}
|
||||
try {
|
||||
LeftOverPrevention leftOverPrevention = new LeftOverPrevention(
|
||||
this.generatedTestSourcesDir, mojoExecution, session);
|
||||
LeftOverPrevention leftOverPrevention = new LeftOverPrevention(this.generatedTestSourcesDir, mojoExecution,
|
||||
session);
|
||||
TestGenerator generator = new TestGenerator(config);
|
||||
int generatedClasses = generator.generate();
|
||||
getLog().info("Generated " + generatedClasses + " test classes.");
|
||||
@@ -328,14 +312,11 @@ public class GenerateTestsMojo extends AbstractMojo {
|
||||
}
|
||||
catch (ContractVerifierException e) {
|
||||
throw new MojoExecutionException(
|
||||
String.format("Spring Cloud Contract Verifier Plugin exception: %s",
|
||||
e.getMessage()),
|
||||
e);
|
||||
String.format("Spring Cloud Contract Verifier Plugin exception: %s", e.getMessage()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupConfig(ContractVerifierConfigProperties config,
|
||||
File contractsDirectory) {
|
||||
private void setupConfig(ContractVerifierConfigProperties config, File contractsDirectory) {
|
||||
config.setContractsDslDir(contractsDirectory);
|
||||
config.setGeneratedTestSourcesDir(this.generatedTestSourcesDir);
|
||||
config.setGeneratedTestResourcesDir(this.generatedTestResourcesDir);
|
||||
|
||||
@@ -41,19 +41,18 @@ class LeftOverPrevention {
|
||||
|
||||
private final File generatedDirectory;
|
||||
|
||||
LeftOverPrevention(File generatedDirectory, MojoExecution mojoExecution,
|
||||
MavenSession session) throws MojoExecutionException {
|
||||
LeftOverPrevention(File generatedDirectory, MojoExecution mojoExecution, MavenSession session)
|
||||
throws MojoExecutionException {
|
||||
this.generatedDirectory = generatedDirectory;
|
||||
this.incrementalBuildHelper = new IncrementalBuildHelper(mojoExecution, session);
|
||||
this.incrementalBuildHelper.beforeRebuildExecution(
|
||||
new IncrementalBuildHelperRequest().outputDirectory(generatedDirectory));
|
||||
this.incrementalBuildHelper
|
||||
.beforeRebuildExecution(new IncrementalBuildHelperRequest().outputDirectory(generatedDirectory));
|
||||
}
|
||||
|
||||
void deleteLeftOvers() throws MojoExecutionException {
|
||||
if (generatedDirectory.exists()) {
|
||||
incrementalBuildHelper
|
||||
.afterRebuildExecution(new IncrementalBuildHelperRequest()
|
||||
.outputDirectory(generatedDirectory));
|
||||
.afterRebuildExecution(new IncrementalBuildHelperRequest().outputDirectory(generatedDirectory));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,18 +34,15 @@ final class ManifestCreator {
|
||||
Manifest manifest = new Manifest();
|
||||
Plugin verifierMavenPlugin = findMavenPlugin(project.getBuildPlugins());
|
||||
if (verifierMavenPlugin != null) {
|
||||
manifest.addConfiguredAttribute(
|
||||
new Manifest.Attribute("Spring-Cloud-Contract-Maven-Plugin-Version",
|
||||
verifierMavenPlugin.getVersion()));
|
||||
manifest.addConfiguredAttribute(new Manifest.Attribute("Spring-Cloud-Contract-Maven-Plugin-Version",
|
||||
verifierMavenPlugin.getVersion()));
|
||||
}
|
||||
if (verifierMavenPlugin != null
|
||||
&& !verifierMavenPlugin.getDependencies().isEmpty()) {
|
||||
Dependency verifierDependency = findVerifierDependency(
|
||||
verifierMavenPlugin.getDependencies());
|
||||
if (verifierMavenPlugin != null && !verifierMavenPlugin.getDependencies().isEmpty()) {
|
||||
Dependency verifierDependency = findVerifierDependency(verifierMavenPlugin.getDependencies());
|
||||
if (verifierDependency != null) {
|
||||
String verifierVersion = verifierDependency.getVersion();
|
||||
manifest.addConfiguredAttribute(new Manifest.Attribute(
|
||||
"Spring-Cloud-Contract-Verifier-Version", verifierVersion));
|
||||
manifest.addConfiguredAttribute(
|
||||
new Manifest.Attribute("Spring-Cloud-Contract-Verifier-Version", verifierVersion));
|
||||
}
|
||||
}
|
||||
return manifest;
|
||||
|
||||
@@ -73,12 +73,10 @@ class MavenContractsDownloader {
|
||||
|
||||
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, boolean failOnNoContracts) {
|
||||
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, boolean failOnNoContracts) {
|
||||
this.project = project;
|
||||
this.contractDependency = contractDependency;
|
||||
this.contractsPath = contractsPath;
|
||||
@@ -95,54 +93,42 @@ class MavenContractsDownloader {
|
||||
this.failOnNoStubs = failOnNoContracts;
|
||||
}
|
||||
|
||||
File downloadAndUnpackContractsIfRequired(ContractVerifierConfigProperties config,
|
||||
File defaultContractsDir) {
|
||||
String contractsDirFromProp = this.project.getProperties()
|
||||
.getProperty(CONTRACTS_DIRECTORY_PROP);
|
||||
File downloadedContractsDir = StringUtils.hasText(contractsDirFromProp)
|
||||
? new File(contractsDirFromProp) : null;
|
||||
File downloadAndUnpackContractsIfRequired(ContractVerifierConfigProperties config, File defaultContractsDir) {
|
||||
String contractsDirFromProp = this.project.getProperties().getProperty(CONTRACTS_DIRECTORY_PROP);
|
||||
File downloadedContractsDir = StringUtils.hasText(contractsDirFromProp) ? new File(contractsDirFromProp) : null;
|
||||
// reuse downloaded contracts from another mojo
|
||||
if (downloadedContractsDir != null && downloadedContractsDir.exists()) {
|
||||
this.log.info(
|
||||
"Another mojo has downloaded the contracts - will reuse them from ["
|
||||
+ downloadedContractsDir + "]");
|
||||
this.log.info("Another mojo has downloaded the contracts - will reuse them from [" + downloadedContractsDir
|
||||
+ "]");
|
||||
final ContractDownloader.InclusionProperties inclusionProperties = contractDownloader()
|
||||
.createNewInclusionProperties(downloadedContractsDir);
|
||||
config.setIncludedContracts(inclusionProperties.getIncludedContracts());
|
||||
config.setIncludedRootFolderAntPattern(
|
||||
inclusionProperties.getIncludedRootFolderAntPattern());
|
||||
config.setIncludedRootFolderAntPattern(inclusionProperties.getIncludedRootFolderAntPattern());
|
||||
return downloadedContractsDir;
|
||||
}
|
||||
else if (shouldDownloadContracts()) {
|
||||
this.log.info(
|
||||
"Download dependency is provided - will retrieve contracts from a remote location");
|
||||
this.log.info("Download dependency is provided - will retrieve contracts from a remote location");
|
||||
final ContractDownloader contractDownloader = contractDownloader();
|
||||
final File downloadedContracts = contractDownloader
|
||||
.unpackAndDownloadContracts();
|
||||
final File downloadedContracts = contractDownloader.unpackAndDownloadContracts();
|
||||
final ContractDownloader.InclusionProperties inclusionProperties = contractDownloader
|
||||
.createNewInclusionProperties(downloadedContracts);
|
||||
config.setIncludedContracts(inclusionProperties.getIncludedContracts());
|
||||
config.setIncludedRootFolderAntPattern(
|
||||
inclusionProperties.getIncludedRootFolderAntPattern());
|
||||
this.project.getProperties().setProperty(CONTRACTS_DIRECTORY_PROP,
|
||||
downloadedContracts.getAbsolutePath());
|
||||
config.setIncludedRootFolderAntPattern(inclusionProperties.getIncludedRootFolderAntPattern());
|
||||
this.project.getProperties().setProperty(CONTRACTS_DIRECTORY_PROP, downloadedContracts.getAbsolutePath());
|
||||
return downloadedContracts;
|
||||
}
|
||||
this.log.info("Will use contracts provided in the folder [" + defaultContractsDir
|
||||
+ "]");
|
||||
this.log.info("Will use contracts provided in the folder [" + defaultContractsDir + "]");
|
||||
return defaultContractsDir;
|
||||
}
|
||||
|
||||
private boolean shouldDownloadContracts() {
|
||||
return this.contractDependency != null
|
||||
&& StringUtils.hasText(this.contractDependency.getArtifactId())
|
||||
return this.contractDependency != null && StringUtils.hasText(this.contractDependency.getArtifactId())
|
||||
|| StringUtils.hasText(this.contractsRepositoryUrl);
|
||||
}
|
||||
|
||||
private ContractDownloader contractDownloader() {
|
||||
return new ContractDownloader(stubDownloader(), stubConfiguration(),
|
||||
this.contractsPath, this.project.getGroupId(),
|
||||
this.project.getArtifactId(), this.project.getVersion());
|
||||
return new ContractDownloader(stubDownloader(), stubConfiguration(), this.contractsPath,
|
||||
this.project.getGroupId(), this.project.getArtifactId(), this.project.getVersion());
|
||||
}
|
||||
|
||||
private StubDownloader stubDownloader() {
|
||||
@@ -152,11 +138,9 @@ class MavenContractsDownloader {
|
||||
|
||||
StubRunnerOptions buildOptions() {
|
||||
StubRunnerOptionsBuilder builder = new StubRunnerOptionsBuilder()
|
||||
.withOptions(StubRunnerOptions.fromSystemProps())
|
||||
.withStubsMode(this.stubsMode).withUsername(this.repositoryUsername)
|
||||
.withPassword(this.repositoryPassword)
|
||||
.withDeleteStubsAfterTest(this.deleteStubsAfterTest)
|
||||
.withProperties(this.contractsProperties)
|
||||
.withOptions(StubRunnerOptions.fromSystemProps()).withStubsMode(this.stubsMode)
|
||||
.withUsername(this.repositoryUsername).withPassword(this.repositoryPassword)
|
||||
.withDeleteStubsAfterTest(this.deleteStubsAfterTest).withProperties(this.contractsProperties)
|
||||
.withFailOnNoStubs(this.failOnNoStubs);
|
||||
if (StringUtils.hasText(this.contractsRepositoryUrl)) {
|
||||
builder.withStubRepositoryRoot(this.contractsRepositoryUrl);
|
||||
|
||||
@@ -40,12 +40,10 @@ import org.springframework.util.StringUtils;
|
||||
@Mojo(name = "pushStubsToScm")
|
||||
public class PushStubsToScmMojo extends AbstractMojo {
|
||||
|
||||
@Parameter(defaultValue = "${project.build.directory}", readonly = true,
|
||||
required = true)
|
||||
@Parameter(defaultValue = "${project.build.directory}", readonly = true, required = true)
|
||||
private File projectBuildDirectory;
|
||||
|
||||
@Parameter(property = "stubsDirectory",
|
||||
defaultValue = "${project.build.directory}/stubs")
|
||||
@Parameter(property = "stubsDirectory", defaultValue = "${project.build.directory}/stubs")
|
||||
private File outputDirectory;
|
||||
|
||||
/**
|
||||
@@ -57,8 +55,7 @@ public class PushStubsToScmMojo extends AbstractMojo {
|
||||
/**
|
||||
* Set this to "true" to bypass only JAR creation.
|
||||
*/
|
||||
@Parameter(property = "spring.cloud.contract.verifier.publish-stubs-to-scm.skip",
|
||||
defaultValue = "false")
|
||||
@Parameter(property = "spring.cloud.contract.verifier.publish-stubs-to-scm.skip", defaultValue = "false")
|
||||
private boolean taskSkip;
|
||||
|
||||
@Parameter(defaultValue = "${project}", readonly = true)
|
||||
@@ -107,34 +104,27 @@ public class PushStubsToScmMojo extends AbstractMojo {
|
||||
@Override
|
||||
public void execute() {
|
||||
if (this.skip || this.taskSkip) {
|
||||
getLog().info(
|
||||
"Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip="
|
||||
+ this.skip
|
||||
+ ", spring.cloud.contract.verifier.publish-stubs-to-scm.skip="
|
||||
+ this.taskSkip);
|
||||
getLog().info("Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip="
|
||||
+ this.skip + ", spring.cloud.contract.verifier.publish-stubs-to-scm.skip=" + this.taskSkip);
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isEmpty(this.contractsRepositoryUrl) || !ScmStubDownloaderBuilder
|
||||
.isProtocolAccepted(this.contractsRepositoryUrl)) {
|
||||
if (StringUtils.isEmpty(this.contractsRepositoryUrl)
|
||||
|| !ScmStubDownloaderBuilder.isProtocolAccepted(this.contractsRepositoryUrl)) {
|
||||
getLog().info("Skipping pushing stubs to scm since your "
|
||||
+ "[contractsRepositoryUrl] property doesn't match any of the accepted protocols");
|
||||
return;
|
||||
}
|
||||
String projectName = this.project.getGroupId() + ":"
|
||||
+ this.project.getArtifactId() + ":" + this.project.getVersion();
|
||||
String projectName = this.project.getGroupId() + ":" + this.project.getArtifactId() + ":"
|
||||
+ this.project.getVersion();
|
||||
getLog().info("Pushing Stubs to SCM for project [" + projectName + "]");
|
||||
new ContractProjectUpdater(buildOptions()).updateContractProject(projectName,
|
||||
this.outputDirectory.toPath());
|
||||
new ContractProjectUpdater(buildOptions()).updateContractProject(projectName, this.outputDirectory.toPath());
|
||||
}
|
||||
|
||||
StubRunnerOptions buildOptions() {
|
||||
StubRunnerOptionsBuilder builder = new StubRunnerOptionsBuilder()
|
||||
.withOptions(StubRunnerOptions.fromSystemProps())
|
||||
.withStubRepositoryRoot(this.contractsRepositoryUrl)
|
||||
.withStubsMode(this.contractsMode)
|
||||
.withUsername(this.contractsRepositoryUsername)
|
||||
.withPassword(this.contractsRepositoryPassword)
|
||||
.withDeleteStubsAfterTest(this.deleteStubsAfterTest)
|
||||
.withOptions(StubRunnerOptions.fromSystemProps()).withStubRepositoryRoot(this.contractsRepositoryUrl)
|
||||
.withStubsMode(this.contractsMode).withUsername(this.contractsRepositoryUsername)
|
||||
.withPassword(this.contractsRepositoryPassword).withDeleteStubsAfterTest(this.deleteStubsAfterTest)
|
||||
.withProperties(this.contractsProperties);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -45,8 +45,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Mariusz Smykula
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@Mojo(name = "run", requiresProject = false,
|
||||
requiresDependencyResolution = ResolutionScope.RUNTIME)
|
||||
@Mojo(name = "run", requiresProject = false, requiresDependencyResolution = ResolutionScope.RUNTIME)
|
||||
public class RunMojo extends AbstractMojo {
|
||||
|
||||
private final LocalStubRunner localStubRunner;
|
||||
@@ -65,8 +64,7 @@ public class RunMojo extends AbstractMojo {
|
||||
/**
|
||||
* HTTP port for the WireMock server that serves stubs.
|
||||
*/
|
||||
@Parameter(property = "spring.cloud.contract.verifier.http.port",
|
||||
defaultValue = "8080")
|
||||
@Parameter(property = "spring.cloud.contract.verifier.http.port", defaultValue = "8080")
|
||||
private int httpPort;
|
||||
|
||||
/**
|
||||
@@ -78,8 +76,7 @@ public class RunMojo extends AbstractMojo {
|
||||
/**
|
||||
* Set this to "true" to bypass verifier test generation.
|
||||
*/
|
||||
@Parameter(property = "spring.cloud.contract.verifier.skipTestOnly",
|
||||
defaultValue = "false")
|
||||
@Parameter(property = "spring.cloud.contract.verifier.skipTestOnly", defaultValue = "false")
|
||||
private boolean skipTestOnly;
|
||||
|
||||
/**
|
||||
@@ -91,22 +88,19 @@ public class RunMojo extends AbstractMojo {
|
||||
/**
|
||||
* Minimal port at which the stub should start.
|
||||
*/
|
||||
@Parameter(property = "spring.cloud.contract.verifier.http.minPort",
|
||||
defaultValue = "10000")
|
||||
@Parameter(property = "spring.cloud.contract.verifier.http.minPort", defaultValue = "10000")
|
||||
private int minPort;
|
||||
|
||||
/**
|
||||
* Maximal port at which the stub should start.
|
||||
*/
|
||||
@Parameter(property = "spring.cloud.contract.verifier.http.maxPort",
|
||||
defaultValue = "15000")
|
||||
@Parameter(property = "spring.cloud.contract.verifier.http.maxPort", defaultValue = "15000")
|
||||
private int maxPort;
|
||||
|
||||
/**
|
||||
* Should the plugin wait for the user to press the key after starting the stubs.
|
||||
*/
|
||||
@Parameter(property = "spring.cloud.contract.verifier.wait-for-key-pressed",
|
||||
defaultValue = "true")
|
||||
@Parameter(property = "spring.cloud.contract.verifier.wait-for-key-pressed", defaultValue = "true")
|
||||
private boolean waitForKeyPressed;
|
||||
|
||||
/**
|
||||
@@ -133,24 +127,19 @@ public class RunMojo extends AbstractMojo {
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
if (this.skip || this.skipTestOnly) {
|
||||
getLog().info(
|
||||
"Skipping verifier execution: spring.cloud.contract.verifier.skip="
|
||||
+ this.skip);
|
||||
getLog().info("Skipping verifier execution: spring.cloud.contract.verifier.skip=" + this.skip);
|
||||
return;
|
||||
}
|
||||
BatchStubRunner batchStubRunner = null;
|
||||
StubRunnerOptionsBuilder optionsBuilder = new StubRunnerOptionsBuilder()
|
||||
.withStubsClassifier(this.stubsClassifier);
|
||||
if (StringUtils.isEmpty(this.stubs)) {
|
||||
StubRunnerOptions options = optionsBuilder
|
||||
.withMinMaxPort(this.httpPort, this.httpPort).build();
|
||||
StubRunner stubRunner = this.localStubRunner
|
||||
.run(resolveStubsDirectory().getAbsolutePath(), options);
|
||||
StubRunnerOptions options = optionsBuilder.withMinMaxPort(this.httpPort, this.httpPort).build();
|
||||
StubRunner stubRunner = this.localStubRunner.run(resolveStubsDirectory().getAbsolutePath(), options);
|
||||
batchStubRunner = new BatchStubRunner(Collections.singleton(stubRunner));
|
||||
}
|
||||
else {
|
||||
StubRunnerOptions options = optionsBuilder.withStubs(this.stubs)
|
||||
.withMinMaxPort(this.minPort, this.maxPort)
|
||||
StubRunnerOptions options = optionsBuilder.withStubs(this.stubs).withMinMaxPort(this.minPort, this.maxPort)
|
||||
.withServerId(this.serverId).build();
|
||||
batchStubRunner = this.remoteStubRunner.run(options, this.repoSession);
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ public class AetherStubDownloaderFactory {
|
||||
private final Settings settings;
|
||||
|
||||
@Inject
|
||||
public AetherStubDownloaderFactory(RepositorySystem repoSystem, MavenProject project,
|
||||
Settings settings) {
|
||||
public AetherStubDownloaderFactory(RepositorySystem repoSystem, MavenProject project, Settings settings) {
|
||||
this.repoSystem = repoSystem;
|
||||
this.project = project;
|
||||
this.settings = settings;
|
||||
@@ -64,13 +63,10 @@ public class AetherStubDownloaderFactory {
|
||||
return new StubDownloaderBuilder() {
|
||||
@Override
|
||||
public StubDownloader build(StubRunnerOptions stubRunnerOptions) {
|
||||
log.info(
|
||||
"Will download contracts using current build's Maven repository setup");
|
||||
return new AetherStubDownloader(
|
||||
AetherStubDownloaderFactory.this.repoSystem,
|
||||
AetherStubDownloaderFactory.this.project
|
||||
.getRemoteProjectRepositories(),
|
||||
repoSession, AetherStubDownloaderFactory.this.settings);
|
||||
log.info("Will download contracts using current build's Maven repository setup");
|
||||
return new AetherStubDownloader(AetherStubDownloaderFactory.this.repoSystem,
|
||||
AetherStubDownloaderFactory.this.project.getRemoteProjectRepositories(), repoSession,
|
||||
AetherStubDownloaderFactory.this.settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,8 +37,7 @@ public class LocalStubRunner {
|
||||
|
||||
public StubRunner run(final String contractsDir, StubRunnerOptions options) {
|
||||
log.info("Launching StubRunner with contracts from " + contractsDir);
|
||||
StubRunner stubRunner = new StubRunner(options, contractsDir,
|
||||
new StubConfiguration(contractsDir));
|
||||
StubRunner stubRunner = new StubRunner(options, contractsDir, new StubConfiguration(contractsDir));
|
||||
stubRunner.runStubs();
|
||||
return stubRunner;
|
||||
}
|
||||
|
||||
@@ -46,23 +46,19 @@ public class RemoteStubRunner {
|
||||
this.aetherStubDownloaderFactory = aetherStubDownloaderFactory;
|
||||
}
|
||||
|
||||
public BatchStubRunner run(StubRunnerOptions options,
|
||||
RepositorySystemSession repositorySystemSession) {
|
||||
StubDownloader stubDownloader = this.aetherStubDownloaderFactory
|
||||
.build(repositorySystemSession).build(options);
|
||||
public BatchStubRunner run(StubRunnerOptions options, RepositorySystemSession repositorySystemSession) {
|
||||
StubDownloader stubDownloader = this.aetherStubDownloaderFactory.build(repositorySystemSession).build(options);
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Launching StubRunner with args: " + options);
|
||||
}
|
||||
BatchStubRunner stubRunner = new BatchStubRunnerFactory(options,
|
||||
stubDownloader).buildBatchStubRunner();
|
||||
BatchStubRunner stubRunner = new BatchStubRunnerFactory(options, stubDownloader).buildBatchStubRunner();
|
||||
RunningStubs runningCollaborators = stubRunner.runStubs();
|
||||
log.info(runningCollaborators.toString());
|
||||
return stubRunner;
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("An exception occurred while trying to execute the stubs: "
|
||||
+ e.getMessage());
|
||||
log.error("An exception occurred while trying to execute the stubs: " + e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,8 +63,7 @@ public abstract class AbstractMojoTest {
|
||||
return new File(this.tmpFolder, name);
|
||||
}
|
||||
|
||||
protected void executeMojo(File baseDir, String goal, Xpp3Dom... parameters)
|
||||
throws Exception {
|
||||
protected void executeMojo(File baseDir, String goal, Xpp3Dom... parameters) throws Exception {
|
||||
MavenProject mavenProject = rule.readMavenProject(baseDir);
|
||||
MavenSession mavenSession = rule.newMavenSession(mavenProject);
|
||||
rule.executeMojo(mavenSession, mavenProject, goal, parameters);
|
||||
|
||||
@@ -43,15 +43,13 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
}
|
||||
|
||||
private Xpp3Dom defaultPackageForTests() {
|
||||
return newParameter("basePackageForTests",
|
||||
"org.springframework.cloud.contract.verifier.tests");
|
||||
return newParameter("basePackageForTests", "org.springframework.cloud.contract.verifier.tests");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateWireMockFromStubsDirectory() throws Exception {
|
||||
File basedir = getBasedir("withStubs");
|
||||
executeMojo(basedir, "convert",
|
||||
newParameter("contractsDirectory", "src/test/resources/stubs"));
|
||||
executeMojo(basedir, "convert", newParameter("contractsDirectory", "src/test/resources/stubs"));
|
||||
assertFilesPresent(basedir,
|
||||
"target/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/mappings/Sample.json"
|
||||
.replace("/", File.separator));
|
||||
@@ -80,8 +78,7 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
@Test
|
||||
public void shouldGenerateContractSpecificationInDefaultLocation() throws Exception {
|
||||
File basedir = getBasedir("basic");
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||
newParameter("testFramework", "SPOCK"));
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(), newParameter("testFramework", "SPOCK"));
|
||||
String path = "target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierSpec.groovy";
|
||||
assertFilesPresent(basedir, path);
|
||||
File test = new File(basedir, path);
|
||||
@@ -99,8 +96,7 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
@Test
|
||||
public void shouldGenerateContractTestsWithCustomImports() throws Exception {
|
||||
File basedir = getBasedir("basic");
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||
newParameter("imports", ""));
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(), newParameter("imports", ""));
|
||||
assertFilesPresent(basedir,
|
||||
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java");
|
||||
}
|
||||
@@ -119,8 +115,7 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
@Test
|
||||
public void shouldGenerateContractTestsWithArraySize() throws Exception {
|
||||
File basedir = getBasedir("basic");
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||
newParameter("assertJsonSize", "true"));
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(), newParameter("assertJsonSize", "true"));
|
||||
assertFilesPresent(basedir,
|
||||
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java");
|
||||
File test = new File(basedir,
|
||||
@@ -153,24 +148,17 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
@Test
|
||||
public void shouldGenerateStubsByDownloadingContractsFromARepo() throws Exception {
|
||||
File basedir = getBasedir("basic-remote-contracts");
|
||||
executeMojo(basedir, "convert",
|
||||
newParameter("contractsRepositoryUrl",
|
||||
"file://" + PluginUnitTest.class.getClassLoader()
|
||||
.getResource("m2repo/repository").getFile()
|
||||
.replace("/", File.separator)));
|
||||
executeMojo(basedir, "convert", newParameter("contractsRepositoryUrl", "file://" + PluginUnitTest.class
|
||||
.getClassLoader().getResource("m2repo/repository").getFile().replace("/", File.separator)));
|
||||
assertFilesPresent(basedir,
|
||||
"target/stubs/META-INF/com.example/server/0.1.BUILD-SNAPSHOT/mappings/com/example/server/client1/contracts/shouldMarkClientAsFraud.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateStubsByDownloadingContractsFromARepoWhenCustomPathIsProvided()
|
||||
throws Exception {
|
||||
public void shouldGenerateStubsByDownloadingContractsFromARepoWhenCustomPathIsProvided() throws Exception {
|
||||
File basedir = getBasedir("complex-remote-contracts");
|
||||
executeMojo(basedir, "convert",
|
||||
newParameter("contractsRepositoryUrl",
|
||||
"file://" + PluginUnitTest.class.getClassLoader()
|
||||
.getResource("m2repo/repository").getFile()
|
||||
.replace("/", File.separator)));
|
||||
executeMojo(basedir, "convert", newParameter("contractsRepositoryUrl", "file://" + PluginUnitTest.class
|
||||
.getClassLoader().getResource("m2repo/repository").getFile().replace("/", File.separator)));
|
||||
assertFilesPresent(basedir,
|
||||
"target/stubs/META-INF/com.example.foo.bar.baz/someartifact/0.1.BUILD-SNAPSHOT/mappings/com/example/server/client1/contracts/shouldMarkClientAsFraud.json");
|
||||
assertFilesNotPresent(basedir,
|
||||
@@ -188,8 +176,7 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateOutputWhenCalledGenerateTestsFromRootProject()
|
||||
throws Exception {
|
||||
public void shouldGenerateOutputWhenCalledGenerateTestsFromRootProject() throws Exception {
|
||||
File basedir = getBasedir("different-module-configuration");
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests());
|
||||
assertFilesPresent(basedir,
|
||||
@@ -200,38 +187,30 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
public void shouldGenerateTestsByDownloadingContractsFromARepo() throws Exception {
|
||||
File basedir = getBasedir("basic-remote-contracts");
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||
newParameter("contractsRepositoryUrl",
|
||||
"file://" + PluginUnitTest.class.getClassLoader()
|
||||
.getResource("m2repo/repository").getFile()
|
||||
.replace("/", File.separator)));
|
||||
newParameter("contractsRepositoryUrl", "file://" + PluginUnitTest.class.getClassLoader()
|
||||
.getResource("m2repo/repository").getFile().replace("/", File.separator)));
|
||||
assertFilesPresent(basedir,
|
||||
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/com/example/server/client1/ContractsTest.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateTestsByDownloadingContractsFromARepoWhenCustomPathIsProvided()
|
||||
throws Exception {
|
||||
public void shouldGenerateTestsByDownloadingContractsFromARepoWhenCustomPathIsProvided() throws Exception {
|
||||
File basedir = getBasedir("complex-remote-contracts");
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||
newParameter("contractsRepositoryUrl",
|
||||
"file://" + PluginUnitTest.class.getClassLoader()
|
||||
.getResource("m2repo/repository").getFile()
|
||||
.replace("/", File.separator)));
|
||||
newParameter("contractsRepositoryUrl", "file://" + PluginUnitTest.class.getClassLoader()
|
||||
.getResource("m2repo/repository").getFile().replace("/", File.separator)));
|
||||
assertFilesPresent(basedir,
|
||||
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/com/example/server/client1/ContractsTest.java");
|
||||
assertFilesNotPresent(basedir,
|
||||
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/com/foo/bar/BazTest.java");
|
||||
assertFilesNotPresent(basedir,
|
||||
"target/stubs/contracts/com/foo/bar/baz/shouldBeIgnoredByPlugin.groovy");
|
||||
assertFilesNotPresent(basedir, "target/stubs/contracts/com/foo/bar/baz/shouldBeIgnoredByPlugin.groovy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateContractTestsWithBaseClassResolvedFromConvention()
|
||||
throws Exception {
|
||||
public void shouldGenerateContractTestsWithBaseClassResolvedFromConvention() throws Exception {
|
||||
File basedir = getBasedir("basic-generated-baseclass");
|
||||
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||
newParameter("testFramework", "JUNIT"));
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(), newParameter("testFramework", "JUNIT"));
|
||||
|
||||
String path = "target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/hello/V1Test.java";
|
||||
assertFilesPresent(basedir, path);
|
||||
@@ -241,12 +220,10 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateContractTestsWithBaseClassResolvedFromConventionForSpock()
|
||||
throws Exception {
|
||||
public void shouldGenerateContractTestsWithBaseClassResolvedFromConventionForSpock() throws Exception {
|
||||
File basedir = getBasedir("basic-generated-baseclass");
|
||||
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||
newParameter("testFramework", "SPOCK"));
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(), newParameter("testFramework", "SPOCK"));
|
||||
|
||||
String path = "target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/hello/V1Spec.groovy";
|
||||
assertFilesPresent(basedir, path);
|
||||
@@ -256,12 +233,10 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateContractTestsWithBaseClassResolvedFromMapping()
|
||||
throws Exception {
|
||||
public void shouldGenerateContractTestsWithBaseClassResolvedFromMapping() throws Exception {
|
||||
File basedir = getBasedir("basic-baseclass-from-mappings");
|
||||
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||
newParameter("testFramework", "JUNIT"));
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(), newParameter("testFramework", "JUNIT"));
|
||||
|
||||
String path = "target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/com/hello/V1Test.java";
|
||||
assertFilesPresent(basedir, path);
|
||||
@@ -271,12 +246,10 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateContractTestsWithBaseClassResolvedFromMappingNameForSpock()
|
||||
throws Exception {
|
||||
public void shouldGenerateContractTestsWithBaseClassResolvedFromMappingNameForSpock() throws Exception {
|
||||
File basedir = getBasedir("basic-baseclass-from-mappings");
|
||||
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||
newParameter("testFramework", "SPOCK"));
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(), newParameter("testFramework", "SPOCK"));
|
||||
|
||||
String path = "target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/com/hello/V1Spec.groovy";
|
||||
assertFilesPresent(basedir, path);
|
||||
@@ -286,12 +259,10 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateContractTestsWithAFileContainingAListOfContracts()
|
||||
throws Exception {
|
||||
public void shouldGenerateContractTestsWithAFileContainingAListOfContracts() throws Exception {
|
||||
File basedir = getBasedir("multiple-contracts");
|
||||
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||
newParameter("testFramework", "JUNIT"));
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(), newParameter("testFramework", "JUNIT"));
|
||||
|
||||
String path = "target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/com/hello/V1Test.java";
|
||||
assertFilesPresent(basedir, path);
|
||||
@@ -302,8 +273,7 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateStubsWithAFileContainingAListOfContracts()
|
||||
throws Exception {
|
||||
public void shouldGenerateStubsWithAFileContainingAListOfContracts() throws Exception {
|
||||
File basedir = getBasedir("multiple-contracts");
|
||||
|
||||
executeMojo(basedir, "convert", newParameter("stubsDirectory", "target/foo"));
|
||||
@@ -347,8 +317,7 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
File test = new File(basedir,
|
||||
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java");
|
||||
String testContents = readFileToString(test, defaultCharset());
|
||||
int countOccurrencesOf = StringUtils.countOccurrencesOf(testContents,
|
||||
"\t\tMockMvcRequestSpecification");
|
||||
int countOccurrencesOf = StringUtils.countOccurrencesOf(testContents, "\t\tMockMvcRequestSpecification");
|
||||
then(countOccurrencesOf).isEqualTo(4);
|
||||
}
|
||||
|
||||
@@ -358,8 +327,7 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
|
||||
executeMojo(basedir, "pushStubsToScm");
|
||||
|
||||
then(this.capture.toString())
|
||||
.contains("Skipping pushing stubs to scm since your");
|
||||
then(this.capture.toString()).contains("Skipping pushing stubs to scm since your");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -367,10 +335,8 @@ public class PluginUnitTest extends AbstractMojoTest {
|
||||
File basedir = getBasedir("complex-common-repo-with-messaging");
|
||||
|
||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||
newParameter("contractsRepositoryUrl",
|
||||
"file://" + PluginUnitTest.class.getClassLoader()
|
||||
.getResource("m2repo/repository").getFile()
|
||||
.replace("/", File.separator)));
|
||||
newParameter("contractsRepositoryUrl", "file://" + PluginUnitTest.class.getClassLoader()
|
||||
.getResource("m2repo/repository").getFile().replace("/", File.separator)));
|
||||
assertFilesPresent(basedir,
|
||||
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/common_repo_with_inclusion/kafka_topics/coupon_sent/src/main/resources/contracts/rule_engine_daemon/MessagingTest.java");
|
||||
assertFilesPresent(basedir,
|
||||
|
||||
Reference in New Issue
Block a user