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