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