forked from MovingBlocks/FacadeApplet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
254 lines (208 loc) · 8.02 KB
/
build.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
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
// This facade is for running the game as an applet
// Grab all the common stuff like plugins to use, artifact repositories, code analysis config
apply from: "$rootDir/config/gradle/common.gradle"
import org.apache.tools.ant.filters.FixCrLfFilter;
def LWJGL_VERSION = '2.9.3'
def LWJGL_VERSION_APPLET = '2.9.1'
def JINPUT_VERSION = '2.0.5'
// Declare "extra properties" (variables) for the project - a Gradle thing that makes them special.
ext {
// Project paths
dirUnsigned = "$buildDir/unsigned"
subDirLibs = 'libs'
subDirModules = 'modules'
destDirApplet = 'distributions/applet'
// Read environment variables, including variables passed by jenkins continuous integration server
env = System.getenv()
}
configurations {
applet
modules {
description = 'Modules without dependencies'
// This is needed as otherwise any included module would also get copied in with engine libs etc
transitive = false
}
}
dependencies {
compile (group: 'org.lwjgl.lwjgl', name: 'lwjgl_util_applet', version: LWJGL_VERSION_APPLET)
compile (group: 'org.terasology.engine', name: 'engine', version: '+')
modules (group: 'org.terasology.modules', name: 'Core', version: '+')
modules (group: 'org.terasology.modules', name: 'CoreSampleGameplay', version: '+')
}
jar {
archiveName = "applet.jar"
manifest.mainAttributes('Permissions': 'all-permissions')
manifest.mainAttributes('Codebase': '*')
manifest.mainAttributes('Application-Name': 'Terasology Applet')
manifest.mainAttributes('Application-Library-Allowable-Codebase': '*')
manifest.mainAttributes('Caller-Allowable-Codebase': '*')
manifest.mainAttributes('Trusted-Only': 'false')
}
// Distribute modules - with the option to provide a list of additional modules to include as dependencies
// Example command including additional modules: gradlew -PextraModules="Signalling,BlockNetwork"
task addModules () {
description = "Prepares modules for distribution"
// If the execution was supplied with an extraModules property then include those modules as well
if (project.hasProperty('extraModules')) {
extraModules.split(',').each { String dependency ->
logger.lifecycle('Extra module: ' + dependency)
dependencies {
modules (group: 'org.terasology.modules', name: dependency, version: '+')
}
}
}
}
task copyExtras(type:Copy) {
description = "Copies all extras to the applet folder"
from ("README.md") {
filter(FixCrLfFilter, eol:FixCrLfFilter.CrLf.newInstance("crlf"))
rename('README.md', 'README')
}
from ("LICENSE") {
filter(FixCrLfFilter, eol:FixCrLfFilter.CrLf.newInstance("crlf"))
}
from ("NOTICE") {
filter(FixCrLfFilter, eol:FixCrLfFilter.CrLf.newInstance("crlf"))
}
into("$buildDir/$destDirApplet")
}
task copyLibs(type:Copy, dependsOn: addModules) {
description = "Copies all libs to the applet folder"
into(dirUnsigned)
// Applet jar itself
from jar
// Lib jars
into(subDirLibs) {
from configurations.runtime
}
// Modules (just Core + CoreSampleGameplay unless extraModules is passed in)
into(subDirModules) {
from configurations.modules
}
// UPDATE after bug below fixed: the applet failed with 2.9.2 :-( Attempted partial rollback, but then we need the hack again ...
// TODO: Remove this part as soon as LWJGL applet jars work correctly
// see https://github.com/LWJGL/lwjgl/pull/73
// Overwrite invalid AppLibAC attribute ("true") in LWJGL 2.9.1 jars
def lwjglFiles = fileTree(dir: "$dirUnsigned/$subDirLibs", include: 'lwjgl_util_applet*.jar')
doLast {
lwjglFiles.each {
logger.lifecycle("Fixing manifest in invalid LWJGL file $it");
ant.jar(destfile: it, update: true) {
delegate.manifest {
attribute(name: 'Application-Library-Allowable-Codebase', value: '*')
}
}
}
}
}
task createIndexHtml(type:Copy) {
def noNatives = files(configurations.runtime).filter {
!it.name.endsWith('natives-linux.jar') &&
!it.name.endsWith('natives-windows.jar') &&
!it.name.endsWith('natives-osx.jar')
}
// add all libs to classpath
def jars = []
noNatives.each {
jars += subDirLibs + '/' + it.getName()
}
def modules = []
configurations.modules.each {
modules += it.getName()
}
from('index.html')
into("$buildDir/$destDirApplet")
expand(lwjglVersion: LWJGL_VERSION,
lwjglVersionApplet: LWJGL_VERSION_APPLET,
jinputVersion : JINPUT_VERSION,
jars : jars.join(", "),
modules : modules.join(", "))
}
// TODO: Maybe split this out as a tiny plugin or something sometime?
class IncrementalSigningTask extends DefaultTask {
@Input
String certFile
@Input
String certAlias
@Input
String certStorePass
@Input
String certKeyPass
@InputFiles
FileTree inputTree
@OutputDirectory
File outputDir
@TaskAction
void execute(IncrementalTaskInputs inputs) {
outputDir.mkdirs()
def ood = new HashSet()
inputs.outOfDate( {
ood += it.file
})
logger.info("Signing with certifacte $certFile")
inputTree.visit { change ->
if (change.directory) {
change.relativePath.getFile(outputDir).mkdirs()
} else if (ood.contains(change.file)) {
try {
def target = change.relativePath.getFile(outputDir)
if (project.hasProperty("certificateFile")) {
logger.debug("Signing file $change.file")
logger.debug("Storing signed file $target")
ant.signjar(
jar: change.file,
signedjar: target,
keystore: certFile,
alias: certAlias,
storepass: certStorePass,
keypass: certKeyPass,
tsaurl: 'http://time.certum.pl/')
} else {
// If the certificate setup is not present just copy the files to emulate this step
logger.debug("Bypassing signing, just copying $target")
ant.copy(file: change.file, tofile: target)
}
} catch (Exception e) {
logger.warn("Error signing", e)
}
}
logger.lifecycle("Processed for applet: $change.relativePath");
}
logger.lifecycle("Signing process complete (enabled or not)")
}
}
// Sign the jar files so they can get full rights in a browser
task signLibs(type: IncrementalSigningTask, dependsOn: [copyLibs]) {
inputTree = fileTree(dirUnsigned)
outputDir = file("$buildDir/$destDirApplet")
if (project.hasProperty("certificateFile")) {
certFile = certificateFile
certAlias = certificateAlias
certStorePass = certificateStorePass
certKeyPass = certificateKeyPass
} else {
logger.warn("Certificate file property not present (debug session?) - NOT signing jars")
certFile = "INVALID"
certAlias = "INVALID"
certStorePass = "INVALID"
certKeyPass = "INVALID"
}
}
task distApplet(dependsOn: [signLibs, createIndexHtml, copyExtras]) {
description = "Creates an Applet folder"
}
task distAppletZip(type:Zip) {
description = "Creates an Applet ZIP file from '$buildDir/$destDirApplet'"
dependsOn distApplet
archiveName = "applet.zip"
from "$buildDir/$destDirApplet"
}
// Prep an IntelliJ module for the facade
idea {
module {
// Change around the output a bit
inheritOutputDirs = false
outputDir = file('build/classes')
testOutputDir = file('build/testClasses')
}
}