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
21 mainClassName = launcherClass
22 def classes = "$jalviewDir/$classesDir"
24 // configure classpath/args for j8/j11 compilation
26 def jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
29 def compile_source_compatibility
30 def compile_target_compatibility
33 buildProperties = jalviewDir + "/" + classesDir +"/" + buildPropertiesFile
39 def JAVA_INTEGER_VERSION
40 //def additional_compiler_args = []
41 // this property is for the Java library used in eclipse
42 def eclipse_java_runtime_name
43 if (JAVA_VERSION.equals("1.8")) {
44 JAVA_INTEGER_VERSION = "8"
48 compile_source_compatibility = 1.8
49 compile_target_compatibility = 1.8
50 eclipse_java_runtime_name = "JavaSE-1.8"
51 } else if (JAVA_VERSION.equals("11")) {
52 JAVA_INTEGER_VERSION = "11"
54 libDistDir = j11libDir
55 compile_source_compatibility = 11
56 compile_target_compatibility = 11
57 eclipse_java_runtime_name = "JavaSE-11"
58 /* compile without modules -- using classpath libraries
59 additional_compiler_args += [
60 '--module-path', ext.modules_compileClasspath.asPath,
61 '--add-modules', j11modules
64 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
65 JAVA_INTEGER_VERSION = JAVA_VERSION
67 libDistDir = j11libDir
68 compile_source_compatibility = JAVA_VERSION
69 compile_target_compatibility = JAVA_VERSION
70 eclipse_java_runtime_name = "JavaSE-11"
71 /* compile without modules -- using classpath libraries
72 additional_compiler_args += [
73 '--module-path', ext.modules_compileClasspath.asPath,
74 '--add-modules', j11modules
78 throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview")
85 srcDirs "$jalviewDir/$sourceDir"
86 outputDir = file("$classes")
90 srcDirs "$jalviewDir/$resourceDir"
93 compileClasspath = files(sourceSets.main.java.outputDir)
94 compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
96 runtimeClasspath = compileClasspath
103 name = eclipse_project_name
105 natures 'org.eclipse.jdt.core.javanature',
106 'org.eclipse.buildship.core.gradleprojectnature'
108 buildCommand 'org.eclipse.jdt.core.javabuilder'
109 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
113 //defaultOutputDir = sourceSets.main.java.outputDir
115 configurations.each{ if (it.isCanBeResolved()) {
120 minusConfigurations += removeThese
121 plusConfigurations = [ ]
125 def removeTheseToo = []
126 HashMap<String, Boolean> addedSrcPath = new HashMap<>();
127 cp.entries.each { entry ->
128 if (entry.kind == 'src') {
129 if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) {
130 removeTheseToo += entry
132 addedSrcPath.putAt(entry.path, true)
136 cp.entries.removeAll(removeTheseToo)
138 cp.entries += new Output("bin/main")
139 cp.entries += new Library(fileReference(helpParentDir))
140 cp.entries += new Library(fileReference(resourceDir))
142 HashMap<String, Boolean> addedLibPath = new HashMap<>();
144 // changing from sourcesets.main.classpath to specific Java version lib
145 //sourceSets.main.compileClasspath.each{
146 fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").each {
147 //don't want to add outputDir as eclipse is using its own output dir in bin/main
148 if (it.isDirectory() || ! it.exists()) {
149 // don't add dirs to classpath
152 def itPath = it.toString()
153 if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
154 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
156 if (addedLibPath.get(itPath)) {
157 //println("Not adding duplicate entry "+itPath)
159 //println("Adding entry "+itPath)
160 cp.entries += new Library(fileReference(itPath))
161 addedLibPath.put(itPath, true)
168 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
172 // for the IDE, use java 11 compatibility
173 sourceCompatibility = compile_source_compatibility
174 targetCompatibility = compile_target_compatibility
175 javaRuntimeName = eclipse_java_runtime_name
179 withProperties { props ->
180 def jalview_prefs = new Properties()
181 def ins = new FileInputStream(jalviewDirAbsolutePath+"/"+eclipse_extra_jdt_prefs_file)
182 jalview_prefs.load(ins)
184 jalview_prefs.forEach { t, v ->
185 if (props.getAt(t) == null) {
194 //synchronizationTasks eclipseClasspath
195 //autoBuildTasks eclipseClasspath
202 sourceCompatibility = compile_source_compatibility
203 targetCompatibility = compile_target_compatibility
204 //options.compilerArgs = additional_compiler_args
205 print ("Setting target compatibility to "+targetCompatibility+"\n")
211 delete sourceSets.main.java.outputDir
215 task jalviewjsUnzipFiles {
216 def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip")
217 zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip
220 zipFiles.each { file_zip ->
222 from zipTree(file_zip)
223 into jalviewjs_site_dir
228 inputs.files zipFiles
229 outputs.dir jalviewjs_site_dir
233 def eclipseDropinsDir
234 def eclipsePluginsDir
235 task jalviewjsEclipsePaths {
236 if (OperatingSystem.current().isMacOsX()) {
237 eclipseDropinsDir = jalviewjs_eclipse_root+"/Contents/Eclipse/dropins"
238 eclipsePluginsDir = jalviewjs_eclipse_root+"/Contents/Eclipse/plugins"
239 eclipseBinary = jalviewjs_eclipse_root+"/Contents/MacOS/eclipse"
240 } else if (OperatingSystem.current().isWindows()) { // check this!
241 eclipseDropinsDir = jalviewjs_eclipse_root+"/dropins"
242 eclipsePluginsDir = jalviewjs_eclipse_root+"/plugins"
243 eclipseBinary = jalviewjs_eclipse_root+"/eclipse"
244 } else { // linux or unix
245 eclipseDropinsDir = jalviewjs_eclipse_root+"/dropins"
246 eclipsePluginsDir = jalviewjs_eclipse_root+"/plugins"
247 eclipseBinary = jalviewjs_eclipse_root+"/eclipse"
251 task jalviewjsEclipseCopyDropins (type: Copy) {
252 dependsOn jalviewjsEclipsePaths
253 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir)
254 def outputDir = eclipseDropinsDir
260 outputFiles += outputDir+"/"+filename
263 outputs.files outputFiles
264 inputs.files inputFiles
267 task jalviewjsEclipseCopyPlugins (type: Copy) {
268 dependsOn jalviewjsEclipsePaths
269 def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_plugins_dir)
270 def outputDir = eclipsePluginsDir
276 outputFiles += outputDir+"/"+filename
279 outputs.files outputFiles
280 inputs.files inputFiles
283 def tempEclipseWorkspace = ""
285 task jalviewjsSetTempEclipseWorkspace {
286 tempEclipseWorkspace = file(jalviewjs_eclipse_workspace)
287 if (!tempEclipseWorkspace.exists() && jalviewjs_eclipse_workspace.startsWith(File.separator)) {
288 tempEclipseWorkspace = File.createTempDir()
289 print("ECLIPSE WORKSPACE: "+tempEclipseWorkspace.getPath())
290 tempEclipseWorkspace.deleteOnExit()
294 task jalviewjsEclipseSetup {
295 dependsOn jalviewjsEclipseCopyDropins
296 dependsOn jalviewjsEclipseCopyPlugins
297 dependsOn jalviewjsSetTempEclipseWorkspace
301 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
302 outputFile (jalviewDir+"/"+jalviewjs_j2s_settings)
303 def props = project.properties.sort { it.key }
304 props.each { prop, val ->
305 if (prop.startsWith("j2s.") && val != null) {
309 outputs.file(outputFile)
312 task jalviewjsCopyResources (type: Copy) {
313 def inputFiles = fileTree(dir: jalviewjs_resource_dir)
314 def outputDir = jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir
320 outputFiles += outputDir+"/"+filename
323 outputs.files outputFiles
324 inputs.files inputFiles
327 task jalviewjsCopySiteResources (type: Copy) {
328 def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir)
329 def outputDir = jalviewjs_site_dir
335 outputFiles += outputDir+"/"+filename
338 outputs.files outputFiles
339 inputs.files inputFiles
342 task cleanJalviewjsSite {
343 delete jalviewjs_site_dir
346 task jalviewjsProjectImport(type: Exec) {
347 // work out how to do this!
348 dependsOn eclipseProject
349 dependsOn eclipseClasspath
351 dependsOn jalviewjsEclipsePaths
352 dependsOn jalviewjsEclipseSetup
353 executable(eclipseBinary)
354 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", tempEclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
356 def tempdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview"
360 task jalviewjsTranspile(type: Exec) {
361 dependsOn jalviewjsProjectImport
362 dependsOn jalviewjsEclipsePaths
363 executable(eclipseBinary)
364 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ])
367 task jalviewjsBuildSite {
368 dependsOn jalviewjsUnzipFiles
369 dependsOn jalviewjsCopyResources
370 dependsOn jalviewjsCopySiteResources
371 dependsOn jalviewjsTranspile
374 task jalviewjsSiteTar(type: Tar) {
375 dependsOn jalviewjsBuildSite
376 def outputFilename = "site.tar.gz"
378 archiveFileName = outputFilename
379 } catch (Exception e) {
380 archiveName = outputFilename
383 compression Compression.GZIP
385 from jalviewjs_site_dir
386 into jalviewjs_site_dir
388 inputs.dir(jalviewjs_site_dir)
392 dependsOn jalviewjsCreateJ2sSettings
393 dependsOn jalviewjsBuildSite