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
11 id 'com.diffplug.gradle.oomph.ide' version '3.18.0'
23 mainClassName = launcherClass
24 def classes = "$jalviewDir/$classesDir"
26 // configure classpath/args for j8/j11 compilation
28 def jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
31 def compile_source_compatibility
32 def compile_target_compatibility
35 buildProperties = jalviewDir + "/" + classesDir +"/" + buildPropertiesFile
43 def JAVA_INTEGER_VERSION
44 //def additional_compiler_args = []
45 // this property is for the Java library used in eclipse
46 def eclipse_java_runtime_name
47 if (JAVA_VERSION.equals("1.8")) {
48 JAVA_INTEGER_VERSION = "8"
52 compile_source_compatibility = 1.8
53 compile_target_compatibility = 1.8
54 eclipse_java_runtime_name = "JavaSE-1.8"
55 } else if (JAVA_VERSION.equals("11")) {
56 JAVA_INTEGER_VERSION = "11"
58 libDistDir = j11libDir
59 compile_source_compatibility = 11
60 compile_target_compatibility = 11
61 eclipse_java_runtime_name = "JavaSE-11"
62 /* compile without modules -- using classpath libraries
63 additional_compiler_args += [
64 '--module-path', ext.modules_compileClasspath.asPath,
65 '--add-modules', j11modules
68 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
69 JAVA_INTEGER_VERSION = JAVA_VERSION
71 libDistDir = j11libDir
72 compile_source_compatibility = JAVA_VERSION
73 compile_target_compatibility = JAVA_VERSION
74 eclipse_java_runtime_name = "JavaSE-11"
75 /* compile without modules -- using classpath libraries
76 additional_compiler_args += [
77 '--module-path', ext.modules_compileClasspath.asPath,
78 '--add-modules', j11modules
82 throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview")
89 srcDirs "$jalviewDir/$sourceDir"
90 outputDir = file("$classes")
94 srcDirs "$jalviewDir/$resourceDir"
97 compileClasspath = files(sourceSets.main.java.outputDir)
98 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
100 runtimeClasspath = compileClasspath
107 name = eclipse_project_name
109 natures 'org.eclipse.jdt.core.javanature',
110 'org.eclipse.buildship.core.gradleprojectnature'
112 buildCommand 'org.eclipse.jdt.core.javabuilder'
113 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
117 //defaultOutputDir = sourceSets.main.java.outputDir
119 configurations.each{ if (it.isCanBeResolved()) {
124 minusConfigurations += removeThese
125 plusConfigurations = [ ]
129 def removeTheseToo = []
130 HashMap<String, Boolean> addedSrcPath = new HashMap<>();
131 cp.entries.each { entry ->
132 if (entry.kind == 'src') {
133 if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) {
134 removeTheseToo += entry
136 addedSrcPath.putAt(entry.path, true)
140 cp.entries.removeAll(removeTheseToo)
142 cp.entries += new Output(eclipse_bin_dir+"/main")
143 cp.entries += new Library(fileReference(helpParentDir))
144 cp.entries += new Library(fileReference(resourceDir))
146 HashMap<String, Boolean> addedLibPath = new HashMap<>();
148 // changing from sourcesets.main.classpath to specific Java version lib
149 //sourceSets.main.compileClasspath.each{
150 fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").each {
151 //don't want to add outputDir as eclipse is using its own output dir in bin/main
152 if (it.isDirectory() || ! it.exists()) {
153 // don't add dirs to classpath
156 def itPath = it.toString()
157 if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
158 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
160 if (addedLibPath.get(itPath)) {
161 //println("Not adding duplicate entry "+itPath)
163 //println("Adding entry "+itPath)
164 cp.entries += new Library(fileReference(itPath))
165 addedLibPath.put(itPath, true)
172 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
176 // for the IDE, use java 11 compatibility
177 sourceCompatibility = compile_source_compatibility
178 targetCompatibility = compile_target_compatibility
179 javaRuntimeName = eclipse_java_runtime_name
183 withProperties { props ->
184 def jalview_prefs = new Properties()
185 def ins = new FileInputStream(jalviewDirAbsolutePath+"/"+eclipse_extra_jdt_prefs_file)
186 jalview_prefs.load(ins)
188 jalview_prefs.forEach { t, v ->
189 if (props.getAt(t) == null) {
198 //synchronizationTasks eclipseClasspath
199 //autoBuildTasks eclipseClasspath
206 sourceCompatibility = compile_source_compatibility
207 targetCompatibility = compile_target_compatibility
208 //options.compilerArgs = additional_compiler_args
209 print ("Setting target compatibility to "+targetCompatibility+"\n")
215 delete sourceSets.main.java.outputDir
219 task jalviewjsUnzipFiles {
220 def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip")
221 zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip
224 zipFiles.each { file_zip ->
226 from zipTree(file_zip)
227 into jalviewjs_site_dir
232 inputs.files zipFiles
233 outputs.dir jalviewjs_site_dir
237 def eclipseDropinsDir
238 def eclipsePluginsDir
239 task jalviewjsEclipsePaths {
240 def eclipseRoot = jalviewjs_eclipse_root
241 if (eclipseRoot.startsWith("~")) {
242 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
244 if (OperatingSystem.current().isMacOsX()) {
245 eclipseRoot += "/Eclipse.app"
246 eclipseDropinsDir = eclipseRoot+"/Contents/Eclipse/dropins"
247 eclipsePluginsDir = eclipseRoot+"/Contents/Eclipse/plugins"
248 eclipseBinary = eclipseRoot+"/Contents/MacOS/eclipse"
249 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
250 eclipseDropinsDir = eclipseRoot+"/dropins"
251 eclipsePluginsDir = eclipseRoot+"/plugins"
252 eclipseBinary = eclipseRoot+"/eclipse"
253 } else { // linux or unix
254 eclipseDropinsDir = eclipseRoot+"/dropins"
255 eclipsePluginsDir = eclipseRoot+"/plugins"
256 eclipseBinary = eclipseRoot+"/eclipse"
258 println("ECLIPSE ROOT: "+eclipseRoot)
261 task jalviewjsEclipseCopyDropins (type: Copy) {
262 dependsOn jalviewjsEclipsePaths
263 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
264 def outputDir = eclipseDropinsDir
270 outputFiles += outputDir+"/"+filename
273 outputs.files outputFiles
274 inputs.files inputFiles
277 task jalviewjsEclipseCopyPlugins (type: Copy) {
278 dependsOn jalviewjsEclipsePaths
279 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_plugins_dir)
280 def outputDir = eclipsePluginsDir
286 outputFiles += outputDir+"/"+filename
289 outputs.files outputFiles
290 inputs.files inputFiles
293 def tempEclipseWorkspace = ""
295 task jalviewjsSetTempEclipseWorkspace {
296 tempEclipseWorkspace = file(jalviewjs_eclipse_workspace)
297 if (!tempEclipseWorkspace.exists()) {
298 tempEclipseWorkspace = File.createTempDir()
299 tempEclipseWorkspace.deleteOnExit()
301 println("ECLIPSE WORKSPACE: "+tempEclipseWorkspace.getPath())
308 repo 'http://download.eclipse.org/buildship/updates/e45/milestones/3.x/'
309 feature 'org.eclipse.buildship'
312 task jalviewjsEclipseSetup {
313 dependsOn jalviewjsEclipseCopyDropins
314 dependsOn jalviewjsEclipseCopyPlugins
315 dependsOn jalviewjsSetTempEclipseWorkspace
319 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
320 outputFile (jalviewDir+"/"+jalviewjs_j2s_settings)
321 def props = project.properties.sort { it.key }
322 props.each { prop, val ->
323 if (prop.startsWith("j2s.") && val != null) {
327 outputs.file(outputFile)
330 task jalviewjsCopyResources (type: Copy) {
331 def inputFiles = fileTree(dir: jalviewjs_resource_dir)
332 def outputDir = jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir
338 outputFiles += outputDir+"/"+filename
341 outputs.files outputFiles
342 inputs.files inputFiles
345 task jalviewjsCopySiteResources (type: Copy) {
346 def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir)
347 def outputDir = jalviewjs_site_dir
353 outputFiles += outputDir+"/"+filename
356 outputs.files outputFiles
357 inputs.files inputFiles
360 task cleanJalviewjs {
362 delete jalviewDir+"/"+jalviewjs_site_dir
363 delete jalviewDir+"/"+eclipse_bin_dir
364 delete file(tempEclipseWorkspace.getAbsolutePath()+"/.metadata")
365 delete jalviewDir+"/"+jalviewjs_j2s_settings
369 task jalviewjsProjectImport(type: Exec) {
370 // work out how to do this!
371 dependsOn eclipseProject
372 dependsOn eclipseClasspath
374 dependsOn jalviewjsEclipsePaths
375 dependsOn jalviewjsEclipseSetup
376 executable(eclipseBinary)
377 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", tempEclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
379 def projdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core/"
380 inputs.file(jalviewDir+"/.project")
384 task jalviewjsTranspile(type: Exec) {
385 dependsOn jalviewjsCreateJ2sSettings
386 dependsOn jalviewjsProjectImport
387 dependsOn jalviewjsEclipsePaths
388 executable(eclipseBinary)
389 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ])
390 inputs.dir(sourceDir)
391 outputs.dir(eclipse_bin_dir+"/main")
392 outputs.file(eclipse_bin_dir+"/main/jalview/bin/Jalview.class")
393 outputs.dir(jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir)
396 task jalviewjsBuildSite {
397 dependsOn jalviewjsUnzipFiles
398 dependsOn jalviewjsCopyResources
399 dependsOn jalviewjsCopySiteResources
400 dependsOn jalviewjsTranspile
403 task jalviewjsSiteTar(type: Tar) {
404 dependsOn jalviewjsBuildSite
405 def outputFilename = "site.tar.gz"
407 archiveFileName = outputFilename
408 } catch (Exception e) {
409 archiveName = outputFilename
412 compression Compression.GZIP
414 from jalviewjs_site_dir
415 into jalviewjs_site_dir // this is inside the tar file
417 inputs.dir(jalviewjs_site_dir)
421 dependsOn jalviewjsBuildSite
424 def jalviewjsServer = null
425 task jalviewjsServerStart {
428 if (jalviewjsServer != null) {
429 println("SERVER ALREADY RUNNING. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
432 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
433 def port = Integer.valueOf(jalviewjs_server_port)
436 while(port < start+1000 && !running) {
438 jalviewjsServer = factory.start(new File(jalviewDirAbsolutePath+"/"+jalviewjs_site_dir), port)
440 println("SERVER STARTED. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
441 //println("Ctrl-c to stop.");java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000);
442 } catch (Exception e) {
453 /* server persists in gradle daemon but reference is not accessible across builds
454 task jalviewjsServerStop {
457 if (jalviewjsServer != null) {
459 println("SERVER ON PORT "+jalviewjsServer.getPort()+" STOPPING. Run gradle jalviewjsServerStart to start again.")
460 jalviewjsServer.stop()
463 println("SERVER NOT RUNNING. Run gradle jalviewjsServerStart to start.")