+task jalviewjsIDE_checkJ2sPlugin {
+ group "00 JalviewJS in Eclipse"
+ description "Compare the swingjs/net.sf.j2s.core.jar file with the Eclipse IDE's plugin version (found in the 'dropins' dir)"
+
+ doFirst {
+ def j2sPlugin = string("${jalviewDir}/${jalviewjs_j2s_plugin}")
+ def j2sPluginFile = file(j2sPlugin)
+ def eclipseHome = System.properties["eclipse.home.location"]
+ def copyPlugin = jalviewjs_eclipseIDE_auto_copy_j2s_plugin == "true"
+ def doCopy = false
+ if (eclipseHome == null || ! IN_ECLIPSE) {
+ throw new StopExecutionException("Cannot find running Eclipse home from System.properties['eclipse.home.location']. Skipping J2S Plugin Check.")
+ }
+ def eclipseJ2sPlugin = "${eclipseHome}/dropins/${j2sPluginFile.getName()}"
+ def eclipseJ2sPluginFile = file(eclipseJ2sPlugin)
+ if (!eclipseJ2sPluginFile.exists()) {
+ def msg = "Eclipse J2S Plugin is not installed"
+ println(msg)
+ if (! copyPlugin) {
+ throw new GradleException(msg)
+ }
+ doCopy = true
+ }
+
+ def digest = MessageDigest.getInstance("MD5")
+
+ digest.update(j2sPluginFile.text.bytes)
+ def j2sPluginMd5 = new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
+
+ digest.update(eclipseJ2sPluginFile.text.bytes)
+ def eclipseJ2sPluginMd5 = new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
+
+ if (j2sPluginMd5 != eclipseJ2sPluginMd5) {
+ def msg = "WARNING! Eclipse J2S Plugin '${eclipseJ2sPlugin}' is different to this commit's version '${j2sPlugin}'"
+ println(msg)
+ if (! copyPlugin) {
+ throw new StopExecutionException(msg)
+ }
+ doCopy = true
+ }
+
+ if (doCopy) {
+ def msg = "WARNING! Auto-copying this commit's j2s plugin version '${j2sPlugin}' to Eclipse J2S Plugin '${eclipseJ2sPlugin}'\n May require an Eclipse restart"
+ println(msg)
+ copy {
+ from j2sPlugin
+ eclipseJ2sPluginFile.getParentFile().mkdirs()
+ into eclipseJ2sPluginFile.getParent()
+ }
+ } else {
+ def msg = "Eclipse J2S Plugin is the same as '${j2sPlugin}'"
+ println(msg)
+ }
+ }
+}
+