Skip to content
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
2 changes: 1 addition & 1 deletion buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencyResolutionManagement {
}

versionCatalogs {
create("libs") {
register("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ constructor(
}

devPubTasks.publishAllToDevRepo.configure {
// By name: `tasks.matching {}` and `tasks.named {}` realize every task when resolved.
// By name: `tasks.matching {}` and `tasks.named {}` realise every task when resolved.
// Added here because the task only exists once maven-publish has the dev repo.
dependsOn("publishAllPublicationsTo${DEV_PUB__MAVEN_REPO_NAME}Repository")
}
Expand Down Expand Up @@ -396,7 +396,6 @@ constructor(
}
}


private fun getGmm(
project: Project,
publication: MavenPublication,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.adamko.gradle.dev_publish

import dev.adamko.gradle.dev_publish.services.DevPublishService.Companion.SERVICE_NAME
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import org.gradle.kotlin.dsl.*
import org.gradle.testfixtures.ProjectBuilder

/**
* Dev publish tasks in one project share a staging directory,
* so they must not run in parallel.
*/
class DevPublishServiceUsageTest : FunSpec({

val project = ProjectBuilder.builder()
.withName("foo-project")
.build()
project.plugins.apply(DevPublishPlugin::class)

test("expect the service allows only one usage at a time") {
val registration = project.gradle.sharedServices.registrations
.getByName("${SERVICE_NAME}_${project.path}")

registration.maxParallelUsages.orNull shouldBe 1
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ class DeprecatedTaskTest : FunSpec({
val reportContent = reportFile.readText()

withClue("the Problems API entry should be in ${reportFile.name}") {
reportContent shouldContain "deprecated-task"
reportContent shouldContain "Dev Publish"
reportContent shouldContain "is deprecated"
reportContent shouldContain "Task ':generatePublicationHashTask' is deprecated"
reportContent shouldContain "Task 'generatePublicationHashTask', in root project 'deprecated-task', is deprecated. It will be removed in Dev Publish version 2.0."
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import dev.adamko.gradle.dev_publish.test_utils.*
import io.kotest.assertions.assertSoftly
import io.kotest.core.spec.style.FunSpec
import io.kotest.core.test.TestScope
import io.kotest.matchers.paths.shouldExist
import io.kotest.matchers.paths.shouldNotExist
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.*
Expand Down Expand Up @@ -55,7 +57,7 @@ class DevMavenRepoDependencyTest : FunSpec({
.trim()

assertSoftly {
repoChecksum shouldNotBe "no-files"
repoChecksum shouldNotBe EmptyRepoChecksum
repoChecksum.shouldBeSingleLine()
repoChecksum shouldHaveLength 64 // SHA-256 checksum length
repoChecksum.shouldBeHexadecimal()
Expand All @@ -64,6 +66,33 @@ class DevMavenRepoDependencyTest : FunSpec({
}
}

context("a project with a custom devMavenRepo") {
val project = project(devMavenRepo = "custom-repo")

test("expect the consumer's tests find the publication in the custom repo") {
project.runner
.withArguments(":test")
.forwardOutput()
.build {
shouldHaveTaskWithAnyOutcome(":test", SUCCESS, FROM_CACHE, UP_TO_DATE)
}
}

test("expect the custom location is recorded") {
val repoLocation = project.projectDir
.resolve("build/tmp/.maven-dev/metadata/dev.publish.metadata.repo-location.txt")
.readText()
.trim()

repoLocation shouldBe "../../../custom-repo"
}

test("expect nothing is published to the default location") {
project.projectDir.resolve("build/custom-repo").shouldExist()
project.projectDir.resolve("build/maven-dev").shouldNotExist()
}
}

context("a project where updateDevRepo is disabled") {
// the metadata file still records where the repo would be, so the recorded path resolves to a
// directory that was never created
Expand Down Expand Up @@ -98,11 +127,19 @@ class DevMavenRepoDependencyTest : FunSpec({

companion object {

private fun TestScope.project(): GradleProjectTest =
/** SHA-256 of no input, which is the checksum of an empty repo. */
private const val EmptyRepoChecksum = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"

/** @param[devMavenRepo] `devPublish.devMavenRepo`, relative to the build dir, or `null` for the default. */
private fun TestScope.project(
devMavenRepo: String? = null,
): GradleProjectTest =
gradleKtsProjectTest(
projectName = "dev-maven-repo-dependency",
testProjectPath = testCase.descriptor.slashSeparatedPath(),
) {
// an earlier run would have left the default repo behind
file("build").deleteRecursively()

buildGradleKts = """
|plugins {
Expand All @@ -122,6 +159,8 @@ class DevMavenRepoDependencyTest : FunSpec({
| }
|}
|
|${devMavenRepo?.let { "devPublish.devMavenRepo = layout.buildDirectory.dir(\"$it\")" } ?: ""}
|
|dependencies {
| testImplementation(devPublish.dependency())
| testImplementation(kotlin("test"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.kotest.core.spec.style.FunSpec
import io.kotest.core.test.TestCaseOrder
import io.kotest.core.test.TestScope
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import kotlin.io.path.*

/**
Expand Down Expand Up @@ -51,6 +52,80 @@ class RepoChecksumIncrementalTest : FunSpec({
}
}

context("when one file in a shared directory changes, in a full run") {
val project = project()

// full runs, because an incremental run only re-hashes the changed file
RepoFiles.forEach { repoFile ->
test("expect modifying $repoFile changes the checksum") {
val file = project.projectDir.resolve("$RepoDir/$repoFile")
val original = file.readText()

project.runGenerate("--rerun")
val before = project.repoChecksum()

file.writeText("modified")
project.runGenerate("--rerun")
val after = project.repoChecksum()

file.writeText(original)
after shouldNotBe before
}
}
}

context("when every file moves to another directory") {
val project = project()

// move every file, so only the directory changes, not which contents are present
test("expect the checksum changes") {
project.runGenerate()
val before = project.repoChecksum()

RepoFiles.forEach { repoFile ->
project.projectDir.resolve("$RepoDir/$repoFile").moveTo(
project.projectDir.resolve("fake-repo/com/example/lib/2.0.0/$repoFile")
.createParentDirectories()
)
}
project.runGenerate()

project.repoChecksum() shouldNotBe before
}
}

context("when two files in different directories have the same contents") {
val project = project()

// like empty javadoc jars from two modules
val libJavadoc = project.projectDir.resolve("$RepoDir/lib-1.0.0-javadoc.jar")
val otherJavadoc = project.projectDir.resolve("fake-repo/com/example/other/1.0.0/other-1.0.0-javadoc.jar")
listOf(libJavadoc, otherJavadoc).forEach { file ->
file.createParentDirectories().writeText("empty javadoc")
}

// only contents change, so the file set is unchanged and the second run is incremental
test("expect modifying one of them gives the full-run checksum") {
project.runGenerate()
otherJavadoc.writeText("modified")
project.runGenerate()
val incremental = project.repoChecksum()

project.runGenerate("--rerun")
project.repoChecksum() shouldBe incremental
}

test("expect changing a file to match another file's contents gives the full-run checksum") {
project.runGenerate()
otherJavadoc.writeText(libJavadoc.readText())
project.runGenerate()
val incremental = project.repoChecksum()

project.runGenerate("--rerun")
project.repoChecksum() shouldBe incremental
}
}

context("when every file is renamed, like a SNAPSHOT re-publish") {
val project = project()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.kotest.core.spec.style.FunSpec
import io.kotest.core.test.TestScope
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldNotContain
import kotlin.io.path.invariantSeparatorsPathString
import org.gradle.testkit.runner.TaskOutcome.SKIPPED

/**
Expand Down Expand Up @@ -73,7 +74,27 @@ class SigningTest : FunSpec({
output shouldContain "no configured signatory"
// signing is genuinely required here, so Gradle's error is the correct one.
// Dev Publish must not replace it with advice the build has already followed.
output shouldNotContain "cannot publish to the dev Maven repository without a signatory"
output shouldNotContain "Dev Publish cannot publish"
}
}
}

context("when the same build also publishes to Maven local") {
// todo also test a custom file-based repo
val project = project(setRequired = "publishingOutsideDevRepo")

test("expect signing is NOT skipped, and the build fails without a signatory") {
project.runner
.withArguments(
":updateDevRepo",
":publishMavenJavaPublicationToMavenLocal",
// keep the real ~/.m2 untouched, in case signing is skipped and the publish succeeds
"-Dmaven.repo.local=${project.projectDir.resolve("maven-local").invariantSeparatorsPathString}",
)
.forwardOutput()
.buildAndFail {
output shouldContain "no configured signatory"
output shouldNotContain "Dev Publish cannot publish"
}
}
}
Expand Down
Loading