Bumping versions
This commit is contained in:
@@ -112,7 +112,8 @@ public class ContractVerifierExtension implements Serializable {
|
||||
private final DirectoryProperty generatedTestJavaSourcesDir;
|
||||
|
||||
/**
|
||||
* Groovy test source directory where tests generated from Contract DSL should be placed
|
||||
* Groovy test source directory where tests generated from Contract DSL should be
|
||||
* placed
|
||||
*/
|
||||
private final DirectoryProperty generatedTestGroovySourcesDir;
|
||||
|
||||
@@ -122,8 +123,8 @@ public class ContractVerifierExtension implements Serializable {
|
||||
private final DirectoryProperty generatedTestResourcesDir;
|
||||
|
||||
/**
|
||||
* Dir where the generated stubs from Groovy DSL should be placed.
|
||||
* You can then mention them in your packaging task to create jar with stubs
|
||||
* Dir where the generated stubs from Groovy DSL should be placed. You can then
|
||||
* mention them in your packaging task to create jar with stubs
|
||||
*/
|
||||
private final DirectoryProperty stubsOutputDir;
|
||||
|
||||
@@ -162,10 +163,10 @@ public class ContractVerifierExtension implements Serializable {
|
||||
private final Dependency contractDependency;
|
||||
|
||||
/**
|
||||
* The path in the JAR with all the contracts where contracts for this particular service lay.
|
||||
* If not provided will be resolved to {@code groupid/artifactid}. Example:
|
||||
* If {@code groupid} is {@code com.example} and {@code artifactid} is {@code service} then the resolved path will be
|
||||
* {@code /com/example/artifactid}
|
||||
* The path in the JAR with all the contracts where contracts for this particular
|
||||
* service lay. If not provided will be resolved to {@code groupid/artifactid}.
|
||||
* Example: If {@code groupid} is {@code com.example} and {@code artifactid} is
|
||||
* {@code service} then the resolved path will be {@code /com/example/artifactid}
|
||||
*/
|
||||
private final Property<String> contractsPath;
|
||||
|
||||
@@ -175,34 +176,36 @@ public class ContractVerifierExtension implements Serializable {
|
||||
private final Property<StubRunnerProperties.StubsMode> contractsMode;
|
||||
|
||||
/**
|
||||
* A package that contains all the base clases for generated tests. If your contract resides in a location
|
||||
* {@code src/test/resources/contracts/com/example/v1/} and you provide the {@code packageWithBaseClasses}
|
||||
* value to {@code com.example.contracts.base} then we will search for a test source file that will
|
||||
* have the package {@code com.example.contracts.base} and name {@code ExampleV1Base}. As you can see
|
||||
* it will take the two last folders to and attach {@code Base} to its name.
|
||||
* A package that contains all the base clases for generated tests. If your contract
|
||||
* resides in a location {@code src/test/resources/contracts/com/example/v1/} and you
|
||||
* provide the {@code packageWithBaseClasses} value to
|
||||
* {@code com.example.contracts.base} then we will search for a test source file that
|
||||
* will have the package {@code com.example.contracts.base} and name
|
||||
* {@code ExampleV1Base}. As you can see it will take the two last folders to and
|
||||
* attach {@code Base} to its name.
|
||||
*/
|
||||
private final Property<String> packageWithBaseClasses;
|
||||
|
||||
/**
|
||||
* A way to override any base class mappings. The keys are regular expressions on the package name
|
||||
* and the values FQN to a base class for that given expression.
|
||||
* Example of a mapping
|
||||
* [.*.com.example.v1..*] to [com.example.SomeBaseClass]
|
||||
* When a contract's package matches the provided regular expression then extending class will be the one
|
||||
* provided in the map - in this case {@code com.example.SomeBaseClass}
|
||||
* A way to override any base class mappings. The keys are regular expressions on the
|
||||
* package name and the values FQN to a base class for that given expression. Example
|
||||
* of a mapping [.*.com.example.v1..*] to [com.example.SomeBaseClass] When a
|
||||
* contract's package matches the provided regular expression then extending class
|
||||
* will be the one provided in the map - in this case
|
||||
* {@code com.example.SomeBaseClass}
|
||||
*/
|
||||
private final BaseClassMapping baseClassMappings;
|
||||
|
||||
/**
|
||||
* If set to true then the {@code target} or {@code build} folders are getting
|
||||
* excluded from any operations. This is used out of the box when working with
|
||||
* common repo with contracts.
|
||||
* excluded from any operations. This is used out of the box when working with common
|
||||
* repo with contracts.
|
||||
*/
|
||||
private final Property<Boolean> excludeBuildFolders;
|
||||
|
||||
/**
|
||||
* If set to {@code false} will NOT delete stubs from a temporary
|
||||
* folder after running tests
|
||||
* If set to {@code false} will NOT delete stubs from a temporary folder after running
|
||||
* tests
|
||||
*/
|
||||
private final Property<Boolean> deleteStubsAfterTest;
|
||||
|
||||
@@ -212,20 +215,22 @@ public class ContractVerifierExtension implements Serializable {
|
||||
private final Property<Boolean> convertToYaml;
|
||||
|
||||
/**
|
||||
* Map of properties that can be passed to custom {@link org.springframework.cloud.contract.stubrunner.StubDownloaderBuilder}
|
||||
* Map of properties that can be passed to custom
|
||||
* {@link org.springframework.cloud.contract.stubrunner.StubDownloaderBuilder}
|
||||
*/
|
||||
private final MapProperty<String, String> contractsProperties;
|
||||
|
||||
/**
|
||||
* Is set to true will not provide the default publication task
|
||||
*
|
||||
* @deprecated - with 3.0.0, the user should include stubs with their own publication(s)
|
||||
* @deprecated - with 3.0.0, the user should include stubs with their own
|
||||
* publication(s)
|
||||
*/
|
||||
@Deprecated
|
||||
private final Property<Boolean> disableStubPublication;
|
||||
|
||||
/**
|
||||
* Source set where the contracts are stored. If not provided will assume {@code test}.
|
||||
* Source set where the contracts are stored. If not provided will assume
|
||||
* {@code test}.
|
||||
*/
|
||||
private final Property<String> sourceSet;
|
||||
|
||||
@@ -241,11 +246,15 @@ public class ContractVerifierExtension implements Serializable {
|
||||
this.ignoredFiles = objects.listProperty(String.class).convention(new ArrayList<>());
|
||||
this.imports = objects.listProperty(String.class).convention(new ArrayList<>());
|
||||
this.staticImports = objects.listProperty(String.class).convention(new ArrayList<>());
|
||||
this.contractsDslDir = objects.directoryProperty().convention(layout.getProjectDirectory().dir("src/test/resources/contracts"));
|
||||
this.contractsDslDir = objects.directoryProperty()
|
||||
.convention(layout.getProjectDirectory().dir("src/test/resources/contracts"));
|
||||
this.generatedTestSourcesDir = objects.directoryProperty();
|
||||
this.generatedTestJavaSourcesDir = objects.directoryProperty().convention(layout.getBuildDirectory().dir("generated-test-sources/contractTest/java"));
|
||||
this.generatedTestGroovySourcesDir = objects.directoryProperty().convention(layout.getBuildDirectory().dir("generated-test-sources/contractTest/groovy"));
|
||||
this.generatedTestResourcesDir = objects.directoryProperty().convention(layout.getBuildDirectory().dir("generated-test-resources/contractTest"));
|
||||
this.generatedTestJavaSourcesDir = objects.directoryProperty()
|
||||
.convention(layout.getBuildDirectory().dir("generated-test-sources/contractTest/java"));
|
||||
this.generatedTestGroovySourcesDir = objects.directoryProperty()
|
||||
.convention(layout.getBuildDirectory().dir("generated-test-sources/contractTest/groovy"));
|
||||
this.generatedTestResourcesDir = objects.directoryProperty()
|
||||
.convention(layout.getBuildDirectory().dir("generated-test-resources/contractTest"));
|
||||
this.stubsOutputDir = objects.directoryProperty().convention(layout.getBuildDirectory().dir("stubs"));
|
||||
this.stubsSuffix = objects.property(String.class).convention("stubs");
|
||||
this.assertJsonSize = objects.property(Boolean.class).convention(false);
|
||||
@@ -255,7 +264,8 @@ public class ContractVerifierExtension implements Serializable {
|
||||
this.publishStubsToScm = objects.newInstance(PublishStubsToScm.class);
|
||||
this.contractDependency = objects.newInstance(Dependency.class);
|
||||
this.contractsPath = objects.property(String.class);
|
||||
this.contractsMode = objects.property(StubRunnerProperties.StubsMode.class).convention(StubRunnerProperties.StubsMode.CLASSPATH);
|
||||
this.contractsMode = objects.property(StubRunnerProperties.StubsMode.class)
|
||||
.convention(StubRunnerProperties.StubsMode.CLASSPATH);
|
||||
this.packageWithBaseClasses = objects.property(String.class);
|
||||
this.baseClassMappings = objects.newInstance(BaseClassMapping.class);
|
||||
this.excludeBuildFolders = objects.property(Boolean.class).convention(false);
|
||||
@@ -559,10 +569,15 @@ public class ContractVerifierExtension implements Serializable {
|
||||
}
|
||||
|
||||
public static class Dependency implements Serializable {
|
||||
|
||||
private final Property<String> groupId;
|
||||
|
||||
private final Property<String> artifactId;
|
||||
|
||||
private final Property<String> version;
|
||||
|
||||
private final Property<String> classifier;
|
||||
|
||||
private final Property<String> stringNotation;
|
||||
|
||||
@Inject
|
||||
@@ -616,17 +631,15 @@ public class ContractVerifierExtension implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Dependency{" +
|
||||
"groupId=" + groupId.getOrNull() +
|
||||
", artifactId=" + artifactId.getOrNull() +
|
||||
", classifier=" + classifier.getOrNull() +
|
||||
", version=" + version.getOrNull() +
|
||||
", stringNotation=" + stringNotation.getOrNull() +
|
||||
'}';
|
||||
return "Dependency{" + "groupId=" + groupId.getOrNull() + ", artifactId=" + artifactId.getOrNull()
|
||||
+ ", classifier=" + classifier.getOrNull() + ", version=" + version.getOrNull()
|
||||
+ ", stringNotation=" + stringNotation.getOrNull() + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class BaseClassMapping implements Serializable {
|
||||
|
||||
private final MapProperty<String, String> baseClassMappings;
|
||||
|
||||
@Inject
|
||||
@@ -645,14 +658,21 @@ public class ContractVerifierExtension implements Serializable {
|
||||
public void baseClassMapping(Map<String, String> mapping) {
|
||||
baseClassMappings.putAll(mapping);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// This class is used as an input to the tasks, so all fields are marked as `@Input` to allow incremental build
|
||||
// This class is used as an input to the tasks, so all fields are marked as `@Input`
|
||||
// to allow incremental build
|
||||
public static class ContractRepository implements Serializable {
|
||||
|
||||
private final Property<String> repositoryUrl;
|
||||
|
||||
private final Property<String> username;
|
||||
|
||||
private final Property<String> password;
|
||||
|
||||
private final Property<Integer> proxyPort;
|
||||
|
||||
private final Property<String> proxyHost;
|
||||
|
||||
@Inject
|
||||
@@ -707,14 +727,11 @@ public class ContractVerifierExtension implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ContractRepository{" +
|
||||
"repositoryUrl=" + repositoryUrl.getOrNull() +
|
||||
", username=" + username.getOrNull() +
|
||||
", password=" + password.getOrNull() +
|
||||
", proxyPort=" + proxyPort.getOrNull() +
|
||||
", proxyHost=" + proxyHost.getOrNull() +
|
||||
'}';
|
||||
return "ContractRepository{" + "repositoryUrl=" + repositoryUrl.getOrNull() + ", username="
|
||||
+ username.getOrNull() + ", password=" + password.getOrNull() + ", proxyPort="
|
||||
+ proxyPort.getOrNull() + ", proxyHost=" + proxyHost.getOrNull() + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class PublishStubsToScm implements Serializable {
|
||||
@@ -750,10 +767,10 @@ public class ContractVerifierExtension implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PublishStubsToScm{" +
|
||||
"contractDependency=" + contractDependency +
|
||||
", contractRepository=" + contractRepository +
|
||||
'}';
|
||||
return "PublishStubsToScm{" + "contractDependency=" + contractDependency + ", contractRepository="
|
||||
+ contractRepository + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,9 +58,8 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
// TODO: Convert to incremental task: https://docs.gradle.org/current/userguide/custom_tasks.html#incremental_tasks
|
||||
/**
|
||||
* Task that copies the contracts in order for the jar task to
|
||||
* generate the jar. It takes into consideration the inclusion
|
||||
* patterns when working with repo with shared contracts.
|
||||
* Task that copies the contracts in order for the jar task to generate the jar. It takes
|
||||
* into consideration the inclusion patterns when working with repo with shared contracts.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @author Anatoliy Balakirev
|
||||
@@ -96,8 +95,8 @@ class ContractsCopyTask extends DefaultTask {
|
||||
/**
|
||||
* @see ContractVerifierExtension#deleteStubsAfterTest
|
||||
*
|
||||
* This property will delete the temporary dependency or Git repository from
|
||||
* which stubs were copied to this task's output directory.
|
||||
* This property will delete the temporary dependency or Git repository from which
|
||||
* stubs were copied to this task's output directory.
|
||||
*/
|
||||
private final Property<Boolean> deleteStubsAfterTest;
|
||||
|
||||
@@ -122,7 +121,8 @@ class ContractsCopyTask extends DefaultTask {
|
||||
copiedContractsFolder = objects.directoryProperty();
|
||||
backupContractsFolder = objects.directoryProperty();
|
||||
|
||||
this.getOutputs().upToDateWhen(task -> !(this.shouldDownloadContracts() && this.getContractDependency().toStubConfiguration().isVersionChanging()));
|
||||
this.getOutputs().upToDateWhen(task -> !(this.shouldDownloadContracts()
|
||||
&& this.getContractDependency().toStubConfiguration().isVersionChanging()));
|
||||
// Lambdas break build caching support
|
||||
this.doFirst(new Action<Task>() {
|
||||
@Override
|
||||
@@ -133,19 +133,20 @@ class ContractsCopyTask extends DefaultTask {
|
||||
branch = StringUtils.hasText(branch) ? branch : "master";
|
||||
UsernamePasswordCredentialsProvider provider = null;
|
||||
if (StringUtils.hasText(contractRepository.getUsername().get())) {
|
||||
provider = new UsernamePasswordCredentialsProvider(contractRepository.getUsername().get(), contractRepository.getPassword().get());
|
||||
provider = new UsernamePasswordCredentialsProvider(contractRepository.getUsername().get(),
|
||||
contractRepository.getPassword().get());
|
||||
}
|
||||
try {
|
||||
Collection<Ref> refs = Git.lsRemoteRepository()
|
||||
.setRemote(repositoryUrl)
|
||||
.setCredentialsProvider(provider)
|
||||
.call();
|
||||
Collection<Ref> refs = Git.lsRemoteRepository().setRemote(repositoryUrl)
|
||||
.setCredentialsProvider(provider).call();
|
||||
for (Ref ref : refs) {
|
||||
if (ref.getName().equals(branch) || ref.getName().equals("refs/heads/" + branch) || ref.getName().equals("refs/tags/" + branch)) {
|
||||
if (ref.getName().equals(branch) || ref.getName().equals("refs/heads/" + branch)
|
||||
|| ref.getName().equals("refs/tags/" + branch)) {
|
||||
contractsProperties.put("git.commit", ref.getObjectId().name());
|
||||
}
|
||||
}
|
||||
} catch (GitAPIException e) {
|
||||
}
|
||||
catch (GitAPIException e) {
|
||||
ContractsCopyTask.this.getLogger().warn("Unable to determine git repository commit id");
|
||||
}
|
||||
}
|
||||
@@ -167,27 +168,34 @@ class ContractsCopyTask extends DefaultTask {
|
||||
contractsDirectory = this.contractsDirectory.getAsFile().getOrNull();
|
||||
antPattern = "**/";
|
||||
}
|
||||
getLogger().info("For project [{}] will use contracts provided in the folder [{}]", getProject().getName(), contractsDirectory);
|
||||
getLogger().info("For project [{}] will use contracts provided in the folder [{}]", getProject().getName(),
|
||||
contractsDirectory);
|
||||
final String contractsRepository = this.contractRepository.getRepositoryUrl().getOrElse("");
|
||||
throwExceptionWhenFailOnNoContracts(contractsDirectory, contractsRepository);
|
||||
|
||||
final String slashSeparatedGroupId = getProject().getGroup().toString().replace(".", File.separator);
|
||||
final String dotSeparatedAntPattern = antPattern.replace(slashSeparatedGroupId, getProject().getGroup().toString());
|
||||
final String dotSeparatedAntPattern = antPattern.replace(slashSeparatedGroupId,
|
||||
getProject().getGroup().toString());
|
||||
File output = copiedContractsFolder.get().getAsFile();
|
||||
getLogger().info("Downloading and unpacking files from [{}] to [{}]. The inclusion ant patterns are [{}] and [{}]", contractsDirectory, output, antPattern, dotSeparatedAntPattern);
|
||||
getLogger().info(
|
||||
"Downloading and unpacking files from [{}] to [{}]. The inclusion ant patterns are [{}] and [{}]",
|
||||
contractsDirectory, output, antPattern, dotSeparatedAntPattern);
|
||||
sync(contractsDirectory, antPattern, dotSeparatedAntPattern, excludeBuildFolders.get(), output);
|
||||
if (convertToYaml.get()) {
|
||||
convertContractsToYaml(contractsDirectory, antPattern, dotSeparatedAntPattern, output, excludeBuildFolders.get());
|
||||
convertContractsToYaml(contractsDirectory, antPattern, dotSeparatedAntPattern, output,
|
||||
excludeBuildFolders.get());
|
||||
}
|
||||
}
|
||||
|
||||
private void convertContractsToYaml(File file, String antPattern, String slashSeparatedAntPattern, File outputContractsFolder, boolean excludeBuildFolders) {
|
||||
private void convertContractsToYaml(File file, String antPattern, String slashSeparatedAntPattern,
|
||||
File outputContractsFolder, boolean excludeBuildFolders) {
|
||||
sync(file, antPattern, slashSeparatedAntPattern, excludeBuildFolders, backupContractsFolder.get().getAsFile());
|
||||
ToYamlConverter.replaceContractWithYaml(outputContractsFolder);
|
||||
getLogger().info("Replaced DSL files with their YAML representation at [{}]", outputContractsFolder);
|
||||
}
|
||||
|
||||
private void sync(File file, String antPattern, String dotSeparatedAntPattern, boolean excludeBuildFolders, File outputContractsFolder) {
|
||||
private void sync(File file, String antPattern, String dotSeparatedAntPattern, boolean excludeBuildFolders,
|
||||
File outputContractsFolder) {
|
||||
getProject().sync(spec -> {
|
||||
spec.from(file);
|
||||
// by default group id is slash separated...
|
||||
@@ -215,23 +223,26 @@ class ContractsCopyTask extends DefaultTask {
|
||||
final ContractDownloader contractDownloader = new ContractDownloader(downloader, configuration,
|
||||
contractsPath.getOrNull(), groupId, artifactId, getProject().getVersion().toString());
|
||||
final File downloadedContracts = contractDownloader.unpackAndDownloadContracts();
|
||||
final ContractDownloader.InclusionProperties inclusionProperties =
|
||||
contractDownloader.createNewInclusionProperties(downloadedContracts);
|
||||
final ContractDownloader.InclusionProperties inclusionProperties = contractDownloader
|
||||
.createNewInclusionProperties(downloadedContracts);
|
||||
|
||||
// TODO: inclusionProperties.includedContracts is never used eventually. Review this:
|
||||
// TODO: inclusionProperties.includedContracts is never used eventually. Review
|
||||
// this:
|
||||
return new DownloadedData(contractsSubDirIfPresent(downloadedContracts), inclusionProperties);
|
||||
}
|
||||
|
||||
private void throwExceptionWhenFailOnNoContracts(@Nullable File file, String contractsRepository) {
|
||||
if (StringUtils.hasText(contractsRepository)) {
|
||||
if (getLogger().isDebugEnabled()) {
|
||||
getLogger().debug("Contracts repository is set, will not throw an exception that the contracts are not found");
|
||||
getLogger().debug(
|
||||
"Contracts repository is set, will not throw an exception that the contracts are not found");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (failOnNoContracts.get() && (!file.exists() || file.listFiles().length == 0)) {
|
||||
String path = file.getAbsolutePath();
|
||||
throw new GradleException("Contracts could not be found: [" + path + "]\nPlease make sure that the contracts were defined, or set the [failOnNoContracts] flag to [false]");
|
||||
throw new GradleException("Contracts could not be found: [" + path
|
||||
+ "]\nPlease make sure that the contracts were defined, or set the [failOnNoContracts] flag to [false]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,13 +258,16 @@ class ContractsCopyTask extends DefaultTask {
|
||||
}
|
||||
|
||||
private class DownloadedData {
|
||||
|
||||
final File downloadedContracts;
|
||||
|
||||
final ContractDownloader.InclusionProperties inclusionProperties;
|
||||
|
||||
private DownloadedData(File downloadedContracts, ContractDownloader.InclusionProperties inclusionProperties) {
|
||||
this.downloadedContracts = downloadedContracts;
|
||||
this.inclusionProperties = inclusionProperties;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Input
|
||||
@@ -278,12 +292,17 @@ class ContractsCopyTask extends DefaultTask {
|
||||
}
|
||||
|
||||
static class Dependency {
|
||||
|
||||
private static final String LATEST_VERSION = "+";
|
||||
|
||||
private final Property<String> groupId;
|
||||
|
||||
private final Property<String> artifactId;
|
||||
|
||||
private final Property<String> version;
|
||||
|
||||
private final Property<String> classifier;
|
||||
|
||||
private final Property<String> stringNotation;
|
||||
|
||||
@Inject
|
||||
@@ -334,11 +353,11 @@ class ContractsCopyTask extends DefaultTask {
|
||||
|
||||
String groupId = this.groupId.getOrNull();
|
||||
String artifactId = this.artifactId.getOrNull();
|
||||
String version = StringUtils.hasText(this.version.getOrNull()) ?
|
||||
this.version.getOrNull() : LATEST_VERSION;
|
||||
String version = StringUtils.hasText(this.version.getOrNull()) ? this.version.getOrNull() : LATEST_VERSION;
|
||||
String classifier = this.classifier.getOrNull();
|
||||
return new StubConfiguration(groupId, artifactId, version, classifier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nested
|
||||
@@ -347,10 +366,15 @@ class ContractsCopyTask extends DefaultTask {
|
||||
}
|
||||
|
||||
static class Repository {
|
||||
|
||||
private final Property<String> repositoryUrl;
|
||||
|
||||
private final Property<String> username;
|
||||
|
||||
private final Property<String> password;
|
||||
|
||||
private final Property<String> proxyHost;
|
||||
|
||||
private final Property<Integer> proxyPort;
|
||||
|
||||
@Inject
|
||||
@@ -391,6 +415,7 @@ class ContractsCopyTask extends DefaultTask {
|
||||
Property<Integer> getProxyPort() {
|
||||
return proxyPort;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Input
|
||||
@@ -432,24 +457,23 @@ class ContractsCopyTask extends DefaultTask {
|
||||
}
|
||||
|
||||
private boolean shouldDownloadContracts() {
|
||||
return StringUtils.hasText(contractDependency.getArtifactId().getOrNull()) ||
|
||||
StringUtils.hasText(contractDependency.getStringNotation().getOrNull()) ||
|
||||
StringUtils.hasText(contractRepository.getRepositoryUrl().getOrNull());
|
||||
return StringUtils.hasText(contractDependency.getArtifactId().getOrNull())
|
||||
|| StringUtils.hasText(contractDependency.getStringNotation().getOrNull())
|
||||
|| StringUtils.hasText(contractRepository.getRepositoryUrl().getOrNull());
|
||||
}
|
||||
|
||||
private StubRunnerOptions createStubRunnerOptions() {
|
||||
StubRunnerOptionsBuilder options = new StubRunnerOptionsBuilder()
|
||||
.withOptions(StubRunnerOptions.fromSystemProps())
|
||||
.withStubRepositoryRoot(contractRepository.repositoryUrl.getOrNull())
|
||||
.withStubsMode(contractsMode.get())
|
||||
.withStubRepositoryRoot(contractRepository.repositoryUrl.getOrNull()).withStubsMode(contractsMode.get())
|
||||
.withUsername(contractRepository.username.getOrNull())
|
||||
.withPassword(contractRepository.password.getOrNull())
|
||||
.withDeleteStubsAfterTest(deleteStubsAfterTest.get())
|
||||
.withProperties(contractsProperties.getOrNull())
|
||||
.withDeleteStubsAfterTest(deleteStubsAfterTest.get()).withProperties(contractsProperties.getOrNull())
|
||||
.withFailOnNoStubs(failOnNoContracts.get());
|
||||
if (contractRepository.proxyPort.isPresent()) {
|
||||
options = options.withProxy(contractRepository.proxyHost.getOrNull(), contractRepository.proxyPort.get());
|
||||
}
|
||||
return options.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -75,8 +75,8 @@ class GenerateClientStubsFromDslTask extends DefaultTask {
|
||||
getLogger().info("Spring Cloud Contract Verifier Plugin: Invoking DSL to client stubs conversion");
|
||||
getLogger().info("Contracts dir is [{}] output stubs dir is [{}]", contractsDslDir.get().getAsFile(), output);
|
||||
List<String> excludedFiles = this.excludedFiles.get();
|
||||
RecursiveFilesConverter converter = new RecursiveFilesConverter(output,
|
||||
contractsDslDir.get().getAsFile(), excludedFiles, ".*", excludeBuildFolders.get());
|
||||
RecursiveFilesConverter converter = new RecursiveFilesConverter(output, contractsDslDir.get().getAsFile(),
|
||||
excludedFiles, ".*", excludeBuildFolders.get());
|
||||
converter.processFiles();
|
||||
}
|
||||
|
||||
@@ -100,4 +100,5 @@ class GenerateClientStubsFromDslTask extends DefaultTask {
|
||||
public Property<Directory> getStubsOutputDir() {
|
||||
return stubsOutputDir;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,24 +51,41 @@ import java.util.List;
|
||||
*/
|
||||
@CacheableTask
|
||||
class GenerateServerTestsTask extends DefaultTask {
|
||||
|
||||
static final String TASK_NAME = "generateContractTests";
|
||||
|
||||
private final DirectoryProperty contractsDslDir;
|
||||
|
||||
private final Property<String> nameSuffixForTests;
|
||||
|
||||
private final Property<String> basePackageForTests;
|
||||
|
||||
private final Property<String> baseClassForTests;
|
||||
|
||||
private final Property<String> packageWithBaseClasses;
|
||||
|
||||
private final ListProperty<String> excludedFiles;
|
||||
|
||||
private final ListProperty<String> ignoredFiles;
|
||||
|
||||
private final ListProperty<String> includedFiles;
|
||||
|
||||
private final ListProperty<String> imports;
|
||||
|
||||
private final ListProperty<String> staticImports;
|
||||
|
||||
private final Property<TestMode> testMode;
|
||||
|
||||
private final Property<TestFramework> testFramework;
|
||||
|
||||
private final MapProperty<String, String> baseClassMappings;
|
||||
|
||||
private final Property<Boolean> assertJsonSize;
|
||||
|
||||
private final Property<Boolean> failOnInProgress;
|
||||
|
||||
private final DirectoryProperty generatedTestSourcesDir;
|
||||
|
||||
private final DirectoryProperty generatedTestResourcesDir;
|
||||
|
||||
@Inject
|
||||
@@ -104,7 +121,8 @@ class GenerateServerTestsTask extends DefaultTask {
|
||||
getLogger().info("Contracts are unpacked to [{}]", contractsDslDir);
|
||||
getLogger().info("Included contracts are [{}]", includedContracts);
|
||||
try {
|
||||
TestGenerator generator = new TestGenerator(toConfigProperties(contractsDslDir, includedContracts, generatedTestSources, generatedTestResources));
|
||||
TestGenerator generator = new TestGenerator(toConfigProperties(contractsDslDir, includedContracts,
|
||||
generatedTestSources, generatedTestResources));
|
||||
int generatedClasses = generator.generate();
|
||||
getLogger().info("Generated {} test classes", generatedClasses);
|
||||
}
|
||||
@@ -203,9 +221,8 @@ class GenerateServerTestsTask extends DefaultTask {
|
||||
return generatedTestResourcesDir;
|
||||
}
|
||||
|
||||
private ContractVerifierConfigProperties toConfigProperties(File contractsDslDir,
|
||||
String includedContracts, File generatedTestSources,
|
||||
File generatedTestResources) {
|
||||
private ContractVerifierConfigProperties toConfigProperties(File contractsDslDir, String includedContracts,
|
||||
File generatedTestSources, File generatedTestResources) {
|
||||
List<String> excludedFiles = this.excludedFiles.get();
|
||||
List<String> ignoredFiles = this.ignoredFiles.get();
|
||||
List<String> includedFiles = this.includedFiles.get();
|
||||
@@ -233,4 +250,5 @@ class GenerateServerTestsTask extends DefaultTask {
|
||||
properties.setFailOnInProgress(failOnInProgress.get());
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,13 +38,13 @@ import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* For SCM based repositories will copy the generated stubs
|
||||
* to the cloned repo with contracts and stubs. Will also
|
||||
* commit the changes and push them to origin.
|
||||
* For SCM based repositories will copy the generated stubs to the cloned repo with
|
||||
* contracts and stubs. Will also commit the changes and push them to origin.
|
||||
*
|
||||
* NOTE: starting with 2.3.0.RELEASE the <code>customize{}</code> closure previously used for
|
||||
* {@link PublishStubsToScmTask} customisation is no longer available. The settings should be applied directly
|
||||
* within the <code>publishStubsToScm</code> closure as in the example above.
|
||||
* NOTE: starting with 2.3.0.RELEASE the <code>customize{}</code> closure previously used
|
||||
* for {@link PublishStubsToScmTask} customisation is no longer available. The settings
|
||||
* should be applied directly within the <code>publishStubsToScm</code> closure as in the
|
||||
* example above.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @author Anatoliy Balakirev
|
||||
@@ -62,8 +62,8 @@ class PublishStubsToScmTask extends DefaultTask {
|
||||
/**
|
||||
* @see ContractVerifierExtension#deleteStubsAfterTest
|
||||
*
|
||||
* This property will delete the Git repository where the input
|
||||
* stubs to this task have been committed.
|
||||
* This property will delete the Git repository where the input stubs to this task
|
||||
* have been committed.
|
||||
*/
|
||||
private final Property<Boolean> deleteStubsAfterTest;
|
||||
|
||||
@@ -85,7 +85,9 @@ class PublishStubsToScmTask extends DefaultTask {
|
||||
this.onlyIf(task -> {
|
||||
String contractRepoUrl = contractRepository.repositoryUrl.getOrElse("");
|
||||
if (StringUtils.isEmpty(contractRepoUrl) || !ScmStubDownloaderBuilder.isProtocolAccepted(contractRepoUrl)) {
|
||||
getLogger().warn("Skipping pushing stubs to scm since your contracts repository URL [{}] doesn't match any of the accepted protocols for SCM stub downloader", contractRepoUrl);
|
||||
getLogger().warn(
|
||||
"Skipping pushing stubs to scm since your contracts repository URL [{}] doesn't match any of the accepted protocols for SCM stub downloader",
|
||||
contractRepoUrl);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -94,10 +96,12 @@ class PublishStubsToScmTask extends DefaultTask {
|
||||
|
||||
@TaskAction
|
||||
void publishStubsToScm() {
|
||||
String projectName = getProject().getGroup().toString() + ":" + getProject().getName() + ":" + getProject().getVersion().toString();
|
||||
String projectName = getProject().getGroup().toString() + ":" + getProject().getName() + ":"
|
||||
+ getProject().getVersion().toString();
|
||||
getLogger().info("Pushing Stubs to SCM for project [{}]", projectName);
|
||||
StubRunnerOptions stubRunnerOptions = createStubRunnerOptions();
|
||||
new ContractProjectUpdater(stubRunnerOptions).updateContractProject(projectName, stubsDir.get().getAsFile().toPath());
|
||||
new ContractProjectUpdater(stubRunnerOptions).updateContractProject(projectName,
|
||||
stubsDir.get().getAsFile().toPath());
|
||||
}
|
||||
|
||||
@Nested
|
||||
@@ -106,10 +110,15 @@ class PublishStubsToScmTask extends DefaultTask {
|
||||
}
|
||||
|
||||
static class Repository {
|
||||
|
||||
private final Property<String> repositoryUrl;
|
||||
|
||||
private final Property<String> username;
|
||||
|
||||
private final Property<String> password;
|
||||
|
||||
private final Property<Integer> proxyPort;
|
||||
|
||||
private final Property<String> proxyHost;
|
||||
|
||||
@Inject
|
||||
@@ -150,6 +159,7 @@ class PublishStubsToScmTask extends DefaultTask {
|
||||
Property<String> getProxyHost() {
|
||||
return proxyHost;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Input
|
||||
@@ -181,16 +191,15 @@ class PublishStubsToScmTask extends DefaultTask {
|
||||
private StubRunnerOptions createStubRunnerOptions() {
|
||||
StubRunnerOptionsBuilder options = new StubRunnerOptionsBuilder()
|
||||
.withOptions(StubRunnerOptions.fromSystemProps())
|
||||
.withStubRepositoryRoot(contractRepository.repositoryUrl.getOrNull())
|
||||
.withStubsMode(contractsMode.get())
|
||||
.withStubRepositoryRoot(contractRepository.repositoryUrl.getOrNull()).withStubsMode(contractsMode.get())
|
||||
.withUsername(contractRepository.username.getOrNull())
|
||||
.withPassword(contractRepository.password.getOrNull())
|
||||
.withDeleteStubsAfterTest(deleteStubsAfterTest.get())
|
||||
.withProperties(contractsProperties.getOrNull())
|
||||
.withDeleteStubsAfterTest(deleteStubsAfterTest.get()).withProperties(contractsProperties.getOrNull())
|
||||
.withFailOnNoStubs(failOnNoContracts.get());
|
||||
if (contractRepository.proxyPort.isPresent()) {
|
||||
options = options.withProxy(contractRepository.proxyHost.getOrNull(), contractRepository.proxyPort.get());
|
||||
}
|
||||
return options.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,26 +49,32 @@ import org.springframework.cloud.contract.verifier.config.TestFramework;
|
||||
/**
|
||||
* Gradle plugin for Spring Cloud Contract Verifier that from the DSL contract can
|
||||
* <ul>
|
||||
* <li>generate tests</li>
|
||||
* <li>generate stubs</li>
|
||||
* <li>generate tests</li>
|
||||
* <li>generate stubs</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Jakub Kubrynski, codearte.io
|
||||
* @author Marcin Grzejszczak
|
||||
* @author Anatoliy Balakirev
|
||||
* @author Shannon Pamperl
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
|
||||
|
||||
private static final String GROUP_NAME = "Verification";
|
||||
|
||||
private static final String EXTENSION_NAME = "contracts";
|
||||
|
||||
private static final String CONTRACT_TEST_SOURCE_SET_NAME = "contractTest";
|
||||
|
||||
private static final String CONTRACT_TEST_COMPILE_ONLY_CONFIGURATION_NAME = "contractTestCompileOnly";
|
||||
|
||||
private static final String CONTRACT_TEST_IMPLEMENTATION_CONFIGURATION_NAME = "contractTestImplementation";
|
||||
|
||||
private static final String CONTRACT_TEST_RUNTIME_ONLY_CONFIGURATION_NAME = "contractTestRuntimeOnly";
|
||||
|
||||
private static final String VERIFIER_STUBS_JAR_TASK_NAME = "verifierStubsJar";
|
||||
|
||||
private static final String CONTRACT_TEST_TASK_NAME = "contractTest";
|
||||
|
||||
private Project project;
|
||||
@@ -77,7 +83,8 @@ public class SpringCloudContractVerifierGradlePlugin implements Plugin<Project>
|
||||
public void apply(Project project) {
|
||||
this.project = project;
|
||||
project.getPlugins().apply(JavaPlugin.class);
|
||||
ContractVerifierExtension extension = project.getExtensions().create(EXTENSION_NAME, ContractVerifierExtension.class);
|
||||
ContractVerifierExtension extension = project.getExtensions().create(EXTENSION_NAME,
|
||||
ContractVerifierExtension.class);
|
||||
|
||||
JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
|
||||
SourceSet contractTestSourceSet = configureSourceSets(extension, javaConvention);
|
||||
@@ -85,7 +92,8 @@ public class SpringCloudContractVerifierGradlePlugin implements Plugin<Project>
|
||||
registerContractTestTask(contractTestSourceSet);
|
||||
|
||||
TaskProvider<ContractsCopyTask> copyContracts = createAndConfigureCopyContractsTask(extension);
|
||||
TaskProvider<GenerateClientStubsFromDslTask> generateClientStubs = createAndConfigureGenerateClientStubs(extension, copyContracts);
|
||||
TaskProvider<GenerateClientStubsFromDslTask> generateClientStubs = createAndConfigureGenerateClientStubs(
|
||||
extension, copyContracts);
|
||||
|
||||
createAndConfigureStubsJarTasks(extension, generateClientStubs);
|
||||
createGenerateTestsTask(extension, contractTestSourceSet, copyContracts);
|
||||
@@ -96,10 +104,12 @@ public class SpringCloudContractVerifierGradlePlugin implements Plugin<Project>
|
||||
if (generatedTestSourcesDir.isPresent()) {
|
||||
if (extension.getTestFramework().get() == TestFramework.SPOCK) {
|
||||
project.getPlugins().withType(GroovyPlugin.class, groovyPlugin -> {
|
||||
GroovySourceSet groovy = ((HasConvention) contractTestSourceSet).getConvention().getPlugin(GroovySourceSet.class);
|
||||
GroovySourceSet groovy = ((HasConvention) contractTestSourceSet).getConvention()
|
||||
.getPlugin(GroovySourceSet.class);
|
||||
groovy.getGroovy().srcDirs(generatedTestSourcesDir);
|
||||
});
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
contractTestSourceSet.getJava().srcDirs(generatedTestSourcesDir);
|
||||
}
|
||||
}
|
||||
@@ -134,7 +144,8 @@ public class SpringCloudContractVerifierGradlePlugin implements Plugin<Project>
|
||||
Configuration testImplementation = configurations.getByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME);
|
||||
Configuration testRuntimeOnly = configurations.getByName(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME);
|
||||
Configuration contractTestCompileOnly = configurations.getByName(CONTRACT_TEST_COMPILE_ONLY_CONFIGURATION_NAME);
|
||||
Configuration contractTestImplementation = configurations.getByName(CONTRACT_TEST_IMPLEMENTATION_CONFIGURATION_NAME);
|
||||
Configuration contractTestImplementation = configurations
|
||||
.getByName(CONTRACT_TEST_IMPLEMENTATION_CONFIGURATION_NAME);
|
||||
Configuration contractTestRuntimeOnly = configurations.getByName(CONTRACT_TEST_RUNTIME_ONLY_CONFIGURATION_NAME);
|
||||
|
||||
contractTestCompileOnly.extendsFrom(testCompileOnly);
|
||||
@@ -143,25 +154,29 @@ public class SpringCloudContractVerifierGradlePlugin implements Plugin<Project>
|
||||
}
|
||||
|
||||
private void registerContractTestTask(SourceSet contractTestSourceSet) {
|
||||
TaskProvider<Test> contractTestTask = project.getTasks().register(CONTRACT_TEST_TASK_NAME, Test.class, contractTest -> {
|
||||
contractTest.setDescription("Runs the contract tests");
|
||||
contractTest.setGroup(GROUP_NAME);
|
||||
contractTest.setTestClassesDirs(contractTestSourceSet.getOutput().getClassesDirs());
|
||||
contractTest.setClasspath(contractTestSourceSet.getRuntimeClasspath());
|
||||
TaskProvider<Test> contractTestTask = project.getTasks().register(CONTRACT_TEST_TASK_NAME, Test.class,
|
||||
contractTest -> {
|
||||
contractTest.setDescription("Runs the contract tests");
|
||||
contractTest.setGroup(GROUP_NAME);
|
||||
contractTest.setTestClassesDirs(contractTestSourceSet.getOutput().getClassesDirs());
|
||||
contractTest.setClasspath(contractTestSourceSet.getRuntimeClasspath());
|
||||
|
||||
contractTest.mustRunAfter(project.getTasks().named(JavaPlugin.TEST_TASK_NAME));
|
||||
});
|
||||
contractTest.mustRunAfter(project.getTasks().named(JavaPlugin.TEST_TASK_NAME));
|
||||
});
|
||||
|
||||
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME, check -> check.dependsOn(contractTestTask));
|
||||
}
|
||||
|
||||
private void createGenerateTestsTask(ContractVerifierExtension extension, SourceSet contractTestSourceSet, TaskProvider<ContractsCopyTask> copyContracts) {
|
||||
TaskProvider<GenerateServerTestsTask> task = project.getTasks().register(GenerateServerTestsTask.TASK_NAME, GenerateServerTestsTask.class);
|
||||
private void createGenerateTestsTask(ContractVerifierExtension extension, SourceSet contractTestSourceSet,
|
||||
TaskProvider<ContractsCopyTask> copyContracts) {
|
||||
TaskProvider<GenerateServerTestsTask> task = project.getTasks().register(GenerateServerTestsTask.TASK_NAME,
|
||||
GenerateServerTestsTask.class);
|
||||
task.configure(generateServerTestsTask -> {
|
||||
generateServerTestsTask.setDescription("Generate server tests from the contracts");
|
||||
generateServerTestsTask.setGroup(GROUP_NAME);
|
||||
|
||||
generateServerTestsTask.getContractsDslDir().convention(copyContracts.flatMap(ContractsCopyTask::getCopiedContractsFolder));
|
||||
generateServerTestsTask.getContractsDslDir()
|
||||
.convention(copyContracts.flatMap(ContractsCopyTask::getCopiedContractsFolder));
|
||||
generateServerTestsTask.getNameSuffixForTests().convention(extension.getNameSuffixForTests());
|
||||
generateServerTestsTask.getBasePackageForTests().convention(extension.getBasePackageForTests());
|
||||
generateServerTestsTask.getBaseClassForTests().convention(extension.getBaseClassForTests());
|
||||
@@ -173,18 +188,21 @@ public class SpringCloudContractVerifierGradlePlugin implements Plugin<Project>
|
||||
generateServerTestsTask.getStaticImports().convention(extension.getStaticImports());
|
||||
generateServerTestsTask.getTestMode().convention(extension.getTestMode());
|
||||
generateServerTestsTask.getTestFramework().convention(extension.getTestFramework());
|
||||
generateServerTestsTask.getBaseClassMappings().convention(extension.getBaseClassMappings().getBaseClassMappings());
|
||||
generateServerTestsTask.getBaseClassMappings()
|
||||
.convention(extension.getBaseClassMappings().getBaseClassMappings());
|
||||
generateServerTestsTask.getAssertJsonSize().convention(extension.getAssertJsonSize());
|
||||
generateServerTestsTask.getFailOnInProgress().convention(extension.getFailOnInProgress());
|
||||
generateServerTestsTask.getGeneratedTestSourcesDir().convention(extension.getTestFramework().flatMap(testFramework -> {
|
||||
Property<Directory> correctSourceSetDir;
|
||||
if (testFramework == TestFramework.SPOCK) {
|
||||
correctSourceSetDir = extension.getGeneratedTestGroovySourcesDir();
|
||||
} else {
|
||||
correctSourceSetDir = extension.getGeneratedTestJavaSourcesDir();
|
||||
}
|
||||
return extension.getGeneratedTestSourcesDir().orElse(correctSourceSetDir);
|
||||
}));
|
||||
generateServerTestsTask.getGeneratedTestSourcesDir()
|
||||
.convention(extension.getTestFramework().flatMap(testFramework -> {
|
||||
Property<Directory> correctSourceSetDir;
|
||||
if (testFramework == TestFramework.SPOCK) {
|
||||
correctSourceSetDir = extension.getGeneratedTestGroovySourcesDir();
|
||||
}
|
||||
else {
|
||||
correctSourceSetDir = extension.getGeneratedTestJavaSourcesDir();
|
||||
}
|
||||
return extension.getGeneratedTestSourcesDir().orElse(correctSourceSetDir);
|
||||
}));
|
||||
generateServerTestsTask.getGeneratedTestResourcesDir().convention(extension.getGeneratedTestResourcesDir());
|
||||
|
||||
generateServerTestsTask.dependsOn(copyContracts);
|
||||
@@ -201,48 +219,60 @@ public class SpringCloudContractVerifierGradlePlugin implements Plugin<Project>
|
||||
|
||||
private void createAndConfigurePublishStubsToScmTask(ContractVerifierExtension extension,
|
||||
TaskProvider<GenerateClientStubsFromDslTask> generateClientStubs) {
|
||||
TaskProvider<PublishStubsToScmTask> task = project.getTasks().register(PublishStubsToScmTask.TASK_NAME, PublishStubsToScmTask.class);
|
||||
TaskProvider<PublishStubsToScmTask> task = project.getTasks().register(PublishStubsToScmTask.TASK_NAME,
|
||||
PublishStubsToScmTask.class);
|
||||
task.configure(publishStubsToScmTask -> {
|
||||
publishStubsToScmTask.setDescription("The generated stubs get committed to the SCM repo and pushed to origin");
|
||||
publishStubsToScmTask
|
||||
.setDescription("The generated stubs get committed to the SCM repo and pushed to origin");
|
||||
publishStubsToScmTask.setGroup(GROUP_NAME);
|
||||
|
||||
ContractVerifierExtension.ContractRepository stubs = extension.getPublishStubsToScm().getContractRepository();
|
||||
ContractVerifierExtension.ContractRepository stubs = extension.getPublishStubsToScm()
|
||||
.getContractRepository();
|
||||
ContractVerifierExtension.ContractRepository original = extension.getContractRepository();
|
||||
|
||||
publishStubsToScmTask.getContractRepository().getRepositoryUrl().convention(stubs.getRepositoryUrl().orElse(original.getRepositoryUrl()));
|
||||
publishStubsToScmTask.getContractRepository().getUsername().convention(stubs.getUsername().orElse(original.getUsername()));
|
||||
publishStubsToScmTask.getContractRepository().getPassword().convention(stubs.getPassword().orElse(original.getPassword()));
|
||||
publishStubsToScmTask.getContractRepository().getProxyHost().convention(stubs.getProxyHost().orElse(original.getProxyHost()));
|
||||
publishStubsToScmTask.getContractRepository().getProxyPort().convention(stubs.getProxyPort().orElse(original.getProxyPort()));
|
||||
publishStubsToScmTask.getContractRepository().getRepositoryUrl()
|
||||
.convention(stubs.getRepositoryUrl().orElse(original.getRepositoryUrl()));
|
||||
publishStubsToScmTask.getContractRepository().getUsername()
|
||||
.convention(stubs.getUsername().orElse(original.getUsername()));
|
||||
publishStubsToScmTask.getContractRepository().getPassword()
|
||||
.convention(stubs.getPassword().orElse(original.getPassword()));
|
||||
publishStubsToScmTask.getContractRepository().getProxyHost()
|
||||
.convention(stubs.getProxyHost().orElse(original.getProxyHost()));
|
||||
publishStubsToScmTask.getContractRepository().getProxyPort()
|
||||
.convention(stubs.getProxyPort().orElse(original.getProxyPort()));
|
||||
publishStubsToScmTask.getContractsMode().convention(extension.getContractsMode());
|
||||
publishStubsToScmTask.getDeleteStubsAfterTest().convention(extension.getDeleteStubsAfterTest());
|
||||
publishStubsToScmTask.getFailOnNoContracts().convention(extension.getFailOnNoContracts());
|
||||
publishStubsToScmTask.getContractsProperties().convention(extension.getContractsProperties());
|
||||
publishStubsToScmTask.getStubsDir().convention(generateClientStubs.flatMap(GenerateClientStubsFromDslTask::getStubsOutputDir));
|
||||
publishStubsToScmTask.getStubsDir()
|
||||
.convention(generateClientStubs.flatMap(GenerateClientStubsFromDslTask::getStubsOutputDir));
|
||||
|
||||
publishStubsToScmTask.dependsOn(generateClientStubs);
|
||||
});
|
||||
}
|
||||
|
||||
private TaskProvider<GenerateClientStubsFromDslTask> createAndConfigureGenerateClientStubs(ContractVerifierExtension extension,
|
||||
TaskProvider<ContractsCopyTask> copyContracts) {
|
||||
TaskProvider<GenerateClientStubsFromDslTask> task = project.getTasks().register(GenerateClientStubsFromDslTask.TASK_NAME, GenerateClientStubsFromDslTask.class, generateClientStubs -> {
|
||||
generateClientStubs.setGroup(GROUP_NAME);
|
||||
generateClientStubs.setDescription("Generate client stubs from the contracts");
|
||||
private TaskProvider<GenerateClientStubsFromDslTask> createAndConfigureGenerateClientStubs(
|
||||
ContractVerifierExtension extension, TaskProvider<ContractsCopyTask> copyContracts) {
|
||||
TaskProvider<GenerateClientStubsFromDslTask> task = project.getTasks().register(
|
||||
GenerateClientStubsFromDslTask.TASK_NAME, GenerateClientStubsFromDslTask.class, generateClientStubs -> {
|
||||
generateClientStubs.setGroup(GROUP_NAME);
|
||||
generateClientStubs.setDescription("Generate client stubs from the contracts");
|
||||
|
||||
generateClientStubs.getContractsDslDir().convention(copyContracts.flatMap(ContractsCopyTask::getCopiedContractsFolder));
|
||||
generateClientStubs.getExcludedFiles().convention(extension.getExcludedFiles());
|
||||
generateClientStubs.getExcludeBuildFolders().convention(extension.getExcludeBuildFolders());
|
||||
generateClientStubs.getContractsDslDir()
|
||||
.convention(copyContracts.flatMap(ContractsCopyTask::getCopiedContractsFolder));
|
||||
generateClientStubs.getExcludedFiles().convention(extension.getExcludedFiles());
|
||||
generateClientStubs.getExcludeBuildFolders().convention(extension.getExcludeBuildFolders());
|
||||
|
||||
generateClientStubs.getStubsOutputDir().convention(extension.getStubsOutputDir().dir(buildRootPath(GenerateClientStubsFromDslTask.DEFAULT_MAPPINGS_FOLDER)));
|
||||
generateClientStubs.getStubsOutputDir().convention(extension.getStubsOutputDir()
|
||||
.dir(buildRootPath(GenerateClientStubsFromDslTask.DEFAULT_MAPPINGS_FOLDER)));
|
||||
|
||||
generateClientStubs.dependsOn(copyContracts);
|
||||
});
|
||||
generateClientStubs.dependsOn(copyContracts);
|
||||
});
|
||||
return task;
|
||||
}
|
||||
|
||||
private void createAndConfigureStubsJarTasks(ContractVerifierExtension extension,
|
||||
TaskProvider<GenerateClientStubsFromDslTask> generateClientStubs) {
|
||||
TaskProvider<GenerateClientStubsFromDslTask> generateClientStubs) {
|
||||
TaskProvider<Jar> verifierStubsJar = project.getTasks().register(VERIFIER_STUBS_JAR_TASK_NAME, Jar.class);
|
||||
verifierStubsJar.configure(stubsJar -> {
|
||||
stubsJar.setDescription("Creates the stubs JAR task");
|
||||
@@ -258,12 +288,14 @@ public class SpringCloudContractVerifierGradlePlugin implements Plugin<Project>
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void createAndConfigureMavenPublishPlugin(TaskProvider<Jar> stubsTask, ContractVerifierExtension extension) {
|
||||
private void createAndConfigureMavenPublishPlugin(TaskProvider<Jar> stubsTask,
|
||||
ContractVerifierExtension extension) {
|
||||
if (!classIsOnClasspath("org.gradle.api.publish.maven.plugins.MavenPublishPlugin")) {
|
||||
project.getLogger().debug("Maven Publish Plugin is not present - won't add default publication");
|
||||
return;
|
||||
}
|
||||
// This must be called within afterEvaluate due to getting data from extension, which must be initialised first:
|
||||
// This must be called within afterEvaluate due to getting data from extension,
|
||||
// which must be initialised first:
|
||||
project.afterEvaluate(inner -> {
|
||||
project.getLogger().debug("Spring Cloud Contract Verifier Plugin: Generating default publication");
|
||||
if (extension.getDisableStubPublication().get()) {
|
||||
@@ -273,10 +305,12 @@ public class SpringCloudContractVerifierGradlePlugin implements Plugin<Project>
|
||||
project.getPlugins().withType(MavenPublishPlugin.class, publishingPlugin -> {
|
||||
PublishingExtension publishingExtension = project.getExtensions().findByType(PublishingExtension.class);
|
||||
if (hasStubsPublication(publishingExtension)) {
|
||||
project.getLogger().info("Spring Cloud Contract Verifier Plugin: Stubs publication was present - won't create a new one. Remember about passing stubs as artifact");
|
||||
project.getLogger().info(
|
||||
"Spring Cloud Contract Verifier Plugin: Stubs publication was present - won't create a new one. Remember about passing stubs as artifact");
|
||||
}
|
||||
else {
|
||||
project.getLogger().debug("Spring Cloud Contract Verifier Plugin: Stubs publication is not present - will create one");
|
||||
project.getLogger().debug(
|
||||
"Spring Cloud Contract Verifier Plugin: Stubs publication is not present - will create one");
|
||||
setPublications(publishingExtension, stubsTask);
|
||||
}
|
||||
});
|
||||
@@ -314,32 +348,45 @@ public class SpringCloudContractVerifierGradlePlugin implements Plugin<Project>
|
||||
}
|
||||
|
||||
private TaskProvider<ContractsCopyTask> createAndConfigureCopyContractsTask(ContractVerifierExtension extension) {
|
||||
TaskProvider<ContractsCopyTask> task = project.getTasks().register(ContractsCopyTask.TASK_NAME, ContractsCopyTask.class, contractsCopyTask -> {
|
||||
contractsCopyTask.setGroup(GROUP_NAME);
|
||||
contractsCopyTask.setDescription("Copies contracts to the output folder");
|
||||
TaskProvider<ContractsCopyTask> task = project.getTasks().register(ContractsCopyTask.TASK_NAME,
|
||||
ContractsCopyTask.class, contractsCopyTask -> {
|
||||
contractsCopyTask.setGroup(GROUP_NAME);
|
||||
contractsCopyTask.setDescription("Copies contracts to the output folder");
|
||||
|
||||
contractsCopyTask.getConvertToYaml().convention(extension.getConvertToYaml());
|
||||
contractsCopyTask.getFailOnNoContracts().convention(extension.getFailOnNoContracts());
|
||||
contractsCopyTask.getContractsDirectory().convention(extension.getContractsDslDir());
|
||||
contractsCopyTask.getContractDependency().getGroupId().convention(extension.getContractDependency().getGroupId());
|
||||
contractsCopyTask.getContractDependency().getArtifactId().convention(extension.getContractDependency().getArtifactId());
|
||||
contractsCopyTask.getContractDependency().getVersion().convention(extension.getContractDependency().getVersion());
|
||||
contractsCopyTask.getContractDependency().getClassifier().convention(extension.getContractDependency().getClassifier());
|
||||
contractsCopyTask.getContractDependency().getStringNotation().convention(extension.getContractDependency().getStringNotation());
|
||||
contractsCopyTask.getContractRepository().getRepositoryUrl().convention(extension.getContractRepository().getRepositoryUrl());
|
||||
contractsCopyTask.getContractRepository().getUsername().convention(extension.getContractRepository().getUsername());
|
||||
contractsCopyTask.getContractRepository().getPassword().convention(extension.getContractRepository().getPassword());
|
||||
contractsCopyTask.getContractRepository().getProxyHost().convention(extension.getContractRepository().getProxyHost());
|
||||
contractsCopyTask.getContractRepository().getProxyPort().convention(extension.getContractRepository().getProxyPort());
|
||||
contractsCopyTask.getContractsMode().convention(extension.getContractsMode());
|
||||
contractsCopyTask.getContractsProperties().convention(extension.getContractsProperties());
|
||||
contractsCopyTask.getContractsPath().convention(extension.getContractsPath());
|
||||
contractsCopyTask.getExcludeBuildFolders().convention(extension.getExcludeBuildFolders());
|
||||
contractsCopyTask.getDeleteStubsAfterTest().convention(extension.getDeleteStubsAfterTest());
|
||||
contractsCopyTask.getConvertToYaml().convention(extension.getConvertToYaml());
|
||||
contractsCopyTask.getFailOnNoContracts().convention(extension.getFailOnNoContracts());
|
||||
contractsCopyTask.getContractsDirectory().convention(extension.getContractsDslDir());
|
||||
contractsCopyTask.getContractDependency().getGroupId()
|
||||
.convention(extension.getContractDependency().getGroupId());
|
||||
contractsCopyTask.getContractDependency().getArtifactId()
|
||||
.convention(extension.getContractDependency().getArtifactId());
|
||||
contractsCopyTask.getContractDependency().getVersion()
|
||||
.convention(extension.getContractDependency().getVersion());
|
||||
contractsCopyTask.getContractDependency().getClassifier()
|
||||
.convention(extension.getContractDependency().getClassifier());
|
||||
contractsCopyTask.getContractDependency().getStringNotation()
|
||||
.convention(extension.getContractDependency().getStringNotation());
|
||||
contractsCopyTask.getContractRepository().getRepositoryUrl()
|
||||
.convention(extension.getContractRepository().getRepositoryUrl());
|
||||
contractsCopyTask.getContractRepository().getUsername()
|
||||
.convention(extension.getContractRepository().getUsername());
|
||||
contractsCopyTask.getContractRepository().getPassword()
|
||||
.convention(extension.getContractRepository().getPassword());
|
||||
contractsCopyTask.getContractRepository().getProxyHost()
|
||||
.convention(extension.getContractRepository().getProxyHost());
|
||||
contractsCopyTask.getContractRepository().getProxyPort()
|
||||
.convention(extension.getContractRepository().getProxyPort());
|
||||
contractsCopyTask.getContractsMode().convention(extension.getContractsMode());
|
||||
contractsCopyTask.getContractsProperties().convention(extension.getContractsProperties());
|
||||
contractsCopyTask.getContractsPath().convention(extension.getContractsPath());
|
||||
contractsCopyTask.getExcludeBuildFolders().convention(extension.getExcludeBuildFolders());
|
||||
contractsCopyTask.getDeleteStubsAfterTest().convention(extension.getDeleteStubsAfterTest());
|
||||
|
||||
contractsCopyTask.getCopiedContractsFolder().convention(extension.getStubsOutputDir().dir(buildRootPath(ContractsCopyTask.CONTRACTS)));
|
||||
contractsCopyTask.getBackupContractsFolder().convention(extension.getStubsOutputDir().dir(buildRootPath(ContractsCopyTask.BACKUP)));
|
||||
});
|
||||
contractsCopyTask.getCopiedContractsFolder()
|
||||
.convention(extension.getStubsOutputDir().dir(buildRootPath(ContractsCopyTask.CONTRACTS)));
|
||||
contractsCopyTask.getBackupContractsFolder()
|
||||
.convention(extension.getStubsOutputDir().dir(buildRootPath(ContractsCopyTask.BACKUP)));
|
||||
});
|
||||
return task;
|
||||
}
|
||||
|
||||
@@ -358,16 +405,11 @@ public class SpringCloudContractVerifierGradlePlugin implements Plugin<Project>
|
||||
private Provider<String> buildRootPath(String path) {
|
||||
return project.provider(() -> {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("META-INF")
|
||||
.append(File.separator)
|
||||
.append(project.getGroup())
|
||||
.append(File.separator)
|
||||
.append(project.getName())
|
||||
.append(File.separator)
|
||||
.append(project.getVersion())
|
||||
.append(File.separator)
|
||||
.append(path);
|
||||
builder.append("META-INF").append(File.separator).append(project.getGroup()).append(File.separator)
|
||||
.append(project.getName()).append(File.separator).append(project.getVersion())
|
||||
.append(File.separator).append(path);
|
||||
return builder.toString();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user