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.*
15 //eclipseDeps.each { compile "p2:${it}:+" }
16 //classpath 'org.eclipse.platform:org.eclipse.osgi:3.15.0'
17 //compile group: 'org.eclipse.platform', name: 'org.eclipse.osgi', version: '3.15.0'
18 //classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.4.0'
27 id 'com.diffplug.gradle.oomph.ide' version '3.18.1'
28 id 'com.diffplug.gradle.equinoxlaunch' version '3.18.1'
30 //id 'com.diffplug.gradle.p2.asmaven' version '3.18.1'
32 //id 'org.eclipse.osgi' version '3.15.0'
39 // The dependencies we actually use
40 'org.eclipse.jdt.core',
44 'org.eclipse.core.contenttype',
45 'org.eclipse.core.jobs',
46 'org.eclipse.core.runtime',
47 'org.eclipse.core.resources',
48 'org.eclipse.equinox.common',
49 'org.eclipse.equinox.preferences',
57 repoEclipse goomph_eclipse_version
58 eclipseDeps.each { p2.addIU(it) }
59 eclipseDeps.each { p2.addIU(it + '.source') }
67 //eclipseDeps.each { compile "p2:${it}:+" }
68 //implementation 'org.eclipse.platform:org.eclipse.osgi:3.15.0'
69 //compile 'org.eclipse.platform:org.eclipse.osgi:3.15.0'
70 //classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.4.0'
84 mainClassName = launcherClass
85 def classes = "$jalviewDir/$classesDir"
87 // configure classpath/args for j8/j11 compilation
89 def jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
92 def compile_source_compatibility
93 def compile_target_compatibility
96 buildProperties = jalviewDir + "/" + classesDir +"/" + buildPropertiesFile
104 def JAVA_INTEGER_VERSION
105 //def additional_compiler_args = []
106 // this property is for the Java library used in eclipse
107 def eclipse_java_runtime_name
108 if (JAVA_VERSION.equals("1.8")) {
109 JAVA_INTEGER_VERSION = "8"
112 libDistDir = j8libDir
113 compile_source_compatibility = 1.8
114 compile_target_compatibility = 1.8
115 eclipse_java_runtime_name = "JavaSE-1.8"
116 } else if (JAVA_VERSION.equals("11")) {
117 JAVA_INTEGER_VERSION = "11"
119 libDistDir = j11libDir
120 compile_source_compatibility = 11
121 compile_target_compatibility = 11
122 eclipse_java_runtime_name = "JavaSE-11"
123 /* compile without modules -- using classpath libraries
124 additional_compiler_args += [
125 '--module-path', ext.modules_compileClasspath.asPath,
126 '--add-modules', j11modules
129 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
130 JAVA_INTEGER_VERSION = JAVA_VERSION
132 libDistDir = j11libDir
133 compile_source_compatibility = JAVA_VERSION
134 compile_target_compatibility = JAVA_VERSION
135 eclipse_java_runtime_name = "JavaSE-11"
136 /* compile without modules -- using classpath libraries
137 additional_compiler_args += [
138 '--module-path', ext.modules_compileClasspath.asPath,
139 '--add-modules', j11modules
143 throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview")
150 srcDirs "$jalviewDir/$sourceDir"
151 outputDir = file("$classes")
155 srcDirs "$jalviewDir/$resourceDir"
158 compileClasspath = files(sourceSets.main.java.outputDir)
159 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
161 runtimeClasspath = compileClasspath
168 name = eclipse_project_name
170 natures 'org.eclipse.jdt.core.javanature',
171 'org.eclipse.buildship.core.gradleprojectnature'
173 buildCommand 'org.eclipse.jdt.core.javabuilder'
174 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
178 //defaultOutputDir = sourceSets.main.java.outputDir
180 configurations.each{ if (it.isCanBeResolved()) {
185 minusConfigurations += removeThese
186 plusConfigurations = [ ]
190 def removeTheseToo = []
191 HashMap<String, Boolean> addedSrcPath = new HashMap<>();
192 cp.entries.each { entry ->
193 if (entry.kind == 'src') {
194 if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) {
195 removeTheseToo += entry
197 addedSrcPath.putAt(entry.path, true)
201 cp.entries.removeAll(removeTheseToo)
203 if (file(eclipse_bin_dir+"/main").isDirectory()) {
204 cp.entries += new Output(eclipse_bin_dir+"/main")
206 if (file(helpParentDir).isDirectory()) {
207 cp.entries += new Library(fileReference(helpParentDir))
209 if (file(resourceDir).isDirectory()) {
210 cp.entries += new Library(fileReference(resourceDir))
213 HashMap<String, Boolean> addedLibPath = new HashMap<>();
215 // changing from sourcesets.main.classpath to specific Java version lib
216 //sourceSets.main.compileClasspath.each{
217 fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").each {
218 //don't want to add outputDir as eclipse is using its own output dir in bin/main
219 if (it.isDirectory() || ! it.exists()) {
220 // don't add dirs to classpath
223 def itPath = it.toString()
224 if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
225 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
227 if (addedLibPath.get(itPath)) {
228 //println("Not adding duplicate entry "+itPath)
230 //println("Adding entry "+itPath)
231 cp.entries += new Library(fileReference(itPath))
232 addedLibPath.put(itPath, true)
239 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
243 // for the IDE, use java 11 compatibility
244 sourceCompatibility = compile_source_compatibility
245 targetCompatibility = compile_target_compatibility
246 javaRuntimeName = eclipse_java_runtime_name
250 withProperties { props ->
251 def jalview_prefs = new Properties()
252 def ins = new FileInputStream(jalviewDirAbsolutePath+"/"+eclipse_extra_jdt_prefs_file)
253 jalview_prefs.load(ins)
255 jalview_prefs.forEach { t, v ->
256 if (props.getAt(t) == null) {
265 //synchronizationTasks eclipseClasspath
266 //autoBuildTasks eclipseClasspath
273 sourceCompatibility = compile_source_compatibility
274 targetCompatibility = compile_target_compatibility
275 //options.compilerArgs = additional_compiler_args
276 print ("Setting target compatibility to "+targetCompatibility+"\n")
282 delete sourceSets.main.java.outputDir
297 repoEclipse goomph_eclipse_version
302 //executionEnvironments = [ eclipse.jdt.javaRuntimeName ]
305 //compilerComplianceLevel( JAVA_INTEGER_VERSION )
307 //repo 'http://download.eclipse.org/buildship/updates/e45/milestones/3.x/'
308 repo goomph_repo_buildship
309 feature goomph_feature_buildship
315 launchTask 'ideJalviewjsBuild', {
316 //it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
317 it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
322 task ideCopyDropins (type: Copy) {
325 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
326 def outputDir = oomphIde.ideDir + "/" + com.diffplug.gradle.FileMisc.macContentsEclipse() + "/dropins"
332 outputFiles += outputDir+"/"+filename
333 println("COPYING ${filename} to ${outputFiles}")
336 outputs.files outputFiles
337 inputs.files inputFiles
341 ide.dependsOn eclipseProject
342 ide.dependsOn eclipseClasspath
343 ide.dependsOn eclipseJdt
344 ide.dependsOn ideCopyDropins
345 ideJalviewjsBuild.dependsOn ideSetupWorkspace
346 ideJalviewjsBuild.dependsOn ideCopyDropins
361 def tempEclipseWorkspace = ""
363 task jalviewjsSetTempEclipseWorkspace {
364 tempEclipseWorkspace = file(jalviewjs_eclipse_workspace)
365 if (!tempEclipseWorkspace.exists()) {
366 tempEclipseWorkspace = File.createTempDir()
367 tempEclipseWorkspace.deleteOnExit()
369 println("ECLIPSE WORKSPACE: "+tempEclipseWorkspace.getPath())
372 task jalviewjsUnzipFiles {
373 def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip")
374 zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip
377 zipFiles.each { file_zip ->
379 from zipTree(file_zip)
380 into jalviewjs_site_dir
385 inputs.files zipFiles
386 outputs.dir jalviewjs_site_dir
390 def eclipseDropinsDir
391 def eclipsePluginsDir
392 task jalviewjsEclipsePaths {
393 def eclipseRoot = jalviewjs_eclipse_root
394 if (eclipseRoot.startsWith("~")) {
395 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
397 if (OperatingSystem.current().isMacOsX()) {
398 eclipseRoot += "/Eclipse.app"
399 eclipseDropinsDir = eclipseRoot+"/Contents/Eclipse/dropins"
400 eclipsePluginsDir = eclipseRoot+"/Contents/Eclipse/plugins"
401 eclipseBinary = eclipseRoot+"/Contents/MacOS/eclipse"
402 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
403 eclipseDropinsDir = eclipseRoot+"/dropins"
404 eclipsePluginsDir = eclipseRoot+"/plugins"
405 eclipseBinary = eclipseRoot+"/eclipse"
406 } else { // linux or unix
407 eclipseDropinsDir = eclipseRoot+"/dropins"
408 eclipsePluginsDir = eclipseRoot+"/plugins"
409 eclipseBinary = eclipseRoot+"/eclipse"
411 println("ECLIPSE ROOT: "+eclipseRoot)
414 task jalviewjsEclipseCopyDropins (type: Copy) {
415 dependsOn jalviewjsEclipsePaths
416 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
417 def outputDir = eclipseDropinsDir
423 outputFiles += outputDir+"/"+filename
426 outputs.files outputFiles
427 inputs.files inputFiles
430 task jalviewjsEclipseCopyPlugins (type: Copy) {
431 dependsOn jalviewjsEclipsePaths
432 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_plugins_dir)
433 def outputDir = eclipsePluginsDir
439 outputFiles += outputDir+"/"+filename
442 outputs.files outputFiles
443 inputs.files inputFiles
446 task jalviewjsEclipseSetup {
447 dependsOn jalviewjsEclipseCopyDropins
448 dependsOn jalviewjsEclipseCopyPlugins
449 dependsOn jalviewjsSetTempEclipseWorkspace
453 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
454 outputFile (jalviewDir+"/"+jalviewjs_j2s_settings)
455 def props = project.properties.sort { it.key }
456 props.each { prop, val ->
457 if (prop.startsWith("j2s.") && val != null) {
461 outputs.file(outputFile)
464 task jalviewjsCopyResources (type: Copy) {
465 def inputFiles = fileTree(dir: jalviewjs_resource_dir)
466 def outputDir = jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir
472 outputFiles += outputDir+"/"+filename
475 outputs.files outputFiles
476 inputs.files inputFiles
479 task jalviewjsCopySiteResources (type: Copy) {
480 def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir)
481 def outputDir = jalviewjs_site_dir
487 outputFiles += outputDir+"/"+filename
490 outputs.files outputFiles
491 inputs.files inputFiles
494 task cleanJalviewjs {
496 delete jalviewDir+"/"+jalviewjs_site_dir
497 delete jalviewDir+"/"+eclipse_bin_dir
498 delete file(tempEclipseWorkspace.getAbsolutePath()+"/.metadata")
499 delete jalviewDir+"/"+jalviewjs_j2s_settings
503 task jalviewjsProjectImport(type: Exec) {
504 // work out how to do this!
505 dependsOn eclipseProject
506 dependsOn eclipseClasspath
508 dependsOn jalviewjsEclipsePaths
509 dependsOn jalviewjsEclipseSetup
510 executable(eclipseBinary)
511 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", tempEclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
513 def projdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core/"
514 inputs.file(jalviewDir+"/.project")
518 task jalviewjsTranspile(type: Exec) {
519 dependsOn jalviewjsCreateJ2sSettings
520 dependsOn jalviewjsProjectImport
521 dependsOn jalviewjsEclipsePaths
522 executable(eclipseBinary)
523 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ])
524 inputs.dir(sourceDir)
525 outputs.dir(eclipse_bin_dir+"/main")
526 outputs.file(eclipse_bin_dir+"/main/jalview/bin/Jalview.class")
527 outputs.dir(jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir)
530 task jalviewjsBuildSite {
531 dependsOn jalviewjsUnzipFiles
532 dependsOn jalviewjsCopyResources
533 dependsOn jalviewjsCopySiteResources
534 dependsOn jalviewjsTranspile
537 task jalviewjsSiteTar(type: Tar) {
538 dependsOn jalviewjsBuildSite
539 def outputFilename = "site.tar.gz"
541 archiveFileName = outputFilename
542 } catch (Exception e) {
543 archiveName = outputFilename
546 compression Compression.GZIP
548 from jalviewjs_site_dir
549 into jalviewjs_site_dir // this is inside the tar file
551 inputs.dir(jalviewjs_site_dir)
555 dependsOn jalviewjsBuildSite
558 def jalviewjsServer = null
559 task jalviewjsServerStart {
562 if (jalviewjsServer != null) {
563 println("SERVER ALREADY RUNNING. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
566 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
567 def port = Integer.valueOf(jalviewjs_server_port)
570 while(port < start+1000 && !running) {
572 jalviewjsServer = factory.start(new File(jalviewDirAbsolutePath+"/"+jalviewjs_site_dir), port)
574 println("SERVER STARTED. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
575 //println("Ctrl-c to stop.");java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000);
576 } catch (Exception e) {
587 /* server persists in gradle daemon but reference is not accessible across builds
588 task jalviewjsServerStop {
591 if (jalviewjsServer != null) {
593 println("SERVER ON PORT "+jalviewjsServer.getPort()+" STOPPING. Run gradle jalviewjsServerStart to start again.")
594 jalviewjsServer.stop()
597 println("SERVER NOT RUNNING. Run gradle jalviewjsServerStart to start.")
604 project.afterEvaluate {
605 tasks.findByName('ideJalviewjsBuild').dependsOn eclipseProject
606 tasks.findByName('ideJalviewjsBuild').dependsOn eclipseClasspath
607 tasks.findByName('ideJalviewjsBuild').dependsOn eclipseJdt