From dd81c1942eeeeb0a524488c9930f5082bbdf9003 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Mon, 11 Jan 2021 21:30:56 +0000 Subject: [PATCH] JAL-3789 Use j2s.config.altfileproperty in .j2s for alternative temporary build/jalviewjs/config/j2s settings file when running a headless build in gradle --- build.gradle | 41 +++++++++++++++++++++++++++++++++++++---- gradle.properties | 14 +++++++++++++- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index ebb8733..f16b882 100644 --- a/build.gradle +++ b/build.gradle @@ -490,6 +490,7 @@ ext { jalviewjsCoreClasslists = [] jalviewjsJalviewTemplateName = string(jalviewjs_name) jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}") + jalviewjsJ2sAltSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_alt_settings}") jalviewjsJ2sProps = null jalviewjsJ2sPlugin = jalviewjs_j2s_plugin @@ -2070,6 +2071,33 @@ task j2sSetHeadlessBuild { } +task jalviewjsEnableAltFileProperty(type: WriteProperties) { + group "jalviewjs" + description "Enable the alternative J2S Config file for headless build" + + outputFile = jalviewjsJ2sSettingsFileName + def j2sPropsFile = file(jalviewjsJ2sSettingsFileName) + def j2sProps = new Properties() + if (j2sPropsFile.exists()) { + try { + def j2sPropsFileFIS = new FileInputStream(j2sPropsFile) + j2sProps.load(j2sPropsFileFIS) + j2sPropsFileFIS.close() + + j2sProps.each { prop, val -> + property(prop, val) + } + } catch (Exception e) { + println("Exception reading ${jalviewjsJ2sSettingsFileName}") + e.printStackTrace() + } + } + if (! j2sProps.stringPropertyNames().contains(jalviewjs_j2s_alt_file_property_config)) { + property(jalviewjs_j2s_alt_file_property_config, jalviewjs_j2s_alt_file_property) + } +} + + task jalviewjsSetEclipseWorkspace { def propKey = "jalviewjs_eclipse_workspace" def propVal = null @@ -2282,7 +2310,7 @@ task jalviewjsTransferUnzipAllLibs { task jalviewjsCreateJ2sSettings(type: WriteProperties) { group "JalviewJS" - description "Create the .j2s file from the j2s.* properties" + description "Create the alternative j2s file from the j2s.* properties" jalviewjsJ2sProps = project.properties.findAll { it.key.startsWith("j2s.") }.sort { it.key } def siteDirProperty = "j2s.site.directory" @@ -2301,11 +2329,11 @@ task jalviewjsCreateJ2sSettings(type: WriteProperties) { property(siteDirProperty,"${jalviewDirRelativePath}/${jalviewjsTransferSiteJsDir}") } } - outputFile = jalviewjsJ2sSettingsFileName + outputFile = jalviewjsJ2sAltSettingsFileName if (! IN_ECLIPSE) { inputs.properties(jalviewjsJ2sProps) - outputs.file(jalviewjsJ2sSettingsFileName) + outputs.file(jalviewjsJ2sAltSettingsFileName) } } @@ -2423,6 +2451,7 @@ task jalviewjsProjectImport(type: Exec) { args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ] if (!IN_ECLIPSE) { args += [ "-D${j2sHeadlessBuildProperty}=true" ] + args += [ "-D${jalviewjs_j2s_alt_file_property}=${jalviewjsJ2sAltSettingsFileName}" ] } inputs.file("${jalviewDir}/.project") @@ -2436,6 +2465,9 @@ task jalviewjsTranspile(type: Exec) { dependsOn jalviewjsEclipseSetup dependsOn jalviewjsProjectImport dependsOn jalviewjsEclipsePaths + if (!IN_ECLIPSE) { + dependsOn jalviewjsEnableAltFileProperty + } doFirst { // do not run a headless transpile when we claim to be in Eclipse @@ -2455,6 +2487,7 @@ task jalviewjsTranspile(type: Exec) { args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ] if (!IN_ECLIPSE) { args += [ "-D${j2sHeadlessBuildProperty}=true" ] + args += [ "-D${jalviewjs_j2s_alt_file_property}=${jalviewjsJ2sAltSettingsFileName}" ] } def stdout @@ -2935,7 +2968,7 @@ task cleanJalviewjsAll { if (eclipseWorkspace != null && file(eclipseWorkspace.getAbsolutePath()+"/.metadata").exists()) { delete file(eclipseWorkspace.getAbsolutePath()+"/.metadata") } - delete "${jalviewDir}/${jalviewjs_j2s_settings}" + delete jalviewjsJ2sAltSettingsFileName } outputs.upToDateWhen( { false } ) diff --git a/gradle.properties b/gradle.properties index b3590a7..1099cb0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -158,6 +158,19 @@ eclipse_project_name = jalview eclipse_bin_dir = bin eclipse_debug = false +## IMPORTANT for headless build +# to enable `gradle jalviewjs` headless build you MUST set +# j2s.config.altfileproperty = org.jalview.jalviewjsj2sfilename +# (or set to whatever value jalviewjs_j2s_alt_file_property is set to) +# in your ./.j2s file +# OR run the task `gradle jalviewjsEnableAltFileProperty` to do that for you (before headless build task) +jalviewjs_j2s_alt_file_property = org.jalview.jalviewjsj2sfilename +jalviewjs_j2s_alt_settings = build/jalviewjs/config/j2s + +# these are used for actual .j2s file to pass on to alt j2s file +jalviewjs_j2s_settings = .j2s +jalviewjs_j2s_alt_file_property_config = j2s.config.altfileproperty + # for developing in Eclipse as IDE, set this to automatically copy current swingjs/net.sf.j2s.core.jar to your dropins dir jalviewjs_eclipseIDE_auto_copy_j2s_plugin = false # Override this in a local.properties file @@ -170,7 +183,6 @@ jalviewjs_libjs_dir = utils/jalviewjs/libjs jalviewjs_site_resource_dir = utils/jalviewjs/site-resources jalviewjs_classlists_dir = utils/jalviewjs/classlists jalviewjs_classlist_jalview = utils/jalviewjs/_j2sclasslist.txt -jalviewjs_j2s_settings = .j2s #jalviewjs_eclipse_workspace = ~/tmp/eclipse-workspace # these 3 files/dirs found in build/jalviewjs jalviewjs_eclipse_tmp_dropins_dir = eclipse_dropins -- 1.7.10.2