JAL-3521 Moved the debian build.gradle to utils/debian/build.gradle.debian
[jalview.git] / utils / debian / build.gradle.debian
1 /* Convention for properties.  Read from gradle.properties, use lower_case_underlines for property names.
2  * For properties set within build.gradle, use camelCaseNoSpace.
3  */
4 import org.apache.tools.ant.filters.ReplaceTokens
5
6
7
8
9 plugins {
10   id 'java'
11 }
12
13
14
15 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
16 def string(Object o) {
17   return o == null ? "" : o.toString()
18 }
19
20
21 ext {
22   jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
23   jalviewDirRelativePath = jalviewDir
24
25
26   ////  
27   // Import releaseProps from the RELEASE file
28   // or a file specified via JALVIEW_RELEASE_FILE if defined
29   // Expect jalview.version and target release branch in jalview.release        
30   def releaseProps = new Properties();
31   def releasePropFile = findProperty("JALVIEW_RELEASE_FILE");
32   def defaultReleasePropFile = "${jalviewDirAbsolutePath}/RELEASE";
33   try {
34     (new File(releasePropFile!=null ? releasePropFile : defaultReleasePropFile)).withInputStream { 
35      releaseProps.load(it)
36     }
37   } catch (Exception fileLoadError) {
38     throw new Error("Couldn't load release properties file "+(releasePropFile==null ? defaultReleasePropFile : "from custom location: releasePropFile"),fileLoadError);
39   }
40   ////
41   // Set JALVIEW_VERSION if it is not already set
42   if (findProperty("JALVIEW_VERSION")==null || "".equals(JALVIEW_VERSION)) {
43     JALVIEW_VERSION = releaseProps.get("jalview.version")
44   }
45   
46
47   // essentials
48   bareSourceDir = string(source_dir)
49   sourceDir = string("${jalviewDir}/${bareSourceDir}")
50   resourceDir = string("${jalviewDir}/${resource_dir}")
51   bareTestSourceDir = string(test_source_dir)
52   testDir = string("${jalviewDir}/${bareTestSourceDir}")
53
54   classesDir = string("${jalviewDir}/${classes_dir}")
55
56
57   resourceClassesDir = classesDir
58
59   testSourceDir = testDir
60   testClassesDir = "${jalviewDir}/${test_output_dir}"
61
62   buildProperties = string("${classesDir}/${build_properties_file}")
63   gitHash = string("")
64   gitBranch = string("")
65
66   println("Using a ${CHANNEL} profile.")
67
68   additional_compiler_args = []
69   // configure classpath/args for j8/j11 compilation
70   if (JAVA_VERSION.equals("1.8")) {
71     JAVA_INTEGER_VERSION = string("8")
72     //libDir = j8libDir
73     libDir = j11libDir
74     libDistDir = j8libDir
75     compile_source_compatibility = 1.8
76     compile_target_compatibility = 1.8
77   } else if (JAVA_VERSION.equals("11")) {
78     JAVA_INTEGER_VERSION = string("11")
79     libDir = j11libDir
80     libDistDir = j11libDir
81     compile_source_compatibility = 11
82     compile_target_compatibility = 11
83   } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
84     JAVA_INTEGER_VERSION = JAVA_VERSION
85     libDir = j11libDir
86     libDistDir = j11libDir
87     compile_source_compatibility = JAVA_VERSION
88     compile_target_compatibility = JAVA_VERSION
89   } else {
90     throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
91   }
92
93
94
95
96   buildingHTML = string("${jalviewDir}/${doc_dir}/building.html")
97   helpFile = string("${resourceClassesDir}/${help_dir}/help.jhm")
98   helpParentDir = string("${jalviewDir}/${help_parent_dir}")
99   helpSourceDir = string("${helpParentDir}/${help_dir}")
100
101
102   // ENDEXT
103 }
104
105
106 sourceSets {
107   main {
108     java {
109       srcDirs sourceDir
110       outputDir = file(classesDir)
111     }
112
113     resources {
114       srcDirs resourceDir
115       srcDirs += helpParentDir
116     }
117
118     jar.destinationDir = file("${jalviewDir}/${package_dir}")
119
120     compileClasspath = files(sourceSets.main.java.outputDir)
121     compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
122
123     runtimeClasspath = compileClasspath
124   }
125
126   test {
127     java {
128       srcDirs testSourceDir
129       outputDir = file(testClassesDir)
130     }
131
132     resources {
133       srcDirs = sourceSets.main.resources.srcDirs
134     }
135
136     compileClasspath = files( sourceSets.test.java.outputDir )
137     compileClasspath += sourceSets.main.compileClasspath
138     compileClasspath += fileTree(dir: "${jalviewDir}/${utils_dir}/testnglibs", include: ["**/*.jar"])
139
140     runtimeClasspath = compileClasspath
141   }
142
143 }
144
145
146
147
148 compileJava {
149
150   doFirst {
151     sourceCompatibility = compile_source_compatibility
152     targetCompatibility = compile_target_compatibility
153     options.compilerArgs = additional_compiler_args
154     print ("Setting target compatibility to "+targetCompatibility+"\n")
155   }
156
157 }
158
159
160 compileTestJava {
161   doFirst {
162     sourceCompatibility = compile_source_compatibility
163     targetCompatibility = compile_target_compatibility
164     options.compilerArgs = additional_compiler_args
165     print ("Setting target compatibility to "+targetCompatibility+"\n")
166   }
167 }
168
169
170 clean {
171   doFirst {
172     delete sourceSets.main.java.outputDir
173   }
174 }
175
176
177 cleanTest {
178   doFirst {
179     delete sourceSets.test.java.outputDir
180   }
181 }
182
183
184 // format is a string like date.format("dd MMMM yyyy")
185 def getDate(format) {
186   def date = new Date()
187   return date.format(format)
188 }
189
190
191 task setGitVals {
192   def hashStdOut = new ByteArrayOutputStream()
193   exec {
194     commandLine "git", "rev-parse", "--short", "HEAD"
195     standardOutput = hashStdOut
196     ignoreExitValue true
197   }
198
199   def branchStdOut = new ByteArrayOutputStream()
200   exec {
201     commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
202     standardOutput = branchStdOut
203     ignoreExitValue true
204   }
205
206   gitHash = hashStdOut.toString().trim()
207   gitBranch = branchStdOut.toString().trim()
208
209   outputs.upToDateWhen { false }
210 }
211
212
213 task createBuildProperties(type: WriteProperties) {
214   dependsOn setGitVals
215   inputs.dir(sourceDir)
216   inputs.dir(resourceDir)
217   file(buildProperties).getParentFile().mkdirs()
218   outputFile (buildProperties)
219   // taking time specific comment out to allow better incremental builds
220   comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
221   //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
222   property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
223   property "VERSION", JALVIEW_VERSION
224   property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
225   outputs.file(outputFile)
226 }
227
228
229 task cleanBuildingHTML(type: Delete) {
230   doFirst {
231     delete buildingHTML
232   }
233 }
234
235
236 task convertBuildingMD(type: Exec) {
237   dependsOn cleanBuildingHTML
238   def buildingMD = "${jalviewDir}/${doc_dir}/building.md"
239   def css = "${jalviewDir}/${doc_dir}/github.css"
240
241   def pandoc = null
242   pandoc_exec.split(",").each {
243     if (file(it.trim()).exists()) {
244       pandoc = it.trim()
245       return true
246     }
247   }
248
249   def hostname = "hostname".execute().text.trim()
250   def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
251   if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) {
252     pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
253   }
254
255   doFirst {
256     if (pandoc != null && file(pandoc).exists()) {
257         commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
258     } else {
259         println("Cannot find pandoc. Skipping convert building.md to HTML")
260         throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
261     }
262   }
263
264   ignoreExitValue true
265
266   inputs.file(buildingMD)
267   inputs.file(css)
268   outputs.file(buildingHTML)
269 }
270
271
272 clean {
273   doFirst {
274     delete buildingHTML
275   }
276 }
277
278
279 task syncDocs(type: Sync) {
280   dependsOn convertBuildingMD
281   def syncDir = "${resourceClassesDir}/${doc_dir}"
282   from fileTree("${jalviewDir}/${doc_dir}")
283   into syncDir
284
285 }
286
287
288 task copyHelp(type: Copy) {
289   def inputDir = helpSourceDir
290   def outputDir = "${resourceClassesDir}/${help_dir}"
291   from(inputDir) {
292     exclude '**/*.gif'
293     exclude '**/*.jpg'
294     exclude '**/*.png'
295     filter(ReplaceTokens,
296       beginToken: '$$',
297       endToken: '$$',
298       tokens: [
299         'Version-Rel': JALVIEW_VERSION,
300         'Year-Rel': getDate("yyyy")
301       ]
302     )
303   }
304   from(inputDir) {
305     include '**/*.gif'
306     include '**/*.jpg'
307     include '**/*.png'
308   }
309   into outputDir
310
311   inputs.dir(inputDir)
312   outputs.files(helpFile)
313   outputs.dir(outputDir)
314 }
315
316
317 task syncResources(type: Sync) {
318   from resourceDir
319   include "**/*.*"
320   into "${resourceClassesDir}"
321   preserve {
322     include "**"
323   }
324 }
325
326
327 task prepare {
328   dependsOn syncResources
329   dependsOn syncDocs
330   dependsOn copyHelp
331 }
332
333
334 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
335 test {
336   dependsOn prepare
337   //dependsOn compileJava ////? DELETE
338
339   dependsOn compileJava //?
340
341   useTestNG() {
342     includeGroups testng_groups
343     excludeGroups testng_excluded_groups
344     preserveOrder true
345     useDefaultListeners=true
346   }
347
348   maxHeapSize = "1024m"
349
350   workingDir = jalviewDir
351   //systemProperties 'clover.jar' System.properties.clover.jar
352   def testLaf = project.findProperty("test_laf")
353   if (testLaf != null) {
354     println("Setting Test LaF to '${testLaf}'")
355     systemProperty "laf", testLaf
356   }
357   def testHiDPIScale = project.findProperty("test_HiDPIScale")
358   if (testHiDPIScale != null) {
359     println("Setting Test HiDPI Scale to '${testHiDPIScale}'")
360     systemProperty "sun.java2d.uiScale", testHiDPIScale
361   }
362   sourceCompatibility = compile_source_compatibility
363   targetCompatibility = compile_target_compatibility
364   jvmArgs += additional_compiler_args
365
366   doFirst {
367   }
368 }
369
370
371 task buildIndices(type: JavaExec) {
372   dependsOn copyHelp
373   classpath = sourceSets.main.compileClasspath
374   main = "com.sun.java.help.search.Indexer"
375   workingDir = "${classesDir}/${help_dir}"
376   def argDir = "html"
377   args = [ argDir ]
378   inputs.dir("${workingDir}/${argDir}")
379
380   outputs.dir("${classesDir}/doc")
381   outputs.dir("${classesDir}/help")
382   outputs.file("${workingDir}/JavaHelpSearch/DOCS")
383   outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
384   outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
385   outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
386   outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
387   outputs.file("${workingDir}/JavaHelpSearch/TMAP")
388 }
389
390
391 task compileLinkCheck(type: JavaCompile) {
392   options.fork = true
393   classpath = files("${jalviewDir}/${utils_dir}")
394   destinationDir = file("${jalviewDir}/${utils_dir}")
395   source = fileTree(dir: "${jalviewDir}/${utils_dir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
396
397   inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java")
398   inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java")
399   outputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.class")
400   outputs.file("${jalviewDir}/${utils_dir}/BufferedLineReader.class")
401 }
402
403
404 task linkCheck(type: JavaExec) {
405   dependsOn prepare, compileLinkCheck
406
407   def helpLinksCheckerOutFile = file("${jalviewDir}/${utils_dir}/HelpLinksChecker.out")
408   classpath = files("${jalviewDir}/${utils_dir}")
409   main = "HelpLinksChecker"
410   workingDir = jalviewDir
411   args = [ "${classesDir}/${help_dir}", "-nointernet" ]
412
413   def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
414   def errFOS = outFOS
415   standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
416     outFOS,
417     standardOutput)
418   errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
419     outFOS,
420     errorOutput)
421
422   inputs.dir("${classesDir}/${help_dir}")
423   outputs.file(helpLinksCheckerOutFile)
424 }
425
426 // import the pubhtmlhelp target
427 ant.properties.basedir = "${jalviewDir}"
428 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
429 ant.importBuild "${utils_dir}/publishHelp.xml"
430
431
432 task cleanPackageDir(type: Delete) {
433   doFirst {
434     delete fileTree(dir: "${jalviewDir}/${package_dir}", include: "*.jar")
435   }
436 }
437
438 jar {
439   dependsOn linkCheck
440   dependsOn buildIndices
441   dependsOn createBuildProperties
442
443   manifest {
444     attributes "Main-Class": main_class,
445     "Permissions": "all-permissions",
446     "Application-Name": "Jalview Desktop",
447     "Codebase": application_codebase
448   }
449
450   destinationDir = file("${jalviewDir}/${package_dir}")
451   archiveName = rootProject.name+".jar"
452
453   exclude "cache*/**"
454   exclude "*.jar"
455   exclude "*.jar.*"
456   exclude "**/*.jar"
457   exclude "**/*.jar.*"
458
459   inputs.dir(classesDir)
460   outputs.file("${jalviewDir}/${package_dir}/${archiveName}")
461 }