Plugin play

- Convert package infos stuff to a proper plugin
- Add extension for specifying which source sets get generated package
  infos
- Move extension classes into their own files
- Move GeneratePackageInfosTask into com.jozufozu.gradle
This commit is contained in:
Jozufozu 2024-04-27 21:15:42 -07:00
parent 1406d21d83
commit 745ccfae10
10 changed files with 106 additions and 50 deletions

View File

@ -27,6 +27,10 @@ gradlePlugin {
plugin.id = 'flywheel.jar-sets'
plugin.implementationClass = 'com.jozufozu.gradle.JarSetPlugin'
}
packageInfosPlugin { PluginDeclaration plugin ->
plugin.id = 'flywheel.package-infos'
plugin.implementationClass = 'com.jozufozu.gradle.PackageInfosPlugin'
}
}
}

View File

@ -1,3 +1,5 @@
package com.jozufozu.gradle
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.tasks.InputDirectory

View File

@ -0,0 +1,23 @@
package com.jozufozu.gradle
import groovy.transform.CompileStatic
import org.gradle.api.Project
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
@CompileStatic
class JarSetExtension {
private final Project project
JarSetExtension(Project project) {
this.project = project
}
JarTaskSet createJars(String name) {
return createJars(name, project.getExtensions().getByType(SourceSetContainer).named(name).get())
}
JarTaskSet createJars(String name, SourceSet... sourceSetSet) {
return JarTaskSet.create(project, name, sourceSetSet)
}
}

View File

@ -4,30 +4,12 @@ package com.jozufozu.gradle
import groovy.transform.CompileStatic
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
@CompileStatic
class JarSetPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
project.extensions.create("jarSets", JarSetExtension, project)
project.extensions.create('jarSets', JarSetExtension, project)
}
}
@CompileStatic
class JarSetExtension {
private final Project project
JarSetExtension(Project project) {
this.project = project
}
JarTaskSet createJars(String name) {
return createJars(name, project.getExtensions().getByType(SourceSetContainer).named(name).get())
}
JarTaskSet createJars(String name, SourceSet... sourceSetSet) {
return JarTaskSet.create(project, name, sourceSetSet)
}
}

View File

@ -0,0 +1,50 @@
package com.jozufozu.gradle
import groovy.transform.CompileStatic
import org.gradle.api.Project
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.SourceSet
@CompileStatic
class PackageInfosExtension {
final Project project
PackageInfosExtension(Project project) {
this.project = project
}
void forSourceSets(SourceSet... sourceSets) {
for (SourceSet sourceSet : sourceSets) {
_forSourceSet(sourceSet)
}
}
private void _forSourceSet(SourceSet sourceSet) {
// 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', 'PackageInfos')
def task = project.tasks.register(taskName, GeneratePackageInfosTask) {
it.group = 'flywheel'
it.description = "Generates package-info files for $sourceSetName packages."
// Only apply to default source directory since we also add the generated
// sources to the source set.
it.sourceRoot.set(project.file("src/$sourceSetName/java"))
it.outputDir.set(project.file("src/$sourceSetName/generatedPackageInfos"))
}
sourceSet.java.srcDir(task)
project.tasks.named('ideaSyncTask').configure {
it.finalizedBy(task)
}
def cleanTask = project.tasks.register(sourceSet.getTaskName('clean', 'PackageInfos'), Delete) {
it.group = 'flywheel'
it.delete(project.file("src/$sourceSetName/generatedPackageInfos"))
}
project.tasks.named('clean').configure {
it.dependsOn(cleanTask)
}
}
}

View File

@ -0,0 +1,14 @@
package com.jozufozu.gradle
import groovy.transform.CompileStatic
import org.gradle.api.Plugin
import org.gradle.api.Project
@CompileStatic
class PackageInfosPlugin implements Plugin<Project> {
@Override
void apply(Project target) {
target.extensions.create('defaultPackageInfos', PackageInfosExtension, target)
}
}

View File

@ -1,31 +0,0 @@
sourceSets.configureEach {
setupGeneratePackageInfos(it)
}
def setupGeneratePackageInfos(SourceSet sourceSet) {
// 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', 'PackageInfos')
def task = tasks.register(taskName, GeneratePackageInfosTask) {
group = 'flywheel'
description = "Generates package-info files for $sourceSetName packages."
// Only apply to default source directory since we also add the generated
// sources to the source set.
sourceRoot = file("src/$sourceSetName/java")
outputDir = file("src/$sourceSetName/generatedPackageInfos")
}
sourceSet.java.srcDir task
tasks.named('ideaSyncTask').configure {
finalizedBy task
}
def cleanTask = tasks.register(sourceSet.getTaskName('clean', 'PackageInfos'), Delete) {
group = 'flywheel'
delete file("src/$sourceSetName/generatedPackageInfos")
}
clean.dependsOn cleanTask
}

View File

@ -40,6 +40,10 @@ sourceSets {
}
}
defaultPackageInfos {
forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
}
// For sharing with other subprojects.
jarSets {
createJars('apiOnly', sourceSets.api).configure {

View File

@ -11,6 +11,10 @@ plugins {
evaluationDependsOn(':common')
defaultPackageInfos {
forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
}
loom {
runs {
client {

View File

@ -11,6 +11,10 @@ plugins {
evaluationDependsOn(':common')
defaultPackageInfos {
forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
}
loom {
forge {
mixinConfig 'flywheel.backend.mixins.json'