Merge branch '1.0.x'

fixes #167
This commit is contained in:
Marcin Grzejszczak
2016-12-28 12:52:15 +01:00
17 changed files with 228 additions and 14 deletions

View File

@@ -342,13 +342,11 @@ Full test is generated by Spring Cloud Contract Verifier.
Spring Cloud Contract Verifier moves TDD to the level of software architecture.
==== Spring Cloud Contract Webinar
==== Spring Cloud Contract video
You can check out the video from the Spring Cloud Contract Webinar to watch the
explanation of the project and the concept of Consuner Driven Contracts. Video was recorded
on 25.10.2016.
You can check out the video from the Warsaw JUG about Spring Cloud Contract:
video::4fJiz0woxAc[youtube]
video::sAAklvxmPmk[youtube,start=538,width=640,height=480]
==== Why?

View File

@@ -17,13 +17,11 @@ Full test is generated by Spring Cloud Contract Verifier.
Spring Cloud Contract Verifier moves TDD to the level of software architecture.
==== Spring Cloud Contract Webinar
==== Spring Cloud Contract video
You can check out the video from the Spring Cloud Contract Webinar to watch the
explanation of the project and the concept of Consuner Driven Contracts. Video was recorded
on 25.10.2016.
You can check out the video from the Warsaw JUG about Spring Cloud Contract:
video::4fJiz0woxAc[youtube]
video::sAAklvxmPmk[youtube,start=538,width=640,height=480]
==== Why?

View File

@@ -67,6 +67,13 @@ class RecursiveFilesConverter {
File sourceFile = contract.path.toFile()
StubGenerator stubGenerator = holder.converterForName(sourceFile.name);
try {
String path = sourceFile.path
if (properties.isExcludeBuildFolders() && (matchesPath(path, "target") || matchesPath(path, "build"))) {
if (log.isDebugEnabled()) {
log.debug("Exclude build folder is set. Path [${path}] contains [target] or [build] in its path")
}
return
}
if (!contract.convertedContract && !stubGenerator) {
return
}
@@ -90,6 +97,10 @@ class RecursiveFilesConverter {
}
}
private boolean matchesPath(String path, String folder) {
return path.matches("^.*${File.separator}${folder}${File.separator}.*\$")
}
private Path createAndReturnTargetDirectory(File sourceFile) {
Path relativePath = Paths.get(properties.contractsDslDir.toURI()).relativize(sourceFile.parentFile.toPath())
Path absoluteTargetPath = outMappingsDir.toPath().resolve(relativePath)

View File

@@ -80,13 +80,21 @@ class RecursiveFilesConverter {
properties.excludedFiles as Set, [] as Set, properties.includedContracts)
ListMultimap<Path, ContractMetadata> contracts = scanner.findContracts()
if (log.isDebugEnabled()) {
log.debug("Found the following contracts $contracts")
log.debug("Found the following contracts ${contracts}")
log.debug("Exclude build folder: [${properties.isExcludeBuildFolders()}]")
}
contracts.asMap().entrySet().each { entry ->
entry.value.each { ContractMetadata contract ->
File sourceFile = contract.path.toFile()
StubGenerator stubGenerator = holder.converterForName(sourceFile.name);
try {
String path = sourceFile.path
if (properties.isExcludeBuildFolders() && (matchesPath(path, "target") || matchesPath(path, "build"))) {
if (log.isDebugEnabled()) {
log.debug("Exclude build folder is set. Path [${path}] contains [target] or [build] in its path")
}
return
}
if (!contract.convertedContract && !stubGenerator) {
return
}
@@ -110,6 +118,10 @@ class RecursiveFilesConverter {
}
}
private boolean matchesPath(String path, String folder) {
return path.matches("^.*${File.separator}${folder}${File.separator}.*\$")
}
private Path createAndReturnTargetDirectory(File sourceFile) {
Path relativePath = Paths.get(properties.contractsDslDir.toURI()).relativize(sourceFile.parentFile.toPath())
Path absoluteTargetPath = outMappingsDir.toPath().resolve(relativePath)

View File

@@ -134,6 +134,13 @@ class ContractVerifierExtension {
*/
Map<String, String> 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.
*/
boolean excludeBuildFolders
void contractDependency(@DelegatesTo(Dependency) Closure closure) {
closure.delegate = contractDependency
closure.call()

View File

@@ -32,6 +32,9 @@ class ContractsCopyTask extends ConventionTask {
project.copy {
from(file)
include(antPattern)
if (props.isExcludeBuildFolders()) {
exclude "**/target/**", "**/build/**"
}
into(outputContractsFolder)
}
}

View File

@@ -27,7 +27,8 @@ class ExtensionToProperties {
stubsSuffix: extension.stubsSuffix,
assertJsonSize: extension.assertJsonSize,
packageWithBaseClasses: extension.packageWithBaseClasses,
baseClassMappings: extension.baseClassMappings
baseClassMappings: extension.baseClassMappings,
excludeBuildFolders: extension.excludeBuildFolders
)
}
}

View File

@@ -90,6 +90,7 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
}
}
//TODO: Deprecate this since starting with 1.1.x
private void addProjectDependencies(Project project) {
//TODO: Consider removing this at some point
project.dependencies.add("testCompile", "com.github.tomakehurst:wiremock:2.1.7")

View File

@@ -108,6 +108,13 @@ public class ConvertMojo extends AbstractMojo {
@Parameter(property = "contractsWorkOffline", defaultValue = "false")
private boolean contractsWorkOffline;
/**
* If {@code true} then any file laying in a path that contains {@code build} or {@code target}
* will get excluded in further processing.
*/
@Parameter(property = "excludeBuildFolders", defaultValue = "false")
private boolean excludeBuildFolders;
@Component(role = MavenResourcesFiltering.class, hint = "default")
private MavenResourcesFiltering mavenResourcesFiltering;
@@ -128,6 +135,7 @@ public class ConvertMojo extends AbstractMojo {
}
// download contracts, unzip them and pass as output directory
ContractVerifierConfigProperties config = new ContractVerifierConfigProperties();
config.setExcludeBuildFolders(this.excludeBuildFolders);
File contractsDirectory = new MavenContractsDownloader(this.project, this.contractDependency,
this.contractsPath, this.contractsRepositoryUrl, this.contractsWorkOffline, getLog(),
this.aetherStubDownloaderFactory, this.repoSession).downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);

View File

@@ -54,6 +54,10 @@ class CopyContracts {
+ "the final JAR with stubs.");
Resource resource = new Resource();
resource.addInclude(this.config.getIncludedRootFolderAntPattern() + "*.*");
if (this.config.isExcludeBuildFolders()) {
resource.addExclude("**/target/**");
resource.addExclude("**/build/**");
}
resource.setDirectory(contractsDirectory.getAbsolutePath());
MavenResourcesExecution execution = new MavenResourcesExecution();
execution.setResources(Collections.singletonList(resource));

View File

@@ -243,4 +243,17 @@ public class PluginUnitTest {
assertFilesPresent(basedir, "target/foo/mappings/com/hello/v1/should post a user.json");
then(FileUtils.readFileToString(test2)).contains("/users/2");
}
@Test
public void shouldGenerateStubsForCommonRepoWithTargetFolder() throws Exception {
File basedir = this.resources.getBasedir("common-repo");
this.maven.executeMojo(basedir, "convert");
assertFilesNotPresent(basedir, "target/generated-test-sources/contracts/");
// there will be no stubs cause all files are copied to `target` folder
assertFilesNotPresent(basedir, "target/stubs/mappings/");
assertFilesPresent(basedir, "target/stubs/contracts/consumer1/Messaging.groovy");
assertFilesPresent(basedir, "target/stubs/contracts/pom.xml");
}
}

View File

@@ -0,0 +1,37 @@
/**
*
* Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
org.springframework.cloud.contract.spec.Contract.make {
label 'some_label'
input {
messageFrom('jms:input')
messageBody([
bookName: 'foo'
])
messageHeaders {
header('sample', 'header')
}
}
outputMessage {
sentTo('jms:output')
body([
bookName: 'foo'
])
headers {
header('BOOK-NAME', 'foo')
}
}
}

View File

@@ -0,0 +1,34 @@
/**
*
* Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
org.springframework.cloud.contract.spec.Contract.make {
request {
method 'POST'
url('/users') {
}
headers {
header 'Content-Type': 'application/json'
}
body '''{ "login" : "john", "name": "John The Contract" }'''
}
response {
status 200
headers {
header 'Location': '/users/john'
}
}
}

View File

@@ -0,0 +1,34 @@
/**
*
* Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
org.springframework.cloud.contract.spec.Contract.make {
request {
method 'POST'
url('/users') {
}
headers {
header 'Content-Type': 'application/json'
}
}
response {
status 200
headers {
header 'Location': '/users/john'
}
body '''{ "list" : [ "login", "john", "name", "John The Contract" ] }'''
}
}

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2013-2016 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud.verifier.sample</groupId>
<artifactId>common-repo</artifactId>
<version>0.1</version>
<properties>
<skipTests>true</skipTests>
<excludeBuildFolders>true</excludeBuildFolders>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<configuration>
<!-- By default it would search under src/test/resources/ -->
<contractsDirectory>${project.basedir}</contractsDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -110,8 +110,8 @@ class ContractVerifierConfigProperties {
String includedContracts = ".*"
/**
* A ant pattern to match files. Relates to contracts, stubs etc. You can append
* any kind of files you wish e.g {@code $includedRootFolderAntPattern/*.groovy}
* A ant pattern to match files. Gets updated when using repo with common contracts
* to reflect the path to proper folder with contracts.
*/
String includedRootFolderAntPattern = "**/"
@@ -137,4 +137,11 @@ class ContractVerifierConfigProperties {
*/
Map<String, String> 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.
*/
boolean excludeBuildFolders
}