-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.gradle
243 lines (186 loc) · 6.11 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
/*
* Hyperbox - Virtual Infrastructure Manager
* Copyright (C) 2021 Max Dor
*
* https://apps.kamax.io/hyperbox
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.nio.file.Paths
import java.util.regex.Pattern
String buildVersion() {
def versionPattern = Pattern.compile("v(\\d+\\.)?(\\d+\\.)?(\\d+)(-.*)?")
String version = System.getenv('HBOX_SERVER_BUILD_VERSION')
if (version == null || version.size() == 0) {
version = sourceVersion()
}
version = versionPattern.matcher(version).matches() ? version.substring(1) : version
println('Version: ' + version)
return version
}
String sourceVersion() {
String version = System.getenv('HBOX_SERVER_SOURCE_VERSION')
if (version != null && version.size() > 0) {
return version
}
ByteArrayOutputStream out = new ByteArrayOutputStream()
def o = exec {
commandLine = ['git', 'describe', '--tags', '--always', '--dirty']
standardOutput = out
errorOutput = out
ignoreExitValue = true
}
if (o.exitValue != 0) {
if (o.exitValue != 128) {
printf("Unable to determine git version: %s", out.toString())
}
return "UNKNOWN"
}
return out.toString().replace(System.lineSeparator(), '')
}
static String getSysProp(String value, Object fallback) {
// This is required as there is a length limitation on System.properties.getProperty(a,b)
if (!System.properties.containsKey(value)) {
return fallback.toString()
}
return System.properties.get(value)
}
apply plugin: 'application'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
group = 'io.kamax.apps.hbox'
version = buildVersion()
mainClassName = 'io.kamax.hboxc.HyperboxClientApplicationStart'
def buildPath = Paths.get(getSysProp('client.build.bin', layout.buildDirectory.dir('bin').get()))
def buildLinuxPath = buildPath.resolve('linux')
def buildWinPath = buildPath.resolve('win')
String versionInfoFile = "${projectDir}/build/tmp/versionInfo/client.build.properties"
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation "io.kamax.apps.hbox:hbox-api:0.2.+"
implementation 'com.miglayout:miglayout-swing:4.2'
testImplementation 'junit:junit:4.13.2'
}
String getPackageName(String os) {
return "hbox-client-${project.version}-${os}"
}
/-------------------- Binaries build and assembly tasks ------------------------------/
task versionInfo {
doLast {
File versionFile = new File(versionInfoFile)
versionFile.getParentFile().mkdir()
versionFile.text = 'version=' + project.version
}
}
jar {
dependsOn versionInfo
from versionInfoFile
}
distributions {
main {
contents {
from('src/main/img') {
into 'icons'
}
from ('src/main/icons') {
into 'icons'
}
}
}
}
/-------- End of Binaries build and assembly --------/
/-------- Distribution build tasks -----------------/
/----------- Linux ------------/
task assembleLinux(type: Copy) {
dependsOn distZip, installDist
from "build/install/${project.name}"
from 'src/main/scripts/hyperbox'
from 'src/main/hyperbox-client.desktop'
exclude 'bin/hbox-client.bat'
into buildLinuxPath
}
task assembleLinuxDist(type: Copy) {
dependsOn assembleLinux
from 'src/main/scripts/installer/client-installer.sh'
into buildLinuxPath
}
task distLinuxZip(type: Zip) {
dependsOn assembleLinuxDist
archiveFileName = "${getPackageName('linux')}.zip"
destinationDirectory = layout.buildDirectory.dir('distributions')
from buildLinuxPath
}
task distLinuxInstaller(type: Exec) {
dependsOn assembleLinuxDist
commandLine(
'makeself',
buildLinuxPath,
"build/distributions/${getPackageName('linux')}.run",
'Hyperbox Client',
'./client-installer.sh'
)
}
/------- Windows -------/
task assembleWin(type: Copy) {
dependsOn distZip, installDist
from "build/install/${project.name}"
from 'src/main/scripts/hyperbox.bat'
exclude 'bin/hbox-client'
into buildWinPath
}
task distWinZip(type: Zip) {
dependsOn assembleWin
archiveFileName = "${getPackageName('win')}.zip"
destinationDirectory = layout.buildDirectory.dir('distributions')
from buildWinPath
}
task distWinInst(type: Exec) {
dependsOn assembleWin
def distTmp = layout.buildDirectory.dir('tmp/distWinInst').get()
def distNsiTmp = distTmp.file('client-installer.nsi').asFile
doFirst {
copy {
from project.file('src/main/scripts/installer/client-installer.nsi')
into distTmp
}
ant.replace(
file: distNsiTmp,
token: '@CLIENT_INSTALLER_OUTPUT@',
value: project.file("build/distributions/${getPackageName('win')}.exe")
)
ant.replace(
file: distNsiTmp,
token: '@CLIENT_OUT_BIN_DIR@',
value: "${buildWinPath}"
)
ant.replace(
file: distNsiTmp,
token: '@CLIENT_INSTALL_DIR@',
value: "C:\\Program Files\\Hyperbox\\Client"
)
copy {
from distTmp.file('client-installer.nsi')
into buildWinPath
}
}
doLast {
delete {
file buildWinPath.resolve('client-installer.nsi')
}
}
commandLine 'makensis', '-DPROJECT_NAME=Hyperbox Client', '-V2', buildWinPath.resolve('client-installer.nsi').toFile()
}