Skip to content

Commit

Permalink
added support to gradle's configuration avoidance api (#76)
Browse files Browse the repository at this point in the history
## Description
Added support for Gradle's "Configuration Avoidance API". It eases the burden on Gradle configuration step by assuring that a task configuration will only be executed prior to the task execution itself. Thus, if a task isn't predicted to be executed, its configuration won't be loaded.

More details on https://docs.gradle.org/current/userguide/task_configuration_avoidance.html


## Changes
* ![IMPROVE] Added support for Gradle's [Configuration Avoidance API](https://docs.gradle.org/current/userguide/task_configuration_avoidance.html)
  • Loading branch information
Joaquimmnetto authored May 10, 2021
1 parent 1f5d825 commit 6bf4327
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class GithubPublishIntegrationSpec extends GithubPublishIntegrationWithDefaultAu
"""

when:
runTasksSuccessfully("testPublish")
def result = runTasksSuccessfully("testPublish")

then:
def release = getRelease(tagName)
Expand All @@ -357,7 +357,7 @@ class GithubPublishIntegrationSpec extends GithubPublishIntegrationWithDefaultAu
assets.any { it.name == "initial.json" }

when:
runTasksSuccessfully("testPublishOrUpdate")
result = runTasksSuccessfully("testPublishOrUpdate")

then:
def updatedRelease = getRelease(tagName)
Expand Down
17 changes: 7 additions & 10 deletions src/main/groovy/wooga/gradle/github/base/GithubBasePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,12 @@ class GithubBasePlugin implements Plugin<Project> {
null
}))

project.tasks.withType(AbstractGithubTask, new Action<AbstractGithubTask>() {
@Override
void execute(AbstractGithubTask task) {
task.baseUrl.set(extension.baseUrl)
task.repositoryName.set(extension.repositoryName)
task.username.set(extension.username)
task.password.set(extension.password)
task.token.set(extension.token)
}
})
project.tasks.withType(AbstractGithubTask).configureEach { task ->
task.baseUrl.set(extension.baseUrl)
task.repositoryName.set(extension.repositoryName)
task.username.set(extension.username)
task.password.set(extension.password)
task.token.set(extension.token)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,27 @@ class GithubPublishPlugin implements Plugin<Project> {
}

private static void createDefaultPublishTask(final TaskContainer tasks) {
def githubPublish = tasks.create(name: PUBLISH_TASK_NAME, type: GithubPublish, group: GithubBasePlugin.GROUP)
githubPublish.description = "Publish github release"
tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME).dependsOn githubPublish
def githubPublish = tasks.register(PUBLISH_TASK_NAME, GithubPublish)
githubPublish.configure { GithubPublish task ->
task.group = GithubBasePlugin.GROUP
task.description = "Publish github release"
}
tasks.named(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME).configure {task ->
task.dependsOn(githubPublish)
}
}

private static void configurePublishTaskDefaults(final Project project) {
project.tasks.withType(GithubPublish, new Action<GithubPublish>() {
@Override
void execute(GithubPublish task) {
task.prerelease.convention(GithubPublishPluginConvention.defaultPublishPrerelease)
task.draft.convention(GithubPublishPluginConvention.defaultPublishDraft)
task.publishMethod.convention(GithubPublishPluginConvention.defaultPublishMethod)
def projectProvider = project.provider({ project.version.toString() })
project.tasks.withType(GithubPublish).configureEach {task ->
task.prerelease.set(false)
task.draft.set(false)
task.publishMethod.set(PublishMethod.create)

def projectProvider = project.provider({ project.version.toString() })
task.tagName.set(projectProvider)
task.releaseName.set(projectProvider)

task.tagName.convention(projectProvider)
task.releaseName.convention(projectProvider)

task.onlyIf(new Spec<GithubPublish>() {
@Override
boolean isSatisfiedBy(GithubPublish publishTask) {
publishTask.repositoryName.present
}
})
}
})
task.onlyIf { GithubPublish publishTask -> publishTask.repositoryName.present }
}
}
}
4 changes: 2 additions & 2 deletions src/test/groovy/wooga/gradle/github/GithubPluginSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class GithubPluginSpec extends ProjectSpec {
project.plugins.apply(PLUGIN_NAME)

then:
def publishTasks = project.tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME)
def githubPublishTask = project.tasks.getByName(GithubPublishPlugin.PUBLISH_TASK_NAME)
def githubPublishTask = project.tasks.named(GithubPublishPlugin.PUBLISH_TASK_NAME)
def publishTasks = project.tasks.findByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME)
publishTasks.dependsOn.contains(githubPublishTask)
}
}

0 comments on commit 6bf4327

Please sign in to comment.