Initial commit

This commit is contained in:
2022-01-08 19:46:18 +01:00
commit 57ba5a5858
207 changed files with 12402 additions and 0 deletions

43
buildSrc/build.gradle.kts Normal file
View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2019 Owain van Brakel <https://github.com/Owain94>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
plugins {
`kotlin-dsl`
}
repositories {
jcenter()
}
dependencies {
implementation(gradleApi())
implementation(group = "org.json", name = "json", version = "20190722")
implementation(group = "com.savvasdalkitsis", name = "json-merge", version = "0.0.4")
implementation(group = "com.squareup.okhttp3", name = "okhttp", version = "4.2.2")
}
kotlinDslPluginOptions {
experimentalWarning.set(false)
}

View File

@ -0,0 +1,9 @@
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.register
class BootstrapPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.tasks.register<BootstrapTask>("bootstrapPlugins") {}
}
}

View File

@ -0,0 +1,97 @@
import com.savvasdalkitsis.jsonmerger.JsonMerger
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.get
import org.json.JSONArray
import org.json.JSONObject
import java.io.File
import java.nio.file.Paths
import java.security.MessageDigest
import java.text.SimpleDateFormat
import java.util.*
open class BootstrapTask : DefaultTask() {
private fun formatDate(date: Date?) = with(date ?: Date()) {
SimpleDateFormat("yyyy-MM-dd").format(this)
}
private fun hash(file: ByteArray): String {
return MessageDigest.getInstance("SHA-512").digest(file).fold("", { str, it -> str + "%02x".format(it) }).toUpperCase()
}
private fun getBootstrap(filename: String): JSONArray? {
val bootstrapFile = File(filename).readLines()
return JSONObject("{\"plugins\":$bootstrapFile}").getJSONArray("plugins")
}
@TaskAction
fun boostrap() {
if (project == project.rootProject) {
val bootstrapDir = File("${project.projectDir}")
val bootstrapReleaseDir = File("${project.projectDir}/release")
bootstrapReleaseDir.mkdirs()
val plugins = ArrayList<JSONObject>()
val baseBootstrap = getBootstrap("$bootstrapDir/plugins.json") ?: throw RuntimeException("Base bootstrap is null!")
project.subprojects.forEach {
if (it.project.properties.containsKey("PluginName") && it.project.properties.containsKey("PluginDescription")) {
var pluginAdded = false
val plugin = it.project.tasks["jar"].outputs.files.singleFile
val releases = ArrayList<JsonBuilder>()
releases.add(JsonBuilder(
"version" to it.project.version,
"requires" to ProjectVersions.apiVersion,
"date" to formatDate(Date()),
"url" to "${project.rootProject.extra.get("GithubUrl")}/blob/master/release/${it.project.name}-${it.project.version}.jar?raw=true",
"sha512sum" to hash(plugin.readBytes())
))
val pluginObject = JsonBuilder(
"name" to it.project.extra.get("PluginName"),
"id" to nameToId(it.project.extra.get("PluginName") as String),
"description" to it.project.extra.get("PluginDescription"),
"provider" to it.project.extra.get("PluginProvider"),
"projectUrl" to it.project.extra.get("ProjectSupportUrl"),
"releases" to releases.toTypedArray()
).jsonObject()
for (i in 0 until baseBootstrap.length()) {
val item = baseBootstrap.getJSONObject(i)
if (item.get("id") != nameToId(it.project.extra.get("PluginName") as String)) {
continue
}
if (it.project.version.toString() in item.getJSONArray("releases").toString()) {
pluginAdded = true
plugins.add(item)
break
}
plugins.add(JsonMerger(arrayMergeMode = JsonMerger.ArrayMergeMode.MERGE_ARRAY).merge(item, pluginObject))
pluginAdded = true
}
if (!pluginAdded)
{
plugins.add(pluginObject)
}
plugin.copyTo(Paths.get(bootstrapReleaseDir.toString(), "${it.project.name}-${it.project.version}.jar").toFile())
}
}
File(bootstrapDir, "plugins.json").printWriter().use { out ->
out.println(plugins.toString())
}
}
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2019 Owain van Brakel <https://github.com/Owain94>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
object ProjectVersions {
const val openosrsVersion = "4.17.0"
const val apiVersion = "^1.0.0"
}
object Libraries {
private object Versions {
const val apacheCommonsText = "1.9"
const val gson = "2.8.8"
const val guice = "5.0.1"
const val javax = "1.3.2"
const val lombok = "1.18.22"
const val okhttp3 = "4.9.0"
const val pf4j = "3.6.0"
const val findbugs = "3.0.1"
const val rxjava = "3.1.3"
const val slf4j = "2.0.0-alpha5"
}
const val apacheCommonsText = "org.apache.commons:commons-text:${Versions.apacheCommonsText}"
const val gson = "com.google.code.gson:gson:${Versions.gson}"
const val guice = "com.google.inject:guice:${Versions.guice}"
const val javax = "javax.annotation:javax.annotation-api:${Versions.javax}"
const val lombok = "org.projectlombok:lombok:${Versions.lombok}"
const val okhttp3 = "com.squareup.okhttp3:okhttp:${Versions.okhttp3}"
const val pf4j = "org.pf4j:pf4j:${Versions.pf4j}"
const val findbugs = "com.google.code.findbugs:jsr305:${Versions.findbugs}"
const val rxjava = "io.reactivex.rxjava3:rxjava:${Versions.rxjava}"
const val slf4j = "org.slf4j:slf4j-api:${Versions.slf4j}"
}

View File

@ -0,0 +1,57 @@
import org.json.JSONArray
import org.json.JSONObject
class JsonBuilder() {
private var json = JSONObject()
constructor(vararg pairs: Pair<String, *>) : this() {
add(*pairs)
}
fun add(vararg pairs: Pair<String, *>) {
for ((key, value) in pairs) {
when (value) {
is Boolean -> json.put(key, value)
is Number -> add(key, value)
is String -> json.put(key, value)
is JsonBuilder -> json.put(key, value.json)
is Array<*> -> add(key, value)
is JSONObject -> json.put(key, value)
is JSONArray -> json.put(key, value)
}
}
}
fun add(key: String, value: Number): JsonBuilder {
when (value) {
is Int -> json.put(key, value)
is Long -> json.put(key, value)
is Float -> json.put(key, value)
is Double -> json.put(key, value)
else -> {}
}
return this
}
fun <T> add(key: String, items: Array<T>): JsonBuilder {
val jsonArray = JSONArray()
items.forEach {
when (it) {
is String,is Long,is Int, is Boolean -> jsonArray.put(it)
is JsonBuilder -> jsonArray.put(it.json)
else -> try {jsonArray.put(it)} catch (ignored:Exception) {
}
}
}
json.put(key, jsonArray)
return this
}
fun jsonObject() = json
override fun toString() = json.toString()
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2019 Owain van Brakel <https://github.com/Owain94>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
fun nameToId(name: String): String {
return name.replace("[^A-Za-z]".toRegex(), "").toLowerCase() + "-plugin"
}