mirror of
https://github.com/Anvilcraft/modpacktools
synced 2024-12-28 07:53:40 +01:00
add BuilderContainerTagTest.kt
move convertAStoManifest into ASUtil.kt convertAStoManifest will throw exception if forge version is invalid add out to gitignore
This commit is contained in:
parent
b3b077796d
commit
4944f7c934
5 changed files with 104 additions and 81 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
|
gradle.properties
|
||||||
.gradle
|
.gradle
|
||||||
.idea
|
.idea
|
||||||
build
|
build
|
||||||
gradle.properties
|
out
|
||||||
|
|
|
@ -9,11 +9,11 @@ import ley.anvil.modpacktools.command.CommandReturn.Companion.fail
|
||||||
import ley.anvil.modpacktools.command.CommandReturn.Companion.success
|
import ley.anvil.modpacktools.command.CommandReturn.Companion.success
|
||||||
import ley.anvil.modpacktools.command.LoadCommand
|
import ley.anvil.modpacktools.command.LoadCommand
|
||||||
import ley.anvil.modpacktools.util.FileToDownload
|
import ley.anvil.modpacktools.util.FileToDownload
|
||||||
|
import ley.anvil.modpacktools.util.addonscript.convertAStoManifest
|
||||||
import ley.anvil.modpacktools.util.addonscript.installFile
|
import ley.anvil.modpacktools.util.addonscript.installFile
|
||||||
import ley.anvil.modpacktools.util.arg
|
import ley.anvil.modpacktools.util.arg
|
||||||
import ley.anvil.modpacktools.util.downloadFiles
|
import ley.anvil.modpacktools.util.downloadFiles
|
||||||
import ley.anvil.modpacktools.util.fPrintln
|
import ley.anvil.modpacktools.util.fPrintln
|
||||||
import ley.anvil.modpacktools.util.manifest.convertAStoManifest
|
|
||||||
import ley.anvil.modpacktools.util.toZip
|
import ley.anvil.modpacktools.util.toZip
|
||||||
import net.sourceforge.argparse4j.impl.Arguments.storeTrue
|
import net.sourceforge.argparse4j.impl.Arguments.storeTrue
|
||||||
import net.sourceforge.argparse4j.inf.ArgumentParser
|
import net.sourceforge.argparse4j.inf.ArgumentParser
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package ley.anvil.modpacktools.util.addonscript
|
package ley.anvil.modpacktools.util.addonscript
|
||||||
|
|
||||||
|
import ley.anvil.addonscript.curse.ManifestJSON
|
||||||
|
import ley.anvil.addonscript.wrapper.ASWrapper
|
||||||
import ley.anvil.modpacktools.TERMC
|
import ley.anvil.modpacktools.TERMC
|
||||||
import ley.anvil.modpacktools.util.fPrintln
|
import ley.anvil.modpacktools.util.fPrintln
|
||||||
|
import ley.anvil.modpacktools.util.manifest.ManifestLinksPair
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
|
@ -68,3 +71,82 @@ fun installFile(installer: String, file: File, outDir: File): InstallFileSuccess
|
||||||
}
|
}
|
||||||
return InstallFileSuccess(true, "installed $file")
|
return InstallFileSuccess(true, "installed $file")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a AS file to a twitch manifest
|
||||||
|
*
|
||||||
|
* @param addonscript the file to convert
|
||||||
|
* @param shouldAddLink if a link for a given relation should be added, does not get called if the relations is a curseforge artifact
|
||||||
|
*/
|
||||||
|
@JvmOverloads
|
||||||
|
fun convertAStoManifest(
|
||||||
|
addonscript: ASWrapper,
|
||||||
|
shouldAddLink: (ASWrapper.RelationWrapper) -> Boolean = {true}
|
||||||
|
): ManifestLinksPair {
|
||||||
|
val ml = ManifestLinksPair()
|
||||||
|
val ver = addonscript.defaultVersion
|
||||||
|
val manifest = ManifestJSON()
|
||||||
|
|
||||||
|
val mcv = ver.version!!.mcversion[0]
|
||||||
|
manifest.minecraft = ManifestJSON.Minecraft()
|
||||||
|
manifest.minecraft.version = mcv
|
||||||
|
manifest.minecraft.modLoaders = mutableListOf()
|
||||||
|
manifest.files = mutableListOf()
|
||||||
|
|
||||||
|
manifest.manifestType = "minecraftModpack"
|
||||||
|
manifest.manifestVersion = 1
|
||||||
|
manifest.name = addonscript.json.meta!!.name ?: addonscript.json.id
|
||||||
|
manifest.version = ver.versionName
|
||||||
|
manifest.author = addonscript.json!!.meta!!.contributors[0].name
|
||||||
|
|
||||||
|
for(rel in ver.getRelations(arrayOf("client"), null)) {
|
||||||
|
if(rel.isModloader) {
|
||||||
|
if(rel.relation.id == "forge") {
|
||||||
|
val forge = ManifestJSON.Modloader()
|
||||||
|
forge.primary = true
|
||||||
|
forge.id = "forge-${rel.versions.latestKnown?.split('-')?.getOrNull(1)
|
||||||
|
?: throw IllegalArgumentException("Forge version format is invalid.")}"
|
||||||
|
manifest.minecraft.modLoaders.add(forge)
|
||||||
|
} else {
|
||||||
|
println("Curse only allows Forge as a modloader. ${rel.relation.id} is not allowed!")
|
||||||
|
}
|
||||||
|
} else if(rel.hasFile()) {
|
||||||
|
val file = rel.file
|
||||||
|
//TODO deduplicate this
|
||||||
|
if(file.file.installer == "internal.jar") {
|
||||||
|
println("internal.jar is not supported on Curse")
|
||||||
|
continue
|
||||||
|
} else if(file.isArtifact && file.artifact.isCurseforge) {
|
||||||
|
val art = file.artifact
|
||||||
|
val f = ManifestJSON.File()
|
||||||
|
f.fileID = art.fileID
|
||||||
|
f.projectID = art.projectID
|
||||||
|
f.required = "required" in rel.options
|
||||||
|
manifest.files.add(f)
|
||||||
|
} else if(shouldAddLink(rel)) {
|
||||||
|
ml.links[file.get()] = file.file.installer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(file in ver.getFiles(arrayOf("client", "required"), null)) {
|
||||||
|
if(file.file.installer == "internal.jar") {
|
||||||
|
println("internal.jar is not supported on Curse")
|
||||||
|
continue
|
||||||
|
} else if(file.isArtifact) {
|
||||||
|
val art = file.artifact
|
||||||
|
if(art.isCurseforge) {
|
||||||
|
val f = ManifestJSON.File()
|
||||||
|
f.fileID = art.fileID
|
||||||
|
f.projectID = art.projectID
|
||||||
|
f.required = true
|
||||||
|
manifest.files.add(f)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ml.links[file.get()] = file.file.installer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ml.manifest = manifest
|
||||||
|
|
||||||
|
return ml
|
||||||
|
}
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
package ley.anvil.modpacktools.util.manifest
|
|
||||||
|
|
||||||
import ley.anvil.addonscript.curse.ManifestJSON
|
|
||||||
import ley.anvil.addonscript.wrapper.ASWrapper
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a AS file to a twitch manifest
|
|
||||||
*
|
|
||||||
* @param addonscript the file to convert
|
|
||||||
* @param shouldAddLink if a link for a given relation should be added, does not get called if the relations is a curseforge artifact
|
|
||||||
*/
|
|
||||||
@JvmOverloads
|
|
||||||
fun convertAStoManifest(addonscript: ASWrapper, shouldAddLink: (ASWrapper.RelationWrapper) -> Boolean = {true}): ManifestLinksPair {
|
|
||||||
val ml = ManifestLinksPair()
|
|
||||||
val ver = addonscript.defaultVersion
|
|
||||||
val manifest = ManifestJSON()
|
|
||||||
|
|
||||||
val mcv = ver.version!!.mcversion[0]
|
|
||||||
manifest.minecraft = ManifestJSON.Minecraft()
|
|
||||||
manifest.minecraft.version = mcv
|
|
||||||
manifest.minecraft.modLoaders = mutableListOf()
|
|
||||||
manifest.files = mutableListOf()
|
|
||||||
|
|
||||||
manifest.manifestType = "minecraftModpack"
|
|
||||||
manifest.manifestVersion = 1
|
|
||||||
manifest.name = addonscript.json.meta!!.name ?: addonscript.json.id
|
|
||||||
manifest.version = ver.versionName
|
|
||||||
manifest.author = addonscript.json!!.meta!!.contributors[0].name
|
|
||||||
|
|
||||||
for(rel in ver.getRelations(arrayOf("client"), null)) {
|
|
||||||
if(rel.isModloader) {
|
|
||||||
if(rel.relation.id == "forge") {
|
|
||||||
val forge = ManifestJSON.Modloader()
|
|
||||||
forge.primary = true
|
|
||||||
forge.id = "forge-${rel.versions.latestKnown?.split('-')?.get(1)}"
|
|
||||||
manifest.minecraft.modLoaders.add(forge)
|
|
||||||
} else {
|
|
||||||
println("Curse only allows Forge as a modloader. ${rel.relation.id} is not allowed!")
|
|
||||||
}
|
|
||||||
} else if(rel.hasFile()) {
|
|
||||||
val file = rel.file
|
|
||||||
//TODO deduplicate this
|
|
||||||
if(file.file.installer == "internal.jar") {
|
|
||||||
println("internal.jar is not supported on Curse")
|
|
||||||
continue
|
|
||||||
} else if(file.isArtifact && file.artifact.isCurseforge) {
|
|
||||||
val art = file.artifact
|
|
||||||
val f = ManifestJSON.File()
|
|
||||||
f.fileID = art.fileID
|
|
||||||
f.projectID = art.projectID
|
|
||||||
f.required = "required" in rel.options
|
|
||||||
manifest.files.add(f)
|
|
||||||
} else if(shouldAddLink(rel)) {
|
|
||||||
ml.links[file.get()] = file.file.installer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(file in ver.getFiles(arrayOf("client", "required"), null)) {
|
|
||||||
if(file.file.installer == "internal.jar") {
|
|
||||||
println("internal.jar is not supported on Curse")
|
|
||||||
continue
|
|
||||||
} else if(file.isArtifact) {
|
|
||||||
val art = file.artifact
|
|
||||||
if(art.isCurseforge) {
|
|
||||||
val f = ManifestJSON.File()
|
|
||||||
f.fileID = art.fileID
|
|
||||||
f.projectID = art.projectID
|
|
||||||
f.required = true
|
|
||||||
manifest.files.add(f)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ml.links[file.get()] = file.file.installer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ml.manifest = manifest
|
|
||||||
|
|
||||||
return ml
|
|
||||||
}
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package ley.anvil.modpacktools.util
|
||||||
|
|
||||||
|
import ley.anvil.modpacktools.util.BuilderContainerTag.Companion.html
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class BuilderContainerTagTest {
|
||||||
|
@Test
|
||||||
|
fun htmlBuilder() {
|
||||||
|
assertEquals(
|
||||||
|
"<html><body><h1>Hello</h1></body></html>",
|
||||||
|
html {
|
||||||
|
"body" {
|
||||||
|
"h1"("Hello")
|
||||||
|
}
|
||||||
|
}.render()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue