From fd9221395ade092581a35054a01e11d4ba1e72c7 Mon Sep 17 00:00:00 2001 From: Francisco Solis <30329003+Im-Fran@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:04:07 -0300 Subject: [PATCH] feat: comply with SimpleCoreAPI v0.8.0 * Moved to new module system * Removed some utils that are included in SCAPI * Improved build.gradle.kts (added env check for sonatype publish) * Renamed Main into FilesModule --- build.gradle.kts | 20 +++---- .../theprogramsrc/filesmodule/FilesModule.kt | 22 ++++++++ .../xyz/theprogramsrc/filesmodule/Main.kt | 5 -- .../filesmodule/config/JsonConfig.kt | 2 +- .../filesmodule/config/PropertiesConfig.kt | 2 +- .../filesmodule/config/YmlConfig.kt | 2 +- .../filesmodule/utils/FileUtils.kt | 52 ------------------- src/main/resources/module.properties | 6 --- .../filesmodule/config/JsonConfigTest.kt | 34 ++++++------ .../config/PropertiesConfigTest.kt | 35 +++++++------ .../filesmodule/config/YmlConfigTest.kt | 34 ++++++------ 11 files changed, 91 insertions(+), 123 deletions(-) create mode 100644 src/main/kotlin/xyz/theprogramsrc/filesmodule/FilesModule.kt delete mode 100644 src/main/kotlin/xyz/theprogramsrc/filesmodule/Main.kt delete mode 100644 src/main/kotlin/xyz/theprogramsrc/filesmodule/utils/FileUtils.kt delete mode 100644 src/main/resources/module.properties diff --git a/build.gradle.kts b/build.gradle.kts index 5c85e0e..53442f3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ val env = project.rootProject.file(".env").let { file -> if(file.exists()) file.readLines().filter { it.isNotBlank() && !it.startsWith("#") && it.split("=").size == 2 }.associate { it.split("=")[0] to it.split("=")[1] } else emptyMap() }.toMutableMap().apply { putAll(System.getenv()) } -val projectVersion = env["VERSION"] ?: "0.3.0-SNAPSHOT" +val projectVersion = env["VERSION"] ?: "0.4.0-SNAPSHOT" group = "xyz.theprogramsrc" version = projectVersion @@ -33,7 +33,7 @@ repositories { } dependencies { - compileOnly("xyz.theprogramsrc:simplecoreapi:0.6.2-SNAPSHOT") + compileOnly("xyz.theprogramsrc:simplecoreapi:0.8.0-SNAPSHOT") implementation("me.carleslc.Simple-YAML:Simple-Yaml:1.8.4") @@ -171,14 +171,16 @@ publishing { } } -nexusPublishing { - repositories { - sonatype { - nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) - snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) +if(env["ENV"] == "prod") { + nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) - username.set(env["SONATYPE_USERNAME"]) - password.set(env["SONATYPE_PASSWORD"]) + username.set(env["SONATYPE_USERNAME"]) + password.set(env["SONATYPE_PASSWORD"]) + } } } } diff --git a/src/main/kotlin/xyz/theprogramsrc/filesmodule/FilesModule.kt b/src/main/kotlin/xyz/theprogramsrc/filesmodule/FilesModule.kt new file mode 100644 index 0000000..092a5b0 --- /dev/null +++ b/src/main/kotlin/xyz/theprogramsrc/filesmodule/FilesModule.kt @@ -0,0 +1,22 @@ +package xyz.theprogramsrc.filesmodule + +import xyz.theprogramsrc.simplecoreapi.global.models.module.Module +import xyz.theprogramsrc.simplecoreapi.global.models.module.ModuleDescription + +class FilesModule: Module { + + override val description: ModuleDescription = + ModuleDescription( + name = "@name@", + version = "@version@", + authors = listOf("Im-Fran") + ) + + override fun onDisable() { + TODO("Not yet implemented") + } + + override fun onEnable() { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/src/main/kotlin/xyz/theprogramsrc/filesmodule/Main.kt b/src/main/kotlin/xyz/theprogramsrc/filesmodule/Main.kt deleted file mode 100644 index ad046de..0000000 --- a/src/main/kotlin/xyz/theprogramsrc/filesmodule/Main.kt +++ /dev/null @@ -1,5 +0,0 @@ -package xyz.theprogramsrc.filesmodule - -import xyz.theprogramsrc.simplecoreapi.global.module.Module - -class Main: Module() \ No newline at end of file diff --git a/src/main/kotlin/xyz/theprogramsrc/filesmodule/config/JsonConfig.kt b/src/main/kotlin/xyz/theprogramsrc/filesmodule/config/JsonConfig.kt index f9f1ecc..a5386a1 100644 --- a/src/main/kotlin/xyz/theprogramsrc/filesmodule/config/JsonConfig.kt +++ b/src/main/kotlin/xyz/theprogramsrc/filesmodule/config/JsonConfig.kt @@ -1,7 +1,7 @@ package xyz.theprogramsrc.filesmodule.config import com.google.gson.* -import xyz.theprogramsrc.filesmodule.utils.file +import xyz.theprogramsrc.simplecoreapi.global.utils.extensions.file import java.io.File /** diff --git a/src/main/kotlin/xyz/theprogramsrc/filesmodule/config/PropertiesConfig.kt b/src/main/kotlin/xyz/theprogramsrc/filesmodule/config/PropertiesConfig.kt index 5e853b1..3d5bca3 100644 --- a/src/main/kotlin/xyz/theprogramsrc/filesmodule/config/PropertiesConfig.kt +++ b/src/main/kotlin/xyz/theprogramsrc/filesmodule/config/PropertiesConfig.kt @@ -1,6 +1,6 @@ package xyz.theprogramsrc.filesmodule.config -import xyz.theprogramsrc.filesmodule.utils.file +import xyz.theprogramsrc.simplecoreapi.global.utils.extensions.file import java.io.File import java.util.* diff --git a/src/main/kotlin/xyz/theprogramsrc/filesmodule/config/YmlConfig.kt b/src/main/kotlin/xyz/theprogramsrc/filesmodule/config/YmlConfig.kt index 8f4e7fc..44dd801 100644 --- a/src/main/kotlin/xyz/theprogramsrc/filesmodule/config/YmlConfig.kt +++ b/src/main/kotlin/xyz/theprogramsrc/filesmodule/config/YmlConfig.kt @@ -2,7 +2,7 @@ package xyz.theprogramsrc.filesmodule.config import org.simpleyaml.configuration.ConfigurationSection import org.simpleyaml.configuration.file.YamlConfiguration -import xyz.theprogramsrc.filesmodule.utils.file +import xyz.theprogramsrc.simplecoreapi.global.utils.extensions.file import java.io.File /** diff --git a/src/main/kotlin/xyz/theprogramsrc/filesmodule/utils/FileUtils.kt b/src/main/kotlin/xyz/theprogramsrc/filesmodule/utils/FileUtils.kt deleted file mode 100644 index 883da2c..0000000 --- a/src/main/kotlin/xyz/theprogramsrc/filesmodule/utils/FileUtils.kt +++ /dev/null @@ -1,52 +0,0 @@ -package xyz.theprogramsrc.filesmodule.utils - -import java.io.File - -/** - * Creates the directory named by this abstract pathname, including any - * necessary but nonexistent parent directories. Note that if this - * operation fails it may have succeeded in creating some necessary - * parent directories. - * - * @return The current file - * - * @throws java.lang.SecurityException - * If a security manager exists and its - * [java.lang.SecurityManager#checkRead(String)] - * method does not permit verification of the existence of the - * named directory and all necessary parent directories; or if - * the [java.lang.SecurityManager#checkWrite(String)] - * method does not permit the named directory and all - * necessary parent directories to be created - */ -fun File.folder(): File { - if(!this.exists()) this.mkdirs() - return this -} - -/** - * Atomically creates a new, empty file named by this abstract pathname if - * and only if a file with this name does not yet exist. The check for the - * existence of the file and the creation of the file if it does not exist - * are a single operation that is atomic with respect to all other - * filesystem activities that might affect the file. - *

- * Note: this method should not be used for file-locking, as - * the resulting protocol cannot be made to work reliably. The - * [java.nio.channels.FileLock] - * facility should be used instead. - * - * @return The current file - * - * @throws java.io.IOException - * If an I/O error occurred - * - * @throws java.lang.SecurityException - * If a security manager exists and its - * [java.lang.SecurityManager#checkWrite(String)] - * method denies write access to the file - */ -fun File.file(): File { - if(!this.exists()) this.createNewFile() - return this -} \ No newline at end of file diff --git a/src/main/resources/module.properties b/src/main/resources/module.properties deleted file mode 100644 index 4053b68..0000000 --- a/src/main/resources/module.properties +++ /dev/null @@ -1,6 +0,0 @@ -main=xyz.theprogramsrc.filesmodule.Main -name=FilesModule -description=@description@ -version=@version@ -author=TheProgramSrc -module-id=TheProgramSrc/SimpleCore-FilesModule diff --git a/src/test/kotlin/xyz/theprogramsrc/filesmodule/config/JsonConfigTest.kt b/src/test/kotlin/xyz/theprogramsrc/filesmodule/config/JsonConfigTest.kt index 295a3b1..606afb2 100644 --- a/src/test/kotlin/xyz/theprogramsrc/filesmodule/config/JsonConfigTest.kt +++ b/src/test/kotlin/xyz/theprogramsrc/filesmodule/config/JsonConfigTest.kt @@ -8,22 +8,6 @@ import java.io.File internal class JsonConfigTest { - companion object { - private val config = JsonConfig(File("test.json")) - - @BeforeAll - fun setUp() { - config.destroy() - config.load() - } - - @AfterAll - fun tearDown() { - config.destroy() - } - - } - @Test fun has() { assertFalse(config.has("test")) @@ -81,4 +65,22 @@ internal class JsonConfigTest { assertEquals(3 as Number, config.getNumber("addNumber")) config.remove("addNumber") } + + companion object { + private val config = JsonConfig(File("test.json")) + + @JvmStatic + @BeforeAll + fun setUp() { + config.destroy() + config.load() + } + + @JvmStatic + @AfterAll + fun tearDown() { + config.destroy() + } + + } } \ No newline at end of file diff --git a/src/test/kotlin/xyz/theprogramsrc/filesmodule/config/PropertiesConfigTest.kt b/src/test/kotlin/xyz/theprogramsrc/filesmodule/config/PropertiesConfigTest.kt index a1f19b5..ef12d7a 100644 --- a/src/test/kotlin/xyz/theprogramsrc/filesmodule/config/PropertiesConfigTest.kt +++ b/src/test/kotlin/xyz/theprogramsrc/filesmodule/config/PropertiesConfigTest.kt @@ -8,22 +8,6 @@ import java.io.File internal class PropertiesConfigTest { - companion object { - private val config = PropertiesConfig(File("test.properties")) - - @BeforeAll - fun setUp() { - config.destroy() - config.load() - } - - @AfterAll - fun tearDown() { - config.destroy() - } - - } - @Test fun has() { assertFalse(config.has("test")) @@ -56,4 +40,23 @@ internal class PropertiesConfigTest { assertNull(config.get("test")) assertFalse(config.has("test")) } + + companion object { + private val config = PropertiesConfig(File("test.properties")) + + @JvmStatic + @BeforeAll + fun setUp() { + config.destroy() + config.load() + } + + @JvmStatic + @AfterAll + fun tearDown() { + config.destroy() + } + + } + } \ No newline at end of file diff --git a/src/test/kotlin/xyz/theprogramsrc/filesmodule/config/YmlConfigTest.kt b/src/test/kotlin/xyz/theprogramsrc/filesmodule/config/YmlConfigTest.kt index a7ea732..4fdd85e 100644 --- a/src/test/kotlin/xyz/theprogramsrc/filesmodule/config/YmlConfigTest.kt +++ b/src/test/kotlin/xyz/theprogramsrc/filesmodule/config/YmlConfigTest.kt @@ -8,22 +8,6 @@ import java.io.File internal class YmlConfigTest { - companion object { - private val config = YmlConfig(File("test.yml")) - - @BeforeAll - fun setUp() { - config.destroy() - config.load() - } - - @AfterAll - fun tearDown() { - config.destroy() - } - - } - @Test fun hasAndSet() { assertFalse(config.has("test")) @@ -71,4 +55,22 @@ internal class YmlConfigTest { assertTrue(config.has("test")) config.remove("test") } + + companion object { + private val config = YmlConfig(File("test.yml")) + + @JvmStatic + @BeforeAll + fun setUp() { + config.destroy() + config.load() + } + + @JvmStatic + @AfterAll + fun tearDown() { + config.destroy() + } + + } } \ No newline at end of file