Skip to content

Commit

Permalink
Add filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Jan 28, 2024
1 parent b90911a commit 590e2f2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
Expand All @@ -39,6 +40,9 @@ abstract class GenerateJavadocLinksFile : DefaultTask() {
@get:Input
abstract val defaultJavadocProvider: Property<String>

@get:Nested
abstract val filter: Property<JavadocLinksExtension.DependencyFilter>

fun apiElements(configuration: NamedDomainObjectProvider<Configuration>) {
apiElements.set(configuration.map { it.incoming.artifacts })
apiElementsFiles.setFrom(configuration)
Expand All @@ -52,6 +56,9 @@ abstract class GenerateJavadocLinksFile : DefaultTask() {
val output = StringBuilder()
for (resolvedArtifactResult in apiElements.sorted()) {
val id = resolvedArtifactResult.componentIdentifier() ?: continue
if (!filter.get().test(id)) {
continue
}

output.append("-link ")
val coordinates = coordinates(id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
package org.incendo.cloudbuildlogic

import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
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 java.util.function.Predicate

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

init {
init()
}

private fun init() {
filter.convention(DependencyFilter.NoSnapshots())
}

fun override(dep: ModuleDependency, link: String) {
val key = dep.group + ':' + dep.name + (dep.version?.let { ":$it" } ?: "")
overrides.put(key, link)
overrides.put(key(dep), link)
}

fun override(dep: Provider<out ModuleDependency>, link: String) {
override(dep.get(), link)
}

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

fun exclude(dep: Provider<out ModuleDependency>) {
exclude(dep.get())
}

private fun key(dep: ModuleDependency) = dep.group + ':' + dep.name + (dep.version?.let { ":$it" } ?: "")

fun interface DependencyFilter : Predicate<ModuleComponentIdentifier> {
class NoSnapshots : DependencyFilter {
override fun test(t: ModuleComponentIdentifier): Boolean {
return !t.version.endsWith("-SNAPSHOT")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ abstract class JavadocLinksPlugin : Plugin<Project> {
linksFile.convention(target.layout.buildDirectory.file(name))
overrides.convention(ext.overrides)
defaultJavadocProvider.convention("https://javadoc.io/doc/{group}/{name}/{version}")
filter.convention(ext.filter)
apiElements(apiElementsCopy)
}

Expand Down

0 comments on commit 590e2f2

Please sign in to comment.