-
-
Notifications
You must be signed in to change notification settings - Fork 65
create paper-checkstyle plugin #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jpenilla
merged 17 commits into
PaperMC:main
from
Machine-Maker:feature/paper-checkstyle
Nov 26, 2025
Merged
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
91876ab
create paper-checkstyle plugin
Machine-Maker ec1f935
spotless
Machine-Maker ff6e48d
Move PaperCheckstyleExt
jpenilla 870c7bc
Fix file separator windows issue
jpenilla 8023366
Fix eager task creation
jpenilla 5b5ee46
clean up PaperCheckstyle
jpenilla df1f28c
Move checkstyle version to libs.versions.toml
jpenilla ba2a33a
Add license to versions file
jpenilla fb68e48
add missing comma
jpenilla eabd992
add missing module name
jpenilla f19e206
Merge remote-tracking branch 'upstream/main' into feature/paper-check…
Machine-Maker 016e560
Address review
Machine-Maker 210b377
use same library version file
Machine-Maker b522bfd
bump to latest checkstyle
Machine-Maker 18f43a0
remove unneeded plugin from -core
Machine-Maker 5992fc4
fix spotless
Machine-Maker 7d1924a
add to ext
Machine-Maker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
paperweight-core/src/main/kotlin-templates/io/papermc/paperweight/core/Versions.kt.peb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * paperweight is a Gradle plugin for the PaperMC project. | ||
| * | ||
| * Copyright (c) 2023 Kyle Wood (DenWav) | ||
| * Contributors | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; | ||
| * version 2.1 only, no later versions. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | ||
| * USA | ||
| */ | ||
|
|
||
| package io.papermc.paperweight.core | ||
|
|
||
| object Versions { | ||
| const val CHECKSTYLE: String = "{{ checkstyle_version }}" | ||
| } |
35 changes: 35 additions & 0 deletions
35
paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/JavadocTag.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * paperweight is a Gradle plugin for the PaperMC project. | ||
| * | ||
| * Copyright (c) 2023 Kyle Wood (DenWav) | ||
| * Contributors | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; | ||
| * version 2.1 only, no later versions. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | ||
| * USA | ||
| */ | ||
|
|
||
| package io.papermc.paperweight.checkstyle | ||
|
|
||
| data class JavadocTag(val tag: String, val appliesTo: String, val prefix: String) { | ||
| fun toOptionString(): String { | ||
| return "$tag:$appliesTo:$prefix" | ||
| } | ||
| } | ||
|
|
||
| fun PaperCheckstyleTask.setCustomJavadocTags(tags: Iterable<JavadocTag>) { | ||
| configProperties = (configProperties ?: emptyMap()).toMutableMap().apply { | ||
| this["custom_javadoc_tags"] = tags.joinToString("|") { it.toOptionString() } | ||
| } | ||
| } | ||
49 changes: 49 additions & 0 deletions
49
paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstyle.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * paperweight is a Gradle plugin for the PaperMC project. | ||
| * | ||
| * Copyright (c) 2023 Kyle Wood (DenWav) | ||
| * Contributors | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; | ||
| * version 2.1 only, no later versions. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | ||
| * USA | ||
| */ | ||
|
|
||
| package io.papermc.paperweight.checkstyle | ||
|
|
||
| import io.papermc.paperweight.core.Versions | ||
| import io.papermc.paperweight.util.constants.* | ||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.plugins.quality.CheckstyleExtension | ||
| import org.gradle.kotlin.dsl.* | ||
|
|
||
| abstract class PaperCheckstyle : Plugin<Project> { | ||
|
|
||
| override fun apply(target: Project) { | ||
| val ext = target.extensions.create(PAPER_CHECKSTYLE_EXTENSION, PaperCheckstyleExt::class) | ||
| target.plugins.apply(PaperCheckstylePlugin::class.java) | ||
|
|
||
| target.extensions.configure(CheckstyleExtension::class.java) { | ||
| toolVersion = Versions.CHECKSTYLE | ||
| configDirectory.set(ext.projectLocalCheckstyleConfig) | ||
| } | ||
|
|
||
| target.tasks.withType(PaperCheckstyleTask::class.java).configureEach { | ||
| rootPath.set(project.rootDir.path) | ||
| directoriesToSkip.set(ext.directoriesToSkip) | ||
| typeUseAnnotations.set(ext.typeUseAnnotations) | ||
| } | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstyleExt.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * paperweight is a Gradle plugin for the PaperMC project. | ||
| * | ||
| * Copyright (c) 2023 Kyle Wood (DenWav) | ||
| * Contributors | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; | ||
| * version 2.1 only, no later versions. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | ||
| * USA | ||
| */ | ||
|
|
||
| package io.papermc.paperweight.checkstyle | ||
|
|
||
| import javax.inject.Inject | ||
| import org.gradle.api.file.DirectoryProperty | ||
| import org.gradle.api.file.ProjectLayout | ||
| import org.gradle.api.provider.SetProperty | ||
|
|
||
| @Suppress("LeakingThis") | ||
| abstract class PaperCheckstyleExt { | ||
|
|
||
| @get:Inject | ||
| abstract val layout: ProjectLayout | ||
|
|
||
| abstract val typeUseAnnotations: SetProperty<String> | ||
| abstract val directoriesToSkip: SetProperty<String> | ||
| abstract val projectLocalCheckstyleConfig: DirectoryProperty | ||
|
|
||
| init { | ||
| projectLocalCheckstyleConfig.convention(layout.projectDirectory.dir(".checkstyle")) | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstylePlugin.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * paperweight is a Gradle plugin for the PaperMC project. | ||
| * | ||
| * Copyright (c) 2023 Kyle Wood (DenWav) | ||
| * Contributors | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; | ||
| * version 2.1 only, no later versions. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | ||
| * USA | ||
| */ | ||
|
|
||
| package io.papermc.paperweight.checkstyle | ||
|
|
||
| import org.gradle.api.plugins.quality.Checkstyle | ||
| import org.gradle.api.plugins.quality.CheckstylePlugin | ||
|
|
||
| abstract class PaperCheckstylePlugin : CheckstylePlugin() { | ||
|
|
||
| override fun getTaskType(): Class<Checkstyle> { | ||
| @Suppress("UNCHECKED_CAST") | ||
| return PaperCheckstyleTask::class.java as Class<Checkstyle> | ||
| } | ||
| } |
60 changes: 60 additions & 0 deletions
60
paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstyleTask.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * paperweight is a Gradle plugin for the PaperMC project. | ||
| * | ||
| * Copyright (c) 2023 Kyle Wood (DenWav) | ||
| * Contributors | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; | ||
| * version 2.1 only, no later versions. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | ||
| * USA | ||
| */ | ||
|
|
||
| package io.papermc.paperweight.checkstyle | ||
|
|
||
| import java.nio.file.Paths | ||
| import kotlin.io.path.invariantSeparatorsPathString | ||
| import kotlin.io.path.relativeTo | ||
| import org.gradle.api.plugins.quality.Checkstyle | ||
| import org.gradle.api.provider.Property | ||
| import org.gradle.api.provider.SetProperty | ||
| import org.gradle.api.tasks.Input | ||
| import org.gradle.api.tasks.TaskAction | ||
|
|
||
| abstract class PaperCheckstyleTask : Checkstyle() { | ||
|
|
||
| @get:Input | ||
| abstract val rootPath: Property<String> | ||
|
|
||
| @get:Input | ||
| abstract val directoriesToSkip: SetProperty<String> | ||
|
|
||
| @get:Input | ||
| abstract val typeUseAnnotations: SetProperty<String> | ||
|
|
||
| @TaskAction | ||
| override fun run() { | ||
| val existingProperties = configProperties?.toMutableMap() ?: mutableMapOf() | ||
| existingProperties["type_use_annotations"] = typeUseAnnotations.get().joinToString("|") | ||
| configProperties = existingProperties | ||
| exclude { | ||
| if (it.isDirectory) return@exclude false | ||
| val absPath = it.file.toPath().toAbsolutePath().relativeTo(Paths.get(rootPath.get())) | ||
| val parentPath = (absPath.parent?.invariantSeparatorsPathString + "/") | ||
| directoriesToSkip.get().any { pkg -> parentPath == pkg } | ||
| } | ||
| if (!source.isEmpty) { | ||
| super.run() | ||
| } | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
...main/resources/META-INF/gradle-plugins/io.papermc.paperweight.paper-checkstyle.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| implementation-class=io.papermc.paperweight.checkstyle.PaperCheckstyle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.