import org.apache.tools.ant.filters.ReplaceTokens import org.gradle.internal.os.OperatingSystem import org.gradle.plugins.ide.eclipse.model.* import groovy.transform.ExternalizeMethods plugins { id 'java' id 'application' id 'eclipse' } repositories { jcenter() mavenCentral() mavenLocal() flatDir { dirs gradlePluginsDir } } mainClassName = launcherClass def classes = "$jalviewDir/$classesDir" // configure classpath/args for j8/j11 compilation def jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath() def libDir def libDistDir def compile_source_compatibility def compile_target_compatibility ext { buildProperties = jalviewDir + "/" + classesDir +"/" + buildPropertiesFile gitHash = "" gitBranch = "" } def JAVA_INTEGER_VERSION //def additional_compiler_args = [] // this property is for the Java library used in eclipse def eclipse_java_runtime_name if (JAVA_VERSION.equals("1.8")) { JAVA_INTEGER_VERSION = "8" //libDir = j8libDir libDir = j11libDir libDistDir = j8libDir compile_source_compatibility = 1.8 compile_target_compatibility = 1.8 eclipse_java_runtime_name = "JavaSE-1.8" } else if (JAVA_VERSION.equals("11")) { JAVA_INTEGER_VERSION = "11" libDir = j11libDir libDistDir = j11libDir compile_source_compatibility = 11 compile_target_compatibility = 11 eclipse_java_runtime_name = "JavaSE-11" /* compile without modules -- using classpath libraries additional_compiler_args += [ '--module-path', ext.modules_compileClasspath.asPath, '--add-modules', j11modules ] */ } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) { JAVA_INTEGER_VERSION = JAVA_VERSION libDir = j11libDir libDistDir = j11libDir compile_source_compatibility = JAVA_VERSION compile_target_compatibility = JAVA_VERSION eclipse_java_runtime_name = "JavaSE-11" /* compile without modules -- using classpath libraries additional_compiler_args += [ '--module-path', ext.modules_compileClasspath.asPath, '--add-modules', j11modules ] */ } else { throw new GradleException("JAVA_VERSION=$JAVA_VERSION not currently supported by Jalview") } sourceSets { main { java { srcDirs "$jalviewDir/$sourceDir" outputDir = file("$classes") } resources { srcDirs "$jalviewDir/$resourceDir" } compileClasspath = files(sourceSets.main.java.outputDir) compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"]) runtimeClasspath = compileClasspath } } eclipse { project { name = eclipse_project_name natures 'org.eclipse.jdt.core.javanature', 'org.eclipse.buildship.core.gradleprojectnature' buildCommand 'org.eclipse.jdt.core.javabuilder' buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder' } classpath { //defaultOutputDir = sourceSets.main.java.outputDir def removeThese = [] configurations.each{ if (it.isCanBeResolved()) { removeThese += it } } minusConfigurations += removeThese plusConfigurations = [ ] file { whenMerged { cp -> def removeTheseToo = [] HashMap addedSrcPath = new HashMap<>(); cp.entries.each { entry -> if (entry.kind == 'src') { if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) { removeTheseToo += entry } else { addedSrcPath.putAt(entry.path, true) } } } cp.entries.removeAll(removeTheseToo) cp.entries += new Output("bin/main") cp.entries += new Library(fileReference(helpParentDir)) cp.entries += new Library(fileReference(resourceDir)) HashMap addedLibPath = new HashMap<>(); // changing from sourcesets.main.classpath to specific Java version lib //sourceSets.main.compileClasspath.each{ fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").each { //don't want to add outputDir as eclipse is using its own output dir in bin/main if (it.isDirectory() || ! it.exists()) { // don't add dirs to classpath return } def itPath = it.toString() if (itPath.startsWith(jalviewDirAbsolutePath+"/")) { itPath = itPath.substring(jalviewDirAbsolutePath.length()+1) } if (addedLibPath.get(itPath)) { //println("Not adding duplicate entry "+itPath) } else { //println("Adding entry "+itPath) cp.entries += new Library(fileReference(itPath)) addedLibPath.put(itPath, true) } } } // whenMerged } // file containers 'org.eclipse.buildship.core.gradleclasspathcontainer' } // classpath jdt { // for the IDE, use java 11 compatibility sourceCompatibility = compile_source_compatibility targetCompatibility = compile_target_compatibility javaRuntimeName = eclipse_java_runtime_name /* file { withProperties { props -> def jalview_prefs = new Properties() def ins = new FileInputStream(jalviewDirAbsolutePath+"/"+eclipse_extra_jdt_prefs_file) jalview_prefs.load(ins) ins.close() jalview_prefs.forEach { t, v -> if (props.getAt(t) == null) { props.putAt(t, v) } } } } */ } // jdt //synchronizationTasks eclipseClasspath //autoBuildTasks eclipseClasspath } // eclipse compileJava { doFirst { sourceCompatibility = compile_source_compatibility targetCompatibility = compile_target_compatibility //options.compilerArgs = additional_compiler_args print ("Setting target compatibility to "+targetCompatibility+"\n") } } clean { delete sourceSets.main.java.outputDir } task jalviewjs_unzipFiles { def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip") zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip doLast { zipFiles.each { file_zip -> copy { from zipTree(file_zip) into jalviewjs_site_dir } } } inputs.files zipFiles outputs.dir jalviewjs_site_dir } def eclipseBinary def eclipseDropinsDir def eclipsePluginsDir task jalviewjs_eclipsePaths { if (OperatingSystem.current().isMacOsX()) { eclipseDropinsDir = jalviewjs_eclipse_root+"/Contents/Eclipse/dropins" eclipsePluginsDir = jalviewjs_eclipse_root+"/Contents/Eclipse/plugins" eclipseBinary = jalviewjs_eclipse_root+"/Contents/MacOS/eclipse" } else if (OperatingSystem.current().isWindows()) { // check this! eclipseDropinsDir = jalviewjs_eclipse_root+"/dropins" eclipsePluginsDir = jalviewjs_eclipse_root+"/plugins" eclipseBinary = jalviewjs_eclipse_root+"/eclipse" } else { // linux or unix eclipseDropinsDir = jalviewjs_eclipse_root+"/dropins" eclipsePluginsDir = jalviewjs_eclipse_root+"/plugins" eclipseBinary = jalviewjs_eclipse_root+"/eclipse" } } task jalviewjs_eclipse_copy_dropins (type: Copy) { dependsOn jalviewjs_eclipsePaths def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir) def outputDir = eclipseDropinsDir from inputFiles into outputDir inputs.files inputFiles //outputs.dir outputDir } task jalviewjs_eclipse_copy_plugins (type: Copy) { dependsOn jalviewjs_eclipsePaths def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_plugins_dir) def outputDir = eclipsePluginsDir from inputFiles into outputDir //inputs.files inputFiles //outputs.dir outputDir } def tempEclipseWorkspace = "" task jalviewjs_setTempEclipseWorkspace { tempEclipseWorkspace = file(jalviewjs_eclipse_workspace) if (!tempEclipseWorkspace.exists()) { tempEclipseWorkspace = File.createTempDir() //tempEclipseWorkspace.deleteOnExit() } } task jalviewjs_eclipse_setup { dependsOn jalviewjs_eclipse_copy_dropins dependsOn jalviewjs_eclipse_copy_plugins dependsOn jalviewjs_setTempEclipseWorkspace } task jalviewjs_createJ2sSettings(type: WriteProperties) { outputFile (jalviewDir+"/"+jalviewjs_j2s_settings) def props = project.properties.sort { it.key } props.each { prop, val -> if (prop.startsWith("j2s.") && val != null) { property(prop,val) } } outputs.file(outputFile) } task jalviewjs_copyResources (type: Copy) { from fileTree(dir: jalviewjs_resource_dir) into jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir } task jalviewjs_copySiteResources (type: Copy) { from fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir) into jalviewjs_site_dir } task cleanJalviewjsSite { //delete jalviewjs_site_dir } task jalviewjsProjectImport(type: Exec) { // work out how to do this! //dependsOn eclipse dependsOn jalviewjs_eclipsePaths dependsOn jalviewjs_eclipse_setup executable(eclipseBinary) args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", tempEclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath]) def tempdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview" outputs.dir(tempdir) } task jalviewjsTranspile(type: Exec) { dependsOn jalviewjsProjectImport dependsOn jalviewjs_eclipsePaths executable(eclipseBinary) args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]) } task jalviewjsBuildSite { dependsOn jalviewjs_unzipFiles dependsOn jalviewjs_copyResources dependsOn jalviewjs_copySiteResources dependsOn jalviewjsTranspile } task jalviewjs { dependsOn jalviewjs_createJ2sSettings dependsOn jalviewjsBuildSite }