Skip to content

Commit

Permalink
Adjust task/configuration names, improve snapshot support, improve de…
Browse files Browse the repository at this point in the history
…fault filters
  • Loading branch information
jpenilla committed Jan 29, 2024
1 parent 4095779 commit 53d71fc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class GenerateJavadocLinksFile : DefaultTask() {
@get:Nested
abstract val filter: Property<JavadocLinksExtension.DependencyFilter>

fun apiElements(configuration: NamedDomainObjectProvider<Configuration>) {
fun dependenciesFrom(configuration: NamedDomainObjectProvider<Configuration>) {
apiElements.set(configuration.map { it.incoming.artifacts })
apiElementsFiles.setFrom(configuration)
}
Expand Down Expand Up @@ -90,16 +90,6 @@ abstract class GenerateJavadocLinksFile : DefaultTask() {
private fun ResolvedArtifactResult.componentIdentifier(): ModuleComponentIdentifier? =
id.componentIdentifier as? ModuleComponentIdentifier

private fun coordinates(componentId: ModuleComponentIdentifier): String {
return StringBuilder()
.append(componentId.group)
.append(':')
.append(componentId.module)
.append(':')
.append(componentId.version)
.toString()
}

private fun Provider<Set<ResolvedArtifactResult>>.sorted(): List<ResolvedArtifactResult> = get().sortedWith(
Comparator.comparing<ResolvedArtifactResult, String> { it.id.componentIdentifier.displayName }
.thenComparing(Function { it.file.name })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Input
import java.util.function.Predicate

abstract class JavadocLinksExtension {
abstract val overrides: MapProperty<String, String>
abstract val skip: ListProperty<String>
abstract val excludes: ListProperty<String>
abstract val filter: Property<DependencyFilter>

init {
Expand All @@ -31,7 +32,7 @@ abstract class JavadocLinksExtension {
}

fun exclude(dep: ModuleDependency) {
skip.add(key(dep))
excludes.add(key(dep))
}

fun exclude(dep: Provider<out ModuleDependency>) {
Expand All @@ -41,10 +42,23 @@ abstract class JavadocLinksExtension {
private fun key(dep: ModuleDependency) = dep.group + ':' + dep.name + (dep.version?.let { ":$it" } ?: "")

fun interface DependencyFilter : Predicate<ModuleComponentIdentifier> {
class NoSnapshots : DependencyFilter {
data class NoSnapshots(
@get:Input
val exceptFor: Set<String> = emptySet()
) : DependencyFilter {
override fun test(t: ModuleComponentIdentifier): Boolean {
val coords = coordinates(t)
if (exceptFor.any { coords.startsWith(it) }) {
return true
}
return t !is MavenUniqueSnapshotComponentIdentifier
}
}

class PassThrough : DependencyFilter {
override fun test(ignore: ModuleComponentIdentifier): Boolean {
return true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@ abstract class JavadocLinksPlugin : Plugin<Project> {
return@configureEach
}

val apiElementsCopy = target.configurations.register(apiElementsConfigurationName + "JavadocLinksCopy") {
val linkDependencies = target.configurations.register(formatName("javadocLinks")) {
extendsFrom(target.configurations.named(apiElementsConfigurationName).get())
isCanBeResolved = true
isCanBeConsumed = false
isCanBeDeclared = false
}

val linksFileTask = target.tasks.register<GenerateJavadocLinksFile>(name + "JavadocLinksFile") {
linksFile.convention(target.layout.buildDirectory.file(name))
val linksFileTask = target.tasks.register<GenerateJavadocLinksFile>(formatName("javadocLinksFile")) {
linksFile.convention(target.layout.buildDirectory.file("tmp/$name.options"))
overrides.convention(ext.overrides)
skip.convention(ext.skip)
skip.convention(ext.excludes)
defaultJavadocProvider.convention("https://javadoc.io/doc/{group}/{name}/{version}")
filter.convention(ext.filter)
apiElements(apiElementsCopy)
dependenciesFrom(linkDependencies)
}

target.tasks.maybeConfigure<Javadoc>(javadocTaskName) {
Expand Down
28 changes: 28 additions & 0 deletions src/main/kotlin/org/incendo/cloudbuildlogic/ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package org.incendo.cloudbuildlogic

import org.gradle.api.Action
import org.gradle.api.PolymorphicDomainObjectContainer
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.internal.artifacts.repositories.resolver.MavenUniqueSnapshotComponentIdentifier
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.gradle.api.publish.maven.MavenPomDeveloperSpec
import org.gradle.api.tasks.SourceSet

// set by GitHub Actions
val ProviderFactory.ciBuild: Provider<Boolean>
Expand All @@ -18,6 +21,31 @@ inline fun <reified S> PolymorphicDomainObjectContainer<in S>.maybeConfigure(nam
}
}

fun coordinates(componentId: ModuleComponentIdentifier): String {
val builder = StringBuilder()
.append(componentId.group)
.append(':')
.append(componentId.module)
.append(':')

val ver = if (componentId is MavenUniqueSnapshotComponentIdentifier) {
componentId.snapshotVersion
} else {
componentId.version
}

return builder
.append(ver)
.toString()
}

fun SourceSet.formatName(taskName: String): String {
if (name == "main") {
return taskName
}
return name + taskName.replaceFirstChar(Char::uppercase)
}

fun MavenPomDeveloperSpec.city() {
developer {
id.set("Citymonstret")
Expand Down

0 comments on commit 53d71fc

Please sign in to comment.