forked from google/sagetv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
executable file
·483 lines (407 loc) · 13.6 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
import org.gradle.internal.os.OperatingSystem
plugins {
id "com.jfrog.bintray" version "1.3.1"
}
apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "idea"
// Globals
ext {
sageBuildDir = 'buildoutput'
stageBuildDir = 'build'
appName = 'SageTV'
sageJarName = 'Sage.jar'
sageJarDestinationDir = 'build/release/'
sageReleaseDestinationDir = 'build/serverrelease/'
sageJarPackageDestinationDir = 'build/'
miniJarName = 'MiniClient.jar'
miniJarDestinationDir = 'build/minirelease/'
miniclientReleaseDestinationDir = 'build/clientrelease/'
// This the version of JOGL we are using
jogampVer = '2.3.1'
arch=Integer.parseInt(System.getProperty('sun.arch.data.model')); // 32 or 64
releaseBuild = (System.getProperty("SAGETV_RELEASE", System.getenv("SAGETV_RELEASE")) != null)
snapshotId = (releaseBuild?"":("SNAPSHOT-"+ new java.text.SimpleDateFormat("yyyyMMdd_hhmm").format(new java.util.Date() )))
versionText = new File('java/sage/Version.java').text
majorVersion = (versionText =~ /MAJOR_VERSION = ([0-9]+)/)[0][1]
minorVersion = (versionText =~ /MINOR_VERSION = ([0-9]+)/)[0][1]
microVersion = (versionText =~ /MICRO_VERSION = ([0-9]+)/)[0][1]
buildVersion = getBuildNumber()
baseVersion = "${majorVersion}.${minorVersion}.${microVersion}.${buildVersion}"
versionArch = "${baseVersion}_" + (arch==64 ? 'amd64' : 'i386')
}
version = baseVersion
// Just printing out the SAGETV build version for informational purposes
// System.out.println("SAGETV VERSION ${versionArch}");
// set gradle's buildDir to something other than the default 'build', or
// we'll end up deleting EVERYTHING in 'build' when we ./gradlew clean
buildDir = new File(rootProject.projectDir, sageBuildDir);
repositories {
mavenCentral()
jcenter()
}
configurations {
miniclient.extendsFrom compile
}
// Maybe someday we'll target >1.7 (hopefully)
targetCompatibility = 1.7
sourceCompatibility = 1.7
compileJava {
options.warnings = false
//options.incremental = true
//options.debugOptions.debugLevel = "source,lines,vars"
}
sourceSets {
// main configuration for the Sage.jar
main {
java {
srcDirs = [
'java',
'third_party/Javolution/java',
'third_party/jcraft/java',
'third_party/jtux/java',
'third_party/MetadataExtractor/java',
'third_party/Ogle/java',
'third_party/RSSLIB4J/java',
'third_party/SingularSys/java',
'third_party/GSON/java'
]
excludes = [
// mac files, need to be on a Mac to build these
'sage/QuartzSageRenderer.java',
'sage/miniclient/QuartzGFXCMD.java',
// does not appear to compile, maybe an older file??
'sage/JOGLSageRenderer.java'
]
}
}
test {
java {
srcDirs = [
'test/java'
]
}
}
// Miniclient configuration only specifies the Minimal files and
// javac will find and compile all the dependencies based on the
// main configuration being the sourcepath reference
miniclient {
java {
srcDirs = [
'java'
]
includes = [
'sage/miniclient/MiniClient.java',
'sage/PowerManagement.java',
'sage/UIUtils.java',
'sage/miniclient/OpenGLGFXCMD.java'
]
}
}
}
dependencies {
testCompile 'org.testng:testng:6.1.1'
testCompile "org.mockito:mockito-core:1.9.5"
compile files(
'third_party/UPnPLib/sbbi-upnplib-1.0.3.jar',
'third_party/Oracle/vecmath.jar',
'third_party/Lucene/lucene-core-3.6.0.jar',
'third_party/JCIFS/jcifs-1.1.6.jar',
)
compile 'com.apple:AppleJavaExtensions:1.4'
compile "org.jogamp.jogl:jogl-all:$jogampVer"
compile "org.jogamp.gluegen:gluegen-rt-main:$jogampVer"
// Miniclient dependencies for compiling
miniclientCompile "org.jogamp.gluegen:gluegen-rt-main:$jogampVer"
miniclientCompile "org.jogamp.jogl:jogl-all-main:$jogampVer"
}
test {
useTestNG()
reports.html.destination = file("$sageBuildDir/reports/testng")
systemProperty 'io_test_file', "delete-io-testng."
systemProperty 'nio_test_file', "delete-nio-testng."
systemProperty 'sage.testing', "true"
workingDir = file("$sageBuildDir/sagetv_test/");
workingDir.mkdirs();
}
/**
* this is sort of a hack... normally we'd never set the -sourcepath on a java compile
* but, sagetv usues this hack to selectively compile and include files into each jar
* so we'll mimic the behaviour here until we need to do something different
*/
tasks.withType(JavaCompile) {
//options.fork=true
options.compilerArgs << "-sourcepath" << sourceSets.main.java.srcDirs.join(java.io.File.pathSeparator)
}
task miniclient(type:JavaCompile) << {
}
// remove the Sage.jar before updating it
task cleanSageJar(type: Delete) {
delete sageJarDestinationDir+'/'+sageJarName
}
// build the Sage.jar
task sageJar(type: Jar) {
description = 'Build the Sage.jar'
archiveName = sageJarName
destinationDir = file(sageJarDestinationDir)
from files(sourceSets.main.output.classesDir) {
// exclude the Mac stuff for now
excludes = [
'sage/miniclient/**',
'sage/MacAboutBox*',
'sage/MacApplicationListener.class',
'sage/QuartzRendererView.class'
]
}
from files(sourceSets.main.output.resourcesDir)
// Add in images and localization files
from 'images/SageTV/'
from ('i18n') {
include '*.properties'
}
doLast {
println "$sageJarName created in $sageJarDestinationDir"
}
}
// clean miniclient jar
task cleanMiniJar(type: Delete) {
delete miniJarDestinationDir+'/'+miniJarName
}
// build miniclient jar
task miniclientJar(type: Jar) {
archiveName = miniJarName
destinationDir = file(miniJarDestinationDir)
from files(sourceSets.miniclient.output.classesDir) {
}
// Add in images and localization files
from 'images/MiniClient/'
doLast {
println "$miniJarName created in $miniJarDestinationDir"
}
}
// LinuxOnly: calls a unix script and ensures that JDK_HOME is set
def linuxScript(String script) {
String jdk="$System.env.JDK_HOME"
if (jdk==null || jdk==""||jdk=='null') throw new GradleException('JDK_HOME must be set to the JDK installation directory');
File jdkInclude = new File(new File(jdk),"include");
if (!jdkInclude) throw new GradleException('JDK_HOME does not point to a valid JDK home: ' + jdk);
exec {
workingDir = 'build'
executable script
environment JDK_HOME: jdk
}
}
// currently Linux Only -- Need to look at supporting Windows
task (linuxMiniClientRelease) << {
if (!OperatingSystem.current().isLinux()) {
throw new GradleException('This target is not supported on Windows, yet.');
}
if (!(new File('build/so/libSage.so')).exists()) {
linuxScript('./buildso.sh');
}
if (!(new File('build/elf/mplayer')).exists()) {
linuxScript('./build3rdparty.sh');
}
delete miniclientReleaseDestinationDir
copy {
from('build/minirelease/MiniClient.jar') {
}
from ('build/clientfiles/')
from 'third_party/swscale/libswscale.so'
from ('build/so/libSageX11.so') {
rename 'libSageX11.so', 'libSage.so'
}
from ('build/so/libjtux.so')
from ('build/so/libImageLoader.so')
from ('build/elf/mplayer')
from (configurations.miniclientRuntime)
into(miniclientReleaseDestinationDir)
exclude '**/*-macosx-*', '**/*-solaris-*', '**/*-windows-*', '**/*-android-*', '**/*-linux-arm*'
}
}
// build RAW javadoc
task sageJavadoc(type: Javadoc) {
source = sourceSets.main.allJava
}
/**
* Package SageTV jar and the STV together
*/
task (packageSageJar) << {
file(sageJarPackageDestinationDir).mkdirs();
ant.zip(destfile: new File(sageJarPackageDestinationDir,"SageJar-${baseVersion}.zip").getAbsolutePath()) {
fileset(dir: sageJarDestinationDir) {
include(name: '*.jar')
}
zipfileset(dir: 'stvs/SageTV7', prefix: 'STVs/SageTV7/') {
include(name: 'SageTV7.xml')
}
}
}
/**
* Get the current build number from the git commit history, but use the .buildnumber or SageConstants
* if the git command is not available.
*
* @return build number
*/
def getBuildNumber() {
def buildVerText = new File('java/sage/SageConstants.java').text
// pull the build number from the .buildnumber, if it exists, otherwise, look in SageConstants.java
def buildVer = (new File('.buildnumber').exists())?(new File(".buildnumber").text) : (buildVerText =~ /BUILD_VERSION = ([0-9]+)/)[0][1]
if (OperatingSystem.current().isLinux()) {
// use git to find the build version
ant.exec(
command: 'git rev-list HEAD --count',
os: 'Linux',
failonerror: true,
outputproperty: 'sagebuildnum')
buildVer = ant.sagebuildnum
}
if (buildVer == null) buildVer=0;
return buildVer;
}
/**
* Task to update the build number in SageConstants based on the # of git commits
* Not sure I like it, yet.
*/
task (updateBuildNumber) << {
buildVersion = getBuildNumber()
def file = new File('java/sage/SageConstants.java');
def fileBak = new File('java/sage/SageConstants.java.bak');
if (!fileBak.exists()) {
fileBak.text = file.text
System.out.println("Backed up ${file}")
}
// update SageConstants.java
ant.replaceregexp(
file: 'java/sage/SageConstants.java',
match: "public static final int BUILD_VERSION = [0-9]+;",
replace: "public static final int BUILD_VERSION = ${buildVersion};"
)
// reupdate these values since buildVersion changes
baseVersion = "${majorVersion}.${minorVersion}.${microVersion}.${buildVersion}"
versionArch = "${baseVersion}_" + (arch==64 ? 'amd64' : 'i386')
System.out.println("SAGETV VERSION ${versionArch}");
// save buildnumber to file
// we'll be referencing it later
// Eventually we'll do this, but for now, fetch it every time
// new File('.buildnumber').write(buildVersion)
}
/**
* restore the SageConstants.java that was modified during updateBuildNumber
*/
task (restoreSageConstants) << {
def file = new File('java/sage/SageConstants.java');
def fileBak = new File('java/sage/SageConstants.java.bak');
if (fileBak.exists()) {
file.text = fileBak.text
System.out.println("Restored ${file}");
fileBak.deleteOnExit()
}
}
// task dependencies
compileJava.dependsOn updateBuildNumber
sageJar.dependsOn cleanSageJar, classes, test
miniclientJar.dependsOn clean, miniclientClasses, cleanMiniJar
linuxMiniClientRelease.dependsOn miniclientJar
sageJar.finalizedBy restoreSageConstants
// Eclipse project setup
eclipse {
project {
name = appName
}
classpath {
file {
// java appears twice in the classpath because it is configured for sage and miniclient,
// need to remove the miniclient one, or else it will cause eclipse to complain
whenMerged { classpath ->
def item=null;
classpath.entries.each {
if (it.path == 'java' && it.includes.size()>0) {
item=it
}
}
if (item!=null) {
classpath.entries.remove(item)
}
}
}
}
}
// ======= launch tasks for testing ========
// Run configuration for MiniClient testing
// NOTE you can run with ./gradlew linuxRunMiniClient --debug-jvm and then use
// eclipse remote debugging on port 5005 to debug the app
task linuxRunMiniClient(type:JavaExec) {
description 'Run the MiniClient. Be sure you have run linuxMiniClientRelease at once, to get the dependency jars into the build/clientrelease area.'
main = "sage.miniclient.MiniClient"
classpath = fileTree(miniclientReleaseDestinationDir) {
include '*.jar'
exclude 'MiniClient.jar'
}
classpath += sourceSets.miniclient.runtimeClasspath
classpath += files('images/MiniClient/')
environment 'LD_LIBRARY_PATH', file(miniclientReleaseDestinationDir).getAbsolutePath()
workingDir file(miniclientReleaseDestinationDir)
}
linuxRunMiniClient.doFirst {
if (!new File(miniclientReleaseDestinationDir, 'sageclient.sh').exists()) {
System.out.println('\nRun ./gradlew linuxMiniClientRelease before running the client, for the first time.\n')
System.exit(1)
}
}
// Run configuration for Sage Server testing
// NOTE you can run with ./gradlew linuxRunServer --debug-jvm and then use
// eclipse remote debugging on port 5005 to debug the app
task linuxRunServer(type:JavaExec) {
args '0', '0', 'x', 'sagetv Sage.properties'
main = "sage.Sage"
classpath = sourceSets.main.runtimeClasspath
classpath += files('images/SageTV/')
classpath += files('i18n')
systemProperty 'java.awt.headless', true
environment 'LD_LIBRARY_PATH', file(sageReleaseDestinationDir).getAbsolutePath()
workingDir file(sageReleaseDestinationDir)
}
linuxRunServer.doFirst {
file(sageReleaseDestinationDir).mkdirs()
if (!new File(sageReleaseDestinationDir, 'libSage.so').exists()) {
System.out.println('\nRun build/buildall.sh to setup the build/serverrelease/ directory, before running the server for the first time.\n')
System.exit(1)
}
}
// Upload tasks
// use ./gradlew bintrayUpload
// make sure your BINTRAY_API is set in the environment
//
bintray {
user = System.getenv("BINTRAY_USER")
key = System.getenv("BINTRAY_API");
filesSpec {
// from 'build/release'
from ('build') {
include '*.tar.gz', '*.deb', '*.zip'
}
into "sagetv/${baseVersion}"
}
dryRun = false //Whether to run this as dry-run, without deploying
publish = true //If version should be auto published after an upload
pkg {
repo = 'sagetv'
name = 'SageTV'
userOrg = 'opensagetv'
desc = "SageTV Release"
licenses = ['Apache-2.0']
vcsUrl = 'https://github.com/google/sagetv'
labels = ['sagetv']
publicDownloadNumbers = true
version {
name = "$baseVersion"
released = new Date()
desc = "SageTV ${baseVersion}"
//vcsTag = "V${version}"
//attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin']
}
}
}
// This get run when you call ./gradlew without any targets
defaultTasks 'sageJar'