-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathbuild.gradle
More file actions
311 lines (248 loc) · 8.57 KB
/
Copy pathbuild.gradle
File metadata and controls
311 lines (248 loc) · 8.57 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
buildscript {
repositories { mavenCentral() }
dependencies {
// used at configuration-time for version info
classpath 'org.eclipse.jgit:org.eclipse.jgit:5.7.+'
}
}
plugins {
id 'java'
id 'antlr'
id 'eclipse'
id 'idea'
id 'jacoco'
id 'maven-publish'
id 'com.gradleup.shadow' version '9.2.2'
id 'de.undercouch.download' version '5.6.0'
}
import de.undercouch.gradle.tasks.download.Download
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.ObjectId
import java.util.regex.Pattern
ext.mainClassName = "de.peeeq.wurstio.Main"
version = "1.9.0.0"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}
tasks.withType(JavaCompile).configureEach { options.release = 25 }
jacoco {
toolVersion = "0.8.13"
}
jacocoTestReport {
dependsOn test
reports { xml.required.set(true) }
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
'**/ast/**', '**/jassAst/**', '**/jassIm/**', '**/luaAst/**', '**/antlr/**'
])
}))
}
}
def genDir = "$projectDir/src-gen"
sourceSets {
main {
java.srcDir(genDir)
}
}
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://jitpack.io' }
}
configurations {
// isolated classpath for the generator
astgen
}
dependencies {
implementation 'org.jetbrains:annotations:23.0.0'
// Antlr
antlr "org.antlr:antlr4:4.13.1"
// abstractsyntaxgen (available to IDE via compileOnly; used at runtime via astgen)
compileOnly 'com.github.peterzeller:abstractsyntaxgen:623da1c60f'
astgen 'com.github.peterzeller:abstractsyntaxgen:623da1c60f'
// Tests
testImplementation 'org.testng:testng:7.11.0'
testImplementation 'org.hamcrest:hamcrest-all:1.3'
// Libs
implementation 'com.google.guava:guava:32.1.3-jre'
implementation 'io.vavr:vavr:0.10.7'
implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j:0.24.0'
implementation 'org.eclipse.jdt:org.eclipse.jdt.annotation:2.1.0'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'org.apache.velocity:velocity:1.7'
implementation 'com.github.albfernandez:juniversalchardet:2.4.0'
implementation 'com.github.inwc3:jmpq3:29b55f2c32'
implementation 'com.github.inwc3:wc3libs:bab65b961b'
implementation 'com.github.wurstscript:wurstsetup:393cf5ea39'
implementation 'org.slf4j:slf4j-api:2.0.17'
implementation 'ch.qos.logback:logback-classic:1.5.20'
implementation 'org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r'
implementation 'org.eclipse.jgit:org.eclipse.jgit.ssh.apache:6.7.0.202309050840-r'
implementation 'it.unimi.dsi:fastutil:8.5.16'
// Smallcheck
testImplementation 'com.github.peterzeller:java-smallcheck:3f6a178ba7'
}
configurations.configureEach {
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j"
}
/** -------- AST generation (abstractsyntaxgen) -------- */
def parseqFiles = fileTree(dir: 'parserspec', include: '*.parseq')
def pkgPattern = Pattern.compile(/package\s+(\S+)\s*;/)
tasks.register('genAst') {
// make it incremental/cacheable
inputs.files(parseqFiles)
outputs.dir(genDir)
doLast {
// fetch ExecOperations from Gradle services (no @Inject needed)
ExecOperations execOps = project.services.get(ExecOperations)
parseqFiles.files.each { File f ->
String contents = f.getText('UTF-8')
def m = pkgPattern.matcher(contents)
String pkg = m.find() ? m.group(1) : ""
File targetDir = file("$genDir/${pkg.replace('.', '/')}")
targetDir.mkdirs()
// run: asg.Main <file> <targetDir> using isolated classpath
execOps.javaexec {
classpath = configurations.astgen
mainClass.set('asg.Main')
args(f.absolutePath, targetDir.absolutePath)
}
}
}
}
/** -------- Version info file generation -------- */
tasks.register('versionInfoFile') {
description "Generates a file CompileTimeInfo.java with version number etc."
// resolve git info at configuration time
Git git = Git.open(new File(rootProject.projectDir, '..'))
ObjectId head = git.getRepository().resolve(Constants.HEAD)
String gitRevision = head.abbreviate(8).name()
String gitRevisionlong = head.getName()
String tag = git.describe().setTarget(head).setAlways(true).setTags(true).call()
String wurstVersion = "${version}-${tag}"
inputs.property("wurstVersion", wurstVersion)
def dir = new File("$genDir/de/peeeq/wurstscript/")
def out = new File(dir, 'CompileTimeInfo.java')
outputs.file(out)
doLast {
dir.mkdirs()
String currentTime = new Date().format("yyyy/MM/dd KK:mm:ss")
out.text = """
package de.peeeq.wurstscript;
public class CompileTimeInfo {
public static final String time="${currentTime}";
public static final String revision="${gitRevision}";
public static final String revisionLong="${gitRevisionlong}";
public static final String version="${wurstVersion}";
}
"""
}
}
/** -------- Aggregate generation + wiring into compile -------- */
tasks.register('gen') {
description "Generates code from various input files"
dependsOn 'genAst', 'versionInfoFile', 'generateGrammarSource'
}
tasks.named('compileJava') { it.dependsOn('gen') }
/** -------- Tests -------- */
test {
useTestNG()
jvmArgs(
'-Xmx2g', // local: give it room to finish and dump
'-XX:MaxMetaspaceSize=256m',
'-XX:+HeapDumpOnOutOfMemoryError',
)
}
/** -------- Clean generated sources -------- */
tasks.named('clean') {
doFirst { delete genDir }
}
/** -------- Download helpers -------- */
tasks.register('downloadZipFile', Download) {
src 'https://github.com/wurstscript/wurstStdlib2/archive/master.zip'
dest new File(buildDir, 'stdlib2.zip')
}
tasks.register('downloadAndUnzipFile', Copy) {
dependsOn 'downloadZipFile'
from zipTree(tasks.named('downloadZipFile').get().dest)
into new File(buildDir, '/deps/')
}
/** -------- Shadow / packaging -------- */
shadowJar {
archiveBaseName.set('wurstscript')
archiveClassifier.set('')
archiveVersion.set('')
manifest {
attributes 'Main-Class': mainClassName
}
}
def fatJar = shadowJar.archiveFile.map { it.asFile }
tasks.register('make_for_userdir', Copy) {
dependsOn 'shadowJar'
from fatJar
into "${System.properties['user.home']}/.wurst/"
}
tasks.register('make_for_wurstpack', Copy) {
dependsOn 'shadowJar'
from fatJar
into '../Wurstpack/wurstscript/'
}
tasks.register('create_zip_wurstpack_complete', Zip) {
dependsOn 'make_for_wurstpack'
from '../Wurstpack'
archiveFileName.set('wurstpack_complete.zip')
}
tasks.register('create_zip_wurstpack_compiler', Zip) {
dependsOn 'make_for_wurstpack'
from '../Wurstpack/wurstscript/'
archiveFileName.set('wurstpack_compiler.zip')
}
tasks.register('create_zips') {
dependsOn 'shadowJar', 'create_zip_wurstpack_complete', 'create_zip_wurstpack_compiler'
doLast {
ExecOperations execOps = project.services.get(ExecOperations)
mkdir("../downloads/")
copy {
from fatJar.get()
into '../downloads/'
}
copy {
from '../Wurstpack'
into '../downloads/Wurstpack/'
}
copy {
from '../WurstSetup/build/libs/WurstSetup.jar'
into '../downloads/'
}
mkdir("../Checksums/bin")
execOps.javaexec {
classpath = sourceSets.main.runtimeClasspath
mainClass.set('de.peeeq.wurstio.Checksums')
args("../downloads/Wurstpack/", "../downloads/wurstpack.md5")
}
}
}
/** -------- Hotdoc generation -------- */
tasks.register('generate_hotdoc') {
dependsOn 'compileJava', 'downloadAndUnzipFile'
doLast {
ExecOperations execOps = project.services.get(ExecOperations)
copy {
from("src/main/resources/")
// Gradle 9 output classes dir
into("build/classes/java/main/")
}
execOps.javaexec {
classpath = sourceSets.main.runtimeClasspath
mainClass.set('de.peeeq.wurstio.Main')
args("--hotdoc", "./build/deps/", "../downloads/hotdoc")
}
}
}
/** -------- Apply deployment settings -------- */
apply from: 'deploy.gradle'