Skip to content

Commit

Permalink
Fix javadoc build
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Apr 6, 2024
1 parent fe258d3 commit 9240063
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 134 deletions.
138 changes: 4 additions & 134 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import org.gradle.plugins.ide.idea.model.IdeaModel
import java.nio.file.Files
import kotlin.io.path.Path

plugins {
`java-platform`
Expand Down Expand Up @@ -29,94 +28,6 @@ val targetJavaVersion = jdkVersion.toInt()
group = projGroupId
version = projVersion

enum class NativePlatform(
val osFamilyName: String,
val osArch: String,
classifier: String,
val nativeLibPrefix: String,
val nativeLibSuffix: String,
val taskSuffix: String
) {
WIN_64("windows", "x64", "windows", "", ".dll", "Win64"),
WIN_ARM64("windows", "arm64", "windows-arm64", "", ".dll", "WinArm64"),
LINUX_64("linux", "x64", "linux", "lib", ".so", "Linux64"),
LINUX_ARM32("linux", "arm32", "linux-arm32", "lib", ".so", "LinuxArm32"),
LINUX_ARM64("linux", "arm64", "linux-arm64", "lib", ".so", "LinuxArm64"),
MACOS("macos", "x64", "macos", "lib", ".dylib", "Macos"),
MACOS_ARM64("macos", "arm64", "macos-arm64", "lib", ".dylib", "MacosArm64");

companion object {
val ALL = values()
}

val classifier = "natives-$classifier"
}

enum class NativeBinding(
val bindingName: String,
val basename: String,
vararg val platforms: NativePlatform
) {
GLFW(
"glfw", "glfw3",
NativePlatform.WIN_64,
NativePlatform.LINUX_64, NativePlatform.LINUX_ARM64,
NativePlatform.MACOS, NativePlatform.MACOS_ARM64
),
NFD("nfd", "nfd", *NativePlatform.ALL),
STB("stb", "stb", *NativePlatform.ALL)
}

enum class Artifact(
val artifactName: String,
val projectName: String,
val projectDescription: String,
val subprojectName: String,
val mavenName: String,
val nativeBinding: NativeBinding? = null,
val nativeCIVersion: String? = null
) {
CORE(
"overrungl", "OverrunGL",
"The OverrunGL core library.",
":core", "Core"
),
GLFW(
"overrungl-glfw", "OverrunGL - GLFW bindings",
"A multi-platform library for OpenGL, OpenGL ES and Vulkan development on the desktop. It provides a simple API for creating windows, contexts and surfaces, receiving input and events.",
":glfw", "Glfw", NativeBinding.GLFW
),
JOML(
"overrungl-joml", "OverrunGL - JOML native access",
"A Java math library for OpenGL rendering calculations",
":joml", "Joml"
),
NFD(
"overrungl-nfd", "OverrunGL - Native File Dialog",
"A tiny, neat C library that portably invokes native file open and save dialogs.",
":nfd", "Nfd", NativeBinding.NFD
),
OPENGL(
"overrungl-opengl", "OverrunGL - OpenGL bindings",
"The most widely adopted 2D and 3D graphics API in the industry, bringing thousands of applications to a wide variety of computer platforms.",
":opengl", "Opengl"
),
STB(
"overrungl-stb", "OverrunGL - stb bindings",
"Single-file public domain libraries for fonts, images, ogg vorbis files and more.",
":stb", "Stb", NativeBinding.STB, nativeCIVersion = "0.1.0-alpha.6"
),
//VULKAN("overrungl-vulkan", "OverrunGL - Vulkan bindings",
// "A new generation graphics and compute API that provides high-efficiency, cross-platform access to modern GPUs used in a wide variety of devices from PCs and consoles to mobile phones and embedded platforms.",
// ":vulkan", "Vulkan", null),
;

fun nativeFileName(platform: NativePlatform): String? {
return if (nativeBinding == null) null
else "${nativeBinding.bindingName}/${platform.osFamilyName}/${platform.osArch}/${platform.nativeLibPrefix}${nativeBinding.basename}${platform.nativeLibSuffix}"
}
}

val artifactNameMap = buildMap {
Artifact.values().forEach { put(it.subprojectName, it.artifactName) }
put(":samples", "overrungl-samples")
Expand Down Expand Up @@ -157,10 +68,7 @@ artifactNameMap.forEach { (subprojectName, artifactName) ->
}

extensions.configure<JavaPluginExtension>("java") {
val javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion.set(JavaLanguageVersion.of(targetJavaVersion))
}
toolchain.languageVersion.set(JavaLanguageVersion.of(targetJavaVersion))
withJavadocJar()
withSourcesJar()
}
Expand Down Expand Up @@ -207,48 +115,10 @@ artifactNameMap.forEach { (subprojectName, artifactName) ->
}
}

tasks.register("assembleJavadocArgs") {
group = "build"
val mspFile = Path("${rootProject.layout.buildDirectory.get().asFile}/tmp/modulesourcepath.args")
outputs.file(mspFile)

doLast {
Files.deleteIfExists(mspFile)

Files.writeString(
mspFile, """
--module-source-path
${rootProject.projectDir.path}/modules/*/src/main/java
""".trimIndent()
)
}
}

tasks.register<Javadoc>("aggregateJavadoc") {
javadocTool = the<JavaToolchainService>().javadocToolFor {
languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
dependsOn(tasks["assembleJavadocArgs"])
group = "documentation"
outputs.upToDateWhen { false }
val projectsToDoc = Artifact.values().map { project(it.subprojectName) }
dependsOn(projectsToDoc.map { it.getTasksByName("classes", true) })
source(projectsToDoc.map { it.sourceSets["main"].java })
setDestinationDir(File("${layout.buildDirectory.get().asFile}/docs/javadoc"))

classpath = files(projectsToDoc.map { it.configurations["compileClasspath"].files })

executable = project.findProperty("javadocExecutable") as String?

options.optionFiles = listOf(File("${rootProject.layout.buildDirectory.get().asFile}/tmp/modulesourcepath.args"))
}

allprojects {
tasks.withType<Javadoc> {
javadocTool = the<JavaToolchainService>().javadocToolFor {
languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
options {
verbose()
if (this is CoreJavadocOptions) {
if (jdkEnablePreview.toBoolean()) {
addBooleanOption("-enable-preview", true)
Expand Down Expand Up @@ -377,7 +247,7 @@ publishing.publications {
asElement().getElementsByTagName("dependencies").item(0).apply {
Artifact.values().forEach { module ->
if (module.nativeBinding != null) {
module.nativeBinding.platforms.forEach { appendBOM(it, module) }
module.nativeBinding!!.platforms.forEach { appendBOM(it, module) }
} else {
appendBOM(null, module)
}
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins { `kotlin-dsl` }

repositories { mavenCentral() }
102 changes: 102 additions & 0 deletions buildSrc/src/main/kotlin/myproject.java-conventions.gradle.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* MIT License
*
* Copyright (c) 2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/

enum class NativePlatform(
val osFamilyName: String,
val osArch: String,
classifier: String,
val nativeLibPrefix: String,
val nativeLibSuffix: String,
val taskSuffix: String
) {
WIN_64("windows", "x64", "windows", "", ".dll", "Win64"),
WIN_ARM64("windows", "arm64", "windows-arm64", "", ".dll", "WinArm64"),
LINUX_64("linux", "x64", "linux", "lib", ".so", "Linux64"),
LINUX_ARM32("linux", "arm32", "linux-arm32", "lib", ".so", "LinuxArm32"),
LINUX_ARM64("linux", "arm64", "linux-arm64", "lib", ".so", "LinuxArm64"),
MACOS("macos", "x64", "macos", "lib", ".dylib", "Macos"),
MACOS_ARM64("macos", "arm64", "macos-arm64", "lib", ".dylib", "MacosArm64");

companion object {
val ALL = values()
}

val classifier = "natives-$classifier"
}

enum class NativeBinding(
val bindingName: String,
val basename: String,
vararg val platforms: NativePlatform
) {
GLFW(
"glfw", "glfw3",
NativePlatform.WIN_64,
NativePlatform.LINUX_64, NativePlatform.LINUX_ARM64,
NativePlatform.MACOS, NativePlatform.MACOS_ARM64
),
NFD("nfd", "nfd", *NativePlatform.ALL),
STB("stb", "stb", *NativePlatform.ALL)
}

enum class Artifact(
val artifactName: String,
val projectName: String,
val projectDescription: String,
val subprojectName: String,
val mavenName: String,
val nativeBinding: NativeBinding? = null
) {
CORE(
"overrungl", "OverrunGL",
"The OverrunGL core library.",
":core", "Core"
),
GLFW(
"overrungl-glfw", "OverrunGL - GLFW bindings",
"A multi-platform library for OpenGL, OpenGL ES and Vulkan development on the desktop. It provides a simple API for creating windows, contexts and surfaces, receiving input and events.",
":glfw", "Glfw", NativeBinding.GLFW
),
JOML(
"overrungl-joml", "OverrunGL - JOML native access",
"A Java math library for OpenGL rendering calculations",
":joml", "Joml"
),
NFD(
"overrungl-nfd", "OverrunGL - Native File Dialog",
"A tiny, neat C library that portably invokes native file open and save dialogs.",
":nfd", "Nfd", NativeBinding.NFD
),
OPENGL(
"overrungl-opengl", "OverrunGL - OpenGL bindings",
"The most widely adopted 2D and 3D graphics API in the industry, bringing thousands of applications to a wide variety of computer platforms.",
":opengl", "Opengl"
),
STB(
"overrungl-stb", "OverrunGL - stb bindings",
"Single-file public domain libraries for fonts, images, ogg vorbis files and more.",
":stb", "Stb", NativeBinding.STB
),
//VULKAN("overrungl-vulkan", "OverrunGL - Vulkan bindings",
// "A new generation graphics and compute API that provides high-efficiency, cross-platform access to modern GPUs used in a wide variety of devices from PCs and consoles to mobile phones and embedded platforms.",
// ":vulkan", "Vulkan", null),
;

fun nativeFileName(platform: NativePlatform): String? {
return if (nativeBinding == null) null
else "${nativeBinding.bindingName}/${platform.osFamilyName}/${platform.osArch}/${platform.nativeLibPrefix}${nativeBinding.basename}${platform.nativeLibSuffix}"
}
}
42 changes: 42 additions & 0 deletions modules/overrungl.core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
import java.nio.file.Files
import kotlin.io.path.Path

val overrunMarshalVersion: String by rootProject
val overrunPlatformVersion: String by rootProject

val jdkVersion: String by rootProject
val targetJavaVersion = jdkVersion.toInt()

dependencies {
api("io.github.over-run:marshal:$overrunMarshalVersion")
api("io.github.over-run:platform:$overrunPlatformVersion")
}

tasks.register("assembleJavadocArgs") {
group = "build"
val mspFile = Path("${rootProject.layout.buildDirectory.get().asFile}/tmp/modulesourcepath.args")
outputs.file(mspFile)

doLast {
Files.deleteIfExists(mspFile)

Files.writeString(
mspFile, """
--module-source-path
${rootProject.projectDir.path}/modules/*/src/main/java
""".trimIndent()
)
}
}

tasks.register<Javadoc>("aggregateJavadoc") {
javadocTool = javaToolchains.javadocToolFor {
languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
dependsOn(tasks["assembleJavadocArgs"])
group = "documentation"
outputs.upToDateWhen { false }
val projectsToDoc = Artifact.values().map { rootProject.project(it.subprojectName) }
dependsOn(projectsToDoc.map { it.getTasksByName("classes", true) })
source(projectsToDoc.map { it.sourceSets["main"].java })
setDestinationDir(File("${rootProject.layout.buildDirectory.get().asFile}/docs/javadoc"))

classpath = files(projectsToDoc.map { it.configurations["compileClasspath"].files })

// executable = project.findProperty("javadocExecutable") as String?

options.optionFiles = listOf(File("${rootProject.layout.buildDirectory.get().asFile}/tmp/modulesourcepath.args"))
}

0 comments on commit 9240063

Please sign in to comment.