diff --git a/build.gradle.kts b/build.gradle.kts index be575d1..8af4226 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,6 +17,7 @@ plugins { id("java") id("application") id("idea") + id("maven-publish") id("org.jetbrains.kotlin.jvm") version "1.3.72" id("org.jetbrains.dokka") version "1.4.0-rc" } @@ -90,6 +91,25 @@ task("fatJar", Jar::class) { } archiveBaseName.set(jarName) from(configurations.runtimeClasspath.get() - .map {if(it.isDirectory) it else zipTree(it)}) + .map {if(it.isDirectory) it else zipTree(it)}) with(tasks.jar.get()) -} \ No newline at end of file +} + +publishing { + publications { + create("mavenJava") { + artifactId = "modpacktools" + artifact(tasks.getByName("fatJar")) + } + } + + repositories { + maven { + url = uri("https://data.tilera.xyz/maven/") + credentials { + username = findProperty("mvnUsername") as String? + password = findProperty("mvnPassword") as String? + } + } + } +} diff --git a/src/main/kotlin/ley/anvil/modpacktools/Main.kt b/src/main/kotlin/ley/anvil/modpacktools/Main.kt index 1367a54..292f04a 100644 --- a/src/main/kotlin/ley/anvil/modpacktools/Main.kt +++ b/src/main/kotlin/ley/anvil/modpacktools/Main.kt @@ -83,12 +83,12 @@ fun runCommand(args: Array) { else errorColor ) - } catch(e: NoSuchElementException) { + } catch(_: NoSuchElementException) { fPrintln("Command ${args[0]} not found", *errorColor) println(helpMessage) - } catch(e: CommandLoader.ConfigMissingException) { + } catch(_: CommandLoader.ConfigMissingException) { fPrintln("Config is needed for this command yet it is not present. Run 'init' to generate", *errorColor) - } catch(e: CommandLoader.ModpackJsonMissingException) { + } catch(_: CommandLoader.ModpackJsonMissingException) { fPrintln("Modpackjson is needed for this command yet it is not present.", *errorColor) } catch(e: MissingConfigValueException) { fPrintln("The Config value ${e.missingValue} was expected but was not found", *errorColor) diff --git a/src/main/kotlin/ley/anvil/modpacktools/util/Util.kt b/src/main/kotlin/ley/anvil/modpacktools/util/Util.kt index 6b2775e..3d1981c 100644 --- a/src/main/kotlin/ley/anvil/modpacktools/util/Util.kt +++ b/src/main/kotlin/ley/anvil/modpacktools/util/Util.kt @@ -36,6 +36,8 @@ import kotlin.reflect.jvm.isAccessible * @return the file content as JsonObject */ fun File.readAsJson(): JsonObject { + require(this.exists()) {"File to read doesn't exist"} + val reader = FileReader(this) val out = JsonParser.parseReader(reader) as JsonObject reader.close() @@ -89,8 +91,8 @@ fun URL.httpPostStr(payload: String, contentType: String, additionalHeaders: Map * @return the sanitized URL */ -fun URL.sanitize(): URL? { - return try { +fun URL.sanitize(): URL? = + try { URI(this.protocol, this.userInfo, this.host, @@ -101,7 +103,6 @@ fun URL.sanitize(): URL? { } catch(e: Exception) { null } -} /** * gets a function from the receiver and makes it accessible @@ -127,6 +128,8 @@ infix fun File.mergeTo(other: File): File = File(this.path, other.name) * @param zStream the zip stream to write to */ fun Path.toZip(zStream: ZipOutputStream) { + require(this.toFile().exists()) {"File must exist"} + Files.walkFileTree(this, object : SimpleFileVisitor() { override fun visitFile(file: Path, attrs: BasicFileAttributes?): FileVisitResult { zStream.putNextEntry(ZipEntry(this@toZip.relativize(file).toString())) @@ -152,6 +155,8 @@ fun File.toZip(zStream: ZipOutputStream) = this.toPath().toZip(zStream) * @param outputDir the dir to unzip to */ fun File.unzip(outputDir: File) { + require(this.exists()) {"File must exist"} + val stream = ZipInputStream(FileInputStream(this)) while(true) { val entry = stream.nextEntry ?: break