Skip to content

Commit

Permalink
obtain gson, commons-codec, and commons-compress versions for javadoc…
Browse files Browse the repository at this point in the history
… from DownloadWantedVersionManifestTask#provideVersionParser

use netty version from libs.version.toml because minecraft's netty version doesn't have javadocs
  • Loading branch information
supersaiyansubtlety committed Nov 14, 2024
1 parent f2fc3e3 commit 242b3ad
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 38 deletions.
124 changes: 103 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import org.gradle.api.internal.file.FileOperations
import org.quiltmc.launchermeta.version.v1.Library
import org.quiltmc.launchermeta.version.v1.Version
import quilt.internal.constants.Classifiers
import quilt.internal.constants.Constants
import quilt.internal.task.setup.DownloadWantedVersionManifestTask
import quilt.internal.util.serializable.VersionParser

import java.util.stream.Collectors
import java.util.stream.Stream

import static org.gradle.api.plugins.JavaPlugin.JAVADOC_TASK_NAME
import static quilt.internal.task.setup.DownloadWantedVersionManifestTask.DOWNLOAD_WANTED_VERSION_MANIFEST_TASK_NAME

plugins {
id 'maven-publish'
id 'quilt-mappings'
alias libs.plugins.licenser
}

// put these in fields so we don't have to worry about inadvertently accessing the project during task execution
final FileOperations FILE_OPERATIONS = project.fileOperations
final ProviderFactory PROVIDERS = project.providers
final ObjectFactory OBJECTS = project.objects
final Logger LOGGER = project.logger

final USE_SNAPSHOT_HASHES = false

final ENV = System.getenv()
Expand Down Expand Up @@ -118,13 +132,80 @@ tasks.constantsJar {
tasks.build.dependsOn constantsJar, generatePackageInfoMappings,
compressTiny, tinyJar, v2UnmergedMappingsJar, v2MergedMappingsJar

final FileOperations fileOperations = project.fileOperations

// configure lazily because we get buildDirectory
tasks.named(JAVADOC_TASK_NAME, Javadoc) {
// Needed for javadoc to find the doclet classes.
dependsOn docletClasses

final versionParser = tasks
.named(DOWNLOAD_WANTED_VERSION_MANIFEST_TASK_NAME, DownloadWantedVersionManifestTask)
.flatMap(DownloadWantedVersionManifestTask::provideVersionParser)

final MapProperty<String, String> minecraftLibVersionsByModule = OBJECTS.mapProperty(String, String)
minecraftLibVersionsByModule.set(versionParser
.map(VersionParser::get)
.map(Version::getLibraries)
.map {
it.stream()
.map(Library::getName)
.flatMap { moduleName ->
final delim = ':'
final moduleParts = moduleName.split(delim)

if (moduleParts.length == 3 || moduleParts.length == 4) {
return Stream.of(Map.entry(moduleParts[0] + delim + moduleParts[1], moduleParts[2]))
} else {
LOGGER.error("Unrecognized module format: ${moduleName}")

return Stream.empty()
}
}
.distinct()
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
}
)

final Closure<Provider<String>> provideModuleVersion = { String module ->
final versionProperty = OBJECTS.property(String)
.convention(PROVIDERS.provider { throw new GradleException("Missing version for module: ${module}") })

versionProperty.set(minecraftLibVersionsByModule.getting(module))

return versionProperty
}

final Closure<Provider<String>> formatVersionedUrl = { String baseUrl, Provider<String> version ->
version.map {"${baseUrl}/${it}/" as String }
}

final gsonUrl = formatVersionedUrl(
'https://javadoc.io/doc/com.google.code.gson/gson',
provideModuleVersion('com.google.code.gson:gson')
)

// use hardcoded version because minecraft depends on a version that doesn't have javadocs
final nettyUrl = formatVersionedUrl(
'https://javadoc.io/doc/io.netty/netty-all',
libs.versions.netty.with.javadoc
)

final commonsCompressUrl = formatVersionedUrl(
'https://javadoc.io/doc/org.apache.commons/commons-compress',
provideModuleVersion('org.apache.commons:commons-compress')
)

final commonsCodecUrl = formatVersionedUrl(
'https://javadoc.io/doc/commons-codec/commons-codec',
provideModuleVersion('commons-codec:commons-codec')
)

[
gsonUrl: gsonUrl,
nettyUrl: nettyUrl,
commonsCompressUrl: commonsCompressUrl,
commonsCodecUrl: commonsCodecUrl
].each(inputs::property)

destinationDir = layout.buildDirectory.get().dir('docs').dir(project.version.toString()).getAsFile()
final docletResources = sourceSets.doclet.resources.asFileTree

Expand All @@ -133,7 +214,7 @@ tasks.named(JAVADOC_TASK_NAME, Javadoc) {
maxMemory = '2G'

final debug = providers.gradleProperty('quilt.mappings.debug.javadoc')
.map(Boolean::getBoolean)
.map(Boolean::parseBoolean)
.getOrElse(false)

verbose = debug
Expand All @@ -158,23 +239,6 @@ tasks.named(JAVADOC_TASK_NAME, Javadoc) {
it.use()

addBooleanOption '-allow-script-in-comments', true
links(
"https://javadoc.io/doc/com.google.guava/guava/${libs.versions.guava.get()}/",
"https://javadoc.io/doc/com.google.code.gson/gson/${project.gson}/",
"https://javadoc.io/doc/org.jetbrains/annotations/${libs.versions.jetbrains.annotations.get()}/",
"https://javadoc.io/doc/com.google.code.findbugs/jsr305/${libs.versions.jsr305.get()}/",
"https://javadoc.io/doc/org.apache.commons/commons-compress/${project.commons_compress}/",
"https://javadoc.io/doc/io.netty/netty-all/${project.netty}/",
'https://javadoc.lwjgl.org/',
'https://logging.apache.org/log4j/2.x/javadoc/log4j-api/',
'https://fastutil.di.unimi.it/docs/',
'https://commons.apache.org/proper/commons-logging/javadocs/api-release/',
'https://commons.apache.org/proper/commons-lang/javadocs/api-release/',
'https://commons.apache.org/proper/commons-io/apidocs/',
"https://commons.apache.org/proper/commons-codec/archives/${project.commons_codec}/apidocs/",
"https://javadoc.quiltmc.org/quilt-loader/${libs.versions.quilt.loader.get()}/",
"https://docs.oracle.com/en/java/javase/${project.java}/docs/api/"
)
// https://docs.oracle.com/en/java/javase/21/docs/specs/man/javadoc.html#additional-options-provided-by-the-standard-doclet
addBooleanOption 'Xdoclint:html', true
addBooleanOption 'Xdoclint:syntax', true
Expand All @@ -188,14 +252,32 @@ tasks.named(JAVADOC_TASK_NAME, Javadoc) {
doFirst {
// lazy setting
options {
links(
"https://javadoc.io/doc/com.google.guava/guava/${libs.versions.guava.get()}/",
gsonUrl.get(),
"https://javadoc.io/doc/org.jetbrains/annotations/${libs.versions.jetbrains.annotations.get()}/",
"https://javadoc.io/doc/com.google.code.findbugs/jsr305/${libs.versions.jsr305.get()}/",
commonsCompressUrl.get(),
nettyUrl.get(),
'https://javadoc.lwjgl.org/',
'https://logging.apache.org/log4j/2.x/javadoc/log4j-api/',
'https://fastutil.di.unimi.it/docs/',
'https://commons.apache.org/proper/commons-logging/javadocs/api-release/',
'https://commons.apache.org/proper/commons-lang/javadocs/api-release/',
'https://commons.apache.org/proper/commons-io/apidocs/',
commonsCodecUrl.get(),
"https://javadoc.quiltmc.org/quilt-loader/${libs.versions.quilt.loader.get()}/",
"https://docs.oracle.com/en/java/javase/${project.java}/docs/api/"
)

tagletPath sourceSets.doclet.output.classesDirs.files.toList()
header docletResources.filter { it.name == 'javadoc_header.txt' }.singleFile.text.trim()
addFileOption '-add-stylesheet', docletResources.filter { it.name == 'style.css' }.singleFile
}
}

doLast {
fileOperations.copy {
FILE_OPERATIONS.copy {
it.from docletResources
it.include 'copy_on_click.js'
it.into destinationDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.gradle.api.Project;
import org.gradle.api.plugins.PluginContainer;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.TaskProvider;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -68,14 +67,12 @@ protected MinecraftJarsExtension applyImpl(@NotNull Project project) {
}
);

// put mapped provider in a property so all tasks use the same cached value
final Property<VersionParser> versionParser = this.getObjects().property(VersionParser.class);
versionParser.set(
downloadWantedVersionManifest.flatMap(DownloadWantedVersionManifestTask::provideVersionParser)
);

// provideVersionParser is already cached in a property
tasks.withType(VersionParserConsumingTask.class).configureEach(task -> {
task.getVersionParser().convention(versionParser);
task.getVersionParser().convention(
// versionParser
downloadWantedVersionManifest.flatMap(DownloadWantedVersionManifestTask::provideVersionParser)
);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputFile;
import quilt.internal.constants.Groups;
import quilt.internal.plugin.MinecraftJarsPlugin;
Expand All @@ -27,19 +28,26 @@ public abstract class DownloadWantedVersionManifestTask extends SimpleDownloadTa
@OutputFile
public abstract RegularFileProperty getDest();

@Internal("Depends on output")
abstract Property<VersionParser> getVersionParserImpl();

/**
* @see VersionParserConsumingTask
* @see MinecraftJarsPlugin
*/
public Provider<VersionParser> provideVersionParser() {
return this.getDest()
.map(RegularFile::getAsFile)
.map(VersionParser::new);
return this.getVersionParserImpl();
}

public DownloadWantedVersionManifestTask() {
this.setGroup(Groups.SETUP);

this.getVersionParserImpl().set(
this.getDest()
.map(RegularFile::getAsFile)
.map(VersionParser::new)
);

this.getUrl().convention(this.getManifestVersion().map(SerializableVersionEntry::getUrl));
}
}
4 changes: 0 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ org.gradle.caching=true
quilt.mappings.debug.javadoc=false

# Javadoc linking
commons_codec=1.15
commons_compress=1.21
gson=2.9.1
java=21
netty=4.1.68.Final
3 changes: 1 addition & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ jsr305 = "3.0.2"

dictionary = "f9c2abb8ad2df8bf64df06ae2f6ede86704b82c7"

gson = "2.10.1"
netty = "4.1"
netty_with_javadoc = "4.1.68.Final"

vineflower = "1.10.1"

Expand Down

1 comment on commit 242b3ad

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No difference between head and target.

Please sign in to comment.