forked from kieler/elkjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
312 lines (255 loc) · 8.47 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
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
312
/*
TODO document the script
# Task depencencies
The dependencies are specified at the end of this file,
not within the task definitions.
1) copy (and preprocess) relevant source code
2) generate code for .melk and .xtend files
3) compile java source code
4) run gwt compiler
# Build directory layout
src
+-- elk
+-- elkjs
+-- melk
+-- xtend-gen
*/
plugins {
id 'org.xtext.builder' version '2.0.5'
id 'org.xtext.xtend' version '2.0.5'
id 'java'
}
// make sure all compile tasks use utf8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
// GWT requires to be run with Java [8, 11]
// (http://www.gwtproject.org/release-notes.html#Release_Notes_2_9_0)
if (![JavaVersion.VERSION_1_8,
JavaVersion.VERSION_1_9,
JavaVersion.VERSION_1_10,
JavaVersion.VERSION_11,
].contains(JavaVersion.current())) {
throw new GradleException("elkjs build requires to be run with Java [8, 11] (due to GWT compilation).")
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Settings
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ext.versions = [
emfGwt: '2.12.4',
gwt: '2.9.0',
guava: '27.1-jre',
melk: '0.8.0-SNAPSHOT',
xtext: '2.20.0',
]
if (!hasProperty('elkRepo')) {
ext.elkRepo = '../elk'
}
def elkSources = [
// The core and graph format
"${elkRepo}/plugins/org.eclipse.elk.core/src",
"${elkRepo}/plugins/org.eclipse.elk.graph/src",
"${elkRepo}/plugins/org.eclipse.elk.graph.json/src",
"${elkRepo}/plugins/org.eclipse.elk.alg.common/src",
// The algorithms
"${elkRepo}/plugins/org.eclipse.elk.alg.disco/src",
"${elkRepo}/plugins/org.eclipse.elk.alg.force/src",
"${elkRepo}/plugins/org.eclipse.elk.alg.layered/src",
"${elkRepo}/plugins/org.eclipse.elk.alg.mrtree/src",
"${elkRepo}/plugins/org.eclipse.elk.alg.rectpacking/src",
"${elkRepo}/plugins/org.eclipse.elk.alg.radial/src",
"${elkRepo}/plugins/org.eclipse.elk.alg.spore/src"
]
// the directory to which all sources are copied for compilation
def srcDir = "${buildDir}/src"
def distDir = "${buildDir}/js"
def gwtModule = "org.eclipse.elk.js.ElkJs"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Repositories, Source Sets, and Dependencies
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
repositories {
jcenter()
// for melk compiler
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
configurations {
gwt
}
sourceSets {
// compile xtext related sources. This includes:
// xtend -> java
// melk -> java
xtext {
java {
srcDirs = [ "$srcDir/elk" ]
}
xtendOutputDir = "$srcDir/xtend-gen"
}
main {
java {
srcDirs = [ srcDir ]
}
}
}
def gwtClasspath = [
// gwt requires the folder structure to equal the package structure
"$srcDir/elk",
"$srcDir/elkjs",
"$srcDir/melk",
"$srcDir/xtend-gen",
sourceSets.main.output.classesDirs,
configurations.gwt
]
dependencies {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// melk language
xtextLanguages "org.eclipse.elk:org.eclipse.elk.core.meta:$versions.melk"
// for the minus sign to work in melk files
xtextCompile "org.eclipse.xtext:org.eclipse.xtext.xbase.lib:$versions.xtext"
xtextCompile "com.google.guava:guava:$versions.guava"
xtextCompile "com.google.gwt:gwt-dev:$versions.gwt"
xtextCompile "com.google.gwt:gwt-user:$versions.gwt"
xtextCompile "com.genmymodel.emf.gwt:emf-common:$versions.emfGwt"
xtextCompile "com.genmymodel.emf.gwt:emf-ecore:$versions.emfGwt"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// emf for gwt
compile "com.genmymodel.emf.gwt:emf-common:$versions.emfGwt"
compile "com.genmymodel.emf.gwt:emf-ecore:$versions.emfGwt"
// guava
compile "com.google.guava:guava:$versions.guava"
// gwt
compile "com.google.gwt:gwt-user:$versions.gwt"
compile "com.google.gwt:gwt-dev:$versions.gwt"
// xtend libs
compile "org.eclipse.xtend:org.eclipse.xtend.lib:$versions.xtext"
compile "org.eclipse.xtext:org.eclipse.xtext.xbase.lib:$versions.xtext"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
gwt "com.google.guava:guava-gwt:$versions.guava"
gwt "com.google.gwt:gwt:$versions.gwt"
gwt "com.google.gwt:gwt-dev:$versions.gwt"
gwt "com.google.gwt:gwt-user:$versions.gwt"
//gwt "com.google.gwt:gwt-servlet:$versions.gwt"
gwt "com.genmymodel.emf.gwt:emf-common:$versions.emfGwt:sources"
gwt "com.genmymodel.emf.gwt:emf-ecore:$versions.emfGwt:sources"
// the xtext/xtend gwt plugins only contain the '.gwt.xml' files
// thus the source code has to be retrieved separately
gwt "org.eclipse.xtext:org.eclipse.xtext.xbase.lib:$versions.xtext:sources"
gwt "org.eclipse.xtend:org.eclipse.xtend.lib:$versions.xtext:sources"
gwt "org.eclipse.xtext:org.eclipse.xtext.xbase.lib.gwt:$versions.xtext"
gwt "org.eclipse.xtend:org.eclipse.xtend.lib.gwt:$versions.xtext"
}
// configure the melk language
xtext {
languages {
melk {
fileExtension = 'melk'
setup = 'org.eclipse.elk.core.meta.MetaDataStandaloneSetup'
generator.outlet.producesJava = true
}
}
}
// don't bother the xtext generator with irrelevant source sets
generateXtext.enabled = false
clean {
delete distDir
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Copy Tasks
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
task copyElk(type: Copy) {
from elkSources
into "$srcDir/elk/"
include "**/*.java"
include "**/*.xtend"
include "**/*.melk"
// the gson based json import
exclude "**/ElkGraphJson.java" // java-based api
exclude "**/JsonAdapter.xtend" // the gson implementation
exclude "**/JsonExporter.xtend" // not required here (should be compatible though)
// class is in there for convenience reasons
// usually the factories are generated by the melk compiler
exclude "**/AlgorithmFactory.java"
// exclude because they require ecore.xmi
exclude "**/ElkGraphResource.java"
exclude "**/ElkGraphXMIHelper.java"
exclude "**/ElkGraphXMISave.java"
exclude "**/ElkGraphResourceFactory.java"
// incompatible api, an emulating class is used (java-additional)
exclude "**/alg/common/utils/SVGImage.java"
// after copying, remove those parts of the code
// that have been marked to be incompatible with gwt
doLast {
ant.replaceregexp(
match: '// elkjs-exclude-start(.+?)elkjs-exclude-end',
replace: '',
flags: 'gis',
byline: false) {
fileset(dir: "$srcDir/elk/")
}
}
}
task copyEmul(type: Copy) {
from([
// contains the implementation for json->elk graph importer
// using gwt's json
"./src/java-additional"
])
into "$srcDir/elk/"
}
task copyMelk(type: Copy) {
from "$buildDir/melk/xtext"
into "$srcDir/melk"
}
task copyElkJs(type: Copy) {
from "./src/java"
into "$srcDir/elkjs"
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// GWT Compilation
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def gwtInputs = [
fileTree(srcDir),
sourceSets.main.output.classesDirs
]
task gwtc (type: JavaExec) {
main = 'com.google.gwt.dev.Compiler'
classpath { gwtClasspath }
args = [ gwtModule, '-war', "$buildDir/dist", '-style', 'PRETTY' ]
maxHeapSize = '2G'
inputs.files(gwtInputs)
outputs.dir("$buildDir/dist/elk")
}
task gwtcMinified (type: JavaExec) {
main = 'com.google.gwt.dev.Compiler'
classpath { gwtClasspath }
args = [ gwtModule, '-war', "$buildDir/distMinified" ]
maxHeapSize = '2G'
inputs.files(gwtInputs)
outputs.dir("$buildDir/distMinified/elk")
}
task copyPretty(type: Copy) {
from "$buildDir/dist/elk"
into distDir
include "**/*.js"
}
task copyMinified(type: Copy) {
from "$buildDir/distMinified/elk"
into distDir
include "**/*.js"
rename '(.*).js', '$1.min.js'
}
task lib(dependsOn: [ copyPretty, copyMinified ])
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Task Dependencies
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
generateXtextXtext.dependsOn copyElk
generateXtextXtext.dependsOn copyEmul
copyMelk.dependsOn generateXtextXtext
compileJava.dependsOn copyMelk
compileJava.dependsOn copyElkJs
gwtc.dependsOn compileJava
gwtcMinified.dependsOn compileJava
copyPretty.dependsOn gwtc
copyMinified.dependsOn gwtcMinified