Skip to content

Commit

Permalink
Plugin play
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Jozufozu committed Apr 28, 2024
1 parent 0299caf commit 24fda48
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 50 deletions.
4 changes: 4 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
20 changes: 1 addition & 19 deletions buildSrc/src/main/groovy/com/jozufozu/gradle/JarSetPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}

31 changes: 0 additions & 31 deletions buildSrc/src/main/groovy/flywheel.package-infos.gradle

This file was deleted.

4 changes: 4 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ plugins {

evaluationDependsOn(':common')

defaultPackageInfos {
forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
}

loom {
runs {
client {
Expand Down
4 changes: 4 additions & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ plugins {

evaluationDependsOn(':common')

defaultPackageInfos {
forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
}

loom {
forge {
mixinConfig 'flywheel.backend.mixins.json'
Expand Down

0 comments on commit 24fda48

Please sign in to comment.