diff --git a/api/doc-generator.api b/api/doc-generator.api index 3692404..228d992 100644 --- a/api/doc-generator.api +++ b/api/doc-generator.api @@ -58,6 +58,7 @@ public final class org/hyacinthbots/docgenerator/enums/CommandTypes : java/lang/ public static final field MESSAGE Lorg/hyacinthbots/docgenerator/enums/CommandTypes; public static final field SLASH Lorg/hyacinthbots/docgenerator/enums/CommandTypes; public static final field USER Lorg/hyacinthbots/docgenerator/enums/CommandTypes; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Lorg/hyacinthbots/docgenerator/enums/CommandTypes; public static fun values ()[Lorg/hyacinthbots/docgenerator/enums/CommandTypes; } @@ -69,6 +70,7 @@ public final class org/hyacinthbots/docgenerator/enums/CommandTypes$Companion { public final class org/hyacinthbots/docgenerator/enums/Environment : java/lang/Enum { public static final field DEVELOPMENT Lorg/hyacinthbots/docgenerator/enums/Environment; public static final field PRODUCTION Lorg/hyacinthbots/docgenerator/enums/Environment; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public final fun getValue ()Ljava/lang/String; public static fun valueOf (Ljava/lang/String;)Lorg/hyacinthbots/docgenerator/enums/Environment; public static fun values ()[Lorg/hyacinthbots/docgenerator/enums/Environment; @@ -76,6 +78,7 @@ public final class org/hyacinthbots/docgenerator/enums/Environment : java/lang/E public final class org/hyacinthbots/docgenerator/enums/SupportedFileFormat : java/lang/Enum { public static final field MARKDOWN Lorg/hyacinthbots/docgenerator/enums/SupportedFileFormat; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public final fun getFileExtension ()Ljava/lang/String; public static fun valueOf (Ljava/lang/String;)Lorg/hyacinthbots/docgenerator/enums/SupportedFileFormat; public static fun values ()[Lorg/hyacinthbots/docgenerator/enums/SupportedFileFormat; diff --git a/build.gradle.kts b/build.gradle.kts index e45a47a..bdd5c9d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,14 +1,13 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import java.util.* object Meta { - const val projectVersion = "0.1.2" - const val description = "Generate documentation for KordEx bots!" - const val githubRepo = "HyacinthBots/doc-generator" - const val release = "https://s01.oss.sonatype.org/content/repositories/releases/" - const val snapshot = "https://s01.oss.sonatype.org/content/repositories/snapshots/" + const val PROJECT_VERSION = "0.1.3" + const val DESCRIPTION = "Generate documentation for KordEx bots!" + const val GITHUB_REPO = "HyacinthBots/doc-generator" + const val RELEASE = "https://s01.oss.sonatype.org/content/repositories/releases/" + const val SNAPSHOT = "https://s01.oss.sonatype.org/content/repositories/snapshots/" val version: String get() { @@ -17,7 +16,7 @@ object Meta { return when { !tag.isNullOrBlank() -> tag !branch.isNullOrBlank() && branch.startsWith("refs/heads/") -> - "$projectVersion-SNAPSHOT" + "$PROJECT_VERSION-SNAPSHOT" else -> "undefined" } @@ -43,7 +42,7 @@ plugins { } group = "org.hyacinthbots" -version = Meta.projectVersion +version = Meta.PROJECT_VERSION val javaVersion = 17 repositories { @@ -117,7 +116,7 @@ tasks { detekt { buildUponDefaultConfig = true - config = files("$rootDir/detekt.yml") + config.from(files("$rootDir/detekt.yml")) autoCorrect = true } @@ -150,8 +149,8 @@ publishing { pom { name.set(project.name) - description.set(Meta.description) - url.set("https://github.com/${Meta.githubRepo}") + description.set(Meta.DESCRIPTION) + url.set("https://github.com/${Meta.GITHUB_REPO}") organization { name.set("HyacinthBots") @@ -166,7 +165,7 @@ publishing { issueManagement { system.set("GitHub") - url.set("https://github.com/${Meta.githubRepo}/issues") + url.set("https://github.com/${Meta.GITHUB_REPO}/issues") } licenses { @@ -177,9 +176,9 @@ publishing { } scm { - url.set("https://github.com/${Meta.githubRepo}.git") - connection.set("scm:git:git://github.com/${Meta.githubRepo}.git") - developerConnection.set("scm:git:git://github.com/#${Meta.githubRepo}.git") + url.set("https://github.com/${Meta.GITHUB_REPO}.git") + connection.set("scm:git:git://github.com/${Meta.GITHUB_REPO}.git") + developerConnection.set("scm:git:git://github.com/#${Meta.GITHUB_REPO}.git") } } } @@ -187,7 +186,7 @@ publishing { repositories { maven { - url = uri(if (Meta.isSnapshot) Meta.snapshot else Meta.release) + url = uri(if (Meta.isSnapshot) Meta.SNAPSHOT else Meta.RELEASE) credentials { username = System.getenv("NEXUS_USER") diff --git a/detekt.yml b/detekt.yml index b9413a7..423f270 100644 --- a/detekt.yml +++ b/detekt.yml @@ -209,7 +209,6 @@ naming: active: true functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$' excludeClassPattern: '$^' - ignoreOverridden: true InvalidPackageDeclaration: active: true rootPackage: 'org.HyacinthBots' @@ -281,7 +280,7 @@ style: includeLineWrapping: true ForbiddenComment: active: false - values: ['TODO:', 'FIXME:', 'STOPSHIP:'] + comments: ['TODO:', 'FIXME:', 'STOPSHIP:'] allowedPatterns: '' ForbiddenImport: active: false @@ -308,14 +307,10 @@ style: ignoreNamedArgument: true ignoreEnums: true ignoreRanges: false - MandatoryBracesIfStatements: - active: true MandatoryBracesLoops: active: true OptionalUnit: active: false - OptionalWhenBraces: - active: true PreferToOverPairSyntax: active: true RedundantExplicitType: diff --git a/libs.versions.toml b/gradle/libs.versions.toml similarity index 81% rename from libs.versions.toml rename to gradle/libs.versions.toml index 37b9d37..d3c8fb4 100644 --- a/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,20 +1,20 @@ [versions] -kotlin = "1.8.10" -kordex = "1.5.7-20230412.093301-8" +kotlin = "1.9.10" +kordex = "1.7.1-20231226.111824-10" git-hooks = "0.0.2" licenser = "0.6.1" -bin-compat = "0.13.0" +bin-compat = "0.13.2" -detekt = "1.22.0" -logging = "3.0.5" +detekt = "1.23.4" +logging = "5.1.1" -junit5 = "5.9.2" +junit5 = "5.10.1" [libraries] kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8" } detekt = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } kordex = { module = "com.kotlindiscord.kord.extensions:kord-extensions", version.ref = "kordex" } -logging = { module = "io.github.microutils:kotlin-logging", version.ref = "logging" } +logging = { module = "io.github.oshai:kotlin-logging", version.ref = "logging" } junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit5" } junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit5" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index c1962a7..d64cd49 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a21c6eb..e6aba25 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index aeb74cb..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -83,7 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -130,10 +131,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -141,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -149,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -198,11 +202,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/settings.gradle.kts b/settings.gradle.kts index 8fb7c63..76a7e15 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,9 +1 @@ rootProject.name = "doc-generator" - -dependencyResolutionManagement { - versionCatalogs { - create("libs") { - from(files("libs.versions.toml")) - } - } -} diff --git a/src/main/kotlin/org/hyacinthbots/docgenerator/_Utils.kt b/src/main/kotlin/org/hyacinthbots/docgenerator/_Utils.kt index 6170260..f4c780e 100644 --- a/src/main/kotlin/org/hyacinthbots/docgenerator/_Utils.kt +++ b/src/main/kotlin/org/hyacinthbots/docgenerator/_Utils.kt @@ -33,7 +33,7 @@ import kotlin.io.path.exists */ internal suspend inline fun findOrCreateDocumentsFile(path: Path) { if (!path.exists()) { - DocsGenerator.generatorLogger.debug("File does not exist, creating...") + DocsGenerator.generatorLogger.debug { "File does not exist, creating..." } try { withContext(Dispatchers.IO) { path.createFile() @@ -42,7 +42,7 @@ internal suspend inline fun findOrCreateDocumentsFile(path: Path) { DocsGenerator.generatorLogger.error(e) { e.message } return } - DocsGenerator.generatorLogger.debug("File created successfully...") + DocsGenerator.generatorLogger.debug { "File created successfully..." } } } @@ -91,9 +91,9 @@ internal fun Permissions?.formatPermissionsSet(language: Locale?): String? { this.values.forEach { perm -> permissionsSet.add( - Permission.values.find { it.code.value == perm.code.value } + Permission.entries.find { it.code.value == perm.code.value } ?.translate(language ?: SupportedLocales.ENGLISH) - ?: Permission.Unknown().translate(language ?: SupportedLocales.ENGLISH) + ?: Permission.fromShift(perm.shift).translate(language ?: SupportedLocales.ENGLISH) ) } return permissionsSet.toString().replace("[", "").replace("]", "") diff --git a/src/main/kotlin/org/hyacinthbots/docgenerator/_docAddition.kt b/src/main/kotlin/org/hyacinthbots/docgenerator/_docAddition.kt index e6dd080..f99db99 100644 --- a/src/main/kotlin/org/hyacinthbots/docgenerator/_docAddition.kt +++ b/src/main/kotlin/org/hyacinthbots/docgenerator/_docAddition.kt @@ -68,9 +68,11 @@ internal var ApplicationCommand<*>.subCommandAdditionalDocumentation: MutableMap /** * Private variable to get the persistence of additional docs to work. */ +@Suppress("ObjectPropertyName") private var _additionalDocumentation: MutableMap = mutableMapOf() // I hate but it works /** * Private variable to get the persistence of additional docs to work. */ +@Suppress("ObjectPropertyName") private var _subCommandAdditionalDocumentation: MutableMap = mutableMapOf() // More hatred diff --git a/src/main/kotlin/org/hyacinthbots/docgenerator/_docGenerator.kt b/src/main/kotlin/org/hyacinthbots/docgenerator/_docGenerator.kt index dcedbd4..ffc5e5e 100644 --- a/src/main/kotlin/org/hyacinthbots/docgenerator/_docGenerator.kt +++ b/src/main/kotlin/org/hyacinthbots/docgenerator/_docGenerator.kt @@ -10,7 +10,7 @@ package org.hyacinthbots.docgenerator import com.kotlindiscord.kord.extensions.builders.ExtensibleBotBuilder -import mu.KotlinLogging +import io.github.oshai.kotlinlogging.KotlinLogging import org.hyacinthbots.docgenerator.annotations.ConfigurationBuilderDSL import org.hyacinthbots.docgenerator.builder.ConfigurationBuilder import org.hyacinthbots.docgenerator.enums.Environment @@ -43,19 +43,19 @@ public suspend fun ExtensibleBotBuilder.docsGenerator( hooks { afterExtensionsAdded { if (!action.enabled) { - generatorLogger.debug("Doc generation disabled, not generating!") + generatorLogger.debug { "Doc generation disabled, not generating!" } return@afterExtensionsAdded } when (action.environment.lowercase()) { Environment.PRODUCTION.value -> { - generatorLogger.debug("Production environment detected, not generating!") + generatorLogger.debug { "Production environment detected, not generating!" } return@afterExtensionsAdded } Environment.DEVELOPMENT.value -> { if (action.commandTypes.isEmpty()) { - generatorLogger.error("No command types have been specified! Please specify command types to document") + generatorLogger.error { "No command types have been specified! Please specify command types to document" } return@afterExtensionsAdded } diff --git a/src/main/kotlin/org/hyacinthbots/docgenerator/generator/DocsGenerator.kt b/src/main/kotlin/org/hyacinthbots/docgenerator/generator/DocsGenerator.kt index 33c9b8d..68640ba 100644 --- a/src/main/kotlin/org/hyacinthbots/docgenerator/generator/DocsGenerator.kt +++ b/src/main/kotlin/org/hyacinthbots/docgenerator/generator/DocsGenerator.kt @@ -15,9 +15,9 @@ import com.kotlindiscord.kord.extensions.commands.application.user.UserCommand import com.kotlindiscord.kord.extensions.extensions.Extension import com.kotlindiscord.kord.extensions.i18n.ResourceBundleTranslations import com.kotlindiscord.kord.extensions.i18n.SupportedLocales +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import mu.KotlinLogging import org.hyacinthbots.docgenerator.addArguments import org.hyacinthbots.docgenerator.additionalDocumentation import org.hyacinthbots.docgenerator.enums.CommandTypes @@ -29,7 +29,7 @@ import org.hyacinthbots.docgenerator.subCommandAdditionalDocumentation import org.hyacinthbots.docgenerator.translate import java.io.IOException import java.nio.file.Path -import java.util.* +import java.util.Locale import kotlin.io.path.Path import kotlin.io.path.bufferedWriter @@ -398,7 +398,7 @@ internal object DocsGenerator { writer.flush() writer.close() } - generatorLogger.info("Written documents for ${language.toLanguageTag()}!") + generatorLogger.info { "Written documents for ${language.toLanguageTag()}!" } } } else { // Generate the contents in the target language @@ -410,7 +410,7 @@ internal object DocsGenerator { writer.flush() writer.close() } - generatorLogger.info("Written documents!") + generatorLogger.info { "Written documents!" } } } } diff --git a/src/test/kotlin/UtilsTest.kt b/src/test/kotlin/UtilsTest.kt index d837686..4563569 100644 --- a/src/test/kotlin/UtilsTest.kt +++ b/src/test/kotlin/UtilsTest.kt @@ -65,7 +65,7 @@ class UtilsTest { @Test @Order(4) fun `CommandType ALL contains all command types`(): Unit = runBlocking { - CommandTypes.values().forEach { + CommandTypes.entries.forEach { assertTrue("All commands types were not present in the list: $it is missing.") { it in CommandTypes.ALL }