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
4 changes: 1 addition & 3 deletions .github/workflows/run_gradle_task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,5 @@ jobs:
uses: mikepenz/action-junit-report@v6
if: always()
with:
report_paths: |
**/build/test-results/**/TEST-*.xml
!**/build/project-tests/**
report_paths: modules/*/build/test-results/**/TEST-*.xml
require_tests: false
7 changes: 7 additions & 0 deletions modules/dev-publish-plugin/api/dev-publish-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,23 @@ public final class dev/adamko/gradle/dev_publish/tasks/BaseDevPublishTask$Compan
}

public abstract class dev/adamko/gradle/dev_publish/tasks/GenerateDevPublishMetadataTask : dev/adamko/gradle/dev_publish/tasks/BaseDevPublishTask {
public static final field Companion Ldev/adamko/gradle/dev_publish/tasks/GenerateDevPublishMetadataTask$Companion;
public abstract fun getDevMavenRepo ()Lorg/gradle/api/file/DirectoryProperty;
public final fun getDevMavenRepoRelativeToMetadataDir ()Lorg/gradle/api/provider/Provider;
public abstract fun getOutputDirectory ()Lorg/gradle/api/file/DirectoryProperty;
}

public final class dev/adamko/gradle/dev_publish/tasks/GenerateDevPublishMetadataTask$Companion {
}

public abstract class dev/adamko/gradle/dev_publish/tasks/GeneratePublicationDataChecksumTask : dev/adamko/gradle/dev_publish/tasks/BaseDevPublishTask {
public abstract fun getOutputDirectory ()Lorg/gradle/api/file/DirectoryProperty;
public abstract fun getPublicationData ()Lorg/gradle/api/NamedDomainObjectContainer;
}

public abstract class dev/adamko/gradle/dev_publish/tasks/PublishAllToDevRepoTask : dev/adamko/gradle/dev_publish/tasks/BaseDevPublishTask {
}

public abstract class dev/adamko/gradle/dev_publish/tasks/UpdateDevRepoTask : dev/adamko/gradle/dev_publish/tasks/BaseDevPublishTask {
public fun from (Lorg/gradle/api/provider/Provider;)V
public abstract fun getDevRepo ()Lorg/gradle/api/file/DirectoryProperty;
Expand Down
15 changes: 10 additions & 5 deletions modules/dev-publish-plugin/src/main/kotlin/DevPublishPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ constructor(
usesService(devPubService)

val stagingDevMavenRepo = devPubExtension.stagingDevMavenRepo
val publicationStore = devPubExtension.publicationsStore.dir(this@configurePublishToMavenRepositoryTask.name)

val publicationDir = layout.buildDirectory.dir("tmp/.$DEV_PUB__MAVEN_REPO_DIR/publications/$name")

devPubExtension.publicationDirs.from(
objects.fileCollection().from(publicationDir).builtBy(this)
)

// need to determine the repo lazily because the repo isn't set immediately
val repoIsDevPub = providers.provider { repository?.name == DEV_PUB__MAVEN_REPO_NAME }.orElse(false)
Expand All @@ -237,7 +242,7 @@ constructor(
// Gradle already tracks every publishable file as an input,
// so declaring an output is enough to make the task up-to-date when the publication is unchanged.
outputs
.dir(publicationStore)
.dir(publicationDir)
.withPropertyName("devPubPublicationStore")

outputs.doNotCacheIf("this task only performs simple file modifications") { _ ->
Expand All @@ -252,12 +257,12 @@ constructor(
}
}

doLast_("sync staging repo to publication store") {
doLast_("sync staging repo to publication dir") {
if (repoIsDevPub.get()) {
logger.info { ("[$path] Syncing staging-dev-maven-repo to publication store ${publicationStore.get().asFile.invariantSeparatorsPath}") }
logger.info { ("[$path] Syncing staging-dev-maven-repo to publication dir ${publicationDir.get().asFile.invariantSeparatorsPath}") }
fs.sync {
from(stagingDevMavenRepo)
into(publicationStore)
into(publicationDir)
}

// clear the staging repo for the next task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.adamko.gradle.dev_publish

import dev.adamko.gradle.dev_publish.internal.DevPublishInternalApi
import org.gradle.api.artifacts.Dependency
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
Expand Down Expand Up @@ -66,13 +67,17 @@ abstract class DevPublishPluginExtension
abstract val stagingDevMavenRepo: DirectoryProperty

/**
* Temporary storage of individual publications.
* Temporary storage of this project's current publications, collected by `publishAllToDevRepo`.
*
* This value is intended for internal use and should not typically be configured in build scripts.
*/
@DevPublishInternalApi
abstract val publicationsStore: DirectoryProperty

/** The repo written by each dev repo publish task. Added to by each task, when it is configured. */
@DevPublishInternalApi
abstract val publicationDirs: ConfigurableFileCollection

/**
* Location of stored
* [dev.adamko.gradle.dev_publish.data.PublicationData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class DevPublishTasksContainer(
private val problemsReporter: ProblemReporter,
) {

/** Lifecycle task for publishing dev repos to the current subproject's dev repo. */
val publishAllToDevRepo: TaskProvider<BaseDevPublishTask> =
/** Collects the publications of the current subproject. */
val publishAllToDevRepo: TaskProvider<PublishAllToDevRepoTask> =
tasks.registerPublishAllToDevRepoTask()

/** No longer used: Gradle's own up-to-date checks decide when to publish. */
Expand All @@ -35,12 +35,13 @@ class DevPublishTasksContainer(
val generateDevPublishMetadata: TaskProvider<GenerateDevPublishMetadataTask> =
tasks.registerGenerateDevPublishMetadataTask()

private fun TaskContainer.registerPublishAllToDevRepoTask(): TaskProvider<BaseDevPublishTask> =
register<BaseDevPublishTask>(PUBLISH_ALL_TO_DEV_REPO_TASK_NAME) {
private fun TaskContainer.registerPublishAllToDevRepoTask(): TaskProvider<PublishAllToDevRepoTask> =
register<PublishAllToDevRepoTask>(PUBLISH_ALL_TO_DEV_REPO_TASK_NAME) {
description = "Publishes all Maven publications from this project into the dev Maven repository staging area." +
"This is an internal task that should not typically be manually referenced or called."

outputs.dir(devPubExtension.stagingDevMavenRepo)
publicationDirs.from(devPubExtension.publicationDirs)
publicationsStore.convention(devPubExtension.publicationsStore)
}

@Suppress("DEPRECATION")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dev.adamko.gradle.dev_publish.internal.DevPublishMetadata.REPO_CHECKSUM_F
import dev.adamko.gradle.dev_publish.internal.DevPublishMetadata.REPO_LOCATION_FILE_NAME
import dev.adamko.gradle.dev_publish.internal.checksums.checksum
import dev.adamko.gradle.dev_publish.internal.failDevMavenRepoNotRelative
import dev.adamko.gradle.dev_publish.tasks.GenerateDevPublishMetadataTask.Companion.repoPath
import dev.adamko.gradle.dev_publish.utils.nullOutputStream
import java.nio.file.Path
import java.security.DigestOutputStream
Expand All @@ -22,7 +23,7 @@ import org.gradle.api.problems.Problems
import org.gradle.api.provider.Provider
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.*
import org.gradle.api.tasks.PathSensitivity.RELATIVE
import org.gradle.api.tasks.PathSensitivity.NONE
import org.gradle.work.ChangeType.REMOVED
import org.gradle.work.FileChange
import org.gradle.work.Incremental
Expand Down Expand Up @@ -69,11 +70,25 @@ constructor(
*/
@get:Incremental
@get:InputFiles
@get:PathSensitive(RELATIVE)
@get:PathSensitive(NONE) // file names might include SNAPSHOT timestamps
@get:IgnoreEmptyDirectories
@DevPublishInternalApi
abstract val devMavenRepoTrackedFiles: ConfigurableFileCollection

@get:Input
@get:Optional
internal val devMavenRepoTrackedFilesPaths: Provider<Set<String>>
get() {
return devMavenRepo.zip(devMavenRepoTrackedFiles.elements) { devMavenRepoDir, trackedFiles ->
val devMavenRepo = devMavenRepoDir.asFile.toPath()
trackedFiles
.map { f -> f.asFile.toPath() }
.filter { f -> f.isRegularFile() }
.map { f -> repoPath(devMavenRepo, f) }
.toSortedSet()
}
}

/**
* Patterns of files to exclude from the dev Maven repository up-to-date check.
* See [org.gradle.api.tasks.util.PatternFilterable] for syntax.
Expand Down Expand Up @@ -130,10 +145,14 @@ constructor(
}
stateDir.createDirectories()

// normalizedPath -> cache value
// repoPath -> cache value
val state: MutableMap<String, String> = readStateEntries(stateFile)

updateState(state, inputChanges.getFileChanges(devMavenRepoTrackedFiles))
updateState(
state = state,
fileChanges = inputChanges.getFileChanges(devMavenRepoTrackedFiles),
devMavenRepo = devMavenRepo.get().asFile.toPath(),
)

writeStateEntries(stateFile, state)

Expand All @@ -143,78 +162,108 @@ constructor(
.use { digestStream ->
state.values
.sorted()
.forEach { cacheValue -> digestStream.write("$cacheValue$CHECKSUM_CACHE_VALUE_SEPARATOR") }
.forEach { cacheValue ->
digestStream.write(cacheValue)
digestStream.write(CHECKSUM_CACHE_VALUE_SEPARATOR)
}
}
return md.digest().toHexString()
}
}

/** Separates the normalized path from the cache value, in a state file line. */
private const val STATE_FILE_PATH_SEPARATOR = '\t'
companion object {

/** Ends each line in the state file. */
private const val STATE_FILE_LINE_SEPARATOR = '\n'
/** Separates the normalized path from the cache value, in a state file line. */
private const val STATE_FILE_PATH_SEPARATOR = '\t'

/** Separates cache values in the repo checksum input, so concatenated values can't be ambiguous. */
private const val CHECKSUM_CACHE_VALUE_SEPARATOR = '\n'
/** Ends each line in the state file. */
private const val STATE_FILE_LINE_SEPARATOR = '\n'

/** Separates cache values in the repo checksum input, so concatenated values can't be ambiguous. */
private const val CHECKSUM_CACHE_VALUE_SEPARATOR = "\n"

/** `parentDir:checksum`. The file name is excluded, because SNAPSHOT publishing renames files. */
private fun computeCacheValue(file: Path, normalizedPath: String): String {
val parentDir = Path(normalizedPath).parent
?.invariantSeparatorsPathString
?: "<root>"
return "${parentDir}:${file.checksum()}"
}
/** The timestamp and build number in a SNAPSHOT file name, e.g. `-20261113.215135-1`. */
private val SNAPSHOT_TIMESTAMP = Regex("""-\d{8}\.\d{6}-\d+""")

/**
* Path of [file] relative to [devMavenRepo], with any SNAPSHOT timestamp replaced by `-SNAPSHOT`,
* so re-publishing a SNAPSHOT doesn't change it.
*/
private fun repoPath(devMavenRepo: Path, file: Path): String {
val normalizedFile =
if (file.parent?.name?.endsWith("-SNAPSHOT") == true) {
file.resolveSibling(file.name.replace(SNAPSHOT_TIMESTAMP, "-SNAPSHOT"))
} else {
file
}
return normalizedFile.relativeTo(devMavenRepo).invariantSeparatorsPathString
}

/** Read lines of `normalizedPath<TAB>cacheValue`. */
private fun readStateEntries(stateFile: Path): MutableMap<String, String> {
if (!stateFile.exists()) {
return mutableMapOf()
}
/** `parentDir:checksum`. The file name is excluded, because SNAPSHOT publishing renames files. */
private fun computeCacheValue(file: Path, repoPath: String): String {
val parentDir = Path(repoPath).parent
?.invariantSeparatorsPathString
?: "<root>"
return "${parentDir}:${file.checksum()}"
}

return stateFile.useLines(UTF_8) { lines ->
lines
.filter { it.isNotBlank() }
.associateTo(mutableMapOf()) { line ->
val parts = line.split(STATE_FILE_PATH_SEPARATOR, limit = 2)
require(parts.size == 2) { "Invalid state file line `$line` in ${stateFile.invariantSeparatorsPathString}" }
parts.run { first() to last() }
}
}
}

/** Write lines of `normalizedPath<TAB>cacheValue`. */
private fun writeStateEntries(stateFile: Path, state: Map<String, String>) {
stateFile.writeText(
state.entries.joinToString("") { (normalizedPath, cacheValue) ->
buildString {
append(normalizedPath)
append(STATE_FILE_PATH_SEPARATOR)
append(cacheValue)
append(STATE_FILE_LINE_SEPARATOR)
/** Read lines of `repoPath<TAB>cacheValue`. */
private fun readStateEntries(stateFile: Path): MutableMap<String, String> {
if (!stateFile.exists()) {
return mutableMapOf()
}
},
UTF_8,
)
}

private fun updateState(state: MutableMap<String, String>, fileChanges: Iterable<FileChange>) {
val (removalChanges, modificationChanges) =
fileChanges.partition { it.changeType == REMOVED }

removalChanges.forEach { state.remove(it.normalizedPath) }
return stateFile.useLines(UTF_8) { lines ->
lines
.filter { it.isNotBlank() }
.associateTo(mutableMapOf()) { line ->
val parts = line.split(STATE_FILE_PATH_SEPARATOR, limit = 2)
require(parts.size == 2) { "Invalid state file line `$line` in ${stateFile.invariantSeparatorsPathString}" }
parts.run { first() to last() }
}
}
}

modificationChanges
.parallelStream()
.map { change ->
val file = change.file.toPath()
val cacheValue = computeCacheValue(file, change.normalizedPath)
change.normalizedPath to cacheValue
/** Write lines of `repoPath<TAB>cacheValue`. */
private fun writeStateEntries(stateFile: Path, state: Map<String, String>) {
stateFile.writeText(
state.entries.joinToString("") { (repoPath, cacheValue) ->
buildString {
append(repoPath)
append(STATE_FILE_PATH_SEPARATOR)
append(cacheValue)
append(STATE_FILE_LINE_SEPARATOR)
}
},
UTF_8,
)
}
.collect(Collectors.toList())
.forEach { (normalizedPath, cacheValue) ->
state[normalizedPath] = cacheValue

/**
* Keyed by [repoPath], not [FileChange.getNormalizedPath],
* because [devMavenRepoTrackedFiles] ignores paths, so its normalised paths are empty.
*/
private fun updateState(
state: MutableMap<String, String>,
fileChanges: Iterable<FileChange>,
devMavenRepo: Path,
) {
val (removalChanges, modificationChanges) =
fileChanges.partition { it.changeType == REMOVED }

removalChanges.forEach { state.remove(repoPath(devMavenRepo, it.file.toPath())) }

modificationChanges
.parallelStream()
.map { change ->
val file = change.file.toPath()
val repoPath = repoPath(devMavenRepo, file)
repoPath to computeCacheValue(file, repoPath)
}
.collect(Collectors.toList())
.forEach { (repoPath, cacheValue) ->
state[repoPath] = cacheValue
}
}
}
}
Loading
Loading