From 9d8f5f6abf4a7bc4b1a48063ea370187f7b387eb Mon Sep 17 00:00:00 2001 From: jprocter Date: Wed, 10 Jun 2009 12:03:13 +0000 Subject: [PATCH] com.boxysystems.jgogleanalytics is now an optional dependency --- src/jalview/bin/Cache.java | 96 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 20 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index ccd1393..1a22859 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -23,9 +23,6 @@ import java.util.*; import org.apache.log4j.*; -import com.boxysystems.jgoogleanalytics.FocusPoint; -import com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker; - /** * Stores and retrieves Jalview Application Properties Lists and fields within * list entries are separated by '|' symbols unless otherwise stated (|) clauses @@ -486,9 +483,11 @@ public class Cache } /** - * GA tracker object - null if tracking not enabled. + * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not enabled. */ - public static JGoogleAnalyticsTracker tracker = null; + protected static Object tracker = null; + protected static Class trackerfocus = null; + protected static Class jgoogleanalyticstracker = null; /** * Initialise the google tracker if it is not done already. @@ -497,39 +496,96 @@ public class Cache { if (tracker == null) { + if (jgoogleanalyticstracker==null) + { + // try to get the tracker class + try { + jgoogleanalyticstracker = Cache.class.getClassLoader().loadClass( + "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker"); + trackerfocus = Cache.class.getClassLoader().loadClass( + "com.boxysystems.jgoogleanalytics.FocusPoint"); + } catch (Exception e) + { + log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled."); + tracker = null; + jgoogleanalyticstracker=null; + trackerfocus=null; + return; + } + } + // now initialise tracker + Exception re = null, ex = null; + Error err = null; String vrs = "No Version Accessible"; try { // Google analytics tracking code for Library Finder - tracker = new JGoogleAnalyticsTracker("Jalview Desktop", + tracker = jgoogleanalyticstracker.getConstructor(new Class[] { String.class,String.class,String.class}).newInstance(new Object[] { "Jalview Desktop", (vrs = jalview.bin.Cache.getProperty("VERSION") + "_" + jalview.bin.Cache.getDefault("BUILD_DATE", - "unknown")), "UA-9060947-1"); - tracker.trackAsynchronously(new FocusPoint("Application Started.")); + "unknown")), "UA-9060947-1"}); + jgoogleanalyticstracker.getMethod("trackAsynchronously", new Class[] { trackerfocus }) + .invoke(tracker, new Object[] { trackerfocus.getConstructor( + new Class[] { String.class}).newInstance(new Object[] { "Application Started." })}); } catch (RuntimeException e) { - if (log != null) - { - log.debug("Caught runtime exception in googletracker init:", e); - } - // quietly return. + re = e; } catch (Exception e) { - // unexpected error + ex = e; + } catch (Error e) + { + err = e; + } + if (re != null || ex != null || err != null) + { if (log != null) { - log.warn( - "Failed to initialise GoogleTracker for Jalview Desktop with version " - + vrs, e); + if (re != null) + log + .debug( + "Caught runtime exception in googletracker init:", + re); + if (ex != null) + log.warn( + "Failed to initialise GoogleTracker for Jalview Desktop with version " + + vrs, ex); + if (err != null) + log.error( + "Whilst initing GoogleTracker for Jalview Desktop version " + + vrs, err); } else { - log.warn( - "Failed to initialise GoogleTracker for Jalview Desktop with version " - + vrs, e); + if (re != null) + { + System.err + .println("Debug: Caught runtime exception in googletracker init:" + + vrs); + re.printStackTrace(); + } + if (ex != null) + { + System.err + .println("Warning: Failed to initialise GoogleTracker for Jalview Desktop with version " + + vrs); + ex.printStackTrace(); + } + + if (err != null) + { + System.err + .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version " + + vrs); + err.printStackTrace(); + } } } + else + { + log.debug("Successfully initialised tracker."); + } } } -- 1.7.10.2