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
22 mainClassName = launcherClass
23 def classes = "$jalviewDir/$classesDir"
25 // configure classpath/args for j8/j11 compilation
27 def jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
30 def compile_source_compatibility
31 def compile_target_compatibility
34 buildProperties = jalviewDir + "/" + classesDir +"/" + buildPropertiesFile
40 def JAVA_INTEGER_VERSION
41 //def additional_compiler_args = []
42 // this property is for the Java library used in eclipse
43 def eclipse_java_runtime_name
44 if (JAVA_VERSION.equals("1.8")) {
45 JAVA_INTEGER_VERSION = "8"
49 compile_source_compatibility = 1.8
50 compile_target_compatibility = 1.8
51 eclipse_java_runtime_name = "JavaSE-1.8"
52 } else if (JAVA_VERSION.equals("11")) {
53 JAVA_INTEGER_VERSION = "11"
55 libDistDir = j11libDir
56 compile_source_compatibility = 11
57 compile_target_compatibility = 11
58 eclipse_java_runtime_name = "JavaSE-11"
59 /* compile without modules -- using classpath libraries
60 additional_compiler_args += [
61 '--module-path', ext.modules_compileClasspath.asPath,
62 '--add-modules', j11modules
65 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
66 JAVA_INTEGER_VERSION = JAVA_VERSION
68 libDistDir = j11libDir
69 compile_source_compatibility = JAVA_VERSION
70 compile_target_compatibility = JAVA_VERSION
71 eclipse_java_runtime_name = "JavaSE-11"
72 /* compile without modules -- using classpath libraries
73 additional_compiler_args += [
74 '--module-path', ext.modules_compileClasspath.asPath,
75 '--add-modules', j11modules
79 throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview")
86 srcDirs "$jalviewDir/$sourceDir"
87 outputDir = file("$classes")
91 srcDirs "$jalviewDir/$resourceDir"
94 compileClasspath = files(sourceSets.main.java.outputDir)
95 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
97 runtimeClasspath = compileClasspath
104 name = eclipse_project_name
106 natures 'org.eclipse.jdt.core.javanature',
107 'org.eclipse.buildship.core.gradleprojectnature'
109 buildCommand 'org.eclipse.jdt.core.javabuilder'
110 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
114 //defaultOutputDir = sourceSets.main.java.outputDir
116 configurations.each{ if (it.isCanBeResolved()) {
121 minusConfigurations += removeThese
122 plusConfigurations = [ ]
126 def removeTheseToo = []
127 HashMap<String, Boolean> addedSrcPath = new HashMap<>();
128 cp.entries.each { entry ->
129 if (entry.kind == 'src') {
130 if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) {
131 removeTheseToo += entry
133 addedSrcPath.putAt(entry.path, true)
137 cp.entries.removeAll(removeTheseToo)
139 cp.entries += new Output(eclipse_bin_dir+"/main")
140 cp.entries += new Library(fileReference(helpParentDir))
141 cp.entries += new Library(fileReference(resourceDir))
143 HashMap<String, Boolean> addedLibPath = new HashMap<>();
145 // changing from sourcesets.main.classpath to specific Java version lib
146 //sourceSets.main.compileClasspath.each{
147 fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").each {
148 //don't want to add outputDir as eclipse is using its own output dir in bin/main
149 if (it.isDirectory() || ! it.exists()) {
150 // don't add dirs to classpath
153 def itPath = it.toString()
154 if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
155 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
157 if (addedLibPath.get(itPath)) {
158 //println("Not adding duplicate entry "+itPath)
160 //println("Adding entry "+itPath)
161 cp.entries += new Library(fileReference(itPath))
162 addedLibPath.put(itPath, true)
169 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
173 // for the IDE, use java 11 compatibility
174 sourceCompatibility = compile_source_compatibility
175 targetCompatibility = compile_target_compatibility
176 javaRuntimeName = eclipse_java_runtime_name
180 withProperties { props ->
181 def jalview_prefs = new Properties()
182 def ins = new FileInputStream(jalviewDirAbsolutePath+"/"+eclipse_extra_jdt_prefs_file)
183 jalview_prefs.load(ins)
185 jalview_prefs.forEach { t, v ->
186 if (props.getAt(t) == null) {
195 //synchronizationTasks eclipseClasspath
196 //autoBuildTasks eclipseClasspath
203 sourceCompatibility = compile_source_compatibility
204 targetCompatibility = compile_target_compatibility
205 //options.compilerArgs = additional_compiler_args
206 print ("Setting target compatibility to "+targetCompatibility+"\n")
212 delete sourceSets.main.java.outputDir
216 task jalviewjsUnzipFiles {
217 def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip")
218 zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip
221 zipFiles.each { file_zip ->
223 from zipTree(file_zip)
224 into jalviewjs_site_dir
229 inputs.files zipFiles
230 outputs.dir jalviewjs_site_dir
234 def eclipseDropinsDir
235 def eclipsePluginsDir
236 task jalviewjsEclipsePaths {
237 def eclipseRoot = jalviewjs_eclipse_root
238 if (eclipseRoot.startsWith("~")) {
239 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
241 if (OperatingSystem.current().isMacOsX()) {
242 eclipseRoot += "/Eclipse.app"
243 eclipseDropinsDir = eclipseRoot+"/Contents/Eclipse/dropins"
244 eclipsePluginsDir = eclipseRoot+"/Contents/Eclipse/plugins"
245 eclipseBinary = eclipseRoot+"/Contents/MacOS/eclipse"
246 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
247 eclipseDropinsDir = eclipseRoot+"/dropins"
248 eclipsePluginsDir = eclipseRoot+"/plugins"
249 eclipseBinary = eclipseRoot+"/eclipse"
250 } else { // linux or unix
251 eclipseDropinsDir = eclipseRoot+"/dropins"
252 eclipsePluginsDir = eclipseRoot+"/plugins"
253 eclipseBinary = eclipseRoot+"/eclipse"
255 println("ECLIPSE ROOT: "+eclipseRoot)
258 task jalviewjsEclipseCopyDropins (type: Copy) {
259 dependsOn jalviewjsEclipsePaths
260 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
261 def outputDir = eclipseDropinsDir
267 outputFiles += outputDir+"/"+filename
270 outputs.files outputFiles
271 inputs.files inputFiles
274 task jalviewjsEclipseCopyPlugins (type: Copy) {
275 dependsOn jalviewjsEclipsePaths
276 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_plugins_dir)
277 def outputDir = eclipsePluginsDir
283 outputFiles += outputDir+"/"+filename
286 outputs.files outputFiles
287 inputs.files inputFiles
290 def tempEclipseWorkspace = ""
292 task jalviewjsSetTempEclipseWorkspace {
293 tempEclipseWorkspace = file(jalviewjs_eclipse_workspace)
294 if (!tempEclipseWorkspace.exists()) {
295 tempEclipseWorkspace = File.createTempDir()
296 tempEclipseWorkspace.deleteOnExit()
298 println("ECLIPSE WORKSPACE: "+tempEclipseWorkspace.getPath())
301 task jalviewjsEclipseSetup {
302 dependsOn jalviewjsEclipseCopyDropins
303 dependsOn jalviewjsEclipseCopyPlugins
304 dependsOn jalviewjsSetTempEclipseWorkspace
308 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
309 outputFile (jalviewDir+"/"+jalviewjs_j2s_settings)
310 def props = project.properties.sort { it.key }
311 props.each { prop, val ->
312 if (prop.startsWith("j2s.") && val != null) {
316 outputs.file(outputFile)
319 task jalviewjsCopyResources (type: Copy) {
320 def inputFiles = fileTree(dir: jalviewjs_resource_dir)
321 def outputDir = jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir
327 outputFiles += outputDir+"/"+filename
330 outputs.files outputFiles
331 inputs.files inputFiles
334 task jalviewjsCopySiteResources (type: Copy) {
335 def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir)
336 def outputDir = jalviewjs_site_dir
342 outputFiles += outputDir+"/"+filename
345 outputs.files outputFiles
346 inputs.files inputFiles
349 task cleanJalviewjs {
351 delete jalviewDir+"/"+jalviewjs_site_dir
352 delete jalviewDir+"/"+eclipse_bin_dir
353 delete file(tempEclipseWorkspace.getAbsolutePath()+"/.metadata")
354 delete jalviewDir+"/"+jalviewjs_j2s_settings
358 task jalviewjsProjectImport(type: Exec) {
359 // work out how to do this!
360 dependsOn eclipseProject
361 dependsOn eclipseClasspath
363 dependsOn jalviewjsEclipsePaths
364 dependsOn jalviewjsEclipseSetup
365 executable(eclipseBinary)
366 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", tempEclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
368 def projdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core/"
369 inputs.file(jalviewDir+"/.project")
373 task jalviewjsTranspile(type: Exec) {
374 dependsOn jalviewjsCreateJ2sSettings
375 dependsOn jalviewjsProjectImport
376 dependsOn jalviewjsEclipsePaths
377 executable(eclipseBinary)
378 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ])
379 inputs.dir(sourceDir)
380 outputs.dir(eclipse_bin_dir+"/main")
381 outputs.file(eclipse_bin_dir+"/main/jalview/bin/Jalview.class")
382 outputs.dir(jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir)
385 task jalviewjsBuildSite {
386 dependsOn jalviewjsUnzipFiles
387 dependsOn jalviewjsCopyResources
388 dependsOn jalviewjsCopySiteResources
389 dependsOn jalviewjsTranspile
392 task jalviewjsSiteTar(type: Tar) {
393 dependsOn jalviewjsBuildSite
394 def outputFilename = "site.tar.gz"
396 archiveFileName = outputFilename
397 } catch (Exception e) {
398 archiveName = outputFilename
401 compression Compression.GZIP
403 from jalviewjs_site_dir
404 into jalviewjs_site_dir // this is inside the tar file
406 inputs.dir(jalviewjs_site_dir)
410 dependsOn jalviewjsBuildSite
413 task jalviewjsServer {
414 //dependsOn jalviewjsBuildSite
417 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
418 def port = Integer.valueOf(jalviewjs_server_port)
421 HttpFileServer server
422 println "server wait = ${jalviewjs_server_wait}"
423 while(port < start+100 && !running) {
425 server = factory.start(new File(jalviewDirAbsolutePath+"/"+jalviewjs_site_dir), port)
427 println("SERVER STARTED on "+server.getResourceUrl(jalviewjs_server_resource)+" for ${jalviewjs_server_wait} seconds. Ctrc+C to kill it.")
428 java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000);
429 } catch (Exception e) {