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
16 //eclipseDeps.each { compile "p2:${it}:+" }
17 //classpath 'org.eclipse.platform:org.eclipse.osgi:3.15.0'
18 //compile group: 'org.eclipse.platform', name: 'org.eclipse.osgi', version: '3.15.0'
19 //classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.4.0'
28 id 'com.diffplug.gradle.oomph.ide' version '3.18.1'
29 id 'com.diffplug.gradle.equinoxlaunch' version '3.18.1'
31 //id 'com.diffplug.gradle.p2.asmaven' version '3.18.1'
33 //id 'org.eclipse.osgi' version '3.15.0'
40 // The dependencies we actually use
41 'org.eclipse.jdt.core',
45 'org.eclipse.core.contenttype',
46 'org.eclipse.core.jobs',
47 'org.eclipse.core.runtime',
48 'org.eclipse.core.resources',
49 'org.eclipse.equinox.common',
50 'org.eclipse.equinox.preferences',
58 repoEclipse goomph_eclipse_version
59 eclipseDeps.each { p2.addIU(it) }
60 eclipseDeps.each { p2.addIU(it + '.source') }
68 //eclipseDeps.each { compile "p2:${it}:+" }
69 //implementation 'org.eclipse.platform:org.eclipse.osgi:3.15.0'
70 //compile 'org.eclipse.platform:org.eclipse.osgi:3.15.0'
71 //classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.4.0'
85 mainClassName = launcherClass
86 def classes = "$jalviewDir/$classesDir"
88 // configure classpath/args for j8/j11 compilation
90 def jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
93 def compile_source_compatibility
94 def compile_target_compatibility
97 buildProperties = jalviewDir + "/" + classesDir +"/" + buildPropertiesFile
105 def JAVA_INTEGER_VERSION
106 //def additional_compiler_args = []
107 // this property is for the Java library used in eclipse
108 def eclipse_java_runtime_name
109 if (JAVA_VERSION.equals("1.8")) {
110 JAVA_INTEGER_VERSION = "8"
113 libDistDir = j8libDir
114 compile_source_compatibility = 1.8
115 compile_target_compatibility = 1.8
116 eclipse_java_runtime_name = "JavaSE-1.8"
117 } else if (JAVA_VERSION.equals("11")) {
118 JAVA_INTEGER_VERSION = "11"
120 libDistDir = j11libDir
121 compile_source_compatibility = 11
122 compile_target_compatibility = 11
123 eclipse_java_runtime_name = "JavaSE-11"
124 /* compile without modules -- using classpath libraries
125 additional_compiler_args += [
126 '--module-path', ext.modules_compileClasspath.asPath,
127 '--add-modules', j11modules
130 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
131 JAVA_INTEGER_VERSION = JAVA_VERSION
133 libDistDir = j11libDir
134 compile_source_compatibility = JAVA_VERSION
135 compile_target_compatibility = JAVA_VERSION
136 eclipse_java_runtime_name = "JavaSE-11"
137 /* compile without modules -- using classpath libraries
138 additional_compiler_args += [
139 '--module-path', ext.modules_compileClasspath.asPath,
140 '--add-modules', j11modules
144 throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview")
151 srcDirs "$jalviewDir/$sourceDir"
152 outputDir = file("$classes")
156 srcDirs "$jalviewDir/$resourceDir"
159 compileClasspath = files(sourceSets.main.java.outputDir)
160 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
162 runtimeClasspath = compileClasspath
169 name = eclipse_project_name
171 natures 'org.eclipse.jdt.core.javanature',
172 'org.eclipse.buildship.core.gradleprojectnature'
174 buildCommand 'org.eclipse.jdt.core.javabuilder'
175 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
179 //defaultOutputDir = sourceSets.main.java.outputDir
181 configurations.each{ if (it.isCanBeResolved()) {
186 minusConfigurations += removeThese
187 plusConfigurations = [ ]
191 def removeTheseToo = []
192 HashMap<String, Boolean> addedSrcPath = new HashMap<>();
193 cp.entries.each { entry ->
194 if (entry.kind == 'src') {
195 if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) {
196 removeTheseToo += entry
198 addedSrcPath.putAt(entry.path, true)
202 cp.entries.removeAll(removeTheseToo)
204 if (file(eclipse_bin_dir+"/main").isDirectory()) {
205 cp.entries += new Output(eclipse_bin_dir+"/main")
207 if (file(helpParentDir).isDirectory()) {
208 cp.entries += new Library(fileReference(helpParentDir))
210 if (file(resourceDir).isDirectory()) {
211 cp.entries += new Library(fileReference(resourceDir))
214 HashMap<String, Boolean> addedLibPath = new HashMap<>();
216 // changing from sourcesets.main.classpath to specific Java version lib
217 //sourceSets.main.compileClasspath.each{
218 fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").each {
219 //don't want to add outputDir as eclipse is using its own output dir in bin/main
220 if (it.isDirectory() || ! it.exists()) {
221 // don't add dirs to classpath
224 def itPath = it.toString()
225 if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
226 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
228 if (addedLibPath.get(itPath)) {
229 //println("Not adding duplicate entry "+itPath)
231 //println("Adding entry "+itPath)
232 cp.entries += new Library(fileReference(itPath))
233 addedLibPath.put(itPath, true)
240 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
244 // for the IDE, use java 11 compatibility
245 sourceCompatibility = compile_source_compatibility
246 targetCompatibility = compile_target_compatibility
247 javaRuntimeName = eclipse_java_runtime_name
251 withProperties { props ->
252 def jalview_prefs = new Properties()
253 def ins = new FileInputStream(jalviewDirAbsolutePath+"/"+eclipse_extra_jdt_prefs_file)
254 jalview_prefs.load(ins)
256 jalview_prefs.forEach { t, v ->
257 if (props.getAt(t) == null) {
266 //synchronizationTasks eclipseClasspath
267 //autoBuildTasks eclipseClasspath
274 sourceCompatibility = compile_source_compatibility
275 targetCompatibility = compile_target_compatibility
276 //options.compilerArgs = additional_compiler_args
277 print ("Setting target compatibility to "+targetCompatibility+"\n")
283 delete sourceSets.main.java.outputDir
310 GoomphCacheLocations.override_workspaces = file(jalviewDirAbsolutePath+"/"+goomph_workspace)
312 repoEclipse goomph_eclipse_version
317 //executionEnvironments = [ eclipse.jdt.javaRuntimeName ]
320 //compilerComplianceLevel( JAVA_INTEGER_VERSION )
322 //repo 'http://download.eclipse.org/buildship/updates/e45/milestones/3.x/'
323 repo goomph_repo_buildship
324 feature goomph_feature_buildship
330 launchTask 'ideJalviewjsBuild', {
331 //it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
332 it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
337 task ideCopyDropins (type: Copy) {
340 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
341 def outputDir = oomphIde.ideDir + "/" + com.diffplug.gradle.FileMisc.macContentsEclipse() + "/dropins"
347 outputFiles += outputDir+"/"+filename
348 println("COPYING ${filename} to ${outputFiles}")
351 outputs.files outputFiles
352 inputs.files inputFiles
356 ide.dependsOn eclipseProject
357 ide.dependsOn eclipseClasspath
358 ide.dependsOn eclipseJdt
359 ide.dependsOn ideCopyDropins
360 ideJalviewjsBuild.dependsOn ideSetupWorkspace
361 ideJalviewjsBuild.dependsOn ideCopyDropins
377 def jalviewjsBuildDir
379 task jalviewjsSitePath {
380 if (jalviewjs_site_dir.startsWith("/")) {
381 jalviewjsSiteDir = jalviewjs_site_dir
383 def relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
384 jalviewjsBuildDir = "${relativeBuildDir}/jalviewjs"
385 jalviewjsSiteDir = jalviewjsBuildDir + "/" + jalviewjs_site_dir
389 def tempEclipseWorkspace
390 task jalviewjsSetTempEclipseWorkspace {
391 tempEclipseWorkspace = file(jalviewjs_eclipse_workspace)
392 if (!tempEclipseWorkspace.exists()) {
393 tempEclipseWorkspace = file("${buildDir}/tmp/eclipse-workspace")
394 //tempEclipseWorkspace.deleteOnExit()
396 println("ECLIPSE WORKSPACE: "+tempEclipseWorkspace.getPath())
399 task jalviewjsUnzipFiles {
400 dependsOn jalviewjsSitePath
402 def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip")
403 zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip
406 zipFiles.each { file_zip ->
408 from zipTree(file_zip)
409 into jalviewjsSiteDir
414 inputs.files zipFiles
415 outputs.dir jalviewjsSiteDir
418 def eclipseDropinsDir
420 task jalviewjsEclipsePaths {
421 def eclipseRoot = jalviewjs_eclipse_root
422 if (eclipseRoot.startsWith("~")) {
423 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
425 if (OperatingSystem.current().isMacOsX()) {
426 eclipseRoot += "/Eclipse.app"
427 eclipseDropinsDir = eclipseRoot+"/Contents/Eclipse/dropins"
428 eclipseBinary = eclipseRoot+"/Contents/MacOS/eclipse"
429 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
430 eclipseDropinsDir = eclipseRoot+"/dropins"
431 eclipseBinary = eclipseRoot+"/eclipse"
432 } else { // linux or unix
433 eclipseDropinsDir = eclipseRoot+"/dropins"
434 eclipseBinary = eclipseRoot+"/eclipse"
438 task jalviewjsEclipseCopyDropins (type: Copy) {
439 dependsOn jalviewjsEclipsePaths
440 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
441 def outputDir = eclipseDropinsDir
447 outputFiles += outputDir+"/"+filename
450 outputs.files outputFiles
451 inputs.files inputFiles
454 task jalviewjsEclipseSetup {
455 dependsOn jalviewjsEclipseCopyDropins
456 dependsOn jalviewjsSetTempEclipseWorkspace
460 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
461 dependsOn jalviewjsSitePath
462 outputFile (jalviewDir+"/"+jalviewjs_j2s_settings)
463 def props = project.properties.sort { it.key }
464 def siteDirProperty = "j2s.site.directory"
465 def setSiteDir = false
466 props.each { prop, val ->
467 if (prop.startsWith("j2s.") && val != null) {
468 if (prop == siteDirProperty) {
469 if (!(val.startsWith("/") || val.startsWith("file://") )) {
470 val = jalviewjsSiteDir+"/"+val
477 property(siteDirProperty,"${jalviewjsSiteDir}")
480 outputs.file(outputFile)
483 task jalviewjsCopyResources (type: Copy) {
484 dependsOn jalviewjsSitePath
485 def inputFiles = fileTree(dir: jalviewjs_resource_dir)
486 def outputDir = jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir
492 outputFiles += outputDir+"/"+filename
495 outputs.files outputFiles
496 inputs.files inputFiles
499 task jalviewjsCopySiteResources (type: Copy) {
500 dependsOn jalviewjsSitePath
501 def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir)
502 def outputDir = jalviewjsSiteDir
508 outputFiles += outputDir+"/"+filename
511 outputs.files outputFiles
512 inputs.files inputFiles
515 task cleanJalviewjs {
516 dependsOn jalviewjsSitePath
518 delete jalviewDir+"/"+jalviewjsSiteDir
519 delete jalviewDir+"/"+eclipse_bin_dir
520 delete file(tempEclipseWorkspace.getAbsolutePath()+"/.metadata")
521 delete jalviewDir+"/"+jalviewjs_j2s_settings
525 task jalviewjsProjectImport(type: Exec) {
526 // work out how to do this!
527 dependsOn eclipseProject
528 dependsOn eclipseClasspath
530 dependsOn jalviewjsEclipsePaths
531 dependsOn jalviewjsEclipseSetup
532 executable(eclipseBinary)
533 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", tempEclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
535 def projdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
536 inputs.file(jalviewDir+"/.project")
538 outputs.upToDateWhen { file(projdir).exists() }
548 task jalviewjsTranspile(type: Exec) {
549 dependsOn jalviewjsCreateJ2sSettings
550 dependsOn jalviewjsProjectImport
551 dependsOn jalviewjsEclipsePaths
552 executable(eclipseBinary)
553 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ])
558 stdout = new ByteArrayOutputStream()
559 stderr = new ByteArrayOutputStream()
560 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(new FileOutputStream("${jalviewjsBuildDir}/${jalviewjs_j2s_stdout}"), stdout);
561 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(new FileOutputStream("${jalviewjsBuildDir}/${jalviewjs_j2s_stderr}"), stderr);
564 if (stdout.toString().contains("Error processing ")) {
565 // j2s did not complete transpile
566 throw new TaskExecutionException("Error during transpilation:\n${stderr}\n")
570 inputs.dir(sourceDir)
571 outputs.dir(eclipse_bin_dir+"/main")
572 outputs.dir(jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir)
573 outputs.file(jalviewjsSiteDir+jalviewjs_server_resource)
574 outputs.upToDateWhen { file(jalviewjsSiteDir+jalviewjs_server_resource).exists() }
585 task jalviewjsBuildSite {
586 dependsOn jalviewjsSitePath
587 dependsOn jalviewjsUnzipFiles
588 dependsOn jalviewjsCopyResources
589 dependsOn jalviewjsCopySiteResources
590 dependsOn jalviewjsTranspile
593 task jalviewjsSiteTar(type: Tar) {
594 dependsOn jalviewjsBuildSite
595 def outputFilename = "jalviewjs-site-${JALVIEW_VERSION}.tar.gz"
597 archiveFileName = outputFilename
598 } catch (Exception e) {
599 archiveName = outputFilename
602 compression Compression.GZIP
604 from jalviewjsSiteDir
605 into jalviewjs_site_dir // this is inside the tar file
607 inputs.dir(jalviewjsSiteDir)
611 dependsOn jalviewjsBuildSite
614 def jalviewjsServer = null
615 task jalviewjsServerStart {
616 dependsOn jalviewjsSitePath
619 if (jalviewjsServer != null) {
620 println("SERVER ALREADY RUNNING. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
623 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
624 def port = Integer.valueOf(jalviewjs_server_port)
627 while(port < start+1000 && !running) {
629 def doc_root = new File(jalviewDirAbsolutePath +"/"+ jalviewjsSiteDir)
630 jalviewjsServer = factory.start(doc_root, port)
632 println("SERVER STARTED with document root ${doc_root}.\nGo to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
633 //println("Ctrl-c to stop.");java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000);
634 } catch (Exception e) {
645 /* server persists in gradle daemon but reference is not accessible across builds
646 task jalviewjsServerStop {
649 if (jalviewjsServer != null) {
651 println("SERVER ON PORT "+jalviewjsServer.getPort()+" STOPPING. Run gradle jalviewjsServerStart to start again.")
652 jalviewjsServer.stop()
655 println("SERVER NOT RUNNING. Run gradle jalviewjsServerStart to start.")
662 project.afterEvaluate {
663 tasks.findByName('ideJalviewjsBuild').dependsOn eclipseProject
664 tasks.findByName('ideJalviewjsBuild').dependsOn eclipseClasspath
665 tasks.findByName('ideJalviewjsBuild').dependsOn eclipseJdt