-
-
Notifications
You must be signed in to change notification settings - Fork 452
Aggregate javadoc using build-logic #4457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: 'Generate Javadocs' | ||
on: | ||
release: | ||
types: [released] | ||
|
||
jobs: | ||
build-and-deploy-javadocs: | ||
name: Build and deploy Javadocs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: 'recursive' | ||
|
||
- name: set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '17' | ||
|
||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@8379f6a1328ee0e06e2bb424dadb7b159856a326 | ||
|
||
- name: Generate Aggregate Javadocs | ||
run: | | ||
./gradlew aggregateJavadocs | ||
- name: Deploy | ||
uses: JamesIves/github-pages-deploy-action@6c2d9db40f9296374acc17b90404b6e8864128c8 # pin@4.7.3 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
BRANCH: gh-pages | ||
FOLDER: build/docs/javadoc | ||
CLEAN: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = "build-logic" |
29 changes: 29 additions & 0 deletions
29
build-logic/src/main/kotlin/io.sentry.javadoc.aggregate.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import io.sentry.gradle.AggregateJavadoc | ||
import org.gradle.api.attributes.Category | ||
import org.gradle.api.attributes.LibraryElements | ||
import org.gradle.kotlin.dsl.creating | ||
import org.gradle.kotlin.dsl.getValue | ||
import org.gradle.kotlin.dsl.named | ||
|
||
val javadocPublisher by configurations.creating { | ||
isCanBeConsumed = false | ||
isCanBeResolved = true | ||
attributes { | ||
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) | ||
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named("javadoc")) | ||
} | ||
} | ||
|
||
subprojects { | ||
javadocPublisher.dependencies.add(dependencies.create(this)) | ||
} | ||
|
||
val javadocCollection = javadocPublisher.incoming.artifactView { lenient(true) }.files | ||
|
||
tasks.register("aggregateJavadoc", AggregateJavadoc::class) { | ||
group = "documentation" | ||
description = "Aggregates Javadocs from all subprojects into a single directory." | ||
javadocFiles.set(javadocCollection) | ||
rootDir.set(layout.projectDirectory) | ||
outputDir.set(layout.buildDirectory.dir("docs/javadoc")) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
val javadocConfig: Configuration by configurations.creating { | ||
isCanBeResolved = false | ||
isCanBeConsumed = true | ||
|
||
attributes { | ||
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) | ||
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named("javadoc")) | ||
} | ||
} | ||
|
||
tasks.withType<Javadoc>().configureEach { | ||
setDestinationDir(project.layout.buildDirectory.file("docs/javadoc").get().asFile) | ||
title = "${project.name} $version API" | ||
val opts = options as StandardJavadocDocletOptions | ||
opts.quiet() | ||
opts.encoding = "UTF-8" | ||
opts.memberLevel = JavadocMemberLevel.PROTECTED | ||
opts.links = listOf( | ||
"https://docs.oracle.com/javase/8/docs/api/", | ||
"https://docs.spring.io/spring-framework/docs/current/javadoc-api/", | ||
"https://docs.spring.io/spring-boot/docs/current/api/" | ||
) | ||
} | ||
|
||
artifacts { | ||
add(javadocConfig.name, tasks.named("javadoc")) | ||
} |
41 changes: 41 additions & 0 deletions
41
build-logic/src/main/kotlin/io/sentry/gradle/AggregateJavadoc.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.sentry.gradle | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.FileCollection | ||
import org.gradle.api.file.FileSystemOperations | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.InputFiles | ||
import org.gradle.api.tasks.Internal | ||
import org.gradle.api.tasks.OutputDirectory | ||
import org.gradle.api.tasks.TaskAction | ||
import javax.inject.Inject | ||
|
||
abstract class AggregateJavadoc @Inject constructor( | ||
@get:Internal val fs: FileSystemOperations | ||
) : DefaultTask() { | ||
@get:InputFiles | ||
abstract val javadocFiles: Property<FileCollection> | ||
|
||
// Marked as Internal since this is only used to relativize the paths for the output directories | ||
@get:Internal | ||
abstract val rootDir: DirectoryProperty | ||
|
||
@get:OutputDirectory | ||
abstract val outputDir: DirectoryProperty | ||
|
||
@TaskAction | ||
fun aggregate() { | ||
javadocFiles.get().forEach { file -> | ||
fs.copy { | ||
// Get the relative path of the project directory to the root directory | ||
val relativePath = file.relativeTo(rootDir.get().asFile) | ||
// Remove the 'build/docs/javadoc' part from the path | ||
val projectPath = relativePath.path.replace("build/docs/javadoc", "") | ||
from(file) | ||
// Use the project name as the output directory name so that each javadoc goes into its own directory | ||
into(outputDir.get().file(projectPath)) | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ plugins { | |
alias(libs.plugins.errorprone) apply false | ||
alias(libs.plugins.gradle.versions) apply false | ||
alias(libs.plugins.spring.dependency.management) apply false | ||
id("io.sentry.javadoc.aggregate") | ||
} | ||
|
||
buildscript { | ||
|
@@ -237,7 +238,7 @@ spotless { | |
kotlin { | ||
target("**/*.kt") | ||
ktlint() | ||
targetExclude("**/sentry-native/**") | ||
targetExclude("**/sentry-native/**", "**/build/**") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to add this exclusion otherwise spotless tries to format the generated code in the |
||
} | ||
kotlinGradle { | ||
target("**/*.kts") | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.