-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.gradle.kts
222 lines (190 loc) · 6.18 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider
import aws.sdk.kotlin.services.s3.S3Client
import aws.sdk.kotlin.services.s3.model.PutObjectRequest
import aws.smithy.kotlin.runtime.content.asByteStream
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import kotlinx.coroutines.runBlocking
import org.jetbrains.kotlin.daemon.common.toHexString
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import java.security.MessageDigest
import kotlin.io.path.fileSize
val mainClass = "net.rsprox.gui.ProxyToolGuiKt"
val s3Bucket = "cdn.rsprox.net"
plugins {
alias(libs.plugins.kotlin.jvm)
`maven-publish`
}
allprojects {
apply(plugin = "maven-publish")
group = "net.rsprox"
version = "1.0"
repositories {
mavenCentral()
maven("https://repo.openrs2.org/repository/openrs2-snapshots/")
maven("https://maven.runelab.io/snapshots/")
}
tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
plugins.withType<KotlinPluginWrapper> {
dependencies {
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(11)
explicitApi()
}
}
afterEvaluate {
publishing {
repositories {
maven {
url = uri("s3://$s3Bucket/maven")
credentials(AwsCredentials::class.java) {
accessKey = System.getenv("AWS_ACCESS_KEY_ID")
secretKey = System.getenv("AWS_SECRET_ACCESS_KEY")
}
}
}
}
}
}
subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
}
dependencies {
runtimeOnly(projects.gui.proxyTool)
runtimeOnly(projects.proxy)
}
buildscript {
dependencies {
classpath(libs.bundles.jackson)
classpath(libs.aws.sdk.kotlin.s3)
classpath(libs.jaxb.api) // s3 maven-publish dependency
}
}
data class Bootstrap(
val proxy: Proxy,
val artifacts: List<Artifact>,
)
data class Proxy(
val version: String,
val mainClass: String
)
data class Artifact(
val name: String,
val path: String,
val size: Long,
val hash: String,
)
fun sha256Hash(bytes: ByteArray): String {
val messageDigest = MessageDigest.getInstance("SHA-256")
messageDigest.update(bytes)
return messageDigest.digest().toHexString()
}
suspend fun uploadToS3(
s3Client: S3Client,
file: File,
s3Path: String,
): Artifact {
val request =
PutObjectRequest {
bucket = s3Bucket
key = s3Path
body = file.asByteStream()
}
s3Client.putObject(request)
println("Uploaded $file to s3://$s3Bucket/dependencies/$s3Path")
return Artifact(
file.name,
"https://$s3Bucket/$s3Path",
file.toPath().fileSize(),
sha256Hash(file.readBytes()),
)
}
tasks.register("uploadJarsToS3") {
doLast {
val outputFile = file("bootstrap.json")
val project = project(":gui")
val artifacts = mutableListOf<Artifact>()
val projectArtifacts =
project.configurations.runtimeClasspath
.get()
.resolvedConfiguration
.resolvedArtifacts
runBlocking {
S3Client
.fromEnvironment {
region = "eu-west-1"
credentialsProvider = EnvironmentCredentialsProvider()
}.use { s3 ->
for (artifact in projectArtifacts) {
if (artifact.type != "jar") continue
val group =
artifact.moduleVersion.id.group
.replace('.', '/')
val version = artifact.moduleVersion.id.version
val jarFile = artifact.file
val prefix = "dependencies/$group/${artifact.name}/$version/"
artifacts += uploadToS3(s3, jarFile, "$prefix${jarFile.name}")
}
}
}
val bootstrap = Bootstrap(
proxy = Proxy(version = project.version.toString(), mainClass = mainClass),
artifacts = artifacts.sortedBy { it.name },
)
println("Uploaded ${artifacts.size} artifacts to S3")
outputFile.writeText(jacksonObjectMapper().writeValueAsString(bootstrap))
}
}
tasks.create<JavaExec>("proxy") {
environment("APP_VERSION", project.version)
group = "run"
classpath = sourceSets["main"].runtimeClasspath
mainClass.set(mainClass)
}
tasks.create<JavaExec>("download") {
environment("APP_VERSION", project.version)
group = "run"
classpath = sourceSets["main"].runtimeClasspath
mainClass.set("net.rsprox.proxy.cli.ClientDownloadCommandKt")
}
tasks.create<JavaExec>("tostring") {
environment("APP_VERSION", project.version)
group = "run"
classpath = sourceSets["main"].runtimeClasspath
mainClass.set("net.rsprox.proxy.cli.BinaryToStringCommandKt")
}
tasks.create<JavaExec>("transcribe") {
environment("APP_VERSION", project.version)
group = "run"
classpath = sourceSets["main"].runtimeClasspath
mainClass.set("net.rsprox.proxy.cli.TranscribeCommandKt")
}
tasks.create<JavaExec>("index") {
environment("APP_VERSION", project.version)
group = "run"
classpath = sourceSets["main"].runtimeClasspath
mainClass.set("net.rsprox.proxy.cli.IndexerCommandKt")
}
tasks.create<JavaExec>("patch") {
environment("APP_VERSION", project.version)
group = "run"
classpath = sourceSets["main"].runtimeClasspath
mainClass.set("net.rsprox.proxy.cli.ClientPatcherCommandKt")
}
// fixes some weird error with "Entry classpath.index is a duplicate but no duplicate handling strategy has been set"
// see https://github.com/gradle/gradle/issues/17236
gradle.taskGraph.whenReady {
val duplicateTasks =
allTasks
.filter { it.hasProperty("duplicatesStrategy") }
for (task in duplicateTasks) {
task.setProperty("duplicatesStrategy", "EXCLUDE")
}
}