forked from omegat-org/omegat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
1163 lines (1055 loc) · 41.1 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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import org.apache.tools.ant.filters.ReplaceTokens
import org.apache.tools.ant.filters.FixCrLfFilter
plugins {
id 'application'
id 'java-library'
id 'maven-publish'
id 'signing'
id 'eclipse'
id 'checkstyle'
id 'jacoco'
id 'com.github.spotbugs' version '4.7.10'
id 'org.hidetake.ssh' version '2.10.1'
id 'com.diffplug.spotless' version '6.0.0'
id 'com.github.ben-manes.versions' version '0.39.0'
id 'ru.vyarus.mkdocs' version '3.0.0'
id "org.sonarqube" version "4.0.0.2929"
}
apply from: 'gradle/utils.gradle'
applicationName = 'OmegaT'
mainClassName = 'org.omegat.Main'
ext {
javaVersion = '1.8'
omtVersion = loadProperties(file('src/org/omegat/Version.properties'))
omtFlavor = omtVersion.beta.empty ? 'standard' : 'latest'
omtWebsite = 'https://omegat.org'
envIsCi = project.hasProperty('envIsCi')
localPropsFile = file('local.properties')
if (localPropsFile.file) {
loadProperties(localPropsFile).each { k, v ->
if (!findProperty(k)) {
set(k, v)
}
}
}
}
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
version = omtVersion.version + getUpdateSuffix(omtVersion.update)
java {
withSourcesJar()
withJavadocJar()
}
sourceSets {
main {
java {
srcDir 'src'
}
resources {
srcDir 'src'
}
}
test {
java {
srcDir 'test/src'
}
resources {
srcDir 'test/src'
srcDir 'test/data'
}
}
testIntegration {
java {
srcDir 'test-integration/src'
}
}
}
repositories {
mavenCentral()
}
configurations {
all {
// Temporary exclusion; see https://sourceforge.net/p/omegat/bugs/813/
exclude group: 'org.apache.lucene', module: 'lucene-core'
}
[testRuntime, testCompile]*.exclude group: 'org.languagetool', module: 'language-all'
testIntegrationImplementation.extendsFrom implementation
jaxb
}
ext {
providedLibsDir = file('lib/provided')
languageToolVersion = '3.5'
luceneVersion = '5.2.1'
}
dependencies {
// Libs are provided in the "source" distribution only
if (providedLibsDir.directory) {
implementation fileTree(dir: providedLibsDir, include: '**/*.jar')
} else {
implementation 'commons-io:commons-io:2.11.0'
implementation 'commons-lang:commons-lang:2.6'
// macOS integration
implementation 'org.madlonkay:desktopsupport:0.6.0'
api 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'com.sun.xml.bind:jaxb-impl:2.3.4'
// Data: inline data URL handler
implementation 'tokyo.northside:url-protocol-handler:0.1.4'
// PDF Filter
implementation 'org.apache.pdfbox:pdfbox:2.0.27'
// Aligner
implementation 'net.loomchild:maligna:3.0.1'
// Dictionary
implementation 'com.github.takawitter:trie4j:0.9.8'
implementation 'io.github.eb4j:dsl4j:0.5.3'
implementation 'tokyo.northside:stardict4j:0.5.0'
// Encoding detections
implementation 'com.github.albfernandez:juniversalchardet:2.4.0'
// Legacy projects re-hosted on Maven Central
api 'org.omegat:vldocking:3.0.5'
runtimeOnly 'org.slf4j:slf4j-jdk14:1.7.32' // needed by vldocking
implementation 'org.omegat:htmlparser:1.6-20230203'
implementation 'org.omegat:gnudiff4j:1.15'
implementation 'org.omegat:lib-mnemonics:1.1'
implementation 'org.omegat:jmyspell-core:1.0.0-beta-2'
// LanguageTool
implementation "org.languagetool:languagetool-core:${languageToolVersion}"
runtimeOnly("org.languagetool:language-all:${languageToolVersion}") {
// Temporary exclusion; see https://sourceforge.net/p/omegat/bugs/814/
exclude module: 'lucene-gosen-ipadic'
}
runtimeOnly 'org.omegat.lucene:lucene-gosen:5.0.0:ipadic'
runtimeOnly 'org.languagetool:hunspell-native-libs:2.9'
// Lucene for tokenizers
// Temporary use of custom lucene-core; see https://sourceforge.net/p/omegat/bugs/813/
implementation "org.omegat.lucene:lucene-core:${luceneVersion}-1"
implementation "org.apache.lucene:lucene-analyzers-common:${luceneVersion}"
implementation "org.apache.lucene:lucene-analyzers-kuromoji:${luceneVersion}"
implementation "org.apache.lucene:lucene-analyzers-smartcn:${luceneVersion}"
implementation "org.apache.lucene:lucene-analyzers-stempel:${luceneVersion}"
// Team project server support
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.13.1.202206130422-r'
// Original JSch is unmaintained and dead, so we use forked version, mwiede/jsch
// to fix BUGS#1075, and to support elliptic curve ciphers and improved ssh agent
implementation 'com.github.mwiede:jsch:0.2.3'
// https://mvnrepository.com/artifact/org.eclipse.jgit/org.eclipse.jgit.ssh.jsch
implementation ('org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:5.13.1.202206130422-r') {
exclude module: 'jsch'
}
// For ed25519 and ecdsa support of jsch, java16+ or BC
implementation 'org.bouncycastle:bcprov-jdk15on:1.69'
// For ssh agent support of jsch, Java16+ or junixsocket
implementation 'com.kohlschutter.junixsocket:junixsocket-core:2.4.0'
// For gpg signing
implementation 'org.eclipse.jgit:org.eclipse.jgit.gpg.bc:5.11.1.202105131744-r'
// For subversion
implementation 'org.tmatesoft.svnkit:svnkit:1.10.9'
// Team project conflict resolution
implementation 'org.madlonkay:supertmxmerge:2.0.3'
// Credentials encryption
implementation 'org.jasypt:jasypt:1.9.3'
// Groovy used for scripts - needed at implementation for GroovyClassLoader modifications
// Ivy is needed to handle Grape/@Grab dependencies
runtimeOnly('org.codehaus.groovy:groovy-all:3.0.9@pom') {
transitive = true
}
runtimeOnly 'org.codehaus.groovy:groovy-dateutil:3.0.9'
runtimeOnly 'org.apache.ivy:ivy:2.5.1'
// Script editor
implementation 'com.fifesoft:rsyntaxtextarea:3.2.0'
implementation 'com.fifesoft:rstaui:3.2.0'
implementation ('com.fifesoft:languagesupport:3.1.4') {
exclude module: 'rhino'
}
implementation 'com.fifesoft:autocomplete:3.2.0'
// JSON parser
implementation "com.fasterxml.jackson.core:jackson-core:2.13.4"
implementation "com.fasterxml.jackson.core:jackson-databind:2.13.4.2"
implementation("com.github.ben-manes.caffeine:caffeine:2.9.3") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.class, Bundling.EXTERNAL))
}
}
implementation("com.github.ben-manes.caffeine:jcache:2.9.3") {
exclude module: 'caffeine'
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.class, Bundling.EXTERNAL))
}
}
}
// Test dependencies
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.xmlunit:xmlunit-legacy:2.8.3'
testImplementation("org.languagetool:languagetool-server:${languageToolVersion}") {
exclude group: 'org.slf4j'
}
// LanguageTool unit tests exercise these languages
['be', 'en', 'fr'].each {
testImplementation "org.languagetool:language-${it}:${languageToolVersion}"
}
testRuntimeOnly "org.languagetool:language-pl:${languageToolVersion}"
// JAXB codegen only
jaxb 'com.sun.xml.bind:jaxb-xjc:2.3.4'
testIntegrationImplementation sourceSets.main.output, sourceSets.test.output
}
jar {
def omtPlugins = loadProperties(file('Plugins.properties'))
manifest {
attributes('License': 'GNU Public License version 3 or later',
'Implementation-Version': project.version,
'Permissions': 'all-permissions',
'OmegaT-Plugin': 'true',
'OmegaT-Plugins': omtPlugins.plugin,
'Plugin-Author': 'OmegaT team',
'Plugin-Link': 'https://omegat.org',
'Plugin-Version': project.version,
'Main-Class': mainClassName,
'Class-Path': configurations.runtimeClasspath.collect { "lib/${it.name}" }.join(' '))
ext.pluginAttr = { name, path, category, description ->
attributes('Plugin-Name': name, 'Plugin-Category': category, 'Plugin-Description': description, path)
}
def desc = [:]
omtPlugins.each { key, val ->
if (key.startsWith('plugin.desc')) {
desc[key.split('\\.').last()] = val
} else if (key != 'plugin') {
val.tokenize().each { cls ->
attributes('OmegaT-Plugin': key, cls)
}
}
}
pluginAttr('Dictionary driver[bundle]', 'org/omegat/core/dictionaries/', 'dictionary', desc.dictionary)
pluginAttr('MT connector[bundle]', 'org/omegat/core/machinetranslators/', 'machinetranslator', desc.machinetranslator)
pluginAttr('File filters[bundle]', 'org/omegat/filters2/', 'filter', desc.filters2)
pluginAttr('XML filters[bundle]', 'org/omegat/filters3/', 'filter', desc.filters3)
pluginAttr('New XML filters[bundle]', 'org/omegat/filters4/', 'filter', desc.filters4)
pluginAttr('Tokenizers[bundle]', 'org/omegat/tokenizer/', 'tokenizer', desc.tokenizer)
pluginAttr('Themes [bundle]', 'org/omegat/gui/theme/', 'theme', desc.theme)
pluginAttr('Scripting engine', 'org/omegat/gui/script/', 'miscellaneous', desc.script)
pluginAttr('GUI extensions', 'org/omegat/util/gui/', 'miscellaneous', desc.guiutil)
pluginAttr('Local external search', 'org/omegat/externalfinder/', 'miscellaneous', desc.externalfinder)
}
// Don't include extra stuff like version number in JAR name
archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}"
}
ext {
distsDir = file("${buildDir}/${distsDirName}")
assetDir = findProperty('assetDir') ?: '../'
macJRE = fileTree(dir: assetDir, include: '*-jre_x64_mac_*.tar.gz')
linux64JRE = fileTree(dir: assetDir, include: '*-jre_x64_linux_*.tar.gz')
windowsJRE = fileTree(dir: assetDir, include: '*-jre_x86-32_windows_*.zip')
windowsJRE64 = fileTree(dir: assetDir, include: '*-jre_x64_windows_*.zip')
}
task genDocIndex(type: Copy) {
description = 'Generate the docs index file'
def docPropsFiles = fileTree(dir: 'docs', include: '*/version*.properties').findAll {
file("${it.parent}/index.html").file
}
def isgFiles = fileTree(dir: 'docs', include: '*/instantStartGuideNoTOC.html').findAll {
file("${it.parent}/instantStartGuideNoTOC.html").file
}
inputs.files docPropsFiles
from('doc_src') {
include 'index_template.html'
}
into 'docs'
rename('index_template.html', 'index.html')
doFirst {
def langNameExceptions = loadProperties(file('doc_src/lang_exceptions.properties'))
def isgInfos = isgFiles.collect { isg ->
def code = isg.parentFile.name
def locale = Locale.forLanguageTag(code.replace('_', '-'))
def name = langNameExceptions[code] ?: locale.getDisplayName(locale)
def docVersion = 0
def noManual = true
def status = 'out-of-date'
['code': code, 'name': name, 'version': docVersion, 'status': status, 'nomanual': noManual]
}
def langInfos = docPropsFiles.collect { props ->
def code = props.parentFile.name
def locale = Locale.forLanguageTag(code.replace('_', '-'))
def name = langNameExceptions[code] ?: locale.getDisplayName(locale)
def docVersion = loadProperties(props).version
def noManual = false
def status = docVersion == omtVersion.version ? 'up-to-date' : 'out-of-date'
['code': code, 'name': name, 'version': docVersion, 'status': status, 'nomanual': noManual]
}
def filterSet = langInfos.collect {entry -> entry.code}
def filteredIsgInfos = isgInfos.findAll{entry -> !filterSet.contains(entry.code)}
langInfos.addAll(filteredIsgInfos)
langInfos.sort { entry -> entry.code }
expand('languages': langInfos)
filteringCharset = 'UTF-8'
}
}
task webManual(type: Sync) {
group = 'documentation'
description = 'Generate the HTML manual'
dependsOn genDocIndex
destinationDir = file("${buildDir}/docs/manual")
from 'docs'
from('release') {
include 'doc-license.txt'
}
}
distributions {
main {
contents {
from('docs') {
into 'docs'
exclude 'index.html'
}
from(genDocIndex.outputs) {
into 'docs'
include 'index.html'
}
from('release') {
into 'docs'
include 'changes.txt', 'doc-license.txt', 'OmegaT-license.txt', 'contributors.txt', 'libraries.txt'
filter(FixCrLfFilter, eol: FixCrLfFilter.CrLf.newInstance('crlf'))
}
from('scripts') {
into 'scripts'
}
from('images') {
into 'images'
}
from('release') {
exclude 'contributors.txt', 'libraries.txt'
include '*.txt', '*.html'
filter(ReplaceTokens, tokens: [TRANSLATION_NOTICE: ''])
filter(FixCrLfFilter, eol: FixCrLfFilter.CrLf.newInstance('crlf'))
}
from('release/plugins-specific') {
into 'plugins'
}
from('release/linux-specific') {
filter(ReplaceTokens, tokens:
[VERSION_NUMBER_SUBST: project.version,
JAR_SUBST: jar.archiveName])
fileMode 0755
}
from('release/win32-specific') {
include 'OmegaT.bat'
filter(ReplaceTokens, tokens: [JAR_SUBST: jar.archiveName])
}
from('lib/licenses') {
into 'lib'
}
eachFile {
// Move main JAR up one level from lib.
if (it.name == jar.archiveName) {
it.relativePath = it.relativePath.parent.parent.append(true, jar.archiveName)
}
}
}
distZip.archiveFileName = "${applicationName}_${version}${omtVersion.beta}_Without_JRE.zip"
}
source {
contents {
from(rootDir) {
include 'config/**', 'docs/**', 'images/**', 'lib/**', 'release/**',
'src/**', 'test/**', 'doc_src/**', 'docs_devel/**', 'scripts/**',
'gradle/**', 'gradlew*', '*.gradle', 'README.md', '*.properties'
exclude '**/build/**', 'doc_src/**/pdf/**', 'local.properties'
}
into('lib/provided') {
from configurations.runtimeClasspath
}
}
sourceDistZip.archiveFileName = "${applicationName}_${version}${omtVersion.beta}_Source.zip"
}
mac {
contents {
from('release/mac-specific') {
exclude '**/MacOS/OmegaT', '**/Info.plist', '**/java.entitlements'
}
from('release/mac-specific') {
include '**/MacOS/OmegaT'
fileMode 0755
}
from('release/mac-specific') {
include '**/Info.plist'
expand(version: project.version,
// $APP_ROOT is expanded at runtime by the launcher binary
configfile: '$APP_ROOT/Contents/Resources/Configuration.properties')
}
into('OmegaT.app/Contents/Java') {
with main.contents
exclude '*.sh', '*.kaptn', 'OmegaT', 'OmegaT.bat'
}
if (!macJRE.empty) {
from(tarTree(macJRE.singleFile)) {
into 'OmegaT.app/Contents/PlugIns'
includeEmptyDirs = false
eachFile {
replaceRelativePathSegment(it, /jdk.*-jre/, 'jre.bundle')
}
}
}
}
}
linux64 {
contents {
with main.contents
exclude 'OmegaT.bat'
if (!linux64JRE.empty) {
from(tarTree(linux64JRE.singleFile)) {
includeEmptyDirs = false
eachFile {
replaceRelativePathSegment(it, /jdk.*-jre/, 'jre')
}
}
}
}
}
}
installMacDist {
doFirst {
delete "$destinationDir/OmegaT.app/Contents/PlugIns/jre.bundle"
}
}
def hunspellJar = configurations.runtimeClasspath.files.find {
it.name.startsWith('hunspell-native-libs')
}
task hunspellJarSignedContents(type: Sync) {
onlyIf {
// Set this in e.g. local.properties
condition(project.hasProperty('macCodesignIdentity'), 'Code signing property not set')
}
from zipTree(hunspellJar)
destinationDir = file("$buildDir/hunspell")
doLast {
def jnilibs = fileTree(dir: destinationDir, include: '**/*.jnilib').files
exec {
commandLine('codesign', '--deep', '--force',
'--sign', project.property('macCodesignIdentity'),
'--timestamp',
'--options', 'runtime',
'--entitlements', file('release/mac-specific/java.entitlements'),
*jnilibs.toList())
}
}
}
task hunspellSignedJar(type: Jar) {
from hunspellJarSignedContents.outputs
archiveFileName = hunspellJar.name
}
task installMacSignedDist(type: Sync) {
description = 'Build the signed Mac distribution. Requires an Apple Developer Account.'
onlyIf {
// Set this in e.g. local.properties
condition(project.hasProperty('macCodesignIdentity'), 'Code signing property not set')
}
with distributions.mac.contents
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from(hunspellSignedJar.outputs) {
into 'OmegaT.app/Contents/Java/lib'
}
destinationDir = file("${buildDir}/install/${applicationName}-macSigned")
doFirst {
delete "$destinationDir/OmegaT.app/Contents/PlugIns/jre.bundle"
}
doLast {
exec {
commandLine 'codesign', '--deep', '--force',
'--sign', project.property('macCodesignIdentity'),
'--timestamp',
'--options', 'runtime',
'--entitlements', file('release/mac-specific/java.entitlements'),
file("${destinationDir}/OmegaT.app")
}
}
}
macDistZip {
onlyIf {
condition(!macJRE.empty, 'JRE not found')
}
archiveFileName = "${applicationName}_${project.version}${omtVersion.beta}_Mac.zip"
}
task macSignedDistZip(type: Zip) {
def zipRoot = "${applicationName}_${project.version}${omtVersion.beta}_Mac_Signed"
from(installMacSignedDist.outputs) {
into zipRoot
}
archiveFileName = "${zipRoot}.zip"
}
task macNotarize {
onlyIf {
condition(project.hasProperty('macNotarizationUsername'),
'Username for notarization not set')
}
inputs.files macSignedDistZip.outputs.files
doLast {
exec {
// Assuming setup per instructions at
// https://developer.apple.com/documentation/security/notarizing_your_app_before_distribution/customizing_the_notarization_workflow#3087734
commandLine 'xcrun', 'altool', '--notarize-app',
'--primary-bundle-id', "org.omegat.$version",
'--username', project.property('macNotarizationUsername'),
'--password', '@keychain:AC_PASSWORD',
'--file', inputs.files.singleFile
}
}
}
task macStapledNotarizedDistZip(type: Zip) {
def zipRoot = "${applicationName}_${project.version}${omtVersion.beta}_Mac_Notarized"
from(installMacSignedDist.outputs) {
into zipRoot
}
doFirst {
def app = "${installMacSignedDist.destinationDir}/OmegaT.app"
exec {
commandLine 'xcrun', 'stapler', 'staple', app
}
}
archiveFileName = "${zipRoot}.zip"
}
task mac(dependsOn: [macDistZip, macNotarize]) {
description = 'Build the Mac distributions.'
group = 'distribution'
}
task linux(dependsOn: [linux64DistTar]) {
description = 'Build the Linux distributions.'
group = 'distribution'
}
linux64DistTar {
onlyIf {
condition(!linux64JRE.empty, 'JRE not found')
}
doFirst {
delete "$destinationDirectory/jre"
}
archiveFileName = "${applicationName}_${project.version}${omtVersion.beta}_Linux_64.tar.bz2"
compression = Compression.BZIP2
archiveExtension = 'tar.bz2'
}
// We bundle our startup scripts separately, so disable startScripts.
startScripts.enabled = false
// installDist insists on installing a script. Trick it with a dummy script.
installDist.doFirst {
startScripts.outputDir.mkdirs()
file("${startScripts.outputDir}/${applicationName}").createNewFile()
if (destinationDir.directory) {
// As of Gradle 4.4(?) the application plugin expects `lib` as well
['lib', 'bin'].each { file("${destinationDir}/${it}").mkdirs() }
}
}
// Delete dummy afterwards.
installDist.doLast {
delete "${destinationDir}/bin"
delete startScripts.outputDir
}
// Read in all our custom messages and massage them for inclusion in the .iss
ext.getInnoSetupCustomMessages = {
// Don't include languages that InnoSetup doesn't have strings for
def blacklist = ['cy', 'ia', 'mfe']
// Sort files to ensure English comes first, to set fallback
fileTree(dir: 'release/win32-specific', include: 'CustomMessages*.ini')
.sort()
.collect { file ->
def match = file.name =~ /CustomMessages_?([^\.]*).ini/
if (match) {
def capture = match.group(1)
def lang = capture.empty ? 'en' : capture
if (!blacklist.contains(lang)) {
file.text.replaceAll(/(?m)^([^=]+)/) { "$lang.${it[0]}" }
}
}
}.findAll()
.join(System.lineSeparator())
}
task win {
description = 'Build the Windows distributions.'
group = 'distribution'
}
ext.makeWinTask = { args ->
def fullVersion = project.version + omtVersion.beta
def installerBasename = "OmegaT_${fullVersion}_${args.suffix}"
def installerExe = "${distsDir}/${installerBasename}.exe"
task(type: Sync, args.name) {
description = "Create a Windows installer for ${args.name} distro. " +
'Requires Inno Setup (http://www.jrsoftware.org/isinfo.php).'
with distributions.main.contents
from ('release/win32-specific') {
include 'OmegaT.exe', 'OmegaT.l4J.ini'
}
if (args.jrePath && !args.jrePath.empty) {
from (zipTree(args.jrePath.singleFile)) {
includeEmptyDirs = false
eachFile {
replaceRelativePathSegment(it, /jdk.*-jre/, 'jre')
}
}
}
destinationDir = file("${buildDir}/innosetup/${args.name}")
outputs.file installerExe
onlyIf {
conditions([!args.jrePath || !args.jrePath.empty, 'JRE not found'],
[exePresent('iscc') || exePresent('docker'),
'InnoSetup or Docker not installed'])
}
doFirst {
delete "$destinationDir/jre"
}
doLast {
project.copy {
from('release/win32-specific') {
include 'OmegaT.iss'
}
into(destinationDir)
filter(ReplaceTokens, tokens: [
VERSION_NUMBER_SUBST: fullVersion,
OUTPUT_BASENAME_SUBST: installerBasename.toString(),
CUSTOM_MESSAGES_SUBST: getInnoSetupCustomMessages(),
ARCHITECTURE_SUBST: args.arch ?: ''
])
filter(FixCrLfFilter, eol: FixCrLfFilter.CrLf.newInstance('crlf'))
filteringCharset = 'UTF-8'
}
exec {
// You'd think we could just set the PATH, but there be dragons here
// https://github.com/palantir/gradle-docker/issues/162
def exe = exePresent('iscc') ? 'iscc' : file('release/ci/iscc')
commandLine exe, "${destinationDir}/OmegaT.iss"
}
ant.move file: "${destinationDir}/${installerBasename}.exe",
todir: distsDir
}
}
def signedTaskName = "${args.name}Signed"
task(signedTaskName) {
onlyIf {
// Set these in e.g. local.properties
def props = ['winCodesignFile', 'winCodesignPassword', 'winCodesignTimestampUrl']
conditions([props.every { project.hasProperty(it) }, 'Code signing properties not set'],
[file(installerExe).file, 'Unsigned installer not built'],
[exePresent('osslsigncode') || exePresent('docker'),
'osslsigncode or Docker not installed'])
}
def signedExe = "${distsDir}/${installerBasename}_Signed.exe"
inputs.file installerExe
outputs.file signedExe
doLast {
exec {
// You'd think we could just set the PATH, but there be dragons here
// https://github.com/palantir/gradle-docker/issues/162
def exe = exePresent('osslsigncode') ? 'osslsigncode' : file('release/ci/osslsigncode')
commandLine exe, 'sign',
'-pkcs12', project.property('winCodesignFile'),
'-pass', project.property('winCodesignPassword'),
'-n', applicationName,
'-i', omtWebsite,
'-t', project.property('winCodesignTimestampUrl'),
'-h', 'sha2',
'-in', installerExe,
'-out', signedExe
}
}
dependsOn args.name
}
assemble.dependsOn args.name, signedTaskName
win.dependsOn args.name, signedTaskName
}
makeWinTask(name: 'winNoJRE', suffix: 'Windows_without_JRE')
makeWinTask(name: 'winJRE', suffix: 'Windows', jrePath: windowsJRE)
makeWinTask(name: 'winJRE64', suffix: 'Windows_64', jrePath: windowsJRE64, arch: 'x64')
// Disable .tar distributions for everyone but Linux
tasks.findAll { it.name =~ /[dD]istTar$/ && !it.name.contains('linux') }.each { it.enabled = false }
// Disable .zip distributions for Linux
tasks.findAll { it.name =~ /[dD]istZip$/ && it.name.contains('linux') }.each { it.enabled = false }
processResources {
def revision = detectRevision()
inputs.property 'revision', revision
doLast {
logger.lifecycle("Detected revision ${revision}")
def versionFile = file("${sourceSets.main.output.resourcesDir}/org/omegat/Version.properties")
ant.propertyfile(file: versionFile) {
entry(key: 'revision', value: revision)
}
}
}
task checksums {
def algos = ['SHA-512', 'MD5']
description = "Generate ${algos.join(', ')} checksums for distribution files"
inputs.files fileTree(dir: distsDir, exclude: 'checksums')
def checksumsDir = file("${distsDir}/checksums")
outputs.dir checksumsDir
onlyIf {
condition(distsDir.directory, 'Distfiles not found')
}
doLast {
distsDir.listFiles().findAll { it.file }.each { f ->
algos.each { algo ->
ant.checksum file: f, algorithm: algo, todir: checksumsDir
}
}
}
}
task genJAXB {
description = 'Generate classes for loading and manipulating XML formats'
}
ext.makeJaxbTask = { args ->
def taskName = "gen${args.name.capitalize()}"
task(type: JavaExec, taskName) {
classpath = configurations.jaxb
mainClass = 'com.sun.tools.xjc.XJCFacade'
delegate.args args.args
outputs.dir args.outdir
}
genJAXB.dependsOn taskName
}
makeJaxbTask(name: 'segmentation', outdir: 'src/gen/core/segmentation',
args: ['-no-header', '-d', 'src', '-p', 'gen.core.segmentation', 'src/schemas/srx20.xsd'])
makeJaxbTask(name: 'filters', outdir: 'src/gen/core/filters',
args: ['-no-header', '-d', 'src', '-p', 'gen.core.filters', 'src/schemas/filters.xsd'])
makeJaxbTask(name: 'tbx', outdir: 'src/gen/core/tbx',
args: ['-no-header', '-d', 'src', '-p', 'gen.core.tbx', 'src/schemas/tbx.xsd'])
makeJaxbTask(name: 'project', outdir: 'src/gen/core/project',
args: ['-no-header', '-d', 'src', '-p', 'gen.core.project', 'src/schemas/project_properties.xsd'])
makeJaxbTask(name: 'tmx14', outdir: 'src/gen/core/tmx14',
args: ['-no-header', '-d', 'src', '-p', 'gen.core.tmx14', '-b', 'src/schemas/tmx14.xjb', 'src/schemas/tmx14.xsd'])
task genMac {
description = 'Generate the Mac .app skeleton. Requires AppBundler (https://bitbucket.org/infinitekind/appbundler) ' +
'to be available in ~/.ant/lib'
outputs.dir file('release/mac-specific')
def appbundlerJar = file("${System.getProperty('user.home')}/.ant/lib/appbundler-1.0ea.jar")
onlyIf {
condition(appbundlerJar.file, 'AppBundler not found')
}
doLast {
ant.taskdef(name: 'appbundler',
classname: 'com.oracle.appbundler.AppBundlerTask',
classpath: appbundlerJar)
ant.appbundler(outputdirectory: 'release/mac-specific',
name: applicationName,
displayname: applicationName,
executablename: applicationName,
identifier: 'org.omegat.OmegaT',
icon: 'images/OmegaT.icns',
version: '${version}',
jvmrequired: javaVersion,
shortversion: '${version}',
mainclassname: mainClassName) {
option(value: "-Xdock:name=${applicationName}")
argument(value: '--config-file=${configfile}')
bundledocument(extensions: 'project',
name: "${applicationName} Project",
role: 'editor',
icon: 'images/OmegaT.icns')
bundledocument(extensions: '*',
name: 'All Files',
role: 'none')
plistentry(key: 'JVMRuntime', value: 'jre.bundle')
}
}
}
allprojects {
javadoc {
failOnError = false
}
tasks.withType(JavaCompile) {
options.compilerArgs.addAll '-Xlint', '-Werror'
}
}
spotbugs {
// reportLevel = 'high'
}
tasks.findAll { it.name =~ /^spotbugs.*/ }.each {
it.reports {
xml.enabled = envIsCi
html.enabled = !envIsCi
}
}
checkstyle {
toolVersion = '8.45.1'
}
checkstyleMain.exclude '**/gen/**'
spotless {
enforceCheck false
java {
targetExclude 'src/gen/**'
eclipse().configFile 'docs_devel/docs/assets/eclipse-formatting.xml'
removeUnusedImports()
}
}
task changedOnBranch {
description = 'List files that have been modified on this git branch.'
group = 'omegat workflow'
doLast {
ext.files = project.files(gitModifiedFiles())
ext.files.each { println(it) }
}
}
task spotlessChangedApply {
description = 'Apply code formatting to files that have been changed on the current branch.'
group = 'omegat workflow'
finalizedBy 'spotlessApply'
dependsOn changedOnBranch
doFirst {
spotlessJava.target = changedOnBranch.files.findAll {
it.path.endsWith('.java')
}
}
}
jacoco {
toolVersion="0.8.6"
}
tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
group = 'verification'
reports {
xml.required = true // coveralls plugin depends on xml format report
html.required = true
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: ["gen/core/**/*", "org/omegat/**/gui/*", "org/omegat/**/data/*"])
}))
}
}
// check.dependsOn jacocoTestCoverageVerification
tasks.jacocoTestCoverageVerification {
dependsOn(tasks.test)
violationRules {
rule {
element = 'CLASS'
includes = ['org.omegat.core.machinetranslators.*', 'org.omegat.core.dictionaries.*']
excludes = ['**.*.1', '**.*.2', '**.*.3'] // ignore inner classes
limit { minimum = 0.20 }
}
rule {
element = 'PACKAGE'
includes = ['org.omegat.filters?.*',
'org.omegat.externalfinder', 'org.omegat.languagetools', 'org.omegat.util',
'org.omegat.core.events', 'org.omegat.core.matching', 'org.omegat.core.search',
'org.omegat.core.segmentation', 'org.omegat.core.spellchecker', 'org.omegat.core.statistics',
'org.omegat.core.tagvalidation', 'org.omegat.core.team2.*']
excludes = ['org.omegat.core.team2.gui', 'org.omegat.util.xml.*']
limit { minimum = 0.60 }
}
}
}
task manualPdfs {
description = 'Build PDF manuals for all languages. Requires Docker.'
group = 'omegat workflow'
}
task manualHtmls {
description = 'Build HTML manuals for all languages. Requires Docker.'
group = 'omegat workflow'
}
ext.manualIndexXmls = fileTree(dir: 'doc_src', include: '**/OmegaTUsersManual_xinclude full.xml')
manualIndexXmls.each { xml ->
def lang = xml.parentFile.name
def pdfTaskName = "manualPdf${lang.capitalize()}"
task(pdfTaskName) {
inputs.files fileTree(dir: "doc_src/${lang}", include: '**/*.xml')
outputs.file "${distsDir}/OmegaT_documentation_${lang}.PDF"
doLast {
exec {
workingDir = 'doc_src'
commandLine './docgen', "-Dlanguage=${lang}", 'pdf'
}
copy {
from fileTree(dir: "doc_src/${lang}/pdf", include: '*.PDF')
into distsDir
}
delete fileTree(dir: "doc_src/${lang}", includes: ['pdf/*', 'index.xml'])
}
}
manualPdfs.dependsOn pdfTaskName
def htmlTaskName = "manualHtml${lang.capitalize()}"
task(htmlTaskName) {
inputs.files fileTree(dir: "doc_src/${lang}", include: '**/*.xml')
doLast {
exec {
workingDir = 'doc_src'
commandLine './docgen', "-Dlanguage=${lang}", 'html5'
}
delete fileTree(dir: "doc_src/${lang}", includes: ['xhtml5/**/*', 'index.xml'])
}
}
manualHtmls.dependsOn htmlTaskName
}
task instantStartGuides {
description = 'Build Instant Start guides for all languages. Requires Docker.'
group = 'omegat workflow'
}
task firstSteps {
description = 'Build First Step pages for all languages. Requires Docker.'
group = 'omegat workflow'
}
task updateManuals {
group = 'omegat workflow'
description = 'Update Instant Start guides and HTML manuals.'
dependsOn manualHtmls, firstSteps, instantStartGuides
finalizedBy genDocIndex
}
ext.firstStepsXmls = fileTree(dir: 'doc_src', include: '**/First_Steps.xml')
firstStepsXmls.each { xml ->
def lang = xml.parentFile.name
def taskName = "firstSteps${lang.capitalize()}"
task(taskName) {
inputs.files fileTree(dir: "doc_src/${lang}", include: '**/*.xml')
doLast {
exec {
workingDir = 'doc_src'
commandLine './docgen', "-Dlanguage=${lang}", 'first-steps'
}
}
}
firstSteps.dependsOn taskName
}
ext.instantStartXmls = fileTree(dir: 'doc_src', include: '**/InstantStartGuide.xml')
instantStartXmls.each { xml ->
def lang = xml.parentFile.name
def taskName = "instantStartGuide${lang.capitalize()}"
task(taskName) {
inputs.files fileTree(dir: "doc_src/${lang}", include: '**/*.xml')
doLast {
exec {
workingDir = 'doc_src'