-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor plugin lazy configuration (#29)
Description =========== The plugin as it is now relies heavily on `convention mapping`, a technique which is not part of the public gradle API. This patch removes all usages of `convention mapping` and uses the [`Provider`] API instead. As of this moment this API is still in _incubation_ phase but is a better alternative aready. This patch also means a breaking change not only because of internal API changes but also because the new API in the form of usage was introduced with gradle > 4.7 Changes ======= ![IMPROVE] use [`Provider`] API ![REMOVE] convention mapping ![BREAK] support with gradle < 4.7 [`Provider`]: https://docs.gradle.org/current/userguide/lazy_configuration.html
- Loading branch information
Showing
14 changed files
with
709 additions
and
781 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 198 additions & 0 deletions
198
src/integrationTest/groovy/wooga/gradle/github/GithubPluginExtensionIntegrationSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
package wooga.gradle.github | ||
|
||
import spock.lang.Unroll | ||
|
||
class GithubPluginExtensionIntegrationSpec extends IntegrationSpec { | ||
|
||
def setup() { | ||
buildFile << """ | ||
${applyPlugin(GithubPlugin)} | ||
""".stripIndent() | ||
} | ||
|
||
enum PropertyLocation { | ||
none, script, property, env | ||
|
||
String reason() { | ||
switch (this) { | ||
case script: | ||
return "value is provided in script" | ||
case property: | ||
return "value is provided in props" | ||
case env: | ||
return "value is set in env" | ||
default: | ||
return "no value was configured" | ||
} | ||
} | ||
} | ||
|
||
enum PropertySetType { | ||
setter, setMethod, propertySet | ||
|
||
String reason() { | ||
switch (this) { | ||
case setter: | ||
return "value is provided with setter" | ||
case setMethod: | ||
return "value is with set method" | ||
case propertySet: | ||
return "value is set in property with set" | ||
} | ||
} | ||
} | ||
|
||
String envNameFromProperty(String property) { | ||
"GITHUB_${property.replaceAll(/([A-Z])/, "_\$1").toUpperCase()}" | ||
} | ||
|
||
@Unroll(":#property returns '#testValue' if #reason") | ||
def "extension property :#property returns '#testValue' if #reason"() { | ||
given: | ||
buildFile << """ | ||
task(custom) { | ||
doLast { | ||
def value = "not set" | ||
if(github.${property}.present) { | ||
value = github.${property}.get() | ||
} | ||
println("github.${property}: " + value) | ||
} | ||
} | ||
""" | ||
|
||
and: "a gradle.properties" | ||
def propertiesFile = createFile("gradle.properties") | ||
|
||
def escapedValue = (value instanceof String) ? escapedPath(value) : value | ||
|
||
switch (location) { | ||
case PropertyLocation.script: | ||
buildFile << "github.${property} = ${escapedValue}" | ||
break | ||
case PropertyLocation.property: | ||
propertiesFile << "github.${property} = ${escapedValue}" | ||
break | ||
case PropertyLocation.env: | ||
environmentVariables.set(envNameFromProperty(property), "${value}") | ||
break | ||
default: | ||
break | ||
} | ||
|
||
when: "" | ||
def result = runTasks("custom") | ||
|
||
then: | ||
result.success | ||
result.standardOutput.contains("github.${property}: ${testValue}") | ||
|
||
where: | ||
property | value | expectedValue | providedValue | location | ||
"repositoryName" | "testUser/testRepo" | _ | "testUser/testRepo" | PropertyLocation.property | ||
"repositoryName" | "'testUser/testRepo'" | 'testUser/testRepo' | "testUser/testRepo" | PropertyLocation.script | ||
"repositoryName" | null | "not set" | null | PropertyLocation.none | ||
|
||
"username" | "testUser" | _ | "testUser" | PropertyLocation.property | ||
"username" | "'testUser'" | 'testUser' | "testUser" | PropertyLocation.script | ||
"username" | null | "not set" | null | PropertyLocation.none | ||
|
||
"password" | "testPass" | _ | "testPass" | PropertyLocation.property | ||
"password" | "'testPass'" | 'testPass' | "testPass" | PropertyLocation.script | ||
"password" | null | "not set" | null | PropertyLocation.none | ||
|
||
"token" | "accessToken" | _ | "accessToken" | PropertyLocation.property | ||
"token" | "'accessToken'" | 'accessToken' | "accessToken" | PropertyLocation.script | ||
"token" | null | "not set" | null | PropertyLocation.none | ||
|
||
"baseUrl" | "https://api.github.com" | 'not set' | "https://api.github.com" | PropertyLocation.property | ||
"baseUrl" | "'https://api.github.com'" | 'https://api.github.com' | "https://api.github.com" | PropertyLocation.script | ||
"baseUrl" | null | "not set" | null | PropertyLocation.none | ||
|
||
testValue = (expectedValue == _) ? value : expectedValue | ||
reason = location.reason() + ((location == PropertyLocation.none) ? "" : " with '$providedValue'") | ||
} | ||
|
||
@Unroll | ||
def "can set #property with #type"() { | ||
given: | ||
buildFile << """ | ||
task(custom) { | ||
doLast { | ||
def value = "not set" | ||
if(github.${property}.present) { | ||
value = github.${property}.get() | ||
} | ||
println("github.${property}: " + value) | ||
} | ||
} | ||
""" | ||
|
||
def escapedValue = (value instanceof String) ? escapedPath(value) : value | ||
|
||
switch (type) { | ||
case PropertySetType.setter: | ||
buildFile << "github.${property} = ${escapedValue}" | ||
break | ||
case PropertySetType.setMethod: | ||
buildFile << "github.${property} ${escapedValue}" | ||
break | ||
case PropertySetType.propertySet: | ||
buildFile << "github.${property}.set(${escapedValue})" | ||
break | ||
} | ||
|
||
when: "" | ||
def result = runTasks("custom") | ||
|
||
then: | ||
result.success | ||
result.standardOutput.contains("github.${property}: ${testValue}") | ||
|
||
where: | ||
property | value | expectedValue | type | ||
"repositoryName" | "'testUser/testRepo'" | "testUser/testRepo" | PropertySetType.setter | ||
"repositoryName" | "'testUser/testRepo'" | "testUser/testRepo" | PropertySetType.setMethod | ||
"repositoryName" | "'testUser/testRepo'" | "testUser/testRepo" | PropertySetType.propertySet | ||
|
||
"username" | "'testUser'" | "testUser" | PropertySetType.setter | ||
"username" | "'testUser'" | "testUser" | PropertySetType.setMethod | ||
"username" | "'testUser'" | "testUser" | PropertySetType.propertySet | ||
|
||
"password" | "'testPass'" | "testPass" | PropertySetType.setter | ||
"password" | "'testPass'" | "testPass" | PropertySetType.setMethod | ||
"password" | "'testPass'" | "testPass" | PropertySetType.propertySet | ||
|
||
"token" | "'accessToken'" | "accessToken" | PropertySetType.setter | ||
"token" | "'accessToken'" | "accessToken" | PropertySetType.setMethod | ||
"token" | "'accessToken'" | "accessToken" | PropertySetType.propertySet | ||
|
||
"baseUrl" | "'https://api.github.com'" | "https://api.github.com" | PropertySetType.setter | ||
"baseUrl" | "'https://api.github.com'" | "https://api.github.com" | PropertySetType.setMethod | ||
"baseUrl" | "'https://api.github.com'" | "https://api.github.com" | PropertySetType.propertySet | ||
|
||
testValue = (expectedValue == _) ? value : expectedValue | ||
} | ||
|
||
def "validates repoName property before set"() { | ||
given: "" | ||
buildFile << """ | ||
github.repositoryName = "${repositoryName}" | ||
""".stripIndent() | ||
|
||
when: | ||
def result = runTasks("tasks") | ||
|
||
then: | ||
result.success == (expectedError == null) | ||
if(!result.success) { | ||
outputContains(result, expectedError) | ||
} | ||
|
||
where: | ||
repositoryName | expectedError | ||
'some value' | "Repository value 'some value' is not a valid github repository name. Expecting `owner/repo`" | ||
} | ||
} |
Oops, something went wrong.