+ /**
+ * start a User Config prompt asking if we can log usage statistics.
+ */
+ PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
+ "USAGESTATS", "Jalview Usage Statistics",
+ "Do you want to help make Jalview better by enabling "
+ + "the collection of usage statistics with Google Analytics ?"
+ + "\n\n(you can enable or disable usage tracking in the preferences)",
+ new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ Cache.log.debug(
+ "Initialising googletracker for usage stats.");
+ Cache.initGoogleTracker();
+ Cache.log.debug("Tracking enabled.");
+ }
+ }, new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ Cache.log.debug("Not enabling Google Tracking.");
+ }
+ }, null, true);
+ desktop.addDialogThread(prompter);
+ }
+
+ /**
+ * Locate the given string as a file and pass it to the groovy interpreter.
+ *
+ * @param groovyscript
+ * the script to execute
+ * @param jalviewContext
+ * the Jalview Desktop object passed in to the groovy
+ * binding as the 'Jalview' object.
+ */
+ private void executeGroovyScript(String groovyscript, AlignFrame af)
+ {
+ /**
+ * for scripts contained in files
+ */
+ File tfile = null;
+ /**
+ * script's URI
+ */
+ URL sfile = null;
+ if (groovyscript.trim().equals("STDIN"))
+ {
+ // read from stdin into a tempfile and execute it
+ try
+ {
+ tfile = File.createTempFile("jalview", "groovy");
+ PrintWriter outfile = new PrintWriter(
+ new OutputStreamWriter(new FileOutputStream(tfile)));
+ BufferedReader br = new BufferedReader(
+ new InputStreamReader(System.in));
+ String line = null;
+ while ((line = br.readLine()) != null)
+ {
+ outfile.write(line + "\n");
+ }
+ br.close();
+ outfile.flush();
+ outfile.close();
+
+ } catch (Exception ex)
+ {
+ System.err.println("Failed to read from STDIN into tempfile "
+ + ((tfile == null) ? "(tempfile wasn't created)"
+ : tfile.toString()));
+ ex.printStackTrace();
+ return;
+ }
+ try
+ {
+ sfile = tfile.toURI().toURL();
+ } catch (Exception x)
+ {
+ System.err.println(
+ "Unexpected Malformed URL Exception for temporary file created from STDIN: "
+ + tfile.toURI());
+ x.printStackTrace();
+ return;
+ }
+ }
+ else
+ {
+ try
+ {
+ sfile = new URI(groovyscript).toURL();
+ } catch (Exception x)
+ {
+ tfile = new File(groovyscript);
+ if (!tfile.exists())
+ {
+ System.err.println("File '" + groovyscript + "' does not exist.");
+ return;
+ }
+ if (!tfile.canRead())
+ {
+ System.err.println("File '" + groovyscript + "' cannot be read.");
+ return;
+ }
+ if (tfile.length() < 1)
+ {
+ System.err.println("File '" + groovyscript + "' is empty.");
+ return;
+ }
+ try
+ {
+ sfile = tfile.getAbsoluteFile().toURI().toURL();
+ } catch (Exception ex)
+ {
+ System.err.println("Failed to create a file URL for "
+ + tfile.getAbsoluteFile());
+ return;
+ }
+ }
+ }
+ try