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