import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.internal.os.OperatingSystem
+import org.gradle.plugins.ide.internal.generator.PropertiesPersistableConfigurationObject
+import org.gradle.api.internal.PropertiesTransformer
+import org.gradle.util.ConfigureUtil
import org.gradle.plugins.ide.eclipse.model.Output
import org.gradle.plugins.ide.eclipse.model.Library
import java.security.MessageDigest
id 'java'
id 'application'
id 'eclipse'
+ id "com.diffplug.gradle.spotless" version "3.28.0"
id 'com.github.johnrengelman.shadow' version '4.0.3'
id 'com.install4j.gradle' version '8.0.4'
id 'com.dorongold.task-tree' version '1.5' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree
}
}
+ ////
+ // Import releaseProps from the RELEASE file
+ // or a file specified via JALVIEW_RELEASE_FILE if defined
+ // Expect jalview.version and target release branch in jalview.release
+ def releaseProps = new Properties();
+ def releasePropFile = findProperty("JALVIEW_RELEASE_FILE");
+ def defaultReleasePropFile = "${jalviewDirAbsolutePath}/RELEASE";
+ try {
+ (new File(releasePropFile!=null ? releasePropFile : defaultReleasePropFile)).withInputStream {
+ releaseProps.load(it)
+ }
+ } catch (Exception fileLoadError) {
+ throw new Error("Couldn't load release properties file "+(releasePropFile==null ? defaultReleasePropFile : "from custom location: releasePropFile"),fileLoadError);
+ }
+ ////
+ // Set JALVIEW_VERSION if it is not already set
+ if (findProperty(JALVIEW_VERSION)==null || "".equals(JALVIEW_VERSION)) {
+ JALVIEW_VERSION = releaseProps.get("jalview.version")
+ }
+
// this property set when running Eclipse headlessly
j2sHeadlessBuildProperty = string("net.sf.j2s.core.headlessbuild")
// this property set by Eclipse
J2S_ENABLED = (project.hasProperty('j2s.compiler.status') && project['j2s.compiler.status'] != null && project['j2s.compiler.status'] == "enable")
if (J2S_ENABLED) {
println("J2S ENABLED")
- }
-
+ }
/* *-/
System.properties.sort { it.key }.each {
key, val -> println("SYSTEM PROPERTY ${key}='${val}'")
buildProperties = string("${resourceDir}/${build_properties_file}")
reportRsyncCommand = false
jvlChannelName = CHANNEL.toLowerCase()
+ install4jSuffix = CHANNEL.substring(0, 1).toUpperCase() + CHANNEL.substring(1).toLowerCase(); // BUILD -> Build
+ install4jDSStore = "DS_Store-NON-RELEASE"
+ install4jDMGBackgroundImage = "jalview_dmg_background-NON-RELEASE.png"
+ install4jInstallerName = "${jalview_name} Non-Release Installer"
+ install4jExecutableName = jalview_name.replaceAll("[^\\w]+", "_").toLowerCase()
+ install4jExtraScheme = "jalviewx"
switch (CHANNEL) {
case "BUILD":
if ("".equals(testngExcludedGroups)) {
testngExcludedGroups = "Not-bamboo"
}
+ install4jExtraScheme = "jalviewb"
break
case "RELEASE":
jalviewjs_ignore_transpile_errors = "false"
println("Setting jalviewjs_ignore_transpile_errors to 'false'")
}
+ install4jSuffix = ""
+ install4jDSStore = "DS_Store"
+ install4jDMGBackgroundImage = "jalview_dmg_background.png"
+ install4jInstallerName = "${jalview_name} Installer"
break
case "ARCHIVE":
buildDist = false
}
reportRsyncCommand = true
+ install4jExtraScheme = "jalviewa"
break
case "ARCHIVELOCAL":
}
reportRsyncCommand = true
getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
+ install4jSuffix = "Archive"
+ install4jExtraScheme = "jalviewa"
break
case "DEVELOP":
reportRsyncCommand = true
+
+ // DEVELOP-RELEASE is usually associated with a Jalview release series so set the version
+ JALVIEW_VERSION=JALVIEW_VERSION+"-develop"
+
+ install4jSuffix = "Develop"
+ install4jDSStore = "DS_Store-DEVELOP"
+ install4jDMGBackgroundImage = "jalview_dmg_background-DEVELOP.png"
+ install4jExtraScheme = "jalviewd"
+ install4jInstallerName = "${jalview_name} Develop Installer"
break
case "TEST-RELEASE":
jalviewjs_ignore_transpile_errors = "false"
println("Setting jalviewjs_ignore_transpile_errors to 'false'")
}
+ JALVIEW_VERSION = JALVIEW_VERSION+"-test"
+ install4jSuffix = "Test"
+ install4jDSStore = "DS_Store-TEST-RELEASE"
+ install4jDMGBackgroundImage = "jalview_dmg_background-TEST.png"
+ install4jExtraScheme = "jalviewt"
+ install4jInstallerName = "${jalview_name} Test Installer"
break
case ~/^SCRATCH(|-[-\w]*)$/:
getdownChannelName = CHANNEL
+ JALVIEW_VERSION = JALVIEW_VERSION+"-"+CHANNEL
+
getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
reportRsyncCommand = true
+ install4jSuffix = "Scratch"
break
case "TEST-LOCAL":
getdownAppBase = file(file("${LOCALDIR}").getAbsolutePath()).toURI().toString()
getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
}
+ JALVIEW_VERSION = "TEST"
+ install4jSuffix = "Test-Local"
+ install4jDSStore = "DS_Store-TEST-RELEASE"
+ install4jDMGBackgroundImage = "jalview_dmg_background-TEST.png"
+ install4jExtraScheme = "jalviewt"
+ install4jInstallerName = "${jalview_name} Test Installer"
break
case "LOCAL":
+ JALVIEW_VERSION = "TEST"
getdownAppBase = file(getdownWebsiteDir).toURI().toString()
getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
+ install4jExtraScheme = "jalviewl"
break
default: // something wrong specified
println("Overriding getdown appbase with '${getdownAppBase}'")
}
// sanitise file name for jalview launcher file for this channel
- jvlChannelName = jvlChannelName.replaceAll(/[^\w\-]/,"_")
+ jvlChannelName = jvlChannelName.replaceAll("[^\\w\\-]+", "_")
+ // install4j application and folder names
+ if (install4jSuffix == "") {
+ install4jApplicationName = "${jalview_name}"
+ install4jBundleId = "${install4j_bundle_id}"
+ install4jWinApplicationId = install4j_release_win_application_id
+ } else {
+ install4jApplicationName = "${jalview_name} ${install4jSuffix}"
+ install4jBundleId = "${install4j_bundle_id}-" + install4jSuffix.toLowerCase()
+ // add int hash of install4jSuffix to the last part of the application_id
+ def id = install4j_release_win_application_id
+ def idsplitreverse = id.split("-").reverse()
+ idsplitreverse[0] = idsplitreverse[0].toInteger() + install4jSuffix.hashCode()
+ install4jWinApplicationId = idsplitreverse.reverse().join("-")
+ }
+ // sanitise folder and id names
+ // install4jApplicationFolder = e.g. "Jalview Build"
+ install4jApplicationFolder = install4jApplicationName
+ .replaceAll("[\"'~:/\\\\\\s]", "_") // replace all awkward filename chars " ' ~ : / \
+ .replaceAll("_+", "_") // collapse __
+ install4jInternalId = install4jApplicationName
+ .replaceAll(" ","_")
+ .replaceAll("[^\\w\\-\\.]", "_") // replace other non [alphanumeric,_,-,.]
+ .replaceAll("_+", "") // collapse __
+ //.replaceAll("_*-_*", "-") // collapse _-_
+ install4jUnixApplicationFolder = install4jApplicationName
+ .replaceAll(" ","_")
+ .replaceAll("[^\\w\\-\\.]", "_") // replace other non [alphanumeric,_,-,.]
+ .replaceAll("_+", "_") // collapse __
+ .replaceAll("_*-_*", "-") // collapse _-_
+ .toLowerCase()
getdownAppDir = string("${getdownWebsiteDir}/${getdownAppDistDir}")
//getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
}
+/* hack to change eclipse prefs in .settings files other than org.eclipse.jdt.core.prefs */
+// Class to allow updating arbitrary properties files
+class PropertiesFile extends PropertiesPersistableConfigurationObject {
+ public PropertiesFile(PropertiesTransformer t) { super(t); }
+ @Override protected void load(Properties properties) { }
+ @Override protected void store(Properties properties) { }
+ @Override protected String getDefaultResourceName() { return ""; }
+ // This is necessary, because PropertiesPersistableConfigurationObject fails
+ // if no default properties file exists.
+ @Override public void loadDefaults() { load(new StringBufferInputStream("")); }
+}
+
+// Task to update arbitrary properties files (set outputFile)
+class PropertiesFileTask extends PropertiesGeneratorTask<PropertiesFile> {
+ private final PropertiesFileContentMerger file;
+ public PropertiesFileTask() { file = new PropertiesFileContentMerger(getTransformer()); }
+ protected PropertiesFile create() { return new PropertiesFile(getTransformer()); }
+ protected void configure(PropertiesFile props) {
+ file.getBeforeMerged().execute(props); file.getWhenMerged().execute(props);
+ }
+ public void file(Closure closure) { ConfigureUtil.configure(closure, file); }
+}
+
+task eclipseUIPreferences(type: PropertiesFileTask) {
+ description = "Generate Eclipse additional settings"
+ def filename = "org.eclipse.jdt.ui.prefs"
+ outputFile = "$projectDir/.settings/${filename}" as File
+ file {
+ withProperties {
+ it.load new FileInputStream("$projectDir/utils/eclipse/${filename}" as String)
+ }
+ }
+}
+
+task eclipseGroovyCorePreferences(type: PropertiesFileTask) {
+ description = "Generate Eclipse additional settings"
+ def filename = "org.eclipse.jdt.groovy.core.prefs"
+ outputFile = "$projectDir/.settings/${filename}" as File
+ file {
+ withProperties {
+ it.load new FileInputStream("$projectDir/utils/eclipse/${filename}" as String)
+ }
+ }
+}
+
+task eclipseAllPreferences {
+ dependsOn eclipseJdt
+ dependsOn eclipseUIPreferences
+ dependsOn eclipseGroovyCorePreferences
+}
+
+eclipseUIPreferences.mustRunAfter eclipseJdt
+eclipseGroovyCorePreferences.mustRunAfter eclipseJdt
+
+/* end of eclipse preferences hack */
+
+
task cloverInstr {
// only instrument source, we build test classes as normal
inputs.files files (sourceSets.main.allJava,sourceSets.test.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
compileJava {
-
+ // JBP->BS should the print statement in doFirst refer to compile_target_compatibility ?
+ sourceCompatibility = compile_source_compatibility
+ targetCompatibility = compile_target_compatibility
+ options.compilerArgs = additional_compiler_args
+ options.encoding = "UTF-8"
doFirst {
- sourceCompatibility = compile_source_compatibility
- targetCompatibility = compile_target_compatibility
- options.compilerArgs = additional_compiler_args
print ("Setting target compatibility to "+targetCompatibility+"\n")
}
task createBuildProperties(type: WriteProperties) {
group = "build"
description = "Create the ${buildProperties} file"
+
dependsOn setGitVals
inputs.dir(sourceDir)
inputs.dir(resourceDir)
}
-clean {
- doFirst {
- delete buildingHTML
- }
-}
-
-
task syncDocs(type: Sync) {
dependsOn convertBuildingMD
def syncDir = "${classesDir}/${docDir}"
}
getdownWebsiteResourceFilenames += "${getdownAppDistDir}/${getdown_build_properties}"
- // go through properties looking for getdown_txt_...
+ // set some getdown_txt_ properties then go through all properties looking for getdown_txt_...
def props = project.properties.sort { it.key }
if (getdownAltJavaMinVersion != null && getdownAltJavaMinVersion.length() > 0) {
props.put("getdown_txt_java_min_version", getdownAltJavaMinVersion)
props.put("getdown_txt_multi_java_location", getdownAltMultiJavaLocation)
}
- props.put("getdown_txt_appbase", getdownAppBase)
+ props.put("getdown_txt_title", jalview_name)
+ props.put("getdown_txt_ui.name", install4jApplicationName)
+
+ // start with appbase
+ getdownTextString += "appbase = ${getdownAppBase}\n"
props.each{ prop, val ->
if (prop.startsWith("getdown_txt_") && val != null) {
if (prop.startsWith("getdown_txt_multi_")) {
def getdownLaunchJvl = getdown_launch_jvl_name + ( (jvlChannelName != null && jvlChannelName.length() > 0)?"-${jvlChannelName}":"" ) + ".jvl"
def launchJvl = file("${getdownWebsiteDir}/${getdownLaunchJvl}")
- launchJvl.write("appbase="+props.get("getdown_txt_appbase"))
+ launchJvl.write("appbase=${getdownAppBase}")
copy {
from getdownLauncher
}
+tasks.withType(JavaCompile) {
+ options.encoding = 'UTF-8'
+}
+
+
clean {
doFirst {
delete getdownWebsiteDir
def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
inputs.file(install4jTemplateFile)
inputs.file(install4jFileAssociationsFile)
+ inputs.property("CHANNEL", { CHANNEL })
outputs.file(install4jConfFile)
doLast {
// put file association actions where placeholder action is
def install4jFileAssociationsText = install4jFileAssociationsFile.text
def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
- install4jConfigXml.'**'.action.any { a ->
+ install4jConfigXml.'**'.action.any { a -> // .any{} stops after the first one that returns true
if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
def parent = a.parent()
parent.remove(a)
}
}
+ // use Windows Program Group with Examples folder for RELEASE, and Program Group without Examples for everything else
+ // NB we're deleting the /other/ one!
+ // Also remove the examples subdir from non-release versions
+ def customizedIdToDelete = "PROGRAM_GROUP_RELEASE"
+ // 2.11.1.0 NOT releasing with the Examples folder in the Program Group
+ if (false && CHANNEL=="RELEASE") { // remove 'false && ' to include Examples folder in RELEASE channel
+ customizedIdToDelete = "PROGRAM_GROUP_NON_RELEASE"
+ } else {
+ // remove the examples subdir from Full File Set
+ def files = install4jConfigXml.files[0]
+ def fileset = files.filesets.fileset.find { fs -> fs.'@customizedId' == "FULL_FILE_SET" }
+ def root = files.roots.root.find { r -> r.'@fileset' == fileset.'@id' }
+ def mountPoint = files.mountPoints.mountPoint.find { mp -> mp.'@root' == root.'@id' }
+ def dirEntry = files.entries.dirEntry.find { de -> de.'@mountPoint' == mountPoint.'@id' && de.'@subDirectory' == "examples" }
+ dirEntry.parent().remove(dirEntry)
+ }
+ install4jConfigXml.'**'.action.any { a ->
+ if (a.'@customizedId' == customizedIdToDelete) {
+ def parent = a.parent()
+ parent.remove(a)
+ return true
+ }
+ }
+
+ // remove the "Uninstall Old Jalview (optional)" symlink from DMG for non-release DS_Stores
+ if (! (CHANNEL == "RELEASE" || CHANNEL == "TEST-RELEASE" ) ) {
+ def symlink = install4jConfigXml.'**'.topLevelFiles.symlink.find { sl -> sl.'@name' == "Uninstall Old Jalview (optional).app" }
+ symlink.parent().remove(symlink)
+ }
+
// write install4j file
install4jConfFile.text = XmlUtil.serialize(install4jConfigXml)
}
def install4jBuildDir = "${install4j_build_dir}/${JAVA_VERSION}"
variables = [
- 'JALVIEW_NAME': getdown_txt_title,
+ 'JALVIEW_NAME': jalview_name,
+ 'JALVIEW_APPLICATION_NAME': install4jApplicationName,
'JALVIEW_DIR': "../..",
'OSX_KEYSTORE': OSX_KEYSTORE,
'JSIGN_SH': JSIGN_SH,
'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
'COPYRIGHT_MESSAGE': install4j_copyright_message,
- 'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
- 'INSTALLER_NAME': install4j_installer_name,
+ 'BUNDLE_ID': install4jBundleId,
+ 'INTERNAL_ID': install4jInternalId,
+ 'WINDOWS_APPLICATION_ID': install4jWinApplicationId,
+ 'MACOS_DS_STORE': install4jDSStore,
+ 'MACOS_DMG_BG_IMAGE': install4jDMGBackgroundImage,
+ 'INSTALLER_NAME': install4jInstallerName,
'INSTALL4J_UTILS_DIR': install4j_utils_dir,
'GETDOWN_WEBSITE_DIR': getdown_website_dir,
'GETDOWN_FILES_DIR': getdown_files_dir,
'GETDOWN_INSTALL_DIR': getdown_install_dir,
'INFO_PLIST_FILE_ASSOCIATIONS_FILE': install4j_info_plist_file_associations,
'BUILD_DIR': install4jBuildDir,
+ 'APPLICATION_CATEGORIES': install4j_application_categories,
+ 'APPLICATION_FOLDER': install4jApplicationFolder,
+ 'UNIX_APPLICATION_FOLDER': install4jUnixApplicationFolder,
+ 'EXECUTABLE_NAME': install4jExecutableName,
+ 'EXTRA_SCHEME': install4jExtraScheme,
]
+ //println("INSTALL4J VARIABLES:")
+ //variables.each{k,v->println("${k}=${v}")}
+
destination = "${jalviewDir}/${install4jBuildDir}"
buildSelected = true
}
+spotless {
+ java {
+ eclipse().configFile(eclipse_codestyle_file)
+ }
+}
+
+
task sourceDist(type: Tar) {
def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
eclipseProduct = "${eclipseRoot}/Contents/Eclipse/.eclipseproduct"
} else if (OperatingSystem.current().isWindows()) { // check these paths!!
if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
- eclipseRoot += "/eclipse.exe"
+ eclipseRoot += "/eclipse"
}
- eclipseBinary = "${eclipseRoot}/eclipse"
+ eclipseBinary = "${eclipseRoot}/eclipse.exe"
eclipseProduct = "${eclipseRoot}/.eclipseproduct"
} else { // linux or unix
if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
eclipseRoot += "/eclipse"
+println("eclipseDir exists")
}
eclipseBinary = "${eclipseRoot}/eclipse"
eclipseProduct = "${eclipseRoot}/.eclipseproduct"
def coreBottom = file(suffixFile)
coreFile.getParentFile().mkdirs()
coreFile.createNewFile()
- coreFile.write( coreTop.text )
+ coreFile.write( coreTop.getText("UTF-8") )
list.each {
f ->
if (f.exists()) {
- def t = f.text
+ def t = f.getText("UTF-8")
t.replaceAll("Clazz\\.([^_])","Clazz_${1}")
coreFile.append( t )
} else {
logOutFile.append(msg+"\n")
}
}
- coreFile.append( coreBottom.text )
+ coreFile.append( coreBottom.getText("UTF-8") )
msg = "Generating ${zjsfile}"
println(msg)
def logErrFOS = logOutFOS
javaexec {
- classpath = files(["${jalviewDir}/tools/closure_compiler.jar"])
- args = [ "--js", jsfile, "--js_output_file", zjsfile ]
+ classpath = files(["${jalviewDir}/${jalviewjs_closure_compiler}"])
+ main = "com.google.javascript.jscomp.CommandLineRunner"
+ jvmArgs = [ "-Dfile.encoding=UTF-8" ]
+ args = [ "--compilation_level", "SIMPLE_OPTIMIZATIONS", "--warning_level", "QUIET", "--charset", "UTF-8", "--js", jsfile, "--js_output_file", zjsfile ]
maxHeapSize = "2g"
msg = "\nRunning '"+commandLine.join(' ')+"'\n"