remove gson dependency, update dependency checks

This commit is contained in:
NikkyAI 2018-12-11 15:02:12 +13:00
parent 43ce9491b9
commit b12704d507
10 changed files with 51 additions and 56 deletions

View File

@ -40,6 +40,7 @@ dependencies {
shade(group: "com.github.kittinunf.Fuel", name: "fuel", version: fuelVersion) shade(group: "com.github.kittinunf.Fuel", name: "fuel", version: fuelVersion)
shade(group: "com.github.kittinunf.Fuel", name: "fuel-coroutines", version: fuelVersion) shade(group: "com.github.kittinunf.Fuel", name: "fuel-coroutines", version: fuelVersion)
shade(group: "com.github.kittinunf.Fuel", name: "fuel-kotlinx-serialization", version: fuelVersion)
shade(group: 'com.github.kittinunf.result', name: 'result', version: resultVersion) shade(group: 'com.github.kittinunf.result', name: 'result', version: resultVersion)
// shade group: 'com.github.kittinunf.fuel', name: 'fuel', version: fuelVersion // shade group: 'com.github.kittinunf.fuel', name: 'fuel', version: fuelVersion

View File

@ -20,13 +20,14 @@ dependencies {
compile project(":Jankson") compile project(":Jankson")
shadow(project(':Jankson')) { transitive = false } shadow(project(':Jankson')) { transitive = false }
compile group: 'com.google.code.gson', name: 'gson', version: '+'
compile group: 'com.google.guava', name: 'guava', version: '+' compile group: 'com.google.guava', name: 'guava', version: '+'
compile(group: "com.github.kittinunf.Fuel", name: "fuel", version: fuelVersion) compile(group: "com.github.kittinunf.Fuel", name: "fuel", version: fuelVersion)
shadow(group: "com.github.kittinunf.Fuel", name: "fuel", version: fuelVersion) { transitive = true } shadow(group: "com.github.kittinunf.Fuel", name: "fuel", version: fuelVersion) { transitive = true }
compile(group: "com.github.kittinunf.Fuel", name: "fuel-coroutines", version: fuelVersion) compile(group: "com.github.kittinunf.Fuel", name: "fuel-coroutines", version: fuelVersion)
shadow(group: "com.github.kittinunf.Fuel", name: "fuel-coroutines", version: fuelVersion) { transitive = true } shadow(group: "com.github.kittinunf.Fuel", name: "fuel-coroutines", version: fuelVersion) { transitive = true }
compile(group: "com.github.kittinunf.Fuel", name: "fuel-kotlinx-serialization", version: fuelVersion)
shadow(group: "com.github.kittinunf.Fuel", name: "fuel-kotlinx-serialization", version: fuelVersion) { transitive = true }
// compile(group: 'com.github.kittinunf.result', name: 'result', version: resultVersion) // compile(group: 'com.github.kittinunf.result', name: 'result', version: resultVersion)
// shadow(group: 'com.github.kittinunf.result', name: 'result', version: resultVersion) { transitive = false } // shadow(group: 'com.github.kittinunf.result', name: 'result', version: resultVersion) { transitive = false }

View File

@ -1,11 +1,13 @@
package matterlink.jenkins package matterlink.jenkins
import kotlinx.serialization.Serializable
/** /**
* Created by nikky on 03/02/18. * Created by nikky on 03/02/18.
* @author Nikky * @author Nikky
*/ */
//@JsonIgnoreProperties(ignoreUnknown = true) @Serializable
data class Artifact( data class Artifact(
val displayPath: String, val displayPath: String,
val fileName: String, val fileName: String,

View File

@ -1,8 +1,9 @@
package matterlink.jenkins package matterlink.jenkins
import com.github.kittinunf.fuel.httpGet import com.github.kittinunf.fuel.httpGet
import com.github.kittinunf.fuel.serialization.kotlinxDeserializerOf
import com.github.kittinunf.result.Result import com.github.kittinunf.result.Result
import com.google.gson.Gson import kotlinx.serialization.json.JSON
import matterlink.logger import matterlink.logger
@ -20,10 +21,10 @@ data class Build(
val (request, response, result) = "$url/api/json" val (request, response, result) = "$url/api/json"
.httpGet() .httpGet()
.header("User-Agent" to userAgent) .header("User-Agent" to userAgent)
.responseString() .responseObject(kotlinxDeserializerOf(loader = BuildWithDetails.serializer(), json = JSON.nonstrict))
return when (result) { return when (result) {
is Result.Success -> { is Result.Success -> {
gson.fromJson(result.value, BuildWithDetails::class.java) result.value
} }
is Result.Failure -> { is Result.Failure -> {
logger.error(result.error.toString()) logger.error(result.error.toString())
@ -31,9 +32,5 @@ data class Build(
} }
} }
} }
companion object {
val gson = Gson()
}
} }

View File

@ -1,12 +1,12 @@
package matterlink.jenkins package matterlink.jenkins
import kotlinx.serialization.Serializable
import java.util.Date import java.util.Date
//@JsonIgnoreProperties(ignoreUnknown = true) @Serializable
data class BuildWithDetails( data class BuildWithDetails(
val number: Int, val number: Int,
val url: String, val url: String,
val artifacts: List<Artifact>, val artifacts: List<Artifact>,
// @JsonFormat(shape=JsonFormat.Shape.NUMBER, pattern="s")
val timestamp: Date val timestamp: Date
) )

View File

@ -2,8 +2,9 @@ package matterlink.jenkins
import com.github.kittinunf.fuel.httpGet import com.github.kittinunf.fuel.httpGet
import com.github.kittinunf.fuel.serialization.kotlinxDeserializerOf
import com.github.kittinunf.result.Result import com.github.kittinunf.result.Result
import com.google.gson.Gson import kotlinx.serialization.json.JSON
import matterlink.logger import matterlink.logger
/** /**
@ -21,10 +22,10 @@ class JenkinsServer(val url: String) {
val (_, _, result) = requestURL val (_, _, result) = requestURL
.httpGet() .httpGet()
.header("User-Agent" to userAgent) .header("User-Agent" to userAgent)
.responseString() .responseObject(kotlinxDeserializerOf(loader = Job.serializer(), json = JSON.nonstrict))
return when (result) { return when (result) {
is Result.Success -> { is Result.Success -> {
gson.fromJson(result.value, Job::class.java) result.value
} }
is Result.Failure -> { is Result.Failure -> {
logger.error(result.error.toString()) logger.error(result.error.toString())
@ -33,8 +34,4 @@ class JenkinsServer(val url: String) {
} }
} }
companion object {
val gson = Gson()
}
} }

View File

@ -1,11 +1,13 @@
package matterlink.jenkins package matterlink.jenkins
import kotlinx.serialization.Serializable
/** /**
* Created by nikky on 03/02/18. * Created by nikky on 03/02/18.
* @author Nikky * @author Nikky
*/ */
//@JsonIgnoreProperties(ignoreUnknown = true) @Serializable
data class Job( data class Job(
val url: String, val url: String,
val name: String, val name: String,

View File

@ -1,8 +1,12 @@
package matterlink.update package matterlink.update
import kotlinx.serialization.Serializable
@Serializable
data class CurseFile( data class CurseFile(
val downloadURL: String, val downloadUrl: String,
val fileName: String, val fileName: String,
val fileNameOnDisk: String,
val gameVersion: List<String>, val gameVersion: List<String>,
val releaseType: String, val releaseType: String,
val fileStatus: String val fileStatus: String

View File

@ -1,9 +1,11 @@
package matterlink.update package matterlink.update
import com.google.gson.GsonBuilder import com.github.kittinunf.fuel.core.extensions.cUrlString
import com.github.kittinunf.fuel.httpGet
import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.serialization.list
import matterlink.api.ApiMessage import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst import matterlink.bridge.MessageHandlerInst
import matterlink.config.cfg import matterlink.config.cfg
@ -12,9 +14,9 @@ import matterlink.handlers.LocationHandler
import matterlink.instance import matterlink.instance
import matterlink.jenkins.JenkinsServer import matterlink.jenkins.JenkinsServer
import matterlink.logger import matterlink.logger
import java.io.BufferedReader import com.github.kittinunf.fuel.serialization.kotlinxDeserializerOf
import java.net.HttpURLConnection import com.github.kittinunf.result.Result
import java.net.URL import kotlinx.serialization.json.JSON
object UpdateChecker : CoroutineScope { object UpdateChecker : CoroutineScope {
override val coroutineContext = Job() + CoroutineName("UpdateChacker") override val coroutineContext = Job() + CoroutineName("UpdateChacker")
@ -61,41 +63,30 @@ object UpdateChecker : CoroutineScope {
return return
} }
val gson = GsonBuilder()
// .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
.create()
logger.info("Checking for new versions...") logger.info("Checking for new versions...")
val (request, response, result) = with(instance) {
val url = URL("https://staging_cursemeta.dries007.net/api/v3/direct/addon/287323/files")
val con = url.openConnection() as HttpURLConnection
with(instance) {
val useragent = val useragent =
"MatterLink/$modVersion MinecraftForge/$mcVersion-$forgeVersion (https://github.com/elytra/MatterLink)" "MatterLink/$modVersion MinecraftForge/$mcVersion-$forgeVersion (https://github.com/elytra/MatterLink)"
logger.debug("setting User-Agent: '$useragent'") logger.debug("setting User-Agent: '$useragent'")
con.setRequestProperty("User-Agent", useragent)
"https://curse.nikky.moe/api/addon/287323/files".httpGet()
.header("User-Agent" to useragent)
.responseObject(kotlinxDeserializerOf(loader = CurseFile.serializer().list, json = JSON.nonstrict))
} }
con.connect() val apiUpdateList = when(result) {
is Result.Success -> {
val apiUpdateList = if (200 == con.responseCode) { //HTTP 200 OK result.value
val buffer: BufferedReader = con.inputStream.bufferedReader() }
is Result.Failure -> {
//put all of the buffer content onto the string logger.error("Could not check for updates!")
val content = buffer.readText() logger.error("cUrl: ${request.cUrlString()}")
logger.trace("updateData: $content") logger.error("request: $request")
logger.error("response: $response")
gson.fromJson(content, Array<CurseFile>::class.java) return
.filter { }
it.fileStatus == "SemiNormal" && it.gameVersion.contains(instance.mcVersion)
}
.sortedByDescending { it.fileName.substringAfterLast(" ") }
} else {
logger.error("Could not check for updates!")
return
} }
.filter { it.fileStatus == "SemiNormal" && it.gameVersion.contains(instance.mcVersion) }
val modVersionChunks = instance.modVersion val modVersionChunks = instance.modVersion
.substringBefore("-dev") .substringBefore("-dev")
@ -133,13 +124,13 @@ object UpdateChecker : CoroutineScope {
logger.info("Matterlink out of date! You are $count $version behind") logger.info("Matterlink out of date! You are $count $version behind")
possibleUpdates.forEach { possibleUpdates.forEach {
logger.info("version: ${it.fileName} download: ${it.downloadURL}") logger.info("version: ${it.fileName} download: ${it.downloadUrl}")
} }
logger.warn("Mod out of date! New $version available at ${latest.downloadURL}") logger.warn("Mod out of date! New $version available at ${latest.downloadUrl}")
MessageHandlerInst.transmit( MessageHandlerInst.transmit(
ApiMessage( ApiMessage(
text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}" text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadUrl}"
) )
) )
} }

View File

@ -4,7 +4,7 @@ java -jar forge-installer.jar --installServer
FORGE_FILE=`grep "The server installed successfully, you should now be able to run the file " forge-installer.jar.log | tail -1` FORGE_FILE=`grep "The server installed successfully, you should now be able to run the file " forge-installer.jar.log | tail -1`
FORGE_FILE=${FORGE_FILE#"The server installed successfully, you should now be able to run the file "} FORGE_FILE=${FORGE_FILE#"The server installed successfully, you should now be able to run the file "}
echo FORGE_FILE echo $FORGE_FILE
cp -f "$FORGE_FILE" forge.jar cp -f "$FORGE_FILE" forge.jar
if [ ! $? -eq 0 ]; then if [ ! $? -eq 0 ]; then