Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow choosing StationAPI module branch #52

Merged
merged 3 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,48 @@ open class FabricLikeApiExtension {

}

open class StAPILocation(private val branch: String) : APILocations() {
override fun getUrl(version: String): String {
return "https://maven.glass-launcher.net/$branch/net/modificationstation/StationAPI/$version/StationAPI-$version.pom"
}

override fun getArtifactName(moduleName: String, version: String?): String {
TODO("Not yet implemented")
}

fun getArtifactName(moduleName: String, mainVersion: String, version: String?): String {
return "net.modificationstation.StationAPI.$mainVersion:$moduleName:$version"
}

override fun module(moduleName: String, version: String): String? {
val elements = xmlDoc[version].getElementsByTagName("dependency")

for (i in 0 until elements.length) {
val element = elements.item(i)
var correct = false
var vers: String? = null

for (j in 0 until element.childNodes.length) {
val child = element.childNodes.item(j)

if (child.nodeName == "artifactId" && child.textContent == moduleName) {
correct = true
}

if (child.nodeName == "version") {
vers = child.textContent
}
}

if (correct) {
return getArtifactName(moduleName, version, vers)
}
}

return null
}
}

val locations = mapOf<String, APILocations>(
"fabric" to object : APILocations() {
override fun getUrl(version: String): String {
Expand Down Expand Up @@ -83,47 +125,8 @@ open class FabricLikeApiExtension {
return "org.quiltmc.qsl:$moduleName:$version"
}
},
"station" to object : APILocations() {
override fun getUrl(version: String): String {
return "https://maven.glass-launcher.net/snapshots/net/modificationstation/StationAPI/$version/StationAPI-$version.pom"
}

override fun getArtifactName(moduleName: String, version: String?): String {
TODO("Not yet implemented")
}

fun getArtifactName(moduleName: String, mainVersion: String, version: String?): String {
return "net.modificationstation.StationAPI.$mainVersion:$moduleName:$version"
}

override fun module(moduleName: String, version: String): String? {
val elements = xmlDoc[version].getElementsByTagName("dependency")

for (i in 0 until elements.length) {
val element = elements.item(i)
var correct = false
var vers: String? = null

for (j in 0 until element.childNodes.length) {
val child = element.childNodes.item(j)

if (child.nodeName == "artifactId" && child.textContent == moduleName) {
correct = true
}

if (child.nodeName == "version") {
vers = child.textContent
}
}

if (correct) {
return getArtifactName(moduleName, version, vers)
}
}

return null
}
}
"station_snapshots" to object : StAPILocation("snapshots") {},
"station_releases" to object : StAPILocation("releases") {}
)

@Deprecated(message = "use fabricModule or legacyFabricModule instead", replaceWith = ReplaceWith("fabricModule"))
Expand Down Expand Up @@ -167,8 +170,9 @@ open class FabricLikeApiExtension {
/**
* @since 1.0.0
*/
fun stationModule(moduleName: String, version: String): String {
return locations["station"]!!.module(moduleName, version) ?: throw IllegalStateException("Could not find module $moduleName:$version")
@JvmOverloads
fun stationModule(branch: String = "snapshots", moduleName: String, version: String): String {
Copy link
Collaborator

@wagyourtail wagyourtail Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JVMOverloads otherwise it'll not work properly in groovy

return locations["station_$branch"]!!.module(moduleName, version) ?: throw IllegalStateException("Could not find module $moduleName:$version")
}

}
2 changes: 1 addition & 1 deletion testing/b1.7.3-Babric-Modloader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ unimined.minecraft(sourceSets.modloader) {

mappings {
babricIntermediary()
barn(9)
biny("a00e3b0")
stub.withMappings(["intermediary", "barn"]) {
c("ModLoader", "net/minecraft/src/ModLoader", "net/minecraft/src/ModLoader")
c("BaseMod", "net/minecraft/src/BaseMod", "net/minecraft/src/BaseMod")
Expand Down
Loading