Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration avoidance API support #40

Merged
merged 1 commit into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
buildFile << """
version = "0.1.0"
${applyPlugin(AppCenterPlugin)}
publishAppCenter {
owner = "$owner"
apiToken = "$apiToken"
applicationIdentifier = "$applicationIdentifierIos"
publishAppCenter.configure { t ->
t.owner = "$owner"
t.apiToken = "$apiToken"
t.applicationIdentifier = "$applicationIdentifierIos"
}
""".stripIndent()
}
Expand Down Expand Up @@ -86,8 +86,10 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
testFile = createBigUploadBinary(testFile, File.createTempDir("testUpload", "fileType"), 1024 * 1024 * desiredFileSize)

buildFile << """
publishAppCenter.binary.set(file("${escapedPath(testFile.path)}"))
publishAppCenter.applicationIdentifier.set("$applicationIdentifier")
publishAppCenter.configure {
binary.set(file("${escapedPath(testFile.path)}"))
applicationIdentifier.set("$applicationIdentifier")
}
""".stripIndent()

expect:
Expand All @@ -104,8 +106,10 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
given: "a dummy ipa binary to upload"
def testFile = getClass().getClassLoader().getResource(fileName).path
buildFile << """
publishAppCenter.binary.set(file("$testFile"))
publishAppCenter.applicationIdentifier.set("$applicationIdentifier")
publishAppCenter.configure {
binary.set(file("$testFile"))
applicationIdentifier.set("$applicationIdentifier")
}
""".stripIndent()

expect:
Expand All @@ -121,7 +125,9 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
given: "a dummy ipa binary to upload"
def testFile = getClass().getClassLoader().getResource("test.ipa").path
buildFile << """
publishAppCenter.binary.set(file("$testFile"))
publishAppCenter.configure {
binary.set(file("$testFile"))
}
""".stripIndent()

and: "a future version meta file"
Expand All @@ -139,7 +145,9 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
given: "a dummy ipa binary to upload"
def testFile = getClass().getClassLoader().getResource("test.ipa").path
buildFile << """
publishAppCenter.binary.set(file("$testFile"))
publishAppCenter.configure {
binary.set(file("$testFile"))
}
""".stripIndent()

and: "a future version meta file"
Expand All @@ -163,13 +171,17 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
ensureDistributionGroup("Test2")

buildFile << """
publishAppCenter.destinations = ["Test", "Test2"]
publishAppCenter.configure {
destinations = ["Test", "Test2"]
}
""".stripIndent()

and: "a dummy ipa binary to upload"
def testFile = getClass().getClassLoader().getResource("test.ipa").path
buildFile << """
publishAppCenter.binary.set(file("$testFile"))
publishAppCenter.configure {
binary.set(file("$testFile"))
}
""".stripIndent()

and: "a future version meta file"
Expand All @@ -192,14 +204,18 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
ensureDistributionGroup("Test2")

buildFile << """
publishAppCenter.destination "Test"
publishAppCenter.destination "Test2"
publishAppCenter.configure {
destination "Test"
destination "Test2"
}
""".stripIndent()

and: "a dummy ipa binary to upload"
def testFile = getClass().getClassLoader().getResource("test.ipa").path
buildFile << """
publishAppCenter.binary.set(file("$testFile"))
publishAppCenter.configure {
binary.set(file("$testFile"))
}
""".stripIndent()

and: "a future version meta file"
Expand All @@ -218,13 +234,17 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
def "fails when distribution group is invalid"() {
given: "a publish task with invalid distribution groups"
buildFile << """
publishAppCenter.destination "some value", "some other group"
publishAppCenter.configure {
destination "some value", "some other group"
}
""".stripIndent()

and: "a dummy ipa binary to upload"
def testFile = getClass().getClassLoader().getResource("test.ipa").path
buildFile << """
publishAppCenter.binary = "$testFile"
publishAppCenter.configure {
binary = "$testFile"
}
""".stripIndent()

expect:
Expand All @@ -234,17 +254,21 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
def "can publish custom build infos"() {
given: "publish task with build infos"
buildFile << """
publishAppCenter.buildInfo {
branchName = "master"
commitHash = "000000000000"
commitMessage = "Fix tests"
publishAppCenter.configure {
buildInfo {
branchName = "master"
commitHash = "000000000000"
commitMessage = "Fix tests"
}
}
""".stripIndent()

and: "a dummy ipa binary to upload"
def testFile = getClass().getClassLoader().getResource("test.ipa").path
buildFile << """
publishAppCenter.binary.set(file("$testFile"))
publishAppCenter.configure {
binary.set(file("$testFile"))
}
""".stripIndent()

and: "a future version meta file"
Expand All @@ -271,13 +295,13 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
def "can publish release notes"() {
given: "publish task with release notes text"
buildFile << """
publishAppCenter.releaseNotes = "${releaseNotes}"
publishAppCenter.configure { releaseNotes = "${releaseNotes}" }
""".stripIndent()

and: "a dummy ipa binary to upload"
def testFile = getClass().getClassLoader().getResource("test.ipa").path
buildFile << """
publishAppCenter.binary.set(file("$testFile"))
publishAppCenter.configure { binary.set(file("$testFile")) }
""".stripIndent()

and: "a future version meta file"
Expand All @@ -303,7 +327,7 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
@Unroll()
def "can add publish destinations with :#method and type '#type'"() {
given: "some configured property"
buildFile << "publishAppCenter.${method}(${value})"
buildFile << "publishAppCenter.configure { ${method}(${value}) }"

and: "available groups"
expectedGroups.each {
Expand All @@ -315,7 +339,7 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
and: "a dummy ipa binary to upload"
def testFile = getClass().getClassLoader().getResource("test.ipa").path
buildFile << """
publishAppCenter.binary.set(file("$testFile"))
publishAppCenter.configure { binary.set(file("$testFile")) }
""".stripIndent()

and: "a future version meta file"
Expand Down Expand Up @@ -347,7 +371,7 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
def "can set property :#property with :#method and type '#type'"() {
given: "a task to print publishAppCenter properties"
buildFile << """
task(custom) {
tasks.register("custom") {
doLast {
def value = publishAppCenter.${property}.get()
println("publishAppCenter.${property}: " + value)
Expand All @@ -361,7 +385,7 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
}

and: "some configured property"
buildFile << "publishAppCenter.${method}(${value})"
buildFile << "publishAppCenter.configure { t -> t.${method}(${value}) }"

when: ""
def result = runTasksSuccessfully("custom")
Expand Down Expand Up @@ -415,12 +439,12 @@ class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
def group = ensureDistributionGroup("TestGroupFromId")

and: "configuring destination group by id"
buildFile << "publishAppCenter.destinationId('${group['id']}')"
buildFile << "publishAppCenter.configure { destinationId('${group['id']}') }"

and: "a dummy ipa binary to upload"
def testFile = getClass().getClassLoader().getResource("test.ipa").path
buildFile << """
publishAppCenter.binary.set(file("$testFile"))
publishAppCenter.configure{ binary.set(file("$testFile")) }
""".stripIndent()

and: "a future version meta file"
Expand Down
42 changes: 20 additions & 22 deletions src/main/groovy/wooga/gradle/appcenter/AppCenterPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package wooga.gradle.appcenter
import org.gradle.api.Action
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.publish.plugins.PublishingPlugin
import wooga.gradle.appcenter.internal.DefaultAppCenterPluginExtension

Expand All @@ -39,30 +40,27 @@ class AppCenterPlugin implements Plugin<Project> {

def tasks = project.tasks

def publishAppCenter = tasks.create(name: PUBLISH_APP_CENTER_TASK_NAME, type: AppCenterUploadTask, group: PublishingPlugin.PUBLISH_TASK_GROUP)
publishAppCenter.description = PUBLISH_APP_CENTER_TASK_DESCRIPTION

tasks.withType(AppCenterUploadTask, new Action<AppCenterUploadTask>() {
@Override
void execute(AppCenterUploadTask t) {
t.buildVersion.convention(project.providers.provider({ project.version.toString() }))
t.destinations.set(extension.defaultDestinations)
t.applicationIdentifier.convention(extension.applicationIdentifier)
t.apiToken.convention(extension.apiToken)
t.owner.convention(extension.owner)
t.retryCount.convention(extension.retryCount)
t.retryTimeout.convention(extension.retryTimeout)
}})

project.afterEvaluate(new Action<Project>() {
@Override
void execute(Project _) {
if (extension.isPublishEnabled().get()) {
def lifecyclePublishTask = tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME)
lifecyclePublishTask.dependsOn(publishAppCenter)
def publishAppCenter = tasks.register(PUBLISH_APP_CENTER_TASK_NAME, AppCenterUploadTask,{ t ->
t.group = PublishingPlugin.PUBLISH_TASK_GROUP
t.description = PUBLISH_APP_CENTER_TASK_DESCRIPTION
})

tasks.withType(AppCenterUploadTask).configureEach { t ->
t.buildVersion.convention(project.providers.provider({ project.version.toString() }))
t.destinations.set(extension.defaultDestinations)
t.applicationIdentifier.convention(extension.applicationIdentifier)
t.apiToken.convention(extension.apiToken)
t.owner.convention(extension.owner)
t.retryCount.convention(extension.retryCount)
t.retryTimeout.convention(extension.retryTimeout)
}
project.afterEvaluate {
if (extension.isPublishEnabled().get()) {
tasks.named(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME).configure { task ->
task.dependsOn(publishAppCenter)
}
}
})
}
}

protected static AppCenterPluginExtension create_and_configure_extension(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package wooga.gradle.appcenter
import nebula.test.ProjectSpec
import org.gradle.api.DefaultTask
import org.gradle.api.publish.plugins.PublishingPlugin

import org.gradle.api.tasks.TaskProvider
import spock.lang.Unroll
import wooga.gradle.appcenter.tasks.AppCenterUploadTask

Expand Down Expand Up @@ -67,14 +67,15 @@ class AppCenterPluginSpec extends ProjectSpec {

when:
project.plugins.apply(PLUGIN_NAME)
def publishTask
def publishTaskProvider
project.afterEvaluate {
publishTask = project.tasks.findByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME)
publishTaskProvider = project.tasks.named(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME)
}

then:
project.evaluate()
def publish = project.tasks.findByName(taskName)
def publish = project.tasks.named(taskName)
def publishTask = publishTaskProvider.get()
publishTask.getDependsOn().contains(publish)

where:
Expand Down