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.spotless' version '3.24.2'
32 //id 'com.diffplug.gradle.p2.asmaven' version '3.18.1'
34 //id 'org.eclipse.osgi' version '3.15.0'
41 // The dependencies we actually use
42 'org.eclipse.jdt.core',
46 'org.eclipse.core.contenttype',
47 'org.eclipse.core.jobs',
48 'org.eclipse.core.runtime',
49 'org.eclipse.core.resources',
50 'org.eclipse.equinox.common',
51 'org.eclipse.equinox.preferences',
59 repoEclipse goomph_eclipse_version
60 eclipseDeps.each { p2.addIU(it) }
61 eclipseDeps.each { p2.addIU(it + '.source') }
69 //eclipseDeps.each { compile "p2:${it}:+" }
70 //implementation 'org.eclipse.platform:org.eclipse.osgi:3.15.0'
71 //compile 'org.eclipse.platform:org.eclipse.osgi:3.15.0'
72 //classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.4.0'
79 eclipse(spotless_eclipse_version).configFile eclipse_extra_jdt_prefs_file
92 mainClassName = launcherClass
93 def classes = "$jalviewDir/$classesDir"
95 // configure classpath/args for j8/j11 compilation
97 def jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
100 def compile_source_compatibility
101 def compile_target_compatibility
104 buildProperties = jalviewDir + "/" + classesDir +"/" + buildPropertiesFile
112 def JAVA_INTEGER_VERSION
113 //def additional_compiler_args = []
114 // this property is for the Java library used in eclipse
115 def eclipse_java_runtime_name
116 if (JAVA_VERSION.equals("1.8")) {
117 JAVA_INTEGER_VERSION = "8"
120 libDistDir = j8libDir
121 compile_source_compatibility = 1.8
122 compile_target_compatibility = 1.8
123 eclipse_java_runtime_name = "JavaSE-1.8"
124 } else if (JAVA_VERSION.equals("11")) {
125 JAVA_INTEGER_VERSION = "11"
127 libDistDir = j11libDir
128 compile_source_compatibility = 11
129 compile_target_compatibility = 11
130 eclipse_java_runtime_name = "JavaSE-11"
131 /* compile without modules -- using classpath libraries
132 additional_compiler_args += [
133 '--module-path', ext.modules_compileClasspath.asPath,
134 '--add-modules', j11modules
137 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
138 JAVA_INTEGER_VERSION = JAVA_VERSION
140 libDistDir = j11libDir
141 compile_source_compatibility = JAVA_VERSION
142 compile_target_compatibility = JAVA_VERSION
143 eclipse_java_runtime_name = "JavaSE-11"
144 /* compile without modules -- using classpath libraries
145 additional_compiler_args += [
146 '--module-path', ext.modules_compileClasspath.asPath,
147 '--add-modules', j11modules
151 throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview")
158 srcDirs "$jalviewDir/$sourceDir"
159 outputDir = file("$classes")
163 srcDirs "$jalviewDir/$resourceDir"
166 compileClasspath = files(sourceSets.main.java.outputDir)
167 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
169 runtimeClasspath = compileClasspath
176 name = eclipse_project_name
178 natures 'org.eclipse.jdt.core.javanature',
179 'org.eclipse.buildship.core.gradleprojectnature'
181 buildCommand 'org.eclipse.jdt.core.javabuilder'
182 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
186 //defaultOutputDir = sourceSets.main.java.outputDir
188 configurations.each{ if (it.isCanBeResolved()) {
193 minusConfigurations += removeThese
194 plusConfigurations = [ ]
198 def removeTheseToo = []
199 HashMap<String, Boolean> addedSrcPath = new HashMap<>();
200 cp.entries.each { entry ->
201 if (entry.kind == 'src') {
202 if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) {
203 removeTheseToo += entry
205 addedSrcPath.putAt(entry.path, true)
209 cp.entries.removeAll(removeTheseToo)
211 cp.entries += new Output(eclipse_bin_dir+"/main")
212 cp.entries += new Library(fileReference(helpParentDir))
213 cp.entries += new Library(fileReference(resourceDir))
215 HashMap<String, Boolean> addedLibPath = new HashMap<>();
217 // changing from sourcesets.main.classpath to specific Java version lib
218 //sourceSets.main.compileClasspath.each{
219 fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").each {
220 //don't want to add outputDir as eclipse is using its own output dir in bin/main
221 if (it.isDirectory() || ! it.exists()) {
222 // don't add dirs to classpath
225 def itPath = it.toString()
226 if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
227 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
229 if (addedLibPath.get(itPath)) {
230 //println("Not adding duplicate entry "+itPath)
232 //println("Adding entry "+itPath)
233 cp.entries += new Library(fileReference(itPath))
234 addedLibPath.put(itPath, true)
241 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
245 // for the IDE, use java 11 compatibility
246 sourceCompatibility = compile_source_compatibility
247 targetCompatibility = compile_target_compatibility
248 javaRuntimeName = eclipse_java_runtime_name
252 withProperties { props ->
253 def jalview_prefs = new Properties()
254 def ins = new FileInputStream(jalviewDirAbsolutePath+"/"+eclipse_extra_jdt_prefs_file)
255 jalview_prefs.load(ins)
257 jalview_prefs.forEach { t, v ->
258 if (props.getAt(t) == null) {
267 //synchronizationTasks eclipseClasspath
268 //autoBuildTasks eclipseClasspath
275 sourceCompatibility = compile_source_compatibility
276 targetCompatibility = compile_target_compatibility
277 //options.compilerArgs = additional_compiler_args
278 print ("Setting target compatibility to "+targetCompatibility+"\n")
284 delete sourceSets.main.java.outputDir
299 repoEclipse goomph_eclipse_version
304 //executionEnvironments = [ eclipse.jdt.javaRuntimeName ]
307 //compilerComplianceLevel( JAVA_INTEGER_VERSION )
309 //repo 'http://download.eclipse.org/buildship/updates/e45/milestones/3.x/'
310 repo goomph_repo_buildship
311 feature goomph_feature_buildship
317 launchTask 'ideJalviewjsBuild', {
318 //it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
319 it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
324 task ideCopyDropins (type: Copy) {
327 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
328 def outputDir = oomphIde.ideDir + "/" + com.diffplug.gradle.FileMisc.macContentsEclipse() + "/dropins"
334 outputFiles += outputDir+"/"+filename
335 println("COPYING ${filename} to ${outputFiles}")
338 outputs.files outputFiles
339 inputs.files inputFiles
343 ide.dependsOn ideCopyDropins
344 ideJalviewjsBuild.dependsOn ideSetupWorkspace
345 ideJalviewjsBuild.dependsOn ideCopyDropins
360 def tempEclipseWorkspace = ""
362 task jalviewjsSetTempEclipseWorkspace {
363 tempEclipseWorkspace = file(jalviewjs_eclipse_workspace)
364 if (!tempEclipseWorkspace.exists()) {
365 tempEclipseWorkspace = File.createTempDir()
366 tempEclipseWorkspace.deleteOnExit()
368 println("ECLIPSE WORKSPACE: "+tempEclipseWorkspace.getPath())
371 task jalviewjsUnzipFiles {
372 def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip")
373 zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip
376 zipFiles.each { file_zip ->
378 from zipTree(file_zip)
379 into jalviewjs_site_dir
384 inputs.files zipFiles
385 outputs.dir jalviewjs_site_dir
389 def eclipseDropinsDir
390 def eclipsePluginsDir
391 task jalviewjsEclipsePaths {
392 def eclipseRoot = jalviewjs_eclipse_root
393 if (eclipseRoot.startsWith("~")) {
394 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
396 if (OperatingSystem.current().isMacOsX()) {
397 eclipseRoot += "/Eclipse.app"
398 eclipseDropinsDir = eclipseRoot+"/Contents/Eclipse/dropins"
399 eclipsePluginsDir = eclipseRoot+"/Contents/Eclipse/plugins"
400 eclipseBinary = eclipseRoot+"/Contents/MacOS/eclipse"
401 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
402 eclipseDropinsDir = eclipseRoot+"/dropins"
403 eclipsePluginsDir = eclipseRoot+"/plugins"
404 eclipseBinary = eclipseRoot+"/eclipse"
405 } else { // linux or unix
406 eclipseDropinsDir = eclipseRoot+"/dropins"
407 eclipsePluginsDir = eclipseRoot+"/plugins"
408 eclipseBinary = eclipseRoot+"/eclipse"
410 println("ECLIPSE ROOT: "+eclipseRoot)
413 task jalviewjsEclipseCopyDropins (type: Copy) {
414 dependsOn jalviewjsEclipsePaths
415 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
416 def outputDir = eclipseDropinsDir
422 outputFiles += outputDir+"/"+filename
425 outputs.files outputFiles
426 inputs.files inputFiles
429 task jalviewjsEclipseCopyPlugins (type: Copy) {
430 dependsOn jalviewjsEclipsePaths
431 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_plugins_dir)
432 def outputDir = eclipsePluginsDir
438 outputFiles += outputDir+"/"+filename
441 outputs.files outputFiles
442 inputs.files inputFiles
445 task jalviewjsEclipseSetup {
446 dependsOn jalviewjsEclipseCopyDropins
447 dependsOn jalviewjsEclipseCopyPlugins
448 dependsOn jalviewjsSetTempEclipseWorkspace
452 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
453 outputFile (jalviewDir+"/"+jalviewjs_j2s_settings)
454 def props = project.properties.sort { it.key }
455 props.each { prop, val ->
456 if (prop.startsWith("j2s.") && val != null) {
460 outputs.file(outputFile)
463 task jalviewjsCopyResources (type: Copy) {
464 def inputFiles = fileTree(dir: jalviewjs_resource_dir)
465 def outputDir = jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir
471 outputFiles += outputDir+"/"+filename
474 outputs.files outputFiles
475 inputs.files inputFiles
478 task jalviewjsCopySiteResources (type: Copy) {
479 def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir)
480 def outputDir = jalviewjs_site_dir
486 outputFiles += outputDir+"/"+filename
489 outputs.files outputFiles
490 inputs.files inputFiles
493 task cleanJalviewjs {
495 delete jalviewDir+"/"+jalviewjs_site_dir
496 delete jalviewDir+"/"+eclipse_bin_dir
497 delete file(tempEclipseWorkspace.getAbsolutePath()+"/.metadata")
498 delete jalviewDir+"/"+jalviewjs_j2s_settings
502 task jalviewjsProjectImport(type: Exec) {
503 // work out how to do this!
504 dependsOn eclipseProject
505 dependsOn eclipseClasspath
507 dependsOn jalviewjsEclipsePaths
508 dependsOn jalviewjsEclipseSetup
509 executable(eclipseBinary)
510 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", tempEclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
512 def projdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core/"
513 inputs.file(jalviewDir+"/.project")
517 task jalviewjsTranspile(type: Exec) {
518 dependsOn jalviewjsCreateJ2sSettings
519 dependsOn jalviewjsProjectImport
520 dependsOn jalviewjsEclipsePaths
521 executable(eclipseBinary)
522 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ])
523 inputs.dir(sourceDir)
524 outputs.dir(eclipse_bin_dir+"/main")
525 outputs.file(eclipse_bin_dir+"/main/jalview/bin/Jalview.class")
526 outputs.dir(jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir)
529 task jalviewjsBuildSite {
530 dependsOn jalviewjsUnzipFiles
531 dependsOn jalviewjsCopyResources
532 dependsOn jalviewjsCopySiteResources
533 dependsOn jalviewjsTranspile
536 task jalviewjsSiteTar(type: Tar) {
537 dependsOn jalviewjsBuildSite
538 def outputFilename = "site.tar.gz"
540 archiveFileName = outputFilename
541 } catch (Exception e) {
542 archiveName = outputFilename
545 compression Compression.GZIP
547 from jalviewjs_site_dir
548 into jalviewjs_site_dir // this is inside the tar file
550 inputs.dir(jalviewjs_site_dir)
554 dependsOn jalviewjsBuildSite
557 def jalviewjsServer = null
558 task jalviewjsServerStart {
561 if (jalviewjsServer != null) {
562 println("SERVER ALREADY RUNNING. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
565 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
566 def port = Integer.valueOf(jalviewjs_server_port)
569 while(port < start+1000 && !running) {
571 jalviewjsServer = factory.start(new File(jalviewDirAbsolutePath+"/"+jalviewjs_site_dir), port)
573 println("SERVER STARTED. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
574 //println("Ctrl-c to stop.");java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000);
575 } catch (Exception e) {
586 /* server persists in gradle daemon but reference is not accessible across builds
587 task jalviewjsServerStop {
590 if (jalviewjsServer != null) {
592 println("SERVER ON PORT "+jalviewjsServer.getPort()+" STOPPING. Run gradle jalviewjsServerStart to start again.")
593 jalviewjsServer.stop()
596 println("SERVER NOT RUNNING. Run gradle jalviewjsServerStart to start.")