Skip to content

Commit

Permalink
Add closeStagingRepository and releaseStagingRepository summary tasks (
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Nov 23, 2023
1 parent 00d5611 commit c8977e3
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class NexusPublishPlugin : Plugin<Project> {
companion object {
// visibility for testing
const val SIMPLIFIED_CLOSE_AND_RELEASE_TASK_NAME = "closeAndReleaseStagingRepository"
const val SIMPLIFIED_CLOSE_TASK_NAME = "closeStagingRepository"
const val SIMPLIFIED_RELEASE_TASK_NAME = "releaseStagingRepository"
}

override fun apply(project: Project) {
Expand Down Expand Up @@ -125,10 +127,17 @@ class NexusPublishPlugin : Plugin<Project> {
enabled = false
}
}
rootProject.tasks.register<Task>(SIMPLIFIED_CLOSE_AND_RELEASE_TASK_NAME) {
rootProject.tasks.register(SIMPLIFIED_CLOSE_AND_RELEASE_TASK_NAME) {
group = PublishingPlugin.PUBLISH_TASK_GROUP
description = "Closes and releases open staging repositories in all configured Nexus instances."
enabled = false
}
rootProject.tasks.register(SIMPLIFIED_CLOSE_TASK_NAME) {
group = PublishingPlugin.PUBLISH_TASK_GROUP
description = "Closes open staging repositories in all configured Nexus instances."
}
rootProject.tasks.register(SIMPLIFIED_RELEASE_TASK_NAME) {
group = PublishingPlugin.PUBLISH_TASK_GROUP
description = "Releases open staging repositories in all configured Nexus instances."
}
}

Expand Down Expand Up @@ -235,7 +244,7 @@ class NexusPublishPlugin : Plugin<Project> {
}
}
}
configureSimplifiedCloseAndReleaseTask(rootProject, extension)
configureSimplifiedCloseAndReleaseTasks(rootProject, extension)
}
}

Expand Down Expand Up @@ -346,25 +355,37 @@ class NexusPublishPlugin : Plugin<Project> {
}
}

private fun configureSimplifiedCloseAndReleaseTask(rootProject: Project, extension: NexusPublishExtension) {
private fun configureSimplifiedCloseAndReleaseTasks(rootProject: Project, extension: NexusPublishExtension) {
if (extension.repositories.isNotEmpty()) {
val closeAndReleaseSimplifiedTask = rootProject.tasks.named(SIMPLIFIED_CLOSE_AND_RELEASE_TASK_NAME)
closeAndReleaseSimplifiedTask.configure {
val repositoryNamesAsString = extension.repositories.joinToString(", ") { "'${it.name}'" }
val instanceCardinalityAwareString = if (extension.repositories.size > 1) {
"instances"
} else {
"instance"
}
val repositoryNamesAsString = extension.repositories.joinToString(", ") { "'${it.name}'" }
val instanceCardinalityAwareString = if (extension.repositories.size > 1) {
"instances"
} else {
"instance"
}
val closeAndReleaseSimplifiedTask = rootProject.tasks.named(SIMPLIFIED_CLOSE_AND_RELEASE_TASK_NAME) {
description = "Closes and releases open staging repositories in the following Nexus $instanceCardinalityAwareString: $repositoryNamesAsString"
enabled = true
}
val closeSimplifiedTask = rootProject.tasks.named(SIMPLIFIED_CLOSE_TASK_NAME) {
description = "Closes open staging repositories in the following Nexus $instanceCardinalityAwareString: $repositoryNamesAsString"
}
val releaseSimplifiedTask = rootProject.tasks.named(SIMPLIFIED_RELEASE_TASK_NAME) {
description = "Releases open staging repositories in the following Nexus $instanceCardinalityAwareString: $repositoryNamesAsString"
}
extension.repositories.all {
val repositoryCapitalizedName = this.capitalizedName
val closeAndReleaseTask = rootProject.tasks.named<Task>("closeAndRelease${repositoryCapitalizedName}StagingRepository")
closeAndReleaseSimplifiedTask.configure {
closeAndReleaseSimplifiedTask {
dependsOn(closeAndReleaseTask)
}
val closeTask = rootProject.tasks.named<Task>("close${repositoryCapitalizedName}StagingRepository")
closeSimplifiedTask {
dependsOn(closeTask)
}
val releaseTask = rootProject.tasks.named<Task>("release${repositoryCapitalizedName}StagingRepository")
releaseSimplifiedTask {
dependsOn(releaseTask)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ class TaskOrchestrationTest {
assertThat(simplifiedCloseAndReleaseTasks.first().dependsOn).isEmpty()
}

@Test
internal fun `simplified close task without repository name should be available but trigger nothing if no repositories are configured`() {
initSingleProjectWithDefaultConfiguration()
project.extensions.configure<NexusPublishExtension> {
repositories.clear()
}

val simplifiedCloseTasks = project.getTasksByName(NexusPublishPlugin.SIMPLIFIED_CLOSE_TASK_NAME, true)

assertThat(simplifiedCloseTasks).hasSize(1)
assertThat(simplifiedCloseTasks.first().dependsOn).isEmpty()
}

@Test
internal fun `simplified release task without repository name should be available but trigger nothing if no repositories are configured`() {
initSingleProjectWithDefaultConfiguration()
project.extensions.configure<NexusPublishExtension> {
repositories.clear()
}

val simplifiedReleaseTasks = project.getTasksByName(NexusPublishPlugin.SIMPLIFIED_RELEASE_TASK_NAME, true)

assertThat(simplifiedReleaseTasks).hasSize(1)
assertThat(simplifiedReleaseTasks.first().dependsOn).isEmpty()
}

@Test
internal fun `simplified closeAndRelease task without repository name should depend on all closeAndRelease (created one per defined repository)`() {
initSingleProjectWithDefaultConfiguration()
Expand All @@ -121,6 +147,36 @@ class TaskOrchestrationTest {
.contains("closeAndReleaseOtherNexusStagingRepository")
}

@Test
internal fun `simplified close task without repository name should depend on all close (created one per defined repository)`() {
initSingleProjectWithDefaultConfiguration()
project.extensions.configure<NexusPublishExtension> {
repositories.create("otherNexus")
}

val closeTask = getJustOneTaskByNameOrFail(NexusPublishPlugin.SIMPLIFIED_CLOSE_TASK_NAME)

assertThat(closeTask.taskDependencies.getDependencies(null).map { it.name })
.hasSize(2)
.contains("closeSonatypeStagingRepository")
.contains("closeOtherNexusStagingRepository")
}

@Test
internal fun `simplified release task without repository name should depend on all release (created one per defined repository)`() {
initSingleProjectWithDefaultConfiguration()
project.extensions.configure<NexusPublishExtension> {
repositories.create("otherNexus")
}

val releaseTask = getJustOneTaskByNameOrFail(NexusPublishPlugin.SIMPLIFIED_RELEASE_TASK_NAME)

assertThat(releaseTask.taskDependencies.getDependencies(null).map { it.name })
.hasSize(2)
.contains("releaseSonatypeStagingRepository")
.contains("releaseOtherNexusStagingRepository")
}

@Test
internal fun `description of simplified closeAndRelease task contains names of all defined Nexus instances`() {
initSingleProjectWithDefaultConfiguration()
Expand All @@ -135,6 +191,34 @@ class TaskOrchestrationTest {
.contains("otherNexus")
}

@Test
internal fun `description of simplified close task contains names of all defined Nexus instances`() {
initSingleProjectWithDefaultConfiguration()
project.extensions.configure<NexusPublishExtension> {
repositories.create("otherNexus")
}

val closeTask = getJustOneTaskByNameOrFail(NexusPublishPlugin.SIMPLIFIED_CLOSE_TASK_NAME)

assertThat(closeTask.description)
.contains("sonatype")
.contains("otherNexus")
}

@Test
internal fun `description of simplified release task contains names of all defined Nexus instances`() {
initSingleProjectWithDefaultConfiguration()
project.extensions.configure<NexusPublishExtension> {
repositories.create("otherNexus")
}

val releaseTask = getJustOneTaskByNameOrFail(NexusPublishPlugin.SIMPLIFIED_RELEASE_TASK_NAME)

assertThat(releaseTask.description)
.contains("sonatype")
.contains("otherNexus")
}

private fun initSingleProjectWithDefaultConfiguration() {
project.apply(plugin = "java")
project.apply(plugin = "maven-publish")
Expand Down

0 comments on commit c8977e3

Please sign in to comment.