diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 45ee7442a..223fa0b19 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,6 +5,8 @@ hypo = "1.2.4" serialize = "1.5.1" jst = "1.0.68+paper.2-SNAPSHOT" tinyRemapper = "0.10.4" +# For paper-checkstyle plugin +checkstyle = "10.21.0" [libraries] asm-core = { module = "org.ow2.asm:asm", version.ref = "asm" } @@ -52,6 +54,9 @@ gradle-kotlin-dsl = "org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.g gradle-plugin-kotlin = { module = "org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin" } gradle-plugin-publish = "com.gradle.publish:plugin-publish-plugin:1.2.1" +# for renovate +zCheckstyle = { module = "com.puppycrawl.tools:checkstyle", version.ref = "checkstyle" } + [bundles] asm = ["asm-core", "asm-tree"] cadix = ["cadix-lorenz-core", "cadix-lorenz-asm", "cadix-lorenz-proguard", "cadix-atlas", "cadix-at"] diff --git a/paperweight-core/build.gradle.kts b/paperweight-core/build.gradle.kts index f8336ad71..7fd7b7ee3 100644 --- a/paperweight-core/build.gradle.kts +++ b/paperweight-core/build.gradle.kts @@ -1,6 +1,7 @@ plugins { `config-kotlin` `config-publish` + id("net.kyori.blossom") version "2.1.0" } dependencies { @@ -27,3 +28,13 @@ gradlePlugin { implementationClass = "io.papermc.paperweight.patcher.PaperweightPatcher" } } + +sourceSets { + main { + blossom { + kotlinSources { + property("checkstyle_version", libs.versions.checkstyle) + } + } + } +} diff --git a/paperweight-core/src/main/kotlin-templates/io/papermc/paperweight/core/Versions.kt.peb b/paperweight-core/src/main/kotlin-templates/io/papermc/paperweight/core/Versions.kt.peb new file mode 100644 index 000000000..3122609bf --- /dev/null +++ b/paperweight-core/src/main/kotlin-templates/io/papermc/paperweight/core/Versions.kt.peb @@ -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 }}" +} diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/JavadocTag.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/JavadocTag.kt new file mode 100644 index 000000000..9fe1c4ad9 --- /dev/null +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/JavadocTag.kt @@ -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) { + configProperties = (configProperties ?: emptyMap()).toMutableMap().apply { + this["custom_javadoc_tags"] = tags.joinToString("|") { it.toOptionString() } + } +} diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstyle.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstyle.kt new file mode 100644 index 000000000..9df3e1e7d --- /dev/null +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstyle.kt @@ -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 { + + 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) + } + } +} diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstyleExt.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstyleExt.kt new file mode 100644 index 000000000..7d4ff72dd --- /dev/null +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstyleExt.kt @@ -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 + abstract val directoriesToSkip: SetProperty + abstract val projectLocalCheckstyleConfig: DirectoryProperty + + init { + projectLocalCheckstyleConfig.convention(layout.projectDirectory.dir(".checkstyle")) + } +} diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstylePlugin.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstylePlugin.kt new file mode 100644 index 000000000..c38eae707 --- /dev/null +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstylePlugin.kt @@ -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 { + @Suppress("UNCHECKED_CAST") + return PaperCheckstyleTask::class.java as Class + } +} diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstyleTask.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstyleTask.kt new file mode 100644 index 000000000..070f66973 --- /dev/null +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/checkstyle/PaperCheckstyleTask.kt @@ -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 + + @get:Input + abstract val directoriesToSkip: SetProperty + + @get:Input + abstract val typeUseAnnotations: SetProperty + + @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() + } + } +} diff --git a/paperweight-core/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.paper-checkstyle.properties b/paperweight-core/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.paper-checkstyle.properties new file mode 100644 index 000000000..5bfb6608d --- /dev/null +++ b/paperweight-core/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.paper-checkstyle.properties @@ -0,0 +1 @@ +implementation-class=io.papermc.paperweight.checkstyle.PaperCheckstyle diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt index 536144bb5..fc8c114a3 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt @@ -25,6 +25,7 @@ package io.papermc.paperweight.util.constants import org.gradle.api.Task const val PAPERWEIGHT_EXTENSION = "paperweight" +const val PAPER_CHECKSTYLE_EXTENSION = "paperCheckstyle" const val PAPERWEIGHT_DEBUG = "paperweight.debug" fun paperweightDebug(): Boolean = System.getProperty(PAPERWEIGHT_DEBUG, "false") == "true" const val PAPERWEIGHT_VERBOSE_APPLY_PATCHES = "paperweight.verboseApplyPatches"