Skip to content
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

create paper-checkstyle plugin #281

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.extension.PaperCheckstyleExt
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) = with(target) {
val ext = extensions.create(PAPER_CHECKSTYLE_EXTENSION, PaperCheckstyleExt::class)
plugins.apply(PaperCheckstylePlugin::class.java)

extensions.configure(CheckstyleExtension::class.java) {
toolVersion = "10.21.0"
configDirectory.set(ext.projectLocalCheckstyleConfig)
}

tasks.withType(PaperCheckstyleTask::class.java) {
rootPath.set(project.rootDir.path)
directoriesToSkip.set(ext.directoriesToSkip)
typeUseAnnotations.set(ext.typeUseAnnotations)
}
Unit
}
}
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>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.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?.toString() + "/")
directoriesToSkip.get().any { pkg -> parentPath == pkg }
}
if (!source.isEmpty) {
super.run()
}
}
}
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.core.extension

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"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
implementation-class=io.papermc.paperweight.checkstyle.PaperCheckstyle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading