JAL-3210 ... almost goomph build
[jalview.git] / build.gradle
1 import org.apache.tools.ant.filters.ReplaceTokens
2 import org.gradle.internal.os.OperatingSystem
3 import org.gradle.plugins.ide.eclipse.model.*
4 import groovy.transform.ExternalizeMethods
5 //import org.eclipse.osgi.*
6 import com.diffplug.gradle.GoomphCacheLocations
7
8 buildscript {
9   repositories {
10     /*
11     mavenCentral()
12     jcenter()
13     */
14         mavenLocal()
15   }
16   dependencies {
17     //classpath 'org.apache.ant:org.apache.ant:1.6.5'
18   }
19 }
20
21 plugins {
22   id 'java'
23   id 'application'
24   id 'eclipse'
25   id 'com.diffplug.gradle.oomph.ide' version '3.18.1'
26   id 'com.diffplug.gradle.equinoxlaunch' version '3.18.1'
27   id 'com.diffplug.gradle.eclipse.mavencentral' version '3.18.1'
28 }
29
30
31 def jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
32
33 repositories {
34   jcenter()
35   mavenCentral()
36   maven { url "http://maven.icm.edu.pl/artifactory/repo/" }
37   maven { url "http://maven.geomajas.org/" }
38   maven { url "https://repo.spring.io/plugins-release/" }
39   maven { url "http://maven.thingml.org/thirdparty/" }
40   maven { url "${jalviewDirAbsolutePath}/${m2RepoDir}" }
41   mavenLocal()
42   flatDir {
43     dirs gradlePluginsDir
44   }
45 }
46
47 dependencies {
48     //compile group: 'org.osgi', name: 'org.osgi.service.component', version: '1.4.0'
49 /*
50     source.addMaven('org.eclipse.platform:org.eclipse.osgi:3.14.0')
51     source.addMaven('org.eclipse.platform:org.eclipse.equinox.common:3.10.400')
52     source.addMaven('org.eclipse.platform:org.eclipse.core.jobs:3.10.400')
53     source.addMaven('org.eclipse.platform:org.eclipse.update.configurator:3.4.300')
54     source.addMaven('org.eclipse.platform:org.eclipse.core.runtime:3.16.0')
55     source.addMaven('org.eclipse.platform:org.eclipse.equinox.ds:1.6.0')
56     source.addMaven('javax.inject:com.springsource.javax.inject:1.0.0')
57 */
58   //compile 'org.apache.ant:org.apache.ant:1.6.5'
59 }
60
61
62
63
64
65
66
67 /*
68 p2AsMaven {
69   def requiredBundles = [
70                 'org.eclipse.core.commands',
71                 'org.eclipse.core.resources',
72                 'org.eclipse.core.runtime',
73                 'org.eclipse.ui',
74                 'org.eclipse.ui.ide',
75                 'org.eclipse.jface',
76                 'org.eclipse.swt',
77                 //"org.eclipse.swt.${com.diffplug.common.swt.os.SwtPlatform.getNative()}",
78                 'org.eclipse.equinox.registry',
79                 'org.eclipse.equinox.common',
80                 'org.eclipse.osgi',
81                 'org.eclipse.core.jobs',
82                 'org.eclipse.ui.workbench',
83                 'org.eclipse.jdt.core',
84                 'org.eclipse.jdt.ui',
85                 'org.eclipse.text'
86   ]
87
88   group 'eclipse-deps', {
89     repoEclipse '4.12.0'
90     // reduce the number of plugins downloaded
91     slicingOption 'latestVersionOnly', 'true'
92     requiredBundles.each {
93       iu "${it}"
94     }
95     append true
96   }
97 }
98 */
99
100 /*
101 eclipseMavenCentral {
102   release '4.13.0', {
103     compile 'org.eclipse.osgi'
104     compile 'org.eclipse.equinox.common'
105     compile 'org.eclipse.update.configurator'
106     compile 'org.eclipse.core.runtime'
107     compile 'org.eclipse.core.jobs'
108     compile 'org.eclipse.equinox.ds'
109     compile 'org.eclipse.osgi.services'
110     useNativesForRunningPlatform()
111   }
112 }
113 */
114
115
116
117
118
119
120
121
122
123
124
125
126 mainClassName = launcherClass
127 def classes = "$jalviewDir/$classesDir"
128
129 // configure classpath/args for j8/j11 compilation
130
131 def libDir
132 def libDistDir
133 def compile_source_compatibility
134 def compile_target_compatibility
135
136 ext {
137   buildProperties = jalviewDir + "/" + classesDir +"/" + buildPropertiesFile
138
139   gitHash = ""
140   gitBranch = ""
141
142   jalviewjsServer = ""
143 }
144
145 def JAVA_INTEGER_VERSION
146 //def additional_compiler_args = []
147 // this property is for the Java library used in eclipse
148 def eclipse_java_runtime_name
149 if (JAVA_VERSION.equals("1.8")) {
150   JAVA_INTEGER_VERSION = "8"
151   //libDir = j8libDir
152   libDir = j11libDir
153   libDistDir = j8libDir
154   compile_source_compatibility = 1.8
155   compile_target_compatibility = 1.8
156   eclipse_java_runtime_name = "JavaSE-1.8"
157 } else if (JAVA_VERSION.equals("11")) {
158   JAVA_INTEGER_VERSION = "11"
159   libDir = j11libDir
160   libDistDir = j11libDir
161   compile_source_compatibility = 11
162   compile_target_compatibility = 11
163   eclipse_java_runtime_name = "JavaSE-11"
164   /* compile without modules -- using classpath libraries
165   additional_compiler_args += [
166   '--module-path', ext.modules_compileClasspath.asPath,
167   '--add-modules', j11modules
168   ]
169   */
170 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
171   JAVA_INTEGER_VERSION = JAVA_VERSION
172   libDir = j11libDir
173   libDistDir = j11libDir
174   compile_source_compatibility = JAVA_VERSION
175   compile_target_compatibility = JAVA_VERSION
176   eclipse_java_runtime_name = "JavaSE-11"
177   /* compile without modules -- using classpath libraries
178   additional_compiler_args += [
179   '--module-path', ext.modules_compileClasspath.asPath,
180   '--add-modules', j11modules
181   ]
182   */
183 } else {
184   throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview")
185 }
186
187
188 sourceSets {
189
190   main {
191     java {
192       srcDirs "$jalviewDir/$sourceDir"
193       outputDir = file("$classes")
194     }
195
196     resources {
197       srcDirs "$jalviewDir/$resourceDir"
198     }
199
200     compileClasspath = files(sourceSets.main.java.outputDir)
201     compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
202
203     runtimeClasspath = compileClasspath
204   }
205
206 }
207
208 eclipse {
209   project {
210     name = eclipse_project_name
211
212     natures 'org.eclipse.jdt.core.javanature',
213     'org.eclipse.buildship.core.gradleprojectnature'
214
215     buildCommand 'org.eclipse.jdt.core.javabuilder'
216     buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
217   }
218
219   classpath {
220     //defaultOutputDir = sourceSets.main.java.outputDir
221     def removeThese = []
222     configurations.each{ if (it.isCanBeResolved()) {
223         removeThese += it
224       }
225     }
226
227     minusConfigurations += removeThese
228     plusConfigurations = [ ]
229     file {
230
231       whenMerged { cp ->
232         def removeTheseToo = []
233         HashMap<String, Boolean> addedSrcPath = new HashMap<>();
234         cp.entries.each { entry ->
235           if (entry.kind == 'src') {
236             if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) {
237               removeTheseToo += entry
238             } else {
239               addedSrcPath.putAt(entry.path, true)
240             }
241           }
242         }
243         cp.entries.removeAll(removeTheseToo)
244
245         if (file(eclipse_bin_dir+"/main").isDirectory()) {
246                 cp.entries += new Output(eclipse_bin_dir+"/main")
247         }
248         if (file(helpParentDir).isDirectory()) {
249                 cp.entries += new Library(fileReference(helpParentDir))
250         }
251         if (file(resourceDir).isDirectory()) {
252                 cp.entries += new Library(fileReference(resourceDir))
253         }
254
255         HashMap<String, Boolean> addedLibPath = new HashMap<>();
256
257         // changing from sourcesets.main.classpath to specific Java version lib
258         //sourceSets.main.compileClasspath.each{
259         fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").each {
260           //don't want to add outputDir as eclipse is using its own output dir in bin/main
261           if (it.isDirectory() || ! it.exists()) {
262             // don't add dirs to classpath
263             return
264           }
265           def itPath = it.toString()
266           if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
267             itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
268           }
269           if (addedLibPath.get(itPath)) {
270             //println("Not adding duplicate entry "+itPath)
271           } else {
272             //println("Adding entry "+itPath)
273             cp.entries += new Library(fileReference(itPath))
274             addedLibPath.put(itPath, true)
275           }
276         }
277       } // whenMerged
278
279     } // file
280
281     containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
282   } // classpath
283
284   jdt {
285     // for the IDE, use java 11 compatibility
286     sourceCompatibility = compile_source_compatibility
287     targetCompatibility = compile_target_compatibility
288     javaRuntimeName = eclipse_java_runtime_name
289
290     /*
291     file {
292     withProperties { props ->
293     def jalview_prefs = new Properties()
294     def ins = new FileInputStream(jalviewDirAbsolutePath+"/"+eclipse_extra_jdt_prefs_file)
295     jalview_prefs.load(ins)
296     ins.close()
297     jalview_prefs.forEach { t, v ->
298     if (props.getAt(t) == null) {
299     props.putAt(t, v)
300     }
301     }
302     }
303     }
304      */
305   } // jdt
306
307   //synchronizationTasks eclipseClasspath
308   //autoBuildTasks eclipseClasspath
309 } // eclipse
310
311 /*
312 compileJava {
313
314   doFirst {
315     sourceCompatibility = compile_source_compatibility
316     targetCompatibility = compile_target_compatibility
317     //options.compilerArgs = additional_compiler_args
318     print ("Setting target compatibility to "+targetCompatibility+"\n")
319   }
320
321 }
322
323 clean {
324   delete sourceSets.main.java.outputDir
325 }
326 */
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347 def useIde = useGoomph.equals("true")
348
349 def eclipseWorkspace
350 task jalviewjsSetEclipseWorkspace {
351   def eclipseWsDir = useIde?goomph_workspace:jalviewjs_eclipse_workspace
352   eclipseWorkspace = file(eclipseWsDir)
353   if (!eclipseWorkspace.exists()) {
354     eclipseWorkspace = file("${buildDir}/tmp/eclipse-workspace")
355     //eclipseWorkspace.deleteOnExit()
356   } else if (useIde) {
357     GoomphCacheLocations.override_workspaces = file(eclipseWorkspace.getAbsolutePath())
358     eclipseWorkspace = oomphIde.workspaceRegistry.workspaceDir(project, file(oomphIde.ideDir))
359   }
360   println("ECLIPSE WORKSPACE: "+eclipseWorkspace.getPath())
361 }
362
363 oomphIde {
364   repoEclipse goomph_eclipse_version
365   jdt {
366     /*
367     installedJre {
368       //markDefault = true
369       //executionEnvironments = [ eclipse.jdt.javaRuntimeName ]
370     }
371     */
372     //compilerComplianceLevel( JAVA_INTEGER_VERSION )
373   }
374
375   repo "https://download.eclipse.org/releases/${goomph_eclipse_version_name}/"
376   feature goomph_eclipse_jee_feature, goomph_eclipse_jee_version
377
378   //iu 'org.eclipse.osgi'
379
380   thirdParty {
381     buildship {
382       repo goomph_repo_buildship
383       feature goomph_feature_buildship
384     }
385
386   }
387
388
389
390   // CLI ARGS HERE!
391 }
392
393 equinoxLaunch {
394   ideJalviewjsBuildSetup {
395     //source.addThisProject()
396
397     source.addConfiguration(configurations.compile)
398     source.addConfiguration(configurations.compileClasspath)
399     
400     //source.addMaven('com.ibm.icu:icu4j:65.1')
401     source.addMaven('org.eclipse.birt.runtime:com.ibm.icu:56.1.0.v201601250100')
402
403     source.addMaven('javax.inject:com.springsource.javax.inject:1.0.0')
404
405     //source.addMaven('org.apache.ant:ant:1.6.5')
406     //source.addMaven('org.apache.ant:org.apache.ant:1.6.5')
407     //source.addMaven('ant:ant:1.6.5')
408
409     source.addMaven('org.apache.felix:org.apache.felix.scr:2.1.16')
410
411     source.addMaven('org.osgi:org.osgi.framework:1.9.0')
412     source.addMaven('org.osgi:org.osgi.service.component:1.4.0')
413     source.addMaven('org.osgi:org.osgi.util.promise:1.1.1')
414     source.addMaven('org.osgi:org.osgi.util.function:1.1.0')
415
416 ### TRY AND FIND A HEADLESS BUILD WITHOUT org.eclipse.jdt.apt.core
417     source.addMaven('org.eclipse.maven:org.eclipse.jdt.apt.core:3.8.0')
418     source.addMaven('org.eclipse.maven:org.eclipse.jdt.core:3.8.0')
419     //source.addMaven('org.eclipse.jdt:org.eclipse.jdt.apt.core:3.6.500')
420     //source.addMaven('org.eclipse.jdt:org.eclipse.jdt.core:3.19.0')
421
422     source.addMaven('org.eclipse.platform:org.eclipse.ant.core:3.5.500')
423     source.addMaven('org.eclipse.platform:org.eclipse.compare.core:3.6.600')
424     source.addMaven('org.eclipse.platform:org.eclipse.core.commands:3.9.500')
425     source.addMaven('org.eclipse.platform:org.eclipse.core.contenttype:3.7.400')
426     source.addMaven('org.eclipse.platform:org.eclipse.core.jobs:3.10.500')
427     source.addMaven('org.eclipse.platform:org.eclipse.core.expressions:3.6.500')
428     source.addMaven('org.eclipse.platform:org.eclipse.core.filesystem:1.7.500')
429     source.addMaven('org.eclipse.platform:org.eclipse.core.resources:3.13.500')
430     source.addMaven('org.eclipse.platform:org.eclipse.core.runtime:3.16.0')
431     source.addMaven('org.eclipse.platform:org.eclipse.core.variables:3.4.600')
432     source.addMaven('org.eclipse.platform:org.eclipse.equinox.common:3.10.500')
433     source.addMaven('org.eclipse.platform:org.eclipse.equinox.ds:1.6.0')
434     source.addMaven('org.eclipse.platform:org.eclipse.equinox.app:1.4.300')
435     source.addMaven('org.eclipse.platform:org.eclipse.equinox.registry:3.8.500')
436     source.addMaven('org.eclipse.platform:org.eclipse.equinox.preferences:3.7.500')
437     source.addMaven('org.eclipse.platform:org.eclipse.osgi:3.14.0')
438     source.addMaven('org.eclipse.platform:org.eclipse.team.core:3.8.700')
439     source.addMaven('org.eclipse.platform:org.eclipse.text:3.9.0')
440     // org.eclipse.update.configurator deliberately kept at 3.3.400 see https://github.com/diffplug/goomph/issues/69
441     source.addMaven('org.eclipse.platform:org.eclipse.update.configurator:3.3.400')
442     /*
443     source.addMaven('org.eclipse.platform:org.eclipse.:3.')
444     source.addMaven('org.eclipse.platform:org.eclipse.:3.')
445     source.addMaven('org.eclipse.platform:org.eclipse.:3.')
446     source.addMaven('org.eclipse.platform:org.eclipse.:3.')
447     source.addMaven('org.eclipse.platform:org.eclipse.:3.')
448     */
449
450
451
452
453     launchTask 'ideJalviewjsBuild', {
454       //it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
455       //it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
456       it.args = ["-consoleLog", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
457       //it.vmArgs = ['-Dosgi.bundles=org.eclipse.core.jobs@2:start,org.eclipse.equinox.common@3:start,org.eclipse.core.runtime@2:start']
458       //it.vmArgs = ['-Dequinox.use.ds=false']
459
460     }
461   }
462 }
463
464 /*
465 task ideCopyDropins (type: Copy) {
466   dependsOn ideSetupP2
467
468   def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
469   def outputDir = oomphIde.ideDir + "/" + com.diffplug.gradle.FileMisc.macContentsEclipse() + "/dropins"
470
471   from inputFiles
472   into outputDir
473   def outputFiles = []
474   rename { filename ->
475     outputFiles += outputDir+"/"+filename
476     println("COPYING ${filename} to ${outputFiles}")
477     null
478   }
479   outputs.files outputFiles
480   inputs.files inputFiles
481
482 }
483 */
484
485 ideSetupWorkspace.dependsOn jalviewjsSetEclipseWorkspace
486 ideSetupWorkspace.outputs.upToDateWhen {file(eclipseWorkspace).exists()}
487
488 task ideSetup {
489   dependsOn ideSetupP2
490   dependsOn ideSetupWorkspace
491 }
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507 def jalviewjsBuildDir
508 def jalviewjsSiteDir
509 task jalviewjsSitePath {
510   if (jalviewjs_site_dir.startsWith("/")) {
511     jalviewjsSiteDir = jalviewjs_site_dir
512   } else {
513     def relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
514     jalviewjsBuildDir = "${relativeBuildDir}/jalviewjs"
515     jalviewjsSiteDir = jalviewjsBuildDir + "/" + jalviewjs_site_dir
516   }
517 }
518
519
520 task jalviewjsUnzipFiles {
521   dependsOn jalviewjsSitePath
522
523   def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip")
524   zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip
525
526   doLast {
527     zipFiles.each { file_zip -> 
528       copy {
529         from zipTree(file_zip)
530         into jalviewjsSiteDir
531       }
532     }
533   }
534
535   inputs.files zipFiles
536   outputs.dir jalviewjsSiteDir
537 }
538
539 def eclipseDropinsDir
540 def eclipseBinary
541 task jalviewjsEclipsePaths {
542   def eclipseRoot
543   if (useIde) {
544     eclipseRoot = oomphIde.ideDir
545     eclipseDropinsDir = eclipseRoot+"/"+com.diffplug.gradle.FileMisc.macContentsEclipse()+"/dropins"
546     eclipseBinary = eclipseRoot+"/"+com.diffplug.common.swt.os.OS.getNative().winMacLinux("", "Contents/MacOS", "")+"/eclipse"
547   } else {
548     eclipseRoot = jalviewjs_eclipse_root
549     if (eclipseRoot.startsWith("~")) {
550       eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
551     }
552     if (OperatingSystem.current().isMacOsX()) {
553       eclipseRoot += "/Eclipse.app"
554       eclipseDropinsDir = eclipseRoot+"/Contents/Eclipse/dropins"
555       eclipseBinary = eclipseRoot+"/Contents/MacOS/eclipse"
556     } else if (OperatingSystem.current().isWindows()) { // check these paths!!
557       eclipseDropinsDir = eclipseRoot+"/dropins"
558       eclipseBinary = eclipseRoot+"/eclipse"
559     } else { // linux or unix
560       eclipseDropinsDir = eclipseRoot+"/dropins"
561       eclipseBinary = eclipseRoot+"/eclipse"
562     }
563   }
564   //println("ECLIPSE_ROOT=${eclipseRoot}")
565   //println("ECLIPSE_BINARY=${eclipseBinary}")
566 }
567
568 //task jalviewjsEclipseCopyDropins (type: Copy) {
569 task jalviewjsEclipseCopyDropins {
570   dependsOn jalviewjsEclipsePaths
571   def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir, include: "*.jar")
572   def outputDir = eclipseDropinsDir
573
574   inputs.files inputFiles
575   inputFiles.each { file ->
576     outputs.file(outputDir+"/"+file.name)
577   }
578
579   doLast {
580     def outputFiles = []
581     inputFiles.each { file ->
582       copy {
583         from file
584         into outputDir
585       }
586     }
587   }
588 }
589
590 task jalviewjsEclipseSetup {
591   dependsOn jalviewjsEclipseCopyDropins
592   dependsOn jalviewjsSetEclipseWorkspace
593 }
594
595
596 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
597   dependsOn jalviewjsSitePath
598   outputFile (jalviewDir+"/"+jalviewjs_j2s_settings)
599   def props = project.properties.sort { it.key }
600   def siteDirProperty = "j2s.site.directory"
601   def setSiteDir = false
602   props.each { prop, val ->
603     if (prop.startsWith("j2s.") && val != null) {
604       if (prop == siteDirProperty) {
605         if (!(val.startsWith("/") || val.startsWith("file://") )) {
606           val = jalviewjsSiteDir+"/"+val
607         }
608         setSiteDir = true
609       }
610       property(prop,val)
611     }
612     if (!setSiteDir) {
613       property(siteDirProperty,"${jalviewjsSiteDir}")
614     }
615   }
616   outputs.file(outputFile)
617 }
618
619 task jalviewjsCopyResources (type: Copy) {
620   dependsOn jalviewjsSitePath
621   def inputFiles = fileTree(dir: jalviewjs_resource_dir)
622   def outputDir = jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir
623
624   from inputFiles
625   into outputDir
626   def outputFiles = []
627   rename { filename ->
628     outputFiles += outputDir+"/"+filename
629     null
630   }
631   outputs.files outputFiles
632   inputs.files inputFiles
633 }
634
635 task jalviewjsCopySiteResources (type: Copy) {
636   dependsOn jalviewjsSitePath
637   def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir)
638   def outputDir = jalviewjsSiteDir
639
640   from inputFiles
641   into outputDir
642   def outputFiles = []
643   rename { filename ->
644     outputFiles += outputDir+"/"+filename
645     null
646   }
647   outputs.files outputFiles
648   inputs.files inputFiles
649 }
650
651 task cleanJalviewjs {
652   dependsOn jalviewjsSitePath
653   /*
654   delete jalviewDir+"/"+jalviewjsSiteDir
655   delete jalviewDir+"/"+eclipse_bin_dir
656   delete file(eclipseWorkspace.getAbsolutePath()+"/.metadata")
657   delete jalviewDir+"/"+jalviewjs_j2s_settings
658   */
659 }
660
661 task jalviewjsProjectImport(type: Exec) {
662   // work out how to do this!
663   dependsOn eclipseProject
664   dependsOn eclipseClasspath
665   dependsOn eclipseJdt
666   dependsOn jalviewjsEclipsePaths
667   dependsOn jalviewjsEclipseSetup
668   executable(eclipseBinary)
669   args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", eclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
670
671   def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
672   inputs.file(jalviewDir+"/.project")
673   outputs.dir(projdir)
674   outputs.upToDateWhen { file(projdir).exists() }
675 }
676
677
678
679
680
681
682
683
684 task jalviewjsTranspile(type: Exec) {
685   dependsOn jalviewjsCreateJ2sSettings 
686   dependsOn jalviewjsProjectImport
687   dependsOn jalviewjsEclipsePaths
688   executable(eclipseBinary)
689   args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ])
690
691   def stdout
692   def stderr
693   doFirst {
694     stdout = new ByteArrayOutputStream()
695     stderr = new ByteArrayOutputStream()
696     standardOutput = new org.apache.tools.ant.util.TeeOutputStream(new FileOutputStream("${jalviewjsBuildDir}/${jalviewjs_j2s_stdout}"), stdout);
697     errorOutput = new org.apache.tools.ant.util.TeeOutputStream(new FileOutputStream("${jalviewjsBuildDir}/${jalviewjs_j2s_stderr}"), stderr);
698   }
699   doLast {
700     if (stdout.toString().contains("Error processing ")) {
701       // j2s did not complete transpile
702       throw new GradleException("Error during transpilation:\n${stderr}\nSee eclipse transpile log files '${jalviewjsBuildDir}/${jalviewjs_j2s_stdout}' and '${jalviewjsBuildDir}/${jalviewjs_j2s_stderr}'\n")
703     }
704   }
705
706   inputs.dir(sourceDir)
707   outputs.dir(eclipse_bin_dir+"/main")
708   outputs.files(
709     fileTree(
710       dir: jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir,
711       includes: [ "**/*.js" ],
712       excludes: [
713         //jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir+"/intervalstore/**",
714         //jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir+"/org/json/**",
715         "intervalstore/**",
716         "org/json/**",
717       ]
718     ).files
719   )
720   outputs.file(jalviewjsSiteDir+jalviewjs_server_resource)
721
722 }
723
724
725
726
727
728
729 jalviewjsUnzipFiles.mustRunAfter jalviewjsTranspile
730 jalviewjsTranspile.mustRunAfter jalviewjsCopyResources
731 jalviewjsTranspile.mustRunAfter jalviewjsCopySiteResources
732
733 task jalviewjsBuildSite {
734   dependsOn jalviewjsSitePath
735   dependsOn jalviewjsUnzipFiles
736   dependsOn jalviewjsCopyResources
737   dependsOn jalviewjsCopySiteResources
738   dependsOn jalviewjsTranspile
739 }
740
741 task jalviewjsSiteTar(type: Tar) {
742   dependsOn jalviewjsBuildSite
743   def outputFilename = "jalviewjs-site-${JALVIEW_VERSION}.tar.gz"
744   try {
745     archiveFileName = outputFilename
746   } catch (Exception e) {
747     archiveName = outputFilename
748   }
749
750   compression Compression.GZIP
751
752   from jalviewjsSiteDir
753   into jalviewjs_site_dir // this is inside the tar file
754
755   inputs.dir(jalviewjsSiteDir)
756 }
757
758 def jalviewjsServer = null
759 task jalviewjsServerStart {
760   dependsOn jalviewjsSitePath
761   doLast {
762
763     if (jalviewjsServer != null) {
764       println("SERVER ALREADY RUNNING. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run  gradle jalviewjsServerStop  to stop.")
765     } else {
766
767       SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
768       def port = Integer.valueOf(jalviewjs_server_port)
769       def start = port
770       def running = false
771       while(port < start+1000 && !running) {
772         try {
773           def doc_root = new File(jalviewDirAbsolutePath +"/"+ jalviewjsSiteDir)
774           jalviewjsServer = factory.start(doc_root, port)
775           running = true
776           println("SERVER STARTED with document root ${doc_root}.\nGo to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run  gradle --stop  to stop (kills all gradle daemons).")
777           //println("Ctrl-c to stop.");java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000);
778         } catch (Exception e) {
779           port++;
780         }
781       }
782
783     }
784
785   }
786
787 }
788
789 /* server persists in gradle daemon but reference is not accessible across builds
790 task jalviewjsServerStop {
791   doLast {
792
793     if (jalviewjsServer != null) {
794
795       println("SERVER ON PORT "+jalviewjsServer.getPort()+" STOPPING. Run  gradle jalviewjsServerStart  to start again.")
796       jalviewjsServer.stop()
797
798     } else {
799       println("SERVER NOT RUNNING. Run  gradle jalviewjsServerStart  to start.")
800     }
801
802   }
803 }
804 */
805
806 task ideBuildSite {
807   dependsOn jalviewjsSitePath
808   dependsOn jalviewjsUnzipFiles
809   dependsOn jalviewjsCopyResources
810   dependsOn jalviewjsCopySiteResources
811   dependsOn ideSetup
812   dependsOn ide
813 }
814
815
816
817
818 task jalviewjs {
819   dependsOn jalviewjsBuildSite
820 }
821
822
823 project.afterEvaluate {
824   tasks.findByName('ideJalviewjsBuild').dependsOn eclipseProject
825   tasks.findByName('ideJalviewjsBuild').dependsOn eclipseClasspath
826   tasks.findByName('ideJalviewjsBuild').dependsOn eclipseJdt
827   //tasks.findByName('ideJalviewjsBuild').dependsOn ideSetup
828
829   tasks.findByName('ide').dependsOn eclipseProject
830   tasks.findByName('ide').dependsOn eclipseClasspath
831   tasks.findByName('ide').dependsOn eclipseJdt
832 }
833
834
835