Verified Commit 82266228 authored by AtjonTV's avatar AtjonTV

Release 3.6.0

* Changed
  * Updates are now pulled directly from our gitlab server (better performance, less work and more secure)
Signed-off-by: AtjonTV's avatarAtjonTV <thomas.obernosterer@atvg-studios.com>
parent a38b7335
Pipeline #1986 passed with stages
in 1 minute and 24 seconds
......@@ -116,3 +116,4 @@ hs_err_pid*
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
ktlint
\ No newline at end of file
image: gradle:5.2.1-jdk8
stages:
- build
- test
- lint
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
- if [ ! -e ktlint ]; then curl -sSLO https://github.com/shyiko/ktlint/releases/download/0.31.0/ktlint && chmod a+x ktlint; fi
cache:
paths:
- .gradle/wrapper
- .gradle/caches
- ktlint
build:
stage: build
script:
- gradle build
- gradle shadowJar
artifacts:
paths:
- build/libs/*.jar
expire_in: 4 weeks
only:
refs:
- branches
test:
stage: test
script:
- gradle test
artifacts:
paths:
- build/reports/tests/test
lint:
stage: lint
script:
- ./ktlint "src/main/**/*.kt"
......@@ -13,7 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
### Security
[3.5.0] - 04.06.2019
## [3.6.0] - 09.06.2019
### Changed
- Updates are now pulled directly from our gitlab server (better performance, less work and more secure)
## [3.5.0] - 04.06.2019
### Added
* Added timed updates (Every minute / 60_000 milli seconds)
......@@ -26,14 +31,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed
* Removed call to `/i/:uuid` if the UUID was not found in the cache
[3.4.0] - 02.06.2019
## 3.4.0] - 02.06.2019
### Added
* Sending Plugin Version to remote for statistics
* Adding in '/aaab token <token>' command
* Implemented remote and refresh_limit usage
[3.3.0] - 01.06.2019
## [3.3.0] - 01.06.2019
### Added
* Config Engine using our custom Konfig format
......
GRADLE="./gradlew"
KTLINT="./ktlint"
all: lint compile package
compile:
$(GRADLE) build
package:
$(GRADLE) shadowJar
lint:
$(KTLINT) "src/main/**/*.kt" -F
test:
$(GRADLE) test
code-version:
find src/main/kotlin -name "*.kt" -type f -exec sed -i 's/<NEXT_VERSION>/$(VERSION)/g' {} \;
sed -i 's/<NEXT_VERSION>/$(VERSION)/g' build.gradle Compatibility.md maven/**
buildscript {
ext.klib_version = '2.1.1'
ext.klib_version = '3.0.1'
ext.fuel_version = '2.1.0'
ext.gson_version = '2.8.5'
ext.spigot_version = '1.13.2'
ext.cosnix_version = '0.4.3'
ext.gitlab_version = '4.11.7'
}
plugins {
......@@ -12,7 +13,7 @@ plugins {
}
group 'com.atvgstudios'
version '3.5.0'
version '3.6.0'
repositories {
mavenCentral()
......@@ -30,6 +31,7 @@ dependencies {
implementation "com.atvgstudios:klib:$klib_version"
implementation "com.atvgstudios.cosnixdb:cosnixdb:$cosnix_version"
implementation "org.spigotmc:spigot:$spigot_version"
implementation "org.gitlab4j:gitlab4j-api:$gitlab_version"
}
compileKotlin {
......
#!/bin/bash
echo $(pwd)
if [ ! -e ktlint ]
then
curl -SLO https://github.com/shyiko/ktlint/releases/download/0.31.0/ktlint
chmod a+x ktlint
fi
\ No newline at end of file
......@@ -38,7 +38,6 @@ object Config {
fun getString(key: String): String {
if (configs.isNotEmpty() && key in configs) {
return configs[key] as String
}
return ""
}
......@@ -46,7 +45,6 @@ object Config {
fun getInt(key: String): Int {
if (configs.isNotEmpty() && key in configs) {
return Integer.parseInt(configs[key] as String)
}
return -1
}
......@@ -54,7 +52,6 @@ object Config {
fun getBoolean(key: String): Boolean {
if (configs.isNotEmpty() && key in configs) {
return (configs[key] as String).toBoolean()
}
return false
}
......
......@@ -6,18 +6,19 @@ import com.atvgstudios.cosnixdb.CosnixDB
import com.google.gson.Gson
import klib.interfaces.Json
import klib.kLibInf
import org.bukkit.Bukkit
import klib.types.SemVer
import org.bukkit.plugin.java.JavaPlugin
import java.lang.reflect.Type
import java.util.*
import java.util.Timer
import java.util.TimerTask
class Plugin : JavaPlugin() {
companion object {
var version: String = "3.5.0"
val prefix = "AAAB-v3 »"
val version = SemVer(3, 6, 0)
const val prefix = "AAAB-v3 »"
}
val t = Timer()
private val timer = Timer()
override fun onEnable() {
Console.log("Initializing AAAB-v3 [Running: $version]")
......@@ -31,8 +32,6 @@ class Plugin : JavaPlugin() {
server.pluginManager.registerEvents(Listener(), this)
getCommand("aaab")?.setExecutor(Commands())
version = Bukkit.getServer().pluginManager.getPlugin("AAAB-v3")?.description?.version ?: version
Console.log("Initialized AAAB-v3!")
Updater.update()
......@@ -43,7 +42,7 @@ class Plugin : JavaPlugin() {
}
fun timedUpdate() {
t.scheduleAtFixedRate(object : TimerTask() {
timer.scheduleAtFixedRate(object : TimerTask() {
override fun run() {
Console.log("Running timed update ..")
Updater.update()
......@@ -52,7 +51,7 @@ class Plugin : JavaPlugin() {
}
override fun onDisable() {
t.cancel()
timer.cancel()
}
private fun createkLibJsonHandler() {
......
package com.atvgstudios.aaab
import com.github.kittinunf.fuel.Fuel
import klib.extensions.Sha1Checksum
import com.atvgstudios.aaab.db.CacheDB
import com.atvgstudios.cosnixdb.CosnixDB
import klib.extensions.toFile
import klib.objects.Konfig
import klib.types.SemVer
import org.bukkit.Bukkit
import org.gitlab4j.api.GitLabApi
import java.io.File
import java.net.URL
import java.net.URI
object Updater {
val SoftwareID = "56e5b4f5"
val SoftwareKey = "aaab_plugin"
private val indexFile = File.createTempFile("atvg-studios_software-index", ".konf")
private val updatedFile = File.createTempFile("atvg-studios_software-update", ".jar")
val artifactURI = "https://gitlab.atvg-studios.at/api/v4/projects/125/jobs/artifacts/master/raw/build/libs/aaab-{ver}-all.jar?job=build"
private val updatedFile = createTempFile()
private val cosnixDB = CosnixDB(CacheDB.DATABASE_KEY)
private var filePath = "/aaab-plugin"
private var fileSig = ""
private var fileVersion = ""
fun getIndex() {
Console.log("Updating version index from Update-Server")
val f = Fuel.get("https://software.atvg-studios.com/index")
.responseString()
val indexContent = f.third.component1() ?: ""
val partialIndexContent = indexContent.split("\n")
val newIndexContent = StringBuilder()
partialIndexContent.forEach {
if (it != "") {
newIndexContent.appendln(it)
}
}
// Write to index cache file
indexFile.writeText(newIndexContent.toString())
private fun downloadFile(uri: String, file: File) {
println("Begin download of $uri")
URI(uri).toURL().openStream().toFile(file)
}
private fun internalCheckUpdate(): Boolean {
val indexSettings = Konfig.parseFile(indexFile)
return if (indexSettings["$SoftwareKey.id"] == SoftwareID) {
filePath = indexSettings["$SoftwareKey.path"] as String
fileSig = indexSettings["$SoftwareKey.sig"] as String
fileVersion = indexSettings["$SoftwareKey.version"] as String
val indexVersion = SemVer.parse("$fileVersion-r1+0")
val liveVersion = SemVer.parse("${Plugin.version}-r1+0")
fun checkUpdate() {
println("Checking for available Updates.")
val gitlab = GitLabApi("https://gitlab.atvg-studios.at/", "")
val tags = gitlab.tagsApi.getTags("125")
if (indexVersion > liveVersion) {
return true
}
false
} else {
false
}
}
val latestVersion = SemVer.parse(tags[0].name.replaceFirst("v", ""))
fun checkUpdate() {
Console.log("Checking for available Updates.")
if (internalCheckUpdate()) {
Console.log("Update available! (Running: ${Plugin.version}, Available: $fileVersion)")
if (latestVersion > Plugin.version) {
Console.log("Update available! (Running: ${Plugin.version}, Available: $latestVersion)")
} else {
Console.log("No Update Available! (Running: ${Plugin.version}, Available: $fileVersion)")
Console.log("No Update Available! (Running: ${Plugin.version}, Available: $latestVersion)")
}
}
fun getUpdate() {
if (internalCheckUpdate()) {
Console.log("Updating! (Running: ${Plugin.version}, Available: $fileVersion)")
Console.log("Downloading $fileVersion from Update-Server.")
URL("https://software.atvg-studios.com$filePath/$SoftwareID-$fileVersion-$fileSig.jar").openStream()
.toFile(updatedFile)
fun actualUpdate() {
println("Checking for available Updates.")
val gitlab = GitLabApi("https://gitlab.atvg-studios.at/", "")
val tags = gitlab.tagsApi.getTags("125")
Console.log("Downloaded $fileVersion, checking Sig!")
val latestVersion = SemVer.parse(tags[0].name.replaceFirst("v", ""))
if (updatedFile.Sha1Checksum() == fileSig) {
Console.log("Verified file Sig successfully!")
if (latestVersion > Plugin.version) {
Console.log("Updating! (Running: ${Plugin.version}, Available: $latestVersion)")
println("Downloading $latestVersion from GitLab-Server.")
val file = File("plugins/aaab-$fileVersion.jar")
if (file.exists()) file.delete()
downloadFile(
artifactURI.replace("{ver}", latestVersion.toString()),
updatedFile
)
val file = File("plugins/aaab-$latestVersion.jar")
if (file.exists()) file.delete()
Console.log("Installing new plugin $fileVersion")
updatedFile.copyTo(file)
Console.log("Installing new plugin $latestVersion")
updatedFile.copyTo(file)
Console.log("Removing old plugin ${Plugin.version}")
val oldFile = File("plugins/aaab-${Plugin.version}.jar")
val oldFile2 = File("plugins/aaab.jar")
if (oldFile.exists()) oldFile.delete()
if (oldFile2.exists()) oldFile2.delete()
Console.log("Removing old plugin ${Plugin.version}")
val oldFile = File("plugins/aaab-${Plugin.version}.jar")
val oldFile2 = File("plugins/aaab.jar")
if (oldFile.exists()) oldFile.delete()
if (oldFile2.exists()) oldFile2.delete()
Console.log("Reloading Server")
Bukkit.getServer().reload()
Console.log("Finished Installation of AAAB Update!")
} else {
Console.log("Cannot confirm file Sig. Aborting Update!")
return
}
Console.log("Reloading Server")
Bukkit.getServer().reload()
Console.log("Finished Installation of AAAB Update!")
} else {
Console.log("No Update Available! (Running: ${Plugin.version}, Available: $latestVersion)")
}
}
fun update() {
getIndex()
checkUpdate()
if (Config.getBoolean("updates")) {
getUpdate()
actualUpdate()
} else {
checkUpdate()
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment