-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
265 lines (230 loc) · 6.52 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
/*
* Copyright (C) 2016 Luke Melaia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import org.apache.commons.io.FileUtils
apply plugin: 'java'
apply plugin: 'application'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
//Gradle run arguments.
//noinspection GroovyUnusedAssignment
applicationDefaultJvmArgs = ["-Dprism.vsync=false"]
/**
* Declare main class.
*/
mainClassName = "org.lmelaia.iseries.Main"
if (!hasProperty('mainClass')) {
ext.mainClass = 'org.lmelaia.iseries.Main'
}
/**
* The full path to the java executable of the JDK.
* Only used for the development environment.
*/
ext.JAVA_PATH = "C:\\Program Files\\Java\\liberica-openjdk-14-full\\bin\\java.exe"
/**
* Maven repository declaration.
*/
repositories {
mavenCentral()
}
/**
* Build script dependencies and declaration.
*/
buildscript {
repositories {
mavenCentral()
}
dependencies{
classpath group: 'commons-io', name: 'commons-io', version: '2.4'
}
}
/**
* List of project dependencies.
*/
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
// https://mvnrepository.com/artifact/com.google.guava/guava
compile group: 'com.google.guava', name: 'guava', version: '29.0-jre'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.8.2'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8.2'
compile project(path: ':src-common')
}
/**
* Edits the jar manifest to include
* the main class and project dependencies.
*/
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect {
"../libs/" + it.getName()
}.join(' '),
'Main-Class': mainClassName
)
}
}
/**
* Tasks and settings for all sub projects.
*/
subprojects {
apply plugin: 'java'
//Skip tests (due to bug).
test.onlyIf {false}
/**
* Copies the project dependencies to a
* newly created lib folder within the build/lib
* folder.
*
* This is done for the build sub project.
*/
task copyDependencies(type: Copy){
into "$buildDir/libs/libs"
from configurations.runtime
}
/**
* Build task dependencies.
*/
build.dependsOn(copyDependencies)
}
//Skip tests (due to bug).
test.onlyIf {false}
/**
* Copies the project dependencies to a
* newly created lib folder within the build/lib
* folder.
*
* This is done for the build sub project.
*/
task copyDependencies(type: Copy){
into "$buildDir/libs/libs"
from configurations.runtime
}
/**
* Gradle run task. Use instead of
* default run task.
*
* Creates a run directory
* containing a runnable distribution
* of the application and executing the
* launcher jar application and redirecting
* the output to the gradle console.
*/
task _run() {
doLast{
createRunDirectory()
runLauncher()
}
}
/**
* Gradle clean run task. Use instead of
* default clean and run tasks.
*
* Cleans the run directory before
* executing the _run task.
*/
task _cleanrun() {
doFirst{
//noinspection GroovyAssignabilityCheck
FileUtils.deleteDirectory(new File(System.getProperty("user.dir") + "/run"))
}
}
/**
* Gradle build task. Use instead of
* default build task.
*
* Builds the project, each sub project and
* runs the build sub project.
*
* Running the build sub project
* will produce a runnable distribution
* of the entire application
* (launcher, application, dependencies, ect.).
*/
task _build(){
//Done by gradle task dependencies.
}
/**
* Creates a new run directory
* containing a runnable distribution
* of the application for test runs.
*/
void createRunDirectory(){
//noinspection GroovyAssignabilityCheck
File runDir = new File(System.getProperty("user.dir") + "/run")
runDir.mkdir()
//noinspection GroovyAssignabilityCheck
File source = new File(System.getProperty("user.dir") + "/buildOutput")
File dest = runDir
try {
FileUtils.copyDirectory(source, dest)
} catch (IOException e) {
println("Could not copy to run directory: " + e.getMessage())
}
}
/**
* Executes the launcher jar in the created
* run directory and redirects all the
* output to the console.
*/
void runLauncher(){
createRunDirectory()
String command = JAVA_PATH + " -jar " +
new File(System.getProperty("user.dir")).getAbsolutePath() +
File.separator + "run" + File.separator + "bin" +
File.separator + "I-Series-Launcher.jar"
//noinspection GroovyAssignabilityCheck
Process appProcess = Runtime.getRuntime().exec(command, null, new File(new File(
System.getProperty("user.dir")).getAbsolutePath() +
File.separator + "run" + File.separator + "bin"))
//noinspection GroovyAssignabilityCheck
Thread t = new Thread(new Runnable() {
@Override
void run() {
String line
//noinspection GroovyAssignabilityCheck
BufferedReader inn = new BufferedReader(
new InputStreamReader(appProcess.getInputStream()))
try {
while ((line = inn.readLine()) != null) {
System.out.println(line)
}
} catch (ignored) {
}
}
}, "Process output printer")
t.setDaemon(true)
t.start()
//noinspection GroovyAssignabilityCheck
System.out.println("\nRESULT: " + appProcess.waitFor())
}
/*
Build task dependencies.
*/
_build.dependsOn(":copyDependencies")
_build.dependsOn("src-build:build")
_build.dependsOn("src-common:build")
_build.dependsOn("src-launcher:build")
_build.dependsOn("src-updater:build")
_build.dependsOn(":build")
_build.finalizedBy("src-build:run")
/*
Run task dependencies.
*/
_run.dependsOn(":_build")
/*
Clean run task dependencies.
*/
_cleanrun.finalizedBy(":_run")