generated from cocolabs/pz-zmod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzomboid.gradle
166 lines (139 loc) · 5.37 KB
/
zomboid.gradle
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
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.Path
import org.apache.commons.io.FileUtils
buildscript {
repositories {
jcenter()
}
dependencies {
classpath group: 'commons-io', name: 'commons-io', version: '2.8.0'
}
}
Properties properties = new Properties()
def propertiesFile = project.rootProject.file('local.properties')
if (propertiesFile.exists()) {
properties.load(propertiesFile.newDataInputStream())
}
project.ext.ideaHome = properties.getProperty('idea.home', '')
project.ext.gameDir = Paths.get(properties.getProperty('game.dir', ''))
if (project.ext.gameDir == null)
{
if (providers.environmentVariable('GAME_DIR').present) {
project.ext.gameDir = Paths.get(providers.environmentVariable('GAME_DIR').get())
}
else if (System.hasProperty('game.dir')) {
project.ext.gameDir = Paths.get(System.getProperty('game.dir'))
}
else throw new RuntimeException("Game directory path not specified")
}
repositories {
maven { url 'https://jitpack.io' }
}
configurations {
zomboid.extendsFrom runtimeOnly
}
dependencies {
// https://github.com/yooksi/pz-zdoc
zomboid 'com.github.yooksi:pz-zdoc:master-SNAPSHOT'
// Project Zomboid libraries
runtimeOnly fileTree(dir: gameDir, include: ['*.jar'])
runtimeOnly files("$buildDir/libs/zomboid-$game_version" + '.jar')
compile files("$buildDir/libs/zomboid-$game_version-sources" + '.jar')
compile files("$buildDir/libs/zdoc-lua-$game_version" + '.jar')
}
task zomboidJar(type: Jar) {
onlyIf {
!project.ext.gameDir.empty
}
description('Assembles a jar archive containing game classes.')
setGroup('build')
archiveFileName = "zomboid-${game_version}.jar"
includeEmptyDirs = false
from project.ext.gameDir
HashSet<String> excludePaths = new HashSet<>()
Files.walk(project.ext.gameDir as Path).withCloseable
{
it.filter({Files.isRegularFile(it) && !it.fileName.toString().endsWith('class') && it.fileName.toString() != "stdlib.lbc"
}).collect().forEach({ excludePaths.add(gameDir.relativize(it as Path).toString()) })
}
setExcludes(excludePaths)
}
jar.dependsOn(zomboidJar)
/**
* Decompile game classes with FernFlower using default IDEA settings.
* Default task behaviour is to decompile all class files found in game root directory.
*
* This can be changed by defining specific file to decompile with project property 'src'.
* example: gradle decompileZomboid -Psrc="<path>"
*/
task decompileZomboid(type: Exec) {
onlyIf {
!project.ext.ideaHome.empty
}
description('Decompile Project Zomboid classes.')
def classpath = "$ideaHome/plugins/java-decompiler/lib/java-decompiler.jar"
def mainClass = 'org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler'
// default parameters used by IDEA compiler
def params = ['-hdc=0', '-dgs=1', '-rsy=1', '-rbr=1', '-lit=1', '-nls=1', '-mpm=60']
def srcDir = file("$buildDir/tmp/zomboid")
if (!srcDir.exists() && !srcDir.mkdirs()) {
throw new IOException("Unable to create decompile tmp dir")
}
// directories containing class files
String[] sourceDirs = ['astar', 'com', 'de', 'fmod', 'javax', 'org', 'se', 'zombie']
for (int i = 0; i < sourceDirs.size(); i++)
{
def sDir = sourceDirs[i]
def copyDest = srcDir.toPath().resolve(sDir).toFile()
def copySrc = gameDir.resolve(sDir).toFile()
logger.info("copying class package \'${copySrc.name}\'")
FileUtils.copyDirectory(copySrc, copyDest)
}
gameDir.resolve(project.ext.has('src') ? project.ext.src : 'zombie').toString()
def destDir = file("$buildDir/generated/sources/zomboid")
// decompiler will throw error if destination dir doesn't exist
destDir.mkdirs()
setCommandLine(['java', '-classpath', classpath, mainClass] + params + srcDir.path + destDir.path)
}
task zomboidSourcesJar(type: Jar) {
description('Assembles a jar containing decompiled game sources.')
setGroup('build')
archiveFileName = "zomboid-${game_version}-sources.jar"
from "$buildDir/generated/sources/zomboid"
}
zomboidSourcesJar.dependsOn(decompileZomboid)
jar.dependsOn(zomboidSourcesJar)
task zomboidLuaJar(type: Jar) {
setGroup('build')
description('Assembles a jar containing compiled lua classes.')
archiveFileName = "zdoc-lua-${game_version}.jar"
destinationDir(file("$buildDir/libs"))
from "$buildDir/generated/sources/zdoc/"
}
jar.dependsOn(zomboidLuaJar)
task annotateZomboidLua(type: JavaExec) {
setGroup('documentation')
description('Annotate game Lua files with EmmyLua annotations.')
main = "io.yooksi.pz.zdoc.Main"
classpath configurations.zomboid
jvmArgs("-Dld.logger=dev")
args('lua', '-i', "$gameDir/media/lua", '-o', 'build/generated/sources/zdoc/')
}
annotateZomboidLua.doFirst {
file('build/generated/sources/zdoc').mkdirs()
}
annotateZomboidLua.doLast {
file('pz-zdoc.log').delete()
}
task compileZomboidLua(type: JavaExec) {
description('Parse game api doc and compile to lua.')
main = "io.yooksi.pz.zdoc.Main"
classpath configurations.zomboid
jvmArgs("-Dld.logger=dev")
args('java', '--api-docs', 'zombie/Lua/LuaManager.GlobalObject.html', '-o',
'build/generated/sources/zdoc/shared/Library', '-e', 'Recipe,Vector2')
}
compileZomboidLua.doFirst {
file('build/generated/sources/zdoc').mkdirs()
}