Fixed cloning of objects
This commit is contained in:
@@ -143,9 +143,11 @@ class GitContractsRepo {
|
||||
else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("The project has already been cloned to [" + file
|
||||
+ "]. Will reset any changes.");
|
||||
+ "]. Will reset any changes and pull the latest ones.");
|
||||
}
|
||||
new GitRepo(file, properties).reset(file);
|
||||
GitRepo gitRepo = new GitRepo(file, properties);
|
||||
gitRepo.reset(file);
|
||||
gitRepo.pull(file);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.plugin
|
||||
|
||||
import groovy.transform.AutoClone
|
||||
import groovy.transform.ToString
|
||||
import org.apache.commons.logging.Log
|
||||
import org.apache.commons.logging.LogFactory
|
||||
@@ -24,12 +23,10 @@ import org.apache.commons.logging.LogFactory
|
||||
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties
|
||||
import org.springframework.cloud.contract.verifier.config.TestFramework
|
||||
import org.springframework.cloud.contract.verifier.config.TestMode
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@ToString
|
||||
@AutoClone
|
||||
class ContractVerifierExtension {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ContractVerifierExtension)
|
||||
@@ -242,7 +239,51 @@ class ContractVerifierExtension {
|
||||
this.disableStubPublication = disableStubPublication
|
||||
}
|
||||
|
||||
@AutoClone
|
||||
ContractVerifierExtension copy() {
|
||||
return new ContractVerifierExtension(
|
||||
testFramework: this.testFramework,
|
||||
testMode: this.testMode,
|
||||
basePackageForTests: this.basePackageForTests,
|
||||
baseClassForTests: this.baseClassForTests,
|
||||
nameSuffixForTests: this.nameSuffixForTests,
|
||||
ruleClassForTests: this.ruleClassForTests,
|
||||
excludedFiles: new ArrayList<String>(this.excludedFiles),
|
||||
includedFiles: new ArrayList<String>(this.includedFiles),
|
||||
ignoredFiles: new ArrayList<String>(this.ignoredFiles),
|
||||
imports: Arrays.asList(this.imports).toArray(),
|
||||
staticImports: Arrays.asList(this.staticImports).toArray(),
|
||||
contractsDslDir: this.contractsDslDir,
|
||||
generatedTestSourcesDir: this.generatedTestSourcesDir,
|
||||
generatedTestResourcesDir: this.generatedTestResourcesDir,
|
||||
stubsOutputDir: this.stubsOutputDir,
|
||||
stubsSuffix: this.stubsSuffix,
|
||||
assertJsonSize: this.assertJsonSize,
|
||||
contractRepository: new ContractRepository(
|
||||
repositoryUrl: this.contractRepository.repositoryUrl,
|
||||
username: this.contractRepository.username,
|
||||
password: this.contractRepository.password,
|
||||
proxyPort: this.contractRepository.proxyPort,
|
||||
proxyHost: this.contractRepository.proxyHost,
|
||||
cacheDownloadedContracts: this.contractRepository.cacheDownloadedContracts
|
||||
),
|
||||
contractDependency: new Dependency(
|
||||
groupId: this.contractDependency.groupId,
|
||||
artifactId: this.contractDependency.artifactId,
|
||||
classifier: this.contractDependency.classifier,
|
||||
version: this.contractDependency.version,
|
||||
stringNotation: this.contractDependency.stringNotation
|
||||
),
|
||||
contractsPath: this.contractsPath,
|
||||
contractsMode: this.contractsMode,
|
||||
packageWithBaseClasses: this.packageWithBaseClasses,
|
||||
baseClassMappings: new HashMap<String, String>(this.baseClassMappings),
|
||||
excludeBuildFolders: this.excludeBuildFolders,
|
||||
deleteStubsAfterTest: this.deleteStubsAfterTest,
|
||||
convertToYaml: this.convertToYaml,
|
||||
contractsProperties: new HashMap<String, String>(this.contractsProperties)
|
||||
)
|
||||
}
|
||||
|
||||
@ToString(includeNames = true, includePackage = false)
|
||||
static class Dependency {
|
||||
String groupId
|
||||
@@ -272,7 +313,6 @@ class ContractVerifierExtension {
|
||||
}
|
||||
}
|
||||
|
||||
@AutoClone
|
||||
@ToString(includeNames = true, includePackage = false)
|
||||
static class BaseClassMapping {
|
||||
private final Map<String, String> delegate
|
||||
@@ -290,7 +330,6 @@ class ContractVerifierExtension {
|
||||
}
|
||||
}
|
||||
|
||||
@AutoClone
|
||||
@ToString(includeNames = true, includePackage = false)
|
||||
static class ContractRepository {
|
||||
/**
|
||||
|
||||
@@ -40,33 +40,34 @@ class PublishStubsToScmTask extends ConventionTask {
|
||||
|
||||
@TaskAction
|
||||
void publishStubsToScm() {
|
||||
if (!shouldRun()) {
|
||||
ContractVerifierExtension clonedExtension = modifyExtension()
|
||||
if (!shouldRun(clonedExtension)) {
|
||||
return
|
||||
}
|
||||
String projectName = project.group.toString() + ":" + project.name.toString() + ":" + this.project.version.toString()
|
||||
project.logger.info("Pushing Stubs to SCM for project [" + projectName + "]")
|
||||
ContractVerifierExtension clonedExtension = modifyExtension()
|
||||
StubRunnerOptions options = getDownloader().options(clonedExtension)
|
||||
new ContractProjectUpdater(options).updateContractProject(projectName, getStubsOutputDir().toPath())
|
||||
}
|
||||
|
||||
private ContractVerifierExtension modifyExtension() {
|
||||
ContractVerifierExtension clone = getConfigProperties().clone()
|
||||
ContractVerifierExtension clone = getConfigProperties().copy()
|
||||
this.closureHolder.extensionClosure.delegate = clone
|
||||
this.closureHolder.extensionClosure.call(clone)
|
||||
return clone
|
||||
}
|
||||
|
||||
private boolean shouldRun() {
|
||||
String contractRepoUrl = getConfigProperties().contractRepository.repositoryUrl ?: ""
|
||||
private boolean shouldRun(ContractVerifierExtension clonedExtension) {
|
||||
String contractRepoUrl = clonedExtension.contractRepository.repositoryUrl ?: ""
|
||||
if (!contractRepoUrl || !ScmStubDownloaderBuilder.isProtocolAccepted(contractRepoUrl)) {
|
||||
project.logger.info("Skipping pushing stubs to scm since your contracts repository URL doesn't match any of the accepted protocols")
|
||||
project.logger.warn("Skipping pushing stubs to scm since your contracts repository URL [${contractRepoUrl}] doesn't match any of the accepted protocols for SCM stub downloader")
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
void customize(@DelegatesTo(ContractVerifierExtension) Closure closure) {
|
||||
project.logger.debug("Storing the extension closure")
|
||||
this.closureHolder.extensionClosure = closure
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright 2013-2018 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.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.contract.verifier.plugin
|
||||
|
||||
import spock.lang.Specification
|
||||
|
||||
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties
|
||||
import org.springframework.cloud.contract.verifier.config.TestFramework
|
||||
import org.springframework.cloud.contract.verifier.config.TestMode
|
||||
|
||||
class ContractVerifierExtensionSpec extends Specification {
|
||||
def "should make a copy of the object"() {
|
||||
given:
|
||||
ContractVerifierExtension original = new ContractVerifierExtension(
|
||||
testFramework: TestFramework.JUNIT5,
|
||||
testMode: TestMode.EXPLICIT,
|
||||
basePackageForTests: "foo1",
|
||||
baseClassForTests: "foo2",
|
||||
nameSuffixForTests: "foo3",
|
||||
ruleClassForTests: "foo4",
|
||||
excludedFiles: ["foo5"],
|
||||
includedFiles: ["foo6"],
|
||||
ignoredFiles: ["foo7"],
|
||||
imports: ["foo8"],
|
||||
staticImports: ["foo9"],
|
||||
contractsDslDir: new File("foo10"),
|
||||
generatedTestSourcesDir: new File("foo11"),
|
||||
generatedTestResourcesDir: new File("foo12"),
|
||||
stubsOutputDir: new File("foo13"),
|
||||
stubsSuffix: 'foo14',
|
||||
assertJsonSize: false,
|
||||
contractRepository: new ContractVerifierExtension.ContractRepository(
|
||||
repositoryUrl: "foo15",
|
||||
username: "foo16",
|
||||
password: "foo17",
|
||||
proxyPort: 18,
|
||||
proxyHost: "foo19",
|
||||
cacheDownloadedContracts: false
|
||||
),
|
||||
contractDependency: new ContractVerifierExtension.Dependency(
|
||||
groupId: "foo20",
|
||||
artifactId: "foo21",
|
||||
classifier: "foo22",
|
||||
version: "foo23",
|
||||
stringNotation: "foo24"
|
||||
),
|
||||
contractsPath: "foo25",
|
||||
contractsMode: StubRunnerProperties.StubsMode.CLASSPATH,
|
||||
packageWithBaseClasses: "foo26",
|
||||
baseClassMappings: [foo27: "foo28"],
|
||||
excludeBuildFolders: false,
|
||||
deleteStubsAfterTest: false,
|
||||
convertToYaml: false,
|
||||
contractsProperties: [foo29: "foo30"]
|
||||
)
|
||||
when:
|
||||
ContractVerifierExtension copy = original.copy()
|
||||
original.with {
|
||||
testFramework = TestFramework.CUSTOM
|
||||
testMode = TestMode.MOCKMVC
|
||||
basePackageForTests = "bar1"
|
||||
baseClassForTests = "bar2"
|
||||
nameSuffixForTests = "bar3"
|
||||
ruleClassForTests = "bar4"
|
||||
excludedFiles = ["bar5"]
|
||||
includedFiles = ["bar6"]
|
||||
ignoredFiles = ["bar7"]
|
||||
imports = ["bar8"]
|
||||
staticImports = ["bar9"]
|
||||
contractsDslDir = new File("bar10")
|
||||
generatedTestSourcesDir = new File("bar11")
|
||||
generatedTestResourcesDir = new File("bar12")
|
||||
stubsOutputDir = new File("bar13")
|
||||
stubsSuffix = 'bar14'
|
||||
assertJsonSize = true
|
||||
contractRepository.with {
|
||||
repositoryUrl = "bar15"
|
||||
username = "bar16"
|
||||
password = "bar17"
|
||||
proxyPort = 28
|
||||
proxyHost = "bar19"
|
||||
cacheDownloadedContracts = true
|
||||
}
|
||||
contractDependency.with {
|
||||
groupId = "bar20"
|
||||
artifactId = "bar21"
|
||||
classifier = "bar22"
|
||||
version = "bar23"
|
||||
stringNotation = "bar24"
|
||||
}
|
||||
contractsPath = "bar25"
|
||||
contractsMode = StubRunnerProperties.StubsMode.REMOTE
|
||||
packageWithBaseClasses = "bar26"
|
||||
baseClassMappings = [bar27 : "bar28"]
|
||||
excludeBuildFolders = true
|
||||
deleteStubsAfterTest = true
|
||||
convertToYaml = true
|
||||
contractsProperties = [bar29 : "bar30"]
|
||||
}
|
||||
then:
|
||||
copy.testFramework == TestFramework.JUNIT5
|
||||
copy.testMode == TestMode.EXPLICIT
|
||||
copy.basePackageForTests == "foo1"
|
||||
copy.baseClassForTests == "foo2"
|
||||
copy.nameSuffixForTests == "foo3"
|
||||
copy.ruleClassForTests == "foo4"
|
||||
copy.excludedFiles == ["foo5"]
|
||||
copy.includedFiles == ["foo6"]
|
||||
copy.ignoredFiles == ["foo7"]
|
||||
copy.imports == ["foo8"]
|
||||
copy.staticImports == ["foo9"]
|
||||
copy.contractsDslDir == new File("foo10")
|
||||
copy.generatedTestSourcesDir == new File("foo11")
|
||||
copy.generatedTestResourcesDir == new File("foo12")
|
||||
copy.stubsOutputDir == new File("foo13")
|
||||
copy.stubsSuffix == 'foo14'
|
||||
copy.assertJsonSize == false
|
||||
copy.contractRepository.repositoryUrl == "foo15"
|
||||
copy.contractRepository.username == "foo16"
|
||||
copy.contractRepository.password == "foo17"
|
||||
copy.contractRepository.proxyPort == 18
|
||||
copy.contractRepository.proxyHost == "foo19"
|
||||
copy.contractRepository.cacheDownloadedContracts == false
|
||||
copy.contractDependency.groupId == "foo20"
|
||||
copy.contractDependency.artifactId == "foo21"
|
||||
copy.contractDependency.classifier == "foo22"
|
||||
copy.contractDependency.version == "foo23"
|
||||
copy.contractDependency.stringNotation == "foo24"
|
||||
copy.contractsPath == "foo25"
|
||||
copy.contractsMode == StubRunnerProperties.StubsMode.CLASSPATH
|
||||
copy.packageWithBaseClasses == "foo26"
|
||||
copy.baseClassMappings == [foo27 : "foo28"]
|
||||
copy.excludeBuildFolders == false
|
||||
copy.deleteStubsAfterTest == false
|
||||
copy.convertToYaml == false
|
||||
copy.contractsProperties == [foo29 : "foo30"]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user