mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-13 05:54:01 +01:00
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:
parent
1406d21d83
commit
745ccfae10
@ -27,6 +27,10 @@ gradlePlugin {
|
|||||||
plugin.id = 'flywheel.jar-sets'
|
plugin.id = 'flywheel.jar-sets'
|
||||||
plugin.implementationClass = 'com.jozufozu.gradle.JarSetPlugin'
|
plugin.implementationClass = 'com.jozufozu.gradle.JarSetPlugin'
|
||||||
}
|
}
|
||||||
|
packageInfosPlugin { PluginDeclaration plugin ->
|
||||||
|
plugin.id = 'flywheel.package-infos'
|
||||||
|
plugin.implementationClass = 'com.jozufozu.gradle.PackageInfosPlugin'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
package com.jozufozu.gradle
|
||||||
|
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.file.DirectoryProperty
|
import org.gradle.api.file.DirectoryProperty
|
||||||
import org.gradle.api.tasks.InputDirectory
|
import org.gradle.api.tasks.InputDirectory
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -4,30 +4,12 @@ package com.jozufozu.gradle
|
|||||||
import groovy.transform.CompileStatic
|
import groovy.transform.CompileStatic
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.tasks.SourceSet
|
|
||||||
import org.gradle.api.tasks.SourceSetContainer
|
|
||||||
|
|
||||||
@CompileStatic
|
@CompileStatic
|
||||||
class JarSetPlugin implements Plugin<Project> {
|
class JarSetPlugin implements Plugin<Project> {
|
||||||
@Override
|
@Override
|
||||||
void apply(Project project) {
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
@ -40,6 +40,10 @@ sourceSets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defaultPackageInfos {
|
||||||
|
forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
|
||||||
|
}
|
||||||
|
|
||||||
// For sharing with other subprojects.
|
// For sharing with other subprojects.
|
||||||
jarSets {
|
jarSets {
|
||||||
createJars('apiOnly', sourceSets.api).configure {
|
createJars('apiOnly', sourceSets.api).configure {
|
||||||
|
@ -11,6 +11,10 @@ plugins {
|
|||||||
|
|
||||||
evaluationDependsOn(':common')
|
evaluationDependsOn(':common')
|
||||||
|
|
||||||
|
defaultPackageInfos {
|
||||||
|
forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
|
||||||
|
}
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
runs {
|
runs {
|
||||||
client {
|
client {
|
||||||
|
@ -11,6 +11,10 @@ plugins {
|
|||||||
|
|
||||||
evaluationDependsOn(':common')
|
evaluationDependsOn(':common')
|
||||||
|
|
||||||
|
defaultPackageInfos {
|
||||||
|
forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
|
||||||
|
}
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
forge {
|
forge {
|
||||||
mixinConfig 'flywheel.backend.mixins.json'
|
mixinConfig 'flywheel.backend.mixins.json'
|
||||||
|
Loading…
Reference in New Issue
Block a user