Cleanup Tachidesk Tasks

This commit is contained in:
Syer10
2024-03-29 16:25:51 -04:00
parent 5aedfea67f
commit d045005641

View File

@@ -12,12 +12,21 @@ import org.gradle.kotlin.dsl.register
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import java.io.File import java.io.File
import java.nio.file.FileSystems import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.util.jar.Attributes import java.util.jar.Attributes
import java.util.jar.JarFile import java.util.jar.JarFile
import java.util.jar.Manifest import java.util.jar.Manifest
import kotlin.streams.asSequence import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.absolutePathString
import kotlin.io.path.copyTo
import kotlin.io.path.deleteExisting
import kotlin.io.path.deleteIfExists
import kotlin.io.path.div
import kotlin.io.path.extension
import kotlin.io.path.isDirectory
import kotlin.io.path.moveTo
import kotlin.io.path.name
import kotlin.io.path.outputStream
import kotlin.io.path.walk
private const val tachideskGroup = "tachidesk" private const val tachideskGroup = "tachidesk"
private const val deleteOldTachideskTask = "deleteOldTachidesk" private const val deleteOldTachideskTask = "deleteOldTachidesk"
@@ -62,15 +71,7 @@ private val apiUrl = if (preview) {
"https://api.github.com/repos/Suwayomi/Suwayomi-Server/releases/tags/$tachideskVersion" "https://api.github.com/repos/Suwayomi/Suwayomi-Server/releases/tags/$tachideskVersion"
} }
private const val tmpJson = "$tmpPath/Suwayomi-Server.json" private const val tmpJson = "$tmpPath/Suwayomi-Server.json"
private val fileSuffix get() = if (preview) {
previewCommit
} else {
tachideskVersion.drop(1)
}
private val tmpServerFolder = "$tmpPath/Suwayomi-Server-$fileSuffix/"
private const val macosFolder = "$tmpPath/macos/"
private const val macosJarFolder = "$tmpPath/macos/jar/" private const val macosJarFolder = "$tmpPath/macos/jar/"
private const val destination = "src/main/resources/"
private const val finalJar = "src/main/resources/Tachidesk.jar" private const val finalJar = "src/main/resources/Tachidesk.jar"
internal class Asset( internal class Asset(
@@ -82,6 +83,7 @@ internal class Release(
val assets: Array<Asset> val assets: Array<Asset>
) )
@OptIn(ExperimentalPathApi::class)
fun TaskContainerScope.registerTachideskTasks(project: Project) { fun TaskContainerScope.registerTachideskTasks(project: Project) {
with(project) { with(project) {
register<Delete>(deleteOldTachideskTask) { register<Delete>(deleteOldTachideskTask) {
@@ -94,7 +96,6 @@ fun TaskContainerScope.registerTachideskTasks(project: Project) {
} }
delete(tachideskJar) delete(tachideskJar)
} }
register<Download>(downloadApiTask) { register<Download>(downloadApiTask) {
group = tachideskGroup group = tachideskGroup
mustRunAfter(deleteOldTachideskTask) mustRunAfter(deleteOldTachideskTask)
@@ -129,16 +130,16 @@ fun TaskContainerScope.registerTachideskTasks(project: Project) {
doFirst { doFirst {
FileSystems.newFileSystem(file(finalJar).toPath()).use { fs -> FileSystems.newFileSystem(file(finalJar).toPath()).use { fs ->
val macJarFolder = file(macosJarFolder).also { it.mkdirs() }.toPath() val macJarFolder = file(macosJarFolder).also { it.mkdirs() }.toPath()
Files.walk(fs.getPath("/"))
.asSequence() fs.getPath("/")
.walk()
.filter { .filter {
!Files.isDirectory(it) && it.toString() !it.isDirectory() && it.extension
.substringAfterLast('.')
.anyEquals("dylib", "jnilib", ignoreCase = true) .anyEquals("dylib", "jnilib", ignoreCase = true)
} }
.forEach { .forEach {
val tmpFile = macJarFolder.resolve(it.fileName.toString()) val tmpFile = macJarFolder / it.name
Files.copy(it, tmpFile) it.copyTo(tmpFile)
exec { exec {
commandLine( commandLine(
"/usr/bin/codesign", "/usr/bin/codesign",
@@ -148,16 +149,14 @@ fun TaskContainerScope.registerTachideskTasks(project: Project) {
"--force", "--force",
"--prefix", "ca.gosyer.", "--prefix", "ca.gosyer.",
"--sign", "Developer ID Application: ${getSigningIdentity()}", "--sign", "Developer ID Application: ${getSigningIdentity()}",
tmpFile.toAbsolutePath().toString(), tmpFile.absolutePathString(),
) )
} }
Files.copy(tmpFile, it, StandardCopyOption.REPLACE_EXISTING) tmpFile.copyTo(it, overwrite = true)
Files.delete(tmpFile) tmpFile.deleteExisting()
} }
} }
} }
} }
register<Task>(modifyTachideskJarManifest) { register<Task>(modifyTachideskJarManifest) {
@@ -178,9 +177,9 @@ fun TaskContainerScope.registerTachideskTasks(project: Project) {
FileSystems.newFileSystem(tachideskJar.toPath()).use { fs -> FileSystems.newFileSystem(tachideskJar.toPath()).use { fs ->
val manifestFile = fs.getPath("META-INF/MANIFEST.MF") val manifestFile = fs.getPath("META-INF/MANIFEST.MF")
val manifestBak = fs.getPath("META-INF/MANIFEST.MF" + ".bak") val manifestBak = fs.getPath("META-INF/MANIFEST.MF" + ".bak")
Files.deleteIfExists(manifestBak) manifestBak.deleteIfExists()
Files.move(manifestFile, manifestBak) manifestFile.moveTo(manifestBak)
Files.newOutputStream(manifestFile).use { manifestFile.outputStream().use {
manifest.write(it) manifest.write(it)
} }
} }