forked from rlf/XRayHunter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
247 lines (227 loc) · 10.3 KB
/
Copy pathbuild.gradle
File metadata and controls
247 lines (227 loc) · 10.3 KB
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import org.apache.tools.ant.filters.ReplaceTokens
import java.util.zip.ZipFile
plugins {
id 'java'
}
def pluginName = '1MB-XRayHunter'
def javaTarget = 25
def paperApiTarget = '26.2'
def paperApiBuild = 84
def paperApiChannel = 'stable'
def paperApiCompileVersion = "${paperApiTarget}.build.${paperApiBuild}-${paperApiChannel}"
def pluginApiVersion = '26.2'
def targetCoreProtectVersion = '24.0-dev1'
def fallbackCoreProtectVersion = '23.4'
def localCompileSupportRoot = file('.gradle/compile-support')
def localCoreProtectJar = new File(localCompileSupportRoot, 'CoreProtect-24.0-dev1.jar')
def centralizedPaperTestServerRoot = file(System.getenv('CODEX_SHARED_SERVERS_ROOT') ?: '../servers')
// Prefer an ignored local compile-cache copy first because some Gradle/sandbox combinations cannot
// inspect the centralized cache path directly during dependency resolution.
// This project must not depend on a repo-local /servers/ folder.
def sharedCoreProtectJarCandidates = [
localCoreProtectJar,
new File(centralizedPaperTestServerRoot, 'cache/Paper-26.2/plugins/CoreProtect-24.0-dev1.jar')
]
def sharedCoreProtectJar = sharedCoreProtectJarCandidates.find { candidate ->
candidate.isFile() && candidate.canRead()
}
def versionPropertiesFile = file('version.properties')
def versionProperties = new Properties()
if (versionPropertiesFile.exists()) {
versionPropertiesFile.withInputStream { stream ->
versionProperties.load(stream)
}
}
def pluginVersion = versionProperties.getProperty('pluginVersion', '2.0.0')
def currentBuildNumber = Integer.parseInt(versionProperties.getProperty('buildNumber', '011'))
def nextBuildNumber = currentBuildNumber + 1
def buildNumber = String.format('%03d', nextBuildNumber)
def pluginBuildVersion = "${pluginVersion}-${buildNumber}-j${javaTarget}-${paperApiTarget}"
def expectedJarName = "${pluginName}-v${pluginBuildVersion}.jar"
group = 'dk.lockfuglsang'
version = pluginBuildVersion
java {
toolchain.languageVersion = JavaLanguageVersion.of(javaTarget)
}
repositories {
mavenCentral()
maven {
name = 'papermc'
url = uri('https://repo.papermc.io/repository/maven-public/')
}
maven {
name = 'playpro'
url = uri('https://maven.playpro.com/')
}
}
dependencies {
compileOnly("io.papermc.paper:paper-api:${paperApiCompileVersion}")
compileOnly("org.jspecify:jspecify:1.0.0")
if (sharedCoreProtectJar != null) {
logger.lifecycle("Using shared CoreProtect compile jar: ${sharedCoreProtectJar}")
compileOnly(files(sharedCoreProtectJar.absoluteFile))
} else {
logger.lifecycle("Shared CoreProtect 24 compile jar not found, falling back to Maven CoreProtect ${fallbackCoreProtectVersion} for local build resilience.")
compileOnly("net.coreprotect:coreprotect:${fallbackCoreProtectVersion}")
}
}
processResources {
inputs.properties([
pluginName : pluginName.toString(),
pluginVersion : pluginVersion.toString(),
buildNumber : buildNumber.toString(),
version : version.toString(),
javaTarget : javaTarget.toString(),
paperApiTarget : paperApiTarget.toString(),
paperApiCompileVersion : paperApiCompileVersion.toString(),
pluginApiVersion : pluginApiVersion.toString(),
targetCoreProtectVersion: targetCoreProtectVersion.toString()
])
filteringCharset = 'UTF-8'
filesMatching(['plugin.yml', 'build-info.properties']) {
filter ReplaceTokens, tokens: [
pluginName : pluginName.toString(),
pluginVersion : pluginVersion.toString(),
buildNumber : buildNumber.toString(),
version : version.toString(),
javaTarget : javaTarget.toString(),
paperApiTarget : paperApiTarget.toString(),
paperApiCompileVersion : paperApiCompileVersion.toString(),
pluginApiVersion : pluginApiVersion.toString(),
targetCoreProtectVersion: targetCoreProtectVersion.toString()
]
}
}
tasks.withType(JavaCompile).configureEach {
options.release = javaTarget
options.compilerArgs += ['-Xlint:deprecation']
}
tasks.jar {
archiveFileName.set(expectedJarName)
doLast {
versionPropertiesFile.text = """# Updated after a successful jar build.
pluginVersion=${pluginVersion}
buildNumber=${buildNumber}
"""
}
}
tasks.register('verifyReleaseMetadata') {
group = 'verification'
description = 'Checks generated release metadata and documentation for version drift.'
dependsOn tasks.processResources
doLast {
if (!(pluginVersion ==~ /\d+\.\d+\.\d+/)) {
throw new GradleException("pluginVersion must be semantic x.y.z, found: ${pluginVersion}")
}
if (!(buildNumber ==~ /\d{3}/)) {
throw new GradleException("buildNumber must use three digits, found: ${buildNumber}")
}
if (pluginApiVersion != paperApiTarget) {
throw new GradleException("plugin api-version ${pluginApiVersion} does not match Paper target ${paperApiTarget}")
}
if (paperApiChannel != 'stable') {
throw new GradleException("Paper API channel must be stable, found: ${paperApiChannel}")
}
def generatedPluginYaml = layout.buildDirectory.file('resources/main/plugin.yml').get().asFile.text
def generatedBuildInfo = layout.buildDirectory.file('resources/main/build-info.properties').get().asFile.text
[
"version: ${pluginBuildVersion}",
"api-version: '${pluginApiVersion}'",
"Paper API ${paperApiCompileVersion}",
"Java ${javaTarget}"
].each { expected ->
if (!generatedPluginYaml.contains(expected)) {
throw new GradleException("Generated plugin.yml is missing: ${expected}")
}
}
[
"plugin-version=${pluginVersion}",
"build-number=${buildNumber}",
"full-version=${pluginBuildVersion}",
"java-target=${javaTarget}",
"paper-api-target=${paperApiTarget}",
"paper-api-compile-version=${paperApiCompileVersion}",
"plugin-api-version=${pluginApiVersion}"
].each { expected ->
if (!generatedBuildInfo.contains(expected)) {
throw new GradleException("Generated build-info.properties is missing: ${expected}")
}
}
def maintainedReleaseDocs = [
file('README.md'),
file('docs/installation.md'),
file('docs/integrations.md'),
file('docs/player-guide.md')
]
def coordinatePattern = ~/26\.2\.build\.\d+-(?:alpha|beta|stable)/
maintainedReleaseDocs.each { releaseDoc ->
def coordinates = (releaseDoc.text =~ coordinatePattern).findAll()
coordinates.each { coordinate ->
if (coordinate != paperApiCompileVersion) {
throw new GradleException("${releaseDoc} contains stale Paper API coordinate ${coordinate}")
}
}
}
def docsManifest = file('docs/plugin-docs.yml').text
[
"java_target: ${javaTarget}",
"paper_target: ${paperApiTarget}",
"paper_api: ${paperApiCompileVersion}",
"paper_build: ${paperApiBuild}",
"paper_channel: ${paperApiChannel.toUpperCase(Locale.ROOT)}"
].each { expected ->
if (!docsManifest.contains(expected)) {
throw new GradleException("docs/plugin-docs.yml is missing: ${expected}")
}
}
}
}
tasks.register('verifyReleaseJar') {
group = 'verification'
description = 'Checks the release jar name, embedded metadata, and Java bytecode target.'
dependsOn tasks.jar
dependsOn tasks.named('verifyReleaseMetadata')
doLast {
def jarFile = tasks.jar.archiveFile.get().asFile
if (jarFile.name != expectedJarName) {
throw new GradleException("Unexpected jar name ${jarFile.name}; expected ${expectedJarName}")
}
new ZipFile(jarFile).withCloseable { zip ->
def pluginYaml = zip.getInputStream(zip.getEntry('plugin.yml')).getText('UTF-8')
def buildInfo = zip.getInputStream(zip.getEntry('build-info.properties')).getText('UTF-8')
if (!pluginYaml.contains("version: ${pluginBuildVersion}")
|| !pluginYaml.contains("api-version: '${pluginApiVersion}'")) {
throw new GradleException('Embedded plugin.yml release metadata is stale')
}
if (!buildInfo.contains("paper-api-compile-version=${paperApiCompileVersion}")
|| !buildInfo.contains("java-target=${javaTarget}")) {
throw new GradleException('Embedded build-info.properties release metadata is stale')
}
def expectedClassMajor = javaTarget + 44
def classEntries = zip.entries().findAll { entry -> entry.name.endsWith('.class') }
if (classEntries.isEmpty()) {
throw new GradleException('Release jar contains no class files')
}
classEntries.each { entry ->
zip.getInputStream(entry).withCloseable { input ->
byte[] header = input.readNBytes(8)
int classMajor = ((header[6] & 0xff) << 8) | (header[7] & 0xff)
if (classMajor != expectedClassMajor) {
throw new GradleException("${entry.name} has class major ${classMajor}; expected ${expectedClassMajor}")
}
}
}
}
def persistedVersionProperties = new Properties()
versionPropertiesFile.withInputStream { stream ->
persistedVersionProperties.load(stream)
}
if (persistedVersionProperties.getProperty('pluginVersion') != pluginVersion
|| persistedVersionProperties.getProperty('buildNumber') != buildNumber) {
throw new GradleException('version.properties does not match the successfully built release')
}
}
}
tasks.named('check') {
dependsOn tasks.named('verifyReleaseJar')
}