Make spotless actually do stuff on kotlin (#437)

This commit is contained in:
Uriel
2023-01-03 13:06:44 -03:00
committed by GitHub
parent 95b2cb15e4
commit 8c1061adca
2 changed files with 108 additions and 90 deletions

View File

@@ -12,7 +12,7 @@ plugins {
kotlin("jvm") version "1.7.21"
application
id("com.github.johnrengelman.shadow") version "7.1.2"
id("com.diffplug.spotless") version "6.11.0"
id("com.diffplug.spotless") version "6.12.0"
id("com.github.gmazzo.buildconfig") version "3.1.0"
}
@@ -110,7 +110,7 @@ buildConfig {
buildConfigField("boolean", "GIT_CLEAN", gitClean.toString())
}
spotless {
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
// optional: limit format enforcement to just the files changed by this feature branch
// ratchetFrom "origin/main"
@@ -130,14 +130,28 @@ spotless {
// endWithNewline()
// indentWithSpaces(2) // YAML cannot contain tabs: https://yaml.org/faq.html
// }
format("kts") {
target("**/*.kts")
targetExclude("**/build/**/*.kts")
// .editorconfig doesn't work so, manual override
// https://github.com/diffplug/spotless/issues/142
val editorConfig =
mapOf(
"indent_size" to 4,
"indent_style" to "tab",
"max_line_length" to 88,
"ktlint_experimental" to "enabled"
)
val ktlintVersion = "0.47.1"
kotlinGradle {
target("*.gradle.kts") // default target for kotlinGradle
ktlint(ktlintVersion)
.setUseExperimental(true)
.editorConfigOverride(editorConfig)
}
kotlin {
target("**/*.kt")
targetExclude("**/build/**.kts")
ktlint("0.47.1")
targetExclude("build/**/**.kt")
ktlint(ktlintVersion)
.setUseExperimental(true)
.editorConfigOverride(editorConfig)
}
java {
targetExclude("**/BuildConfig.java")

View File

@@ -17,90 +17,94 @@ import java.net.ServerSocket
import javax.swing.JOptionPane
import kotlin.system.exitProcess
val VERSION: String = (GIT_VERSION_TAG.ifEmpty { GIT_COMMIT_HASH }) + if (GIT_CLEAN) "" else "-dirty"
val VERSION =
(GIT_VERSION_TAG.ifEmpty { GIT_COMMIT_HASH }) +
if (GIT_CLEAN) "" else "-dirty"
var vrServer: VRServer? = null
fun main(args: Array<String>) {
System.setProperty("awt.useSystemAAFontSettings", "on")
System.setProperty("swing.aatext", "true")
System.setProperty("awt.useSystemAAFontSettings", "on")
System.setProperty("swing.aatext", "true")
val parser: CommandLineParser = DefaultParser()
val formatter = HelpFormatter()
val options = Options()
val help = Option("h", "help", false, "Show help")
val version = Option("V", "version", false, "Show version")
options.addOption(help)
options.addOption(version)
val cmd: CommandLine = try {
parser.parse(options, args, true)
} catch (e: org.apache.commons.cli.ParseException) {
formatter.printHelp("slimevr.jar", options)
exitProcess(1)
}
if (cmd.hasOption("help")) {
formatter.printHelp("slimevr.jar", options)
exitProcess(0)
}
if (cmd.hasOption("version")) {
println("SlimeVR Server $VERSION")
exitProcess(0)
}
val dir = File("").absoluteFile
try {
LogManager.initialize(File(dir, "logs/"), dir)
} catch (e1: java.lang.Exception) {
e1.printStackTrace()
}
LogManager.info("Running version $VERSION")
if (!SystemUtils.isJavaVersionAtLeast(org.apache.commons.lang3.JavaVersion.JAVA_17)) {
LogManager.severe("SlimeVR start-up error! A minimum of Java 17 is required.")
JOptionPane
.showMessageDialog(
null,
"SlimeVR start-up error! A minimum of Java 17 is required.",
"SlimeVR: Java Runtime Mismatch",
JOptionPane.ERROR_MESSAGE
)
return
}
try {
// This is disabled because the config can't be read at this point
// new ServerSocket(6969).close();
ServerSocket(35903).close()
ServerSocket(21110).close()
} catch (e: IOException) {
LogManager
.severe(
"SlimeVR start-up error! Required ports are busy. Make sure there is no other instance of SlimeVR Server running."
)
JOptionPane
.showMessageDialog(
null,
"SlimeVR start-up error! Required ports are busy. Make sure there is no other instance of SlimeVR Server running.",
"SlimeVR: Ports are busy",
JOptionPane.ERROR_MESSAGE
)
return
}
try {
vrServer = VRServer()
vrServer!!.start()
Keybinding(vrServer)
} catch (e: Throwable) {
e.printStackTrace()
try {
Thread.sleep(2000L)
} catch (e2: InterruptedException) {
e.printStackTrace()
}
exitProcess(1) // Exit in case error happened on init and window
// not appeared, but some thread
// started
} finally {
try {
Thread.sleep(2000L)
} catch (e: InterruptedException) {
e.printStackTrace()
}
}
val parser: CommandLineParser = DefaultParser()
val formatter = HelpFormatter()
val options = Options()
val help = Option("h", "help", false, "Show help")
val version = Option("V", "version", false, "Show version")
options.addOption(help)
options.addOption(version)
val cmd: CommandLine = try {
parser.parse(options, args, true)
} catch (e: org.apache.commons.cli.ParseException) {
formatter.printHelp("slimevr.jar", options)
exitProcess(1)
}
if (cmd.hasOption("help")) {
formatter.printHelp("slimevr.jar", options)
exitProcess(0)
}
if (cmd.hasOption("version")) {
println("SlimeVR Server $VERSION")
exitProcess(0)
}
val dir = File("").absoluteFile
try {
LogManager.initialize(File(dir, "logs/"), dir)
} catch (e1: java.lang.Exception) {
e1.printStackTrace()
}
LogManager.info("Running version $VERSION")
if (!SystemUtils.isJavaVersionAtLeast(org.apache.commons.lang3.JavaVersion.JAVA_17)) {
LogManager.severe("SlimeVR start-up error! A minimum of Java 17 is required.")
JOptionPane
.showMessageDialog(
null,
"SlimeVR start-up error! A minimum of Java 17 is required.",
"SlimeVR: Java Runtime Mismatch",
JOptionPane.ERROR_MESSAGE
)
return
}
try {
// This is disabled because the config can't be read at this point
// new ServerSocket(6969).close();
ServerSocket(35903).close()
ServerSocket(21110).close()
} catch (e: IOException) {
LogManager
.severe(
"SlimeVR start-up error! Required ports are busy. " +
"Make sure there is no other instance of SlimeVR Server running."
)
JOptionPane
.showMessageDialog(
null,
"SlimeVR start-up error! Required ports are busy. " +
"Make sure there is no other instance of SlimeVR Server running.",
"SlimeVR: Ports are busy",
JOptionPane.ERROR_MESSAGE
)
return
}
try {
vrServer = VRServer()
vrServer!!.start()
Keybinding(vrServer)
} catch (e: Throwable) {
e.printStackTrace()
try {
Thread.sleep(2000L)
} catch (e2: InterruptedException) {
e.printStackTrace()
}
exitProcess(1) // Exit in case error happened on init and window
// not appeared, but some thread
// started
} finally {
try {
Thread.sleep(2000L)
} catch (e: InterruptedException) {
e.printStackTrace()
}
}
}