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'
43 mainClassName = launcherClass
44 def classes = "$jalviewDir/$classesDir"
46 // configure classpath/args for j8/j11 compilation
48 def jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
51 def compile_source_compatibility
52 def compile_target_compatibility
55 buildProperties = jalviewDir + "/" + classesDir +"/" + buildPropertiesFile
63 def JAVA_INTEGER_VERSION
64 //def additional_compiler_args = []
65 // this property is for the Java library used in eclipse
66 def eclipse_java_runtime_name
67 if (JAVA_VERSION.equals("1.8")) {
68 JAVA_INTEGER_VERSION = "8"
72 compile_source_compatibility = 1.8
73 compile_target_compatibility = 1.8
74 eclipse_java_runtime_name = "JavaSE-1.8"
75 } else if (JAVA_VERSION.equals("11")) {
76 JAVA_INTEGER_VERSION = "11"
78 libDistDir = j11libDir
79 compile_source_compatibility = 11
80 compile_target_compatibility = 11
81 eclipse_java_runtime_name = "JavaSE-11"
82 /* compile without modules -- using classpath libraries
83 additional_compiler_args += [
84 '--module-path', ext.modules_compileClasspath.asPath,
85 '--add-modules', j11modules
88 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
89 JAVA_INTEGER_VERSION = JAVA_VERSION
91 libDistDir = j11libDir
92 compile_source_compatibility = JAVA_VERSION
93 compile_target_compatibility = JAVA_VERSION
94 eclipse_java_runtime_name = "JavaSE-11"
95 /* compile without modules -- using classpath libraries
96 additional_compiler_args += [
97 '--module-path', ext.modules_compileClasspath.asPath,
98 '--add-modules', j11modules
102 throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview")
109 srcDirs "$jalviewDir/$sourceDir"
110 outputDir = file("$classes")
114 srcDirs "$jalviewDir/$resourceDir"
117 compileClasspath = files(sourceSets.main.java.outputDir)
118 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
120 runtimeClasspath = compileClasspath
127 name = eclipse_project_name
129 natures 'org.eclipse.jdt.core.javanature',
130 'org.eclipse.buildship.core.gradleprojectnature'
132 buildCommand 'org.eclipse.jdt.core.javabuilder'
133 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
137 //defaultOutputDir = sourceSets.main.java.outputDir
139 configurations.each{ if (it.isCanBeResolved()) {
144 minusConfigurations += removeThese
145 plusConfigurations = [ ]
149 def removeTheseToo = []
150 HashMap<String, Boolean> addedSrcPath = new HashMap<>();
151 cp.entries.each { entry ->
152 if (entry.kind == 'src') {
153 if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) {
154 removeTheseToo += entry
156 addedSrcPath.putAt(entry.path, true)
160 cp.entries.removeAll(removeTheseToo)
162 if (file(eclipse_bin_dir+"/main").isDirectory()) {
163 cp.entries += new Output(eclipse_bin_dir+"/main")
165 if (file(helpParentDir).isDirectory()) {
166 cp.entries += new Library(fileReference(helpParentDir))
168 if (file(resourceDir).isDirectory()) {
169 cp.entries += new Library(fileReference(resourceDir))
172 HashMap<String, Boolean> addedLibPath = new HashMap<>();
174 // changing from sourcesets.main.classpath to specific Java version lib
175 //sourceSets.main.compileClasspath.each{
176 fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").each {
177 //don't want to add outputDir as eclipse is using its own output dir in bin/main
178 if (it.isDirectory() || ! it.exists()) {
179 // don't add dirs to classpath
182 def itPath = it.toString()
183 if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
184 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
186 if (addedLibPath.get(itPath)) {
187 //println("Not adding duplicate entry "+itPath)
189 //println("Adding entry "+itPath)
190 cp.entries += new Library(fileReference(itPath))
191 addedLibPath.put(itPath, true)
198 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
202 // for the IDE, use java 11 compatibility
203 sourceCompatibility = compile_source_compatibility
204 targetCompatibility = compile_target_compatibility
205 javaRuntimeName = eclipse_java_runtime_name
209 withProperties { props ->
210 def jalview_prefs = new Properties()
211 def ins = new FileInputStream(jalviewDirAbsolutePath+"/"+eclipse_extra_jdt_prefs_file)
212 jalview_prefs.load(ins)
214 jalview_prefs.forEach { t, v ->
215 if (props.getAt(t) == null) {
224 //synchronizationTasks eclipseClasspath
225 //autoBuildTasks eclipseClasspath
232 sourceCompatibility = compile_source_compatibility
233 targetCompatibility = compile_target_compatibility
234 //options.compilerArgs = additional_compiler_args
235 print ("Setting target compatibility to "+targetCompatibility+"\n")
241 delete sourceSets.main.java.outputDir
268 GoomphCacheLocations.override_workspaces = file(jalviewDirAbsolutePath+"/"+goomph_workspace)
270 repoEclipse goomph_eclipse_version
275 //executionEnvironments = [ eclipse.jdt.javaRuntimeName ]
278 //compilerComplianceLevel( JAVA_INTEGER_VERSION )
280 repo "https://download.eclipse.org/releases/${goomph_eclipse_version_name}/"
281 feature goomph_eclipse_jee_feature, goomph_eclipse_jee_version
284 repo goomph_repo_buildship
285 feature goomph_feature_buildship
297 launchTask 'ideJalviewjsBuild', {
298 //it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
299 it.args = ["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]
304 task testIde(type: ) {
307 task ideCopyDropins (type: Copy) {
310 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
311 def outputDir = oomphIde.ideDir + "/" + com.diffplug.gradle.FileMisc.macContentsEclipse() + "/dropins"
317 outputFiles += outputDir+"/"+filename
318 println("COPYING ${filename} to ${outputFiles}")
321 outputs.files outputFiles
322 inputs.files inputFiles
341 def jalviewjsBuildDir
343 task jalviewjsSitePath {
344 if (jalviewjs_site_dir.startsWith("/")) {
345 jalviewjsSiteDir = jalviewjs_site_dir
347 def relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
348 jalviewjsBuildDir = "${relativeBuildDir}/jalviewjs"
349 jalviewjsSiteDir = jalviewjsBuildDir + "/" + jalviewjs_site_dir
353 def tempEclipseWorkspace
354 task jalviewjsSetTempEclipseWorkspace {
355 tempEclipseWorkspace = file(jalviewjs_eclipse_workspace)
356 if (!tempEclipseWorkspace.exists()) {
357 tempEclipseWorkspace = file("${buildDir}/tmp/eclipse-workspace")
358 //tempEclipseWorkspace.deleteOnExit()
360 println("ECLIPSE WORKSPACE: "+tempEclipseWorkspace.getPath())
363 task jalviewjsUnzipFiles {
364 dependsOn jalviewjsSitePath
366 def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip")
367 zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip
370 zipFiles.each { file_zip ->
372 from zipTree(file_zip)
373 into jalviewjsSiteDir
378 inputs.files zipFiles
379 outputs.dir jalviewjsSiteDir
382 def eclipseDropinsDir
384 task jalviewjsEclipsePaths {
385 def eclipseRoot = jalviewjs_eclipse_root
386 if (eclipseRoot.startsWith("~")) {
387 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
389 if (OperatingSystem.current().isMacOsX()) {
390 eclipseRoot += "/Eclipse.app"
391 eclipseDropinsDir = eclipseRoot+"/Contents/Eclipse/dropins"
392 eclipseBinary = eclipseRoot+"/Contents/MacOS/eclipse"
393 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
394 eclipseDropinsDir = eclipseRoot+"/dropins"
395 eclipseBinary = eclipseRoot+"/eclipse"
396 } else { // linux or unix
397 eclipseDropinsDir = eclipseRoot+"/dropins"
398 eclipseBinary = eclipseRoot+"/eclipse"
402 task jalviewjsEclipseCopyDropins (type: Copy) {
403 dependsOn jalviewjsEclipsePaths
404 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
405 def outputDir = eclipseDropinsDir
411 outputFiles += outputDir+"/"+filename
414 outputs.files outputFiles
415 inputs.files inputFiles
418 task jalviewjsEclipseSetup {
419 dependsOn jalviewjsEclipseCopyDropins
420 dependsOn jalviewjsSetTempEclipseWorkspace
424 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
425 dependsOn jalviewjsSitePath
426 outputFile (jalviewDir+"/"+jalviewjs_j2s_settings)
427 def props = project.properties.sort { it.key }
428 def siteDirProperty = "j2s.site.directory"
429 def setSiteDir = false
430 props.each { prop, val ->
431 if (prop.startsWith("j2s.") && val != null) {
432 if (prop == siteDirProperty) {
433 if (!(val.startsWith("/") || val.startsWith("file://") )) {
434 val = jalviewjsSiteDir+"/"+val
441 property(siteDirProperty,"${jalviewjsSiteDir}")
444 outputs.file(outputFile)
447 task jalviewjsCopyResources (type: Copy) {
448 dependsOn jalviewjsSitePath
449 def inputFiles = fileTree(dir: jalviewjs_resource_dir)
450 def outputDir = jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir
456 outputFiles += outputDir+"/"+filename
459 outputs.files outputFiles
460 inputs.files inputFiles
463 task jalviewjsCopySiteResources (type: Copy) {
464 dependsOn jalviewjsSitePath
465 def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir)
466 def outputDir = jalviewjsSiteDir
472 outputFiles += outputDir+"/"+filename
475 outputs.files outputFiles
476 inputs.files inputFiles
479 task cleanJalviewjs {
480 dependsOn jalviewjsSitePath
482 delete jalviewDir+"/"+jalviewjsSiteDir
483 delete jalviewDir+"/"+eclipse_bin_dir
484 delete file(tempEclipseWorkspace.getAbsolutePath()+"/.metadata")
485 delete jalviewDir+"/"+jalviewjs_j2s_settings
489 task jalviewjsProjectImport(type: Exec) {
490 // work out how to do this!
491 dependsOn eclipseProject
492 dependsOn eclipseClasspath
494 dependsOn jalviewjsEclipsePaths
495 dependsOn jalviewjsEclipseSetup
496 executable(eclipseBinary)
497 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", tempEclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
499 def projdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
500 inputs.file(jalviewDir+"/.project")
502 outputs.upToDateWhen { file(projdir).exists() }
512 task jalviewjsTranspile(type: Exec) {
513 dependsOn jalviewjsCreateJ2sSettings
514 dependsOn jalviewjsProjectImport
515 dependsOn jalviewjsEclipsePaths
516 executable(eclipseBinary)
517 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ])
522 stdout = new ByteArrayOutputStream()
523 stderr = new ByteArrayOutputStream()
524 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(new FileOutputStream("${jalviewjsBuildDir}/${jalviewjs_j2s_stdout}"), stdout);
525 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(new FileOutputStream("${jalviewjsBuildDir}/${jalviewjs_j2s_stderr}"), stderr);
528 if (stdout.toString().contains("Error processing ")) {
529 // j2s did not complete transpile
530 throw new TaskExecutionException("Error during transpilation:\n${stderr}\n")
534 inputs.dir(sourceDir)
535 outputs.dir(eclipse_bin_dir+"/main")
536 outputs.dir(jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir)
537 outputs.file(jalviewjsSiteDir+jalviewjs_server_resource)
538 outputs.upToDateWhen { file(jalviewjsSiteDir+jalviewjs_server_resource).exists() }
549 task jalviewjsBuildSite {
550 dependsOn jalviewjsSitePath
551 dependsOn jalviewjsUnzipFiles
552 dependsOn jalviewjsCopyResources
553 dependsOn jalviewjsCopySiteResources
554 dependsOn jalviewjsTranspile
557 task jalviewjsSiteTar(type: Tar) {
558 dependsOn jalviewjsBuildSite
559 def outputFilename = "jalviewjs-site-${JALVIEW_VERSION}.tar.gz"
561 archiveFileName = outputFilename
562 } catch (Exception e) {
563 archiveName = outputFilename
566 compression Compression.GZIP
568 from jalviewjsSiteDir
569 into jalviewjs_site_dir // this is inside the tar file
571 inputs.dir(jalviewjsSiteDir)
574 def jalviewjsServer = null
575 task jalviewjsServerStart {
576 dependsOn jalviewjsSitePath
579 if (jalviewjsServer != null) {
580 println("SERVER ALREADY RUNNING. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
583 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
584 def port = Integer.valueOf(jalviewjs_server_port)
587 while(port < start+1000 && !running) {
589 def doc_root = new File(jalviewDirAbsolutePath +"/"+ jalviewjsSiteDir)
590 jalviewjsServer = factory.start(doc_root, port)
592 println("SERVER STARTED with document root ${doc_root}.\nGo to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle --stop to stop (kills all gradle daemons).")
593 //println("Ctrl-c to stop.");java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000);
594 } catch (Exception e) {
605 /* server persists in gradle daemon but reference is not accessible across builds
606 task jalviewjsServerStop {
609 if (jalviewjsServer != null) {
611 println("SERVER ON PORT "+jalviewjsServer.getPort()+" STOPPING. Run gradle jalviewjsServerStart to start again.")
612 jalviewjsServer.stop()
615 println("SERVER NOT RUNNING. Run gradle jalviewjsServerStart to start.")
624 dependsOn ideCopyDropins
628 dependsOn jalviewjsSitePath
629 dependsOn jalviewjsUnzipFiles
630 dependsOn jalviewjsCopyResources
631 dependsOn jalviewjsCopySiteResources
632 dependsOn ideCopyDropins
640 dependsOn jalviewjsBuildSite
644 project.afterEvaluate {
645 tasks.findByName('ideJalviewjsBuild').dependsOn eclipseProject
646 tasks.findByName('ideJalviewjsBuild').dependsOn eclipseClasspath
647 tasks.findByName('ideJalviewjsBuild').dependsOn eclipseJdt
649 tasks.findByName('ide').dependsOn eclipseProject
650 tasks.findByName('ide').dependsOn eclipseClasspath
651 tasks.findByName('ide').dependsOn eclipseJdt