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
10 id 'com.diffplug.gradle.oomph.ide' version '3.18.0'
11 id 'com.diffplug.gradle.equinoxlaunch' version '3.18.0'
13 id 'com.diffplug.gradle.p2.asmaven' version '3.18.0'
20 // The dependencies we actually use
21 'org.eclipse.jdt.core',
25 'org.eclipse.core.contenttype',
26 'org.eclipse.core.jobs',
27 'org.eclipse.core.runtime',
28 'org.eclipse.core.resources',
29 'org.eclipse.equinox.common',
30 'org.eclipse.equinox.preferences',
37 repoEclipse goomph_eclipse_version
38 eclipseDeps.each { p2.addIU(it) }
39 eclipseDeps.each { p2.addIU(it + '.source') }
44 eclipseDeps.each { compile "p2:${it}:+" }
60 mainClassName = launcherClass
61 def classes = "$jalviewDir/$classesDir"
63 // configure classpath/args for j8/j11 compilation
65 def jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
68 def compile_source_compatibility
69 def compile_target_compatibility
72 buildProperties = jalviewDir + "/" + classesDir +"/" + buildPropertiesFile
80 def JAVA_INTEGER_VERSION
81 //def additional_compiler_args = []
82 // this property is for the Java library used in eclipse
83 def eclipse_java_runtime_name
84 if (JAVA_VERSION.equals("1.8")) {
85 JAVA_INTEGER_VERSION = "8"
89 compile_source_compatibility = 1.8
90 compile_target_compatibility = 1.8
91 eclipse_java_runtime_name = "JavaSE-1.8"
92 } else if (JAVA_VERSION.equals("11")) {
93 JAVA_INTEGER_VERSION = "11"
95 libDistDir = j11libDir
96 compile_source_compatibility = 11
97 compile_target_compatibility = 11
98 eclipse_java_runtime_name = "JavaSE-11"
99 /* compile without modules -- using classpath libraries
100 additional_compiler_args += [
101 '--module-path', ext.modules_compileClasspath.asPath,
102 '--add-modules', j11modules
105 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
106 JAVA_INTEGER_VERSION = JAVA_VERSION
108 libDistDir = j11libDir
109 compile_source_compatibility = JAVA_VERSION
110 compile_target_compatibility = JAVA_VERSION
111 eclipse_java_runtime_name = "JavaSE-11"
112 /* compile without modules -- using classpath libraries
113 additional_compiler_args += [
114 '--module-path', ext.modules_compileClasspath.asPath,
115 '--add-modules', j11modules
119 throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview")
126 srcDirs "$jalviewDir/$sourceDir"
127 outputDir = file("$classes")
131 srcDirs "$jalviewDir/$resourceDir"
134 compileClasspath = files(sourceSets.main.java.outputDir)
135 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
137 runtimeClasspath = compileClasspath
144 name = eclipse_project_name
146 natures 'org.eclipse.jdt.core.javanature',
147 'org.eclipse.buildship.core.gradleprojectnature'
149 buildCommand 'org.eclipse.jdt.core.javabuilder'
150 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
154 //defaultOutputDir = sourceSets.main.java.outputDir
156 configurations.each{ if (it.isCanBeResolved()) {
161 minusConfigurations += removeThese
162 plusConfigurations = [ ]
166 def removeTheseToo = []
167 HashMap<String, Boolean> addedSrcPath = new HashMap<>();
168 cp.entries.each { entry ->
169 if (entry.kind == 'src') {
170 if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) {
171 removeTheseToo += entry
173 addedSrcPath.putAt(entry.path, true)
177 cp.entries.removeAll(removeTheseToo)
179 cp.entries += new Output(eclipse_bin_dir+"/main")
180 cp.entries += new Library(fileReference(helpParentDir))
181 cp.entries += new Library(fileReference(resourceDir))
183 HashMap<String, Boolean> addedLibPath = new HashMap<>();
185 // changing from sourcesets.main.classpath to specific Java version lib
186 //sourceSets.main.compileClasspath.each{
187 fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").each {
188 //don't want to add outputDir as eclipse is using its own output dir in bin/main
189 if (it.isDirectory() || ! it.exists()) {
190 // don't add dirs to classpath
193 def itPath = it.toString()
194 if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
195 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
197 if (addedLibPath.get(itPath)) {
198 //println("Not adding duplicate entry "+itPath)
200 //println("Adding entry "+itPath)
201 cp.entries += new Library(fileReference(itPath))
202 addedLibPath.put(itPath, true)
209 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
213 // for the IDE, use java 11 compatibility
214 sourceCompatibility = compile_source_compatibility
215 targetCompatibility = compile_target_compatibility
216 javaRuntimeName = eclipse_java_runtime_name
220 withProperties { props ->
221 def jalview_prefs = new Properties()
222 def ins = new FileInputStream(jalviewDirAbsolutePath+"/"+eclipse_extra_jdt_prefs_file)
223 jalview_prefs.load(ins)
225 jalview_prefs.forEach { t, v ->
226 if (props.getAt(t) == null) {
235 //synchronizationTasks eclipseClasspath
236 //autoBuildTasks eclipseClasspath
243 sourceCompatibility = compile_source_compatibility
244 targetCompatibility = compile_target_compatibility
245 //options.compilerArgs = additional_compiler_args
246 print ("Setting target compatibility to "+targetCompatibility+"\n")
252 delete sourceSets.main.java.outputDir
267 repoEclipse goomph_eclipse_version
272 //executionEnvironments = [ eclipse.jdt.javaRuntimeName ]
275 //compilerComplianceLevel( JAVA_INTEGER_VERSION )
277 //repo 'http://download.eclipse.org/buildship/updates/e45/milestones/3.x/'
278 repo goomph_repo_buildship
279 feature goomph_feature_buildship
284 launchTask 'ideJalviewjsBuild', {
285 //it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
286 it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
291 task ideCopyDropins (type: Copy) {
294 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
295 def outputDir = oomphIde.ideDir + "/" + com.diffplug.gradle.FileMisc.macContentsEclipse() + "/dropins"
301 outputFiles += outputDir+"/"+filename
302 println("COPYING ${filename} to ${outputFiles}")
305 outputs.files outputFiles
306 inputs.files inputFiles
310 ide.dependsOn ideCopyDropins
311 ideJalviewjsBuild.dependsOn ideSetupWorkspace
312 ideJalviewjsBuild.dependsOn ideCopyDropins
327 def tempEclipseWorkspace = ""
329 task jalviewjsSetTempEclipseWorkspace {
330 tempEclipseWorkspace = file(jalviewjs_eclipse_workspace)
331 if (!tempEclipseWorkspace.exists()) {
332 tempEclipseWorkspace = File.createTempDir()
333 tempEclipseWorkspace.deleteOnExit()
335 println("ECLIPSE WORKSPACE: "+tempEclipseWorkspace.getPath())
338 task jalviewjsUnzipFiles {
339 def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip")
340 zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip
343 zipFiles.each { file_zip ->
345 from zipTree(file_zip)
346 into jalviewjs_site_dir
351 inputs.files zipFiles
352 outputs.dir jalviewjs_site_dir
356 def eclipseDropinsDir
357 def eclipsePluginsDir
358 task jalviewjsEclipsePaths {
359 def eclipseRoot = jalviewjs_eclipse_root
360 if (eclipseRoot.startsWith("~")) {
361 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
363 if (OperatingSystem.current().isMacOsX()) {
364 eclipseRoot += "/Eclipse.app"
365 eclipseDropinsDir = eclipseRoot+"/Contents/Eclipse/dropins"
366 eclipsePluginsDir = eclipseRoot+"/Contents/Eclipse/plugins"
367 eclipseBinary = eclipseRoot+"/Contents/MacOS/eclipse"
368 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
369 eclipseDropinsDir = eclipseRoot+"/dropins"
370 eclipsePluginsDir = eclipseRoot+"/plugins"
371 eclipseBinary = eclipseRoot+"/eclipse"
372 } else { // linux or unix
373 eclipseDropinsDir = eclipseRoot+"/dropins"
374 eclipsePluginsDir = eclipseRoot+"/plugins"
375 eclipseBinary = eclipseRoot+"/eclipse"
377 println("ECLIPSE ROOT: "+eclipseRoot)
380 task jalviewjsEclipseCopyDropins (type: Copy) {
381 dependsOn jalviewjsEclipsePaths
382 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
383 def outputDir = eclipseDropinsDir
389 outputFiles += outputDir+"/"+filename
392 outputs.files outputFiles
393 inputs.files inputFiles
396 task jalviewjsEclipseCopyPlugins (type: Copy) {
397 dependsOn jalviewjsEclipsePaths
398 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_plugins_dir)
399 def outputDir = eclipsePluginsDir
405 outputFiles += outputDir+"/"+filename
408 outputs.files outputFiles
409 inputs.files inputFiles
412 task jalviewjsEclipseSetup {
413 dependsOn jalviewjsEclipseCopyDropins
414 dependsOn jalviewjsEclipseCopyPlugins
415 dependsOn jalviewjsSetTempEclipseWorkspace
419 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
420 outputFile (jalviewDir+"/"+jalviewjs_j2s_settings)
421 def props = project.properties.sort { it.key }
422 props.each { prop, val ->
423 if (prop.startsWith("j2s.") && val != null) {
427 outputs.file(outputFile)
430 task jalviewjsCopyResources (type: Copy) {
431 def inputFiles = fileTree(dir: jalviewjs_resource_dir)
432 def outputDir = jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir
438 outputFiles += outputDir+"/"+filename
441 outputs.files outputFiles
442 inputs.files inputFiles
445 task jalviewjsCopySiteResources (type: Copy) {
446 def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir)
447 def outputDir = jalviewjs_site_dir
453 outputFiles += outputDir+"/"+filename
456 outputs.files outputFiles
457 inputs.files inputFiles
460 task cleanJalviewjs {
462 delete jalviewDir+"/"+jalviewjs_site_dir
463 delete jalviewDir+"/"+eclipse_bin_dir
464 delete file(tempEclipseWorkspace.getAbsolutePath()+"/.metadata")
465 delete jalviewDir+"/"+jalviewjs_j2s_settings
469 task jalviewjsProjectImport(type: Exec) {
470 // work out how to do this!
471 dependsOn eclipseProject
472 dependsOn eclipseClasspath
474 dependsOn jalviewjsEclipsePaths
475 dependsOn jalviewjsEclipseSetup
476 executable(eclipseBinary)
477 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", tempEclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
479 def projdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core/"
480 inputs.file(jalviewDir+"/.project")
484 task jalviewjsTranspile(type: Exec) {
485 dependsOn jalviewjsCreateJ2sSettings
486 dependsOn jalviewjsProjectImport
487 dependsOn jalviewjsEclipsePaths
488 executable(eclipseBinary)
489 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ])
490 inputs.dir(sourceDir)
491 outputs.dir(eclipse_bin_dir+"/main")
492 outputs.file(eclipse_bin_dir+"/main/jalview/bin/Jalview.class")
493 outputs.dir(jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir)
496 task jalviewjsBuildSite {
497 dependsOn jalviewjsUnzipFiles
498 dependsOn jalviewjsCopyResources
499 dependsOn jalviewjsCopySiteResources
500 dependsOn jalviewjsTranspile
503 task jalviewjsSiteTar(type: Tar) {
504 dependsOn jalviewjsBuildSite
505 def outputFilename = "site.tar.gz"
507 archiveFileName = outputFilename
508 } catch (Exception e) {
509 archiveName = outputFilename
512 compression Compression.GZIP
514 from jalviewjs_site_dir
515 into jalviewjs_site_dir // this is inside the tar file
517 inputs.dir(jalviewjs_site_dir)
521 dependsOn jalviewjsBuildSite
524 def jalviewjsServer = null
525 task jalviewjsServerStart {
528 if (jalviewjsServer != null) {
529 println("SERVER ALREADY RUNNING. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
532 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
533 def port = Integer.valueOf(jalviewjs_server_port)
536 while(port < start+1000 && !running) {
538 jalviewjsServer = factory.start(new File(jalviewDirAbsolutePath+"/"+jalviewjs_site_dir), port)
540 println("SERVER STARTED. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
541 //println("Ctrl-c to stop.");java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000);
542 } catch (Exception e) {
553 /* server persists in gradle daemon but reference is not accessible across builds
554 task jalviewjsServerStop {
557 if (jalviewjsServer != null) {
559 println("SERVER ON PORT "+jalviewjsServer.getPort()+" STOPPING. Run gradle jalviewjsServerStart to start again.")
560 jalviewjsServer.stop()
563 println("SERVER NOT RUNNING. Run gradle jalviewjsServerStart to start.")