Skip to content

Commit

Permalink
Add ktlint to enforce consistent formatting, drop explicit this
Browse files Browse the repository at this point in the history
There doesn't seem to be a kotlin linter which will enforce explicit this, so I chose to just stop using it
  • Loading branch information
jpenilla committed Aug 24, 2021
1 parent 5391391 commit 1f67fee
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 173 deletions.
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
id("net.kyori.indra")
id("net.kyori.indra.license-header")
id("net.kyori.indra.publishing.gradle-plugin")
id("org.jlleitschuh.gradle.ktlint")
}

group = "xyz.jpenilla"
Expand Down Expand Up @@ -35,6 +36,12 @@ tasks {
freeCompilerArgs = listOf("-Xopt-in=kotlin.io.path.ExperimentalPathApi")
}
}

register("format") {
group = "formatting"
description = "Formats source code according to project style."
dependsOn(licenseFormat, ktlintFormat)
}
}

indra {
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ plugins:
net.kyori.indra.license-header: *indra
net.kyori.indra.publishing.gradle-plugin: *indra
com.gradle.plugin-publish: 0.15.0
org.jlleitschuh.gradle.ktlint: 10.0.0

versions:
jackson: 2.12.3
paperweight: 1.1.10
paperweight: 1.1.11

dependencies:
jacksonModuleKotlin:
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/xyz/jpenilla/runpaper/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal object Constants {
const val RUN_PAPER = "RunPaper"
const val TASK_GROUP = "Run Paper"
const val GRADLE_CACHES_DIRECTORY_NAME = "caches"
const val RUN_PAPER_PATH = "$RUN_PAPER/v1"

object Plugins {
const val SHADOW_PLUGIN_ID = "com.github.johnrengelman.shadow"
Expand All @@ -42,7 +43,7 @@ internal object Constants {
object Properties {
private fun runPaper(propertyName: String) = "xyz.jpenilla.run-paper.$propertyName"

val UPDATE_CHECK_FREQUENCY = this.runPaper("updateCheckFrequency")
val UPDATE_CHECK_FREQUENCY = runPaper("updateCheckFrequency")
}

object Extensions {
Expand Down
64 changes: 30 additions & 34 deletions src/main/kotlin/xyz/jpenilla/runpaper/RunPaper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,37 @@ import org.gradle.kotlin.dsl.registerIfAbsent
import org.gradle.kotlin.dsl.the
import xyz.jpenilla.runpaper.service.PaperclipService
import xyz.jpenilla.runpaper.task.RunServerTask
import java.io.File
import xyz.jpenilla.runpaper.util.find
import xyz.jpenilla.runpaper.util.set
import xyz.jpenilla.runpaper.util.sharedCaches

public class RunPaper : Plugin<Project> {
override fun apply(target: Project) {
val runPaperExtension = target.extensions.create<RunPaperExtension>(Constants.Extensions.RUN_PAPER, target)

target.gradle.sharedServices.registerIfAbsent(Constants.Services.PAPERCLIP, PaperclipService::class) {
this.maxParallelUsages.set(1)
this.parameters.cacheDirectory.set(target.sharedCaches)
this.parameters.refreshDependencies.set(target.gradle.startParameter.isRefreshDependencies)
this.parameters.offlineMode.set(target.gradle.startParameter.isOffline)
maxParallelUsages.set(1)
parameters.cacheDirectory.set(target.sharedCaches.resolve(Constants.RUN_PAPER_PATH))
parameters.refreshDependencies.set(target.gradle.startParameter.isRefreshDependencies)
parameters.offlineMode.set(target.gradle.startParameter.isOffline)
}

target.tasks.register<Delete>(Constants.Tasks.CLEAN_PAPERCLIP_CACHE) {
this.group = Constants.TASK_GROUP
this.description = "Delete all locally cached Paperclips."
this.delete(target.sharedCaches)
group = Constants.TASK_GROUP
description = "Delete all locally cached Paperclips."
delete(target.sharedCaches.resolve(Constants.RUN_PAPER_PATH))
}

val runServer = target.tasks.register<RunServerTask>(Constants.Tasks.RUN_SERVER) {
this.group = Constants.TASK_GROUP
this.description = "Run a Paper server for plugin testing."
group = Constants.TASK_GROUP
description = "Run a Paper server for plugin testing."
}
target.afterEvaluate {
if (!runPaperExtension.detectPluginJar.get()) return@afterEvaluate

runServer {
target.findPluginJar()?.let { pluginJar ->
this.pluginJars(pluginJar)
pluginJars(pluginJar)
}
}
}
Expand All @@ -72,41 +74,35 @@ public class RunPaper : Plugin<Project> {
}
}

private val Project.sharedCaches: File
get() = this.gradle.gradleUserHomeDir.resolve("${Constants.GRADLE_CACHES_DIRECTORY_NAME}/${Constants.RUN_PAPER}/v1")

private fun Project.findPluginJar(): Provider<RegularFile>? {
when {
this.plugins.hasPlugin(Constants.Plugins.PAPERWEIGHT_USERDEV_PLUGIN_ID) -> {
return this.tasks.named<RemapJar>(Constants.Plugins.PAPERWEIGHT_REOBF_JAR_TASK_NAME).flatMap { it.outputJar }
}
this.plugins.hasPlugin(Constants.Plugins.SHADOW_PLUGIN_ID) -> {
return this.tasks.named<AbstractArchiveTask>(Constants.Plugins.SHADOW_JAR_TASK_NAME).flatMap { it.archiveFile }
}
else -> {
val jar = this.tasks.findByName(JavaPlugin.JAR_TASK_NAME) as? AbstractArchiveTask ?: return null
return jar.archiveFile
}
private fun Project.findPluginJar(): Provider<RegularFile>? = when {
plugins.hasPlugin(Constants.Plugins.PAPERWEIGHT_USERDEV_PLUGIN_ID) -> {
tasks.named<RemapJar>(Constants.Plugins.PAPERWEIGHT_REOBF_JAR_TASK_NAME).flatMap { it.outputJar }
}
plugins.hasPlugin(Constants.Plugins.SHADOW_PLUGIN_ID) -> {
tasks.named<AbstractArchiveTask>(Constants.Plugins.SHADOW_JAR_TASK_NAME).flatMap { it.archiveFile }
}
else -> {
tasks.find<AbstractArchiveTask>(JavaPlugin.JAR_TASK_NAME)?.archiveFile
}
}

private fun Project.setupPaperweightCompat(
runServer: TaskProvider<RunServerTask>,
runPaperExtension: RunPaperExtension
) {
val paperweight = this.the<PaperweightUserExtension>()
val paperweight = the<PaperweightUserExtension>()

runServer {
this.minecraftVersion.convention(paperweight.minecraftVersion)
minecraftVersion.convention(paperweight.minecraftVersion)
}

this.tasks.register<RunServerTask>(Constants.Tasks.RUN_MOJANG_MAPPED_SERVER) {
this.group = Constants.TASK_GROUP
this.description = "Run a Mojang mapped Paper server for plugin testing, by integrating with paperweight."
this.serverJar.value(paperweight.mojangMappedServerJar).finalizeValue()
this.minecraftVersion.value(paperweight.minecraftVersion).finalizeValue()
tasks.register<RunServerTask>(Constants.Tasks.RUN_MOJANG_MAPPED_SERVER) {
group = Constants.TASK_GROUP
description = "Run a Mojang mapped Paper server for plugin testing, by integrating with paperweight."
serverJar.value(paperweight.mojangMappedServerJar).disallowChanges()
minecraftVersion.value(paperweight.minecraftVersion).disallowChanges()
if (runPaperExtension.detectPluginJar.get()) {
this.pluginJars(this@setupPaperweightCompat.tasks.named<RemapJar>(Constants.Plugins.PAPERWEIGHT_REOBF_JAR_TASK_NAME).flatMap { it.inputJar })
pluginJars(tasks.named<RemapJar>(Constants.Plugins.PAPERWEIGHT_REOBF_JAR_TASK_NAME).flatMap { it.inputJar })
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/xyz/jpenilla/runpaper/RunPaperExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import org.gradle.api.provider.Property
import org.gradle.kotlin.dsl.property
import xyz.jpenilla.runpaper.task.RunServerTask

public abstract class RunPaperExtension(private val project: Project) {
internal val detectPluginJar: Property<Boolean> = this.project.objects.property<Boolean>().convention(true)
public abstract class RunPaperExtension(project: Project) {
internal val detectPluginJar: Property<Boolean> = project.objects.property<Boolean>().convention(true)

/**
* By default, Run Paper will attempt to discover your plugin `jar` or `shadowJar` and automatically add it to
Expand All @@ -33,6 +33,6 @@ public abstract class RunPaperExtension(private val project: Project) {
* Run Paper, if you create your own [RunServerTask]s you will need to manually add plugin jars regardless.
*/
public fun disablePluginJarDetection() {
this.detectPluginJar.set(false)
detectPluginJar.set(false)
}
}
12 changes: 6 additions & 6 deletions src/main/kotlin/xyz/jpenilla/runpaper/paperapi/DownloadsAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,27 @@ internal class DownloadsAPI {
}

fun projects(): ProjectsResponse {
return this.makeQuery("projects")
return makeQuery("projects")
}

fun project(projectName: String): ProjectResponse {
return this.makeQuery("projects/$projectName")
return makeQuery("projects/$projectName")
}

fun versionGroup(projectName: String, versionGroup: String): VersionGroupResponse {
return this.makeQuery("projects/$projectName/version_group/$versionGroup")
return makeQuery("projects/$projectName/version_group/$versionGroup")
}

fun versionGroupBuilds(projectName: String, versionGroup: String): VersionGroupBuildsResponse {
return this.makeQuery("projects/$projectName/version_group/$versionGroup/builds")
return makeQuery("projects/$projectName/version_group/$versionGroup/builds")
}

fun version(projectName: String, version: String): VersionResponse {
return this.makeQuery("projects/$projectName/versions/$version")
return makeQuery("projects/$projectName/versions/$version")
}

fun build(projectName: String, version: String, build: Int): BuildResponse {
return this.makeQuery("projects/$projectName/versions/$version/builds/$build")
return makeQuery("projects/$projectName/versions/$version/builds/$build")
}

fun downloadURL(projectName: String, version: String, build: Int, download: Download): String {
Expand Down
Loading

0 comments on commit 1f67fee

Please sign in to comment.