mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-30 03:26:07 -05:00
48349a3f5f
* Generate package-info files for all impl and mixin packages
* Add javadoc to generated package-infos, use multiline string
* Simplify code
* Remove manual ApiStatus.Internal on impl classes
* Update CONTRIBUTING.md to remove ApiStatus.Internal for impl classes
* Fix Gradle deprecations
* Fix more Gradle deprecations
* Add task metadata
* Support client-main split
* Remove workaround for client packages
* Try to fix Gradle 8 deprecations
* Try to fix Gradle 8 deprecations, part 2
I'm hoping that using the SourceDirectorySet instead of converting it to a
Set<File> (which is pointless?) will carry the build dependencies over.
* Add clean packageInfo task
Co-authored-by: modmuss50 <modmuss50@gmail.com>
(cherry picked from commit 0d0f21023d
)
78 lines
2.3 KiB
Groovy
78 lines
2.3 KiB
Groovy
import java.nio.file.Files
|
|
|
|
for (def sourceSet in [sourceSets.main, sourceSets.client]) {
|
|
// We have to capture the source set name for the lazy string literals,
|
|
// otherwise it'll just be whatever the last source set is in the list.
|
|
def sourceSetName = sourceSet.name
|
|
def taskName = sourceSet.getTaskName('generate', 'ImplPackageInfos')
|
|
def task = tasks.register(taskName, GenerateImplPackageInfos) {
|
|
group = 'fabric'
|
|
description = "Generates package-info files for $sourceSetName implementation packages."
|
|
|
|
// Only apply to default source directory since we also add the generated
|
|
// sources to the source set.
|
|
sourceRoot = file("src/$sourceSetName/java")
|
|
header = rootProject.file('HEADER')
|
|
outputDir = file("src/generated/$sourceSetName")
|
|
}
|
|
sourceSet.java.srcDir task
|
|
|
|
def cleanTask = tasks.register(sourceSet.getTaskName('clean', 'ImplPackageInfos'), Delete) {
|
|
group = 'fabric'
|
|
delete file("src/generated/$sourceSetName")
|
|
}
|
|
clean.dependsOn cleanTask
|
|
}
|
|
|
|
class GenerateImplPackageInfos extends DefaultTask {
|
|
@InputFile
|
|
File header
|
|
|
|
@SkipWhenEmpty
|
|
@InputDirectory
|
|
final DirectoryProperty sourceRoot = project.objects.directoryProperty()
|
|
|
|
@OutputDirectory
|
|
final DirectoryProperty outputDir = project.objects.directoryProperty()
|
|
|
|
@TaskAction
|
|
def run() {
|
|
def output = outputDir.get().asFile.toPath()
|
|
output.deleteDir()
|
|
def headerText = header.readLines().join("\n") // normalize line endings
|
|
def root = sourceRoot.get().asFile.toPath()
|
|
|
|
for (def dir in ['impl', 'mixin']) {
|
|
def implDir = root.resolve("net/fabricmc/fabric/$dir")
|
|
|
|
if (Files.notExists(implDir)) {
|
|
continue
|
|
}
|
|
|
|
implDir.eachDirRecurse {
|
|
def containsJava = Files.list(it).any {
|
|
Files.isRegularFile(it) && it.fileName.toString().endsWith('.java')
|
|
}
|
|
|
|
if (containsJava && Files.notExists(it.resolve('package-info.java'))) {
|
|
def relativePath = root.relativize(it)
|
|
def target = output.resolve(relativePath)
|
|
Files.createDirectories(target)
|
|
|
|
target.resolve('package-info.java').withWriter {
|
|
def packageName = relativePath.toString().replace(File.separator, '.')
|
|
it.write("""$headerText
|
|
|/**
|
|
| * Implementation code for ${project.name}.
|
|
| */
|
|
|@ApiStatus.Internal
|
|
|package $packageName;
|
|
|
|
|
|import org.jetbrains.annotations.ApiStatus;
|
|
|""".stripMargin())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|