2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.ext.so.SequenceOntology;
24 import jalview.gui.AlignFrame;
25 import jalview.gui.Desktop;
26 import jalview.gui.PromptUserConfig;
27 import jalview.io.AppletFormatAdapter;
28 import jalview.io.BioJsHTMLOutput;
29 import jalview.io.DataSourceType;
30 import jalview.io.FileFormat;
31 import jalview.io.FileFormatException;
32 import jalview.io.FileFormatI;
33 import jalview.io.FileLoader;
34 import jalview.io.HtmlSvgOutput;
35 import jalview.io.IdentifyFile;
36 import jalview.io.NewickFile;
37 import jalview.io.gff.SequenceOntologyFactory;
38 import jalview.schemes.ColourSchemeI;
39 import jalview.schemes.ColourSchemeProperty;
40 import jalview.util.MessageManager;
41 import jalview.util.Platform;
42 import jalview.ws.jws2.Jws2Discoverer;
44 import java.io.BufferedReader;
46 import java.io.FileOutputStream;
47 import java.io.IOException;
48 import java.io.InputStreamReader;
49 import java.io.OutputStreamWriter;
50 import java.io.PrintWriter;
51 import java.net.MalformedURLException;
53 import java.net.URISyntaxException;
55 import java.security.AllPermission;
56 import java.security.CodeSource;
57 import java.security.PermissionCollection;
58 import java.security.Permissions;
59 import java.security.Policy;
60 import java.util.HashMap;
62 import java.util.Vector;
63 import java.util.logging.ConsoleHandler;
64 import java.util.logging.Level;
65 import java.util.logging.Logger;
67 import javax.swing.LookAndFeel;
68 import javax.swing.UIManager;
70 import groovy.lang.Binding;
71 import groovy.util.GroovyScriptEngine;
74 * Main class for Jalview Application <br>
76 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
79 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
80 * jalview.bin.Jalview jalview.bin.Jalview
82 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
83 * embellish '*' to e.g. '*.jar')
91 public static Jalview getInstance()
93 Instance i = Instance.getInstance();
94 return (i.jalview == null ? i.jalview = new Jalview() : i.jalview);
99 Instance.getInstance().jalview = this;
104 Platform.getURLCommandArguments();
107 private boolean headless;
109 public static boolean isHeadlessMode()
111 return getInstance().headless;
114 private Desktop desktop;
116 private AlignFrame currentAlignFrame;
118 public static AlignFrame getCurrentAlignFrame()
120 return getInstance().currentAlignFrame;
123 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
125 getInstance().currentAlignFrame = currentAlignFrame;
130 if (!Platform.isJS())
137 // grab all the rights we can for the JVM
138 Policy.setPolicy(new Policy()
141 public PermissionCollection getPermissions(CodeSource codesource)
143 Permissions perms = new Permissions();
144 perms.add(new AllPermission());
149 public void refresh()
157 * keep track of feature fetching tasks.
165 * TODO: generalise to track all jalview events to orchestrate batch
169 private int queued = 0;
171 private int running = 0;
173 public FeatureFetcher()
178 public void addFetcher(final AlignFrame af,
179 final Vector<String> dasSources)
181 final long id = System.currentTimeMillis();
183 final FeatureFetcher us = this;
184 new Thread(new Runnable()
196 af.setProgressBar(MessageManager
197 .getString("status.das_features_being_retrived"), id);
198 af.featureSettings_actionPerformed(null);
199 af.setProgressBar(null, id);
208 public synchronized boolean allFinished()
210 return queued == 0 && running == 0;
216 * main class for Jalview application
219 * open <em>filename</em>
221 public static void main(String[] args)
223 // setLogging(); // BH - for event debugging in JavaScript
224 new Jalview().doMain(args);
227 private static void logClass(String name)
229 // BH - for event debugging in JavaScript
230 ConsoleHandler consoleHandler = new ConsoleHandler();
231 consoleHandler.setLevel(Level.ALL);
232 Logger logger = Logger.getLogger(name);
233 logger.setLevel(Level.ALL);
234 logger.addHandler(consoleHandler);
237 @SuppressWarnings("unused")
238 private static void setLogging()
246 System.out.println("not in js");
249 // BH - for event debugging in JavaScript (Java mode only)
250 if (!Platform.isJS())
257 Logger.getLogger("").setLevel(Level.ALL);
258 logClass("java.awt.EventDispatchThread");
259 logClass("java.awt.EventQueue");
260 logClass("java.awt.Component");
261 logClass("java.awt.focus.Component");
262 logClass("java.awt.focus.DefaultKeyboardFocusManager");
270 void doMain(String[] args)
273 if (!Platform.isJS())
275 System.setSecurityManager(null);
279 .println("Java version: " + System.getProperty("java.version"));
280 System.out.println(System.getProperty("os.arch") + " "
281 + System.getProperty("os.name") + " "
282 + System.getProperty("os.version"));
284 ArgsParser aparser = new ArgsParser(args);
286 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
287 Cache.loadProperties(usrPropsFile);
288 if (usrPropsFile != null)
291 "CMD [-props " + usrPropsFile + "] executed successfully!");
294 if (!Platform.isJS())
301 if (aparser.contains("help") || aparser.contains("h"))
306 if (aparser.contains(ArgsParser.NODISPLAY)
307 || aparser.contains(ArgsParser.NOGUI)
308 || aparser.contains(ArgsParser.HEADLESS)
309 || "true".equals(System.getProperty("java.awt.headless")))
316 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
317 if (jabawsUrl != null)
321 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
323 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
324 } catch (MalformedURLException e)
327 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
332 // check for property setting
333 String defs = aparser.getValue(ArgsParser.SETPROP);
336 int p = defs.indexOf('=');
339 System.err.println("Ignoring invalid setprop argument : " + defs);
343 System.out.println("Executing setprop argument: " + defs);
346 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
349 defs = aparser.getValue(ArgsParser.SETPROP);
351 System.setProperty("http.agent",
352 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
356 } catch (NoClassDefFoundError error)
358 error.printStackTrace();
359 System.out.println("\nEssential logging libraries not found."
360 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
368 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
369 } catch (Exception ex)
371 System.err.println("Unexpected Look and Feel Exception");
372 ex.printStackTrace();
374 if (Platform.isAMacAndNotJS())
377 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
379 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
381 System.setProperty("apple.laf.useScreenMenuBar", "true");
382 if (lookAndFeel != null)
386 UIManager.setLookAndFeel(lookAndFeel);
387 } catch (Throwable e)
390 "Failed to set QuaQua look and feel: " + e.toString());
393 if (lookAndFeel == null
394 || !(lookAndFeel.getClass().isAssignableFrom(
395 UIManager.getLookAndFeel().getClass()))
396 || !UIManager.getLookAndFeel().getClass().toString()
397 .toLowerCase().contains("quaqua"))
402 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
403 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
404 } catch (Throwable e)
407 "Failed to reset look and feel: " + e.toString());
413 * configure 'full' SO model if preferences say to,
414 * else use the default (SO Lite)
416 if (Cache.getDefault("USE_FULL_SO", false))
418 SequenceOntologyFactory.setInstance(new SequenceOntology());
423 desktop = new Desktop();
424 desktop.setInBatchMode(true); // indicate we are starting up
425 desktop.setVisible(true);
427 if (!Platform.isJS())
434 desktop.startServiceDiscovery();
435 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
437 startUsageStats(desktop);
441 System.err.println("CMD [-nousagestats] executed successfully!");
444 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
446 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
449 // Start the desktop questionnaire prompter with the specified
451 Cache.log.debug("Starting questionnaire url at " + url);
452 desktop.checkForQuestionnaire(url);
453 System.out.println("CMD questionnaire[-" + url
454 + "] executed successfully!");
458 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
460 // Start the desktop questionnaire prompter with the specified
463 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
465 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
467 "Starting questionnaire with default url: " + defurl);
468 desktop.checkForQuestionnaire(defurl);
475 .println("CMD [-noquestionnaire] executed successfully!");
478 if (!aparser.contains(ArgsParser.NONEWS))
480 desktop.checkForNews();
483 BioJsHTMLOutput.updateBioJS();
488 FileFormatI format = null;
489 DataSourceType protocol = null;
490 FileLoader fileLoader = new FileLoader(!headless);
492 // script to execute after all loading is
493 // completed one way or another
494 // extract groovy argument and execute if necessary
495 String groovyscript = aparser.getValue(ArgsParser.GROOVY, true);
496 String file = aparser.getValue(ArgsParser.OPEN, true);
498 if (file == null && desktop == null)
500 System.out.println("No files to open!");
503 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
504 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
505 if (vamsasImport != null || vamsasSession != null)
507 if (desktop == null || headless)
510 "Headless vamsas sessions not yet supported. Sorry.");
513 // if we have a file, start a new session and import it.
514 boolean inSession = false;
515 if (vamsasImport != null)
519 DataSourceType viprotocol = AppletFormatAdapter
520 .checkProtocol(vamsasImport);
521 if (viprotocol == DataSourceType.FILE)
523 inSession = desktop.vamsasImport(new File(vamsasImport));
525 else if (viprotocol == DataSourceType.URL)
527 inSession = desktop.vamsasImport(new URL(vamsasImport));
530 } catch (Exception e)
532 System.err.println("Exeption when importing " + vamsasImport
533 + " as a vamsas document.");
538 System.err.println("Failed to import " + vamsasImport
539 + " as a vamsas document.");
543 System.out.println("Imported Successfully into new session "
544 + desktop.getVamsasApplication().getCurrentSession());
547 if (vamsasSession != null)
549 if (vamsasImport != null)
551 // close the newly imported session and import the Jalview specific
552 // remnants into the new session later on.
553 desktop.vamsasStop_actionPerformed(null);
555 // now join the new session
558 if (desktop.joinVamsasSession(vamsasSession))
561 "Successfully joined vamsas session " + vamsasSession);
565 System.err.println("WARNING: Failed to join vamsas session "
568 } catch (Exception e)
571 "ERROR: Failed to join vamsas session " + vamsasSession);
574 if (vamsasImport != null)
576 // the Jalview specific remnants can now be imported into the new
577 // session at the user's leisure.
579 "Skipping Push for import of data into existing vamsas session."); // TODO:
584 // desktop.getVamsasApplication().push_update();
589 // Finally, deal with the remaining input data.
594 desktop.setProgressBar(
596 .getString("status.processing_commandline_args"),
597 progress = System.currentTimeMillis());
599 System.out.println("CMD [-open " + file + "] executed successfully!");
601 if (!Platform.isJS())
603 * ignore in JavaScript -- can't just check file existence - could load
609 if (!file.startsWith("http://") && !file.startsWith("https://"))
610 // BH 2019 added https check for Java
612 if (!(new File(file)).exists())
614 System.out.println("Can't find " + file);
623 protocol = AppletFormatAdapter.checkProtocol(file);
627 format = new IdentifyFile().identify(file, protocol);
628 } catch (FileFormatException e1)
633 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
637 System.out.println("error");
641 setCurrentAlignFrame(af);
642 data = aparser.getValue(ArgsParser.COLOUR, true);
645 data.replaceAll("%20", " ");
647 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
648 af.getViewport(), af.getViewport().getAlignment(), data);
653 "CMD [-color " + data + "] executed successfully!");
658 // Must maintain ability to use the groups flag
659 data = aparser.getValue(ArgsParser.GROUPS, true);
662 af.parseFeaturesFile(data,
663 AppletFormatAdapter.checkProtocol(data));
664 // System.out.println("Added " + data);
666 "CMD groups[-" + data + "] executed successfully!");
668 data = aparser.getValue(ArgsParser.FEATURES, true);
671 af.parseFeaturesFile(data,
672 AppletFormatAdapter.checkProtocol(data));
673 // System.out.println("Added " + data);
675 "CMD [-features " + data + "] executed successfully!");
678 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
681 af.loadJalviewDataFile(data, null, null, null);
682 // System.out.println("Added " + data);
684 "CMD [-annotations " + data + "] executed successfully!");
686 // set or clear the sortbytree flag.
687 if (aparser.contains(ArgsParser.SORTBYTREE))
689 af.getViewport().setSortByTree(true);
690 if (af.getViewport().getSortByTree())
692 System.out.println("CMD [-sortbytree] executed successfully!");
695 if (aparser.contains(ArgsParser.NOANNOTATION)
696 || aparser.contains(ArgsParser.NOANNOTATION2))
698 af.getViewport().setShowAnnotation(false);
699 if (!af.getViewport().isShowAnnotation())
701 System.out.println("CMD no-annotation executed successfully!");
704 if (aparser.contains(ArgsParser.NOSORTBYTREE))
706 af.getViewport().setSortByTree(false);
707 if (!af.getViewport().getSortByTree())
710 .println("CMD [-nosortbytree] executed successfully!");
713 data = aparser.getValue(ArgsParser.TREE, true);
719 "CMD [-tree " + data + "] executed successfully!");
720 NewickFile nf = new NewickFile(data,
721 AppletFormatAdapter.checkProtocol(data));
723 .setCurrentTree(af.showNewickTree(nf, data).getTree());
724 } catch (IOException ex)
726 System.err.println("Couldn't add tree " + data);
727 ex.printStackTrace(System.err);
730 // TODO - load PDB structure(s) to alignment JAL-629
731 // (associate with identical sequence in alignment, or a specified
733 if (groovyscript != null)
735 // Execute the groovy script after we've done all the rendering stuff
736 // and before any images or figures are generated.
737 System.out.println("Executing script " + groovyscript);
738 executeGroovyScript(groovyscript, af);
739 System.out.println("CMD groovy[" + groovyscript
740 + "] executed successfully!");
743 String imageName = "unnamed.png";
744 while (aparser.getSize() > 1)
750 String outputFormat = aparser.nextValue();
751 file = aparser.nextValue();
753 if (outputFormat.equalsIgnoreCase("png"))
755 af.createPNG(new File(file));
756 imageName = (new File(file)).getName();
757 System.out.println("Creating PNG image: " + file);
760 else if (outputFormat.equalsIgnoreCase("svg"))
762 File imageFile = new File(file);
763 imageName = imageFile.getName();
764 af.createSVG(imageFile);
765 System.out.println("Creating SVG image: " + file);
768 else if (outputFormat.equalsIgnoreCase("html"))
770 File imageFile = new File(file);
771 imageName = imageFile.getName();
772 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
773 htmlSVG.exportHTML(file);
775 System.out.println("Creating HTML image: " + file);
778 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
782 System.err.println("The output html file must not be null");
787 BioJsHTMLOutput.refreshVersionInfo(
788 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
789 } catch (URISyntaxException e)
793 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
794 bjs.exportHTML(file);
796 .println("Creating BioJS MSA Viwer HTML file: " + file);
799 else if (outputFormat.equalsIgnoreCase("imgMap"))
801 af.createImageMap(new File(file), imageName);
802 System.out.println("Creating image map: " + file);
805 else if (outputFormat.equalsIgnoreCase("eps"))
807 File outputFile = new File(file);
809 "Creating EPS file: " + outputFile.getAbsolutePath());
810 af.createEPS(outputFile);
814 af.saveAlignment(file, format);
815 if (af.isSaveAlignmentSuccessful())
817 System.out.println("Written alignment in " + format
818 + " format to " + file);
822 System.out.println("Error writing file " + file + " in "
823 + format + " format!!");
828 while (aparser.getSize() > 0)
830 System.out.println("Unknown arg: " + aparser.nextValue());
834 AlignFrame startUpAlframe = null;
835 // We'll only open the default file if the desktop is visible.
837 // ////////////////////
839 if (!Platform.isJS() && !headless && file == null
840 && vamsasImport == null
841 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
848 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
849 jalview.bin.Cache.getDefault("www.jalview.org",
850 "http://www.jalview.org")
851 + "/examples/exampleFile_2_7.jar");
853 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
855 // hardwire upgrade of the startup file
856 file.replace("_2_3.jar", "_2_7.jar");
857 // and remove the stale setting
858 jalview.bin.Cache.removeProperty("STARTUP_FILE");
861 protocol = DataSourceType.FILE;
863 if (file.indexOf("http:") > -1)
865 protocol = DataSourceType.URL;
868 if (file.endsWith(".jar"))
870 format = FileFormat.Jalview;
876 format = new IdentifyFile().identify(file, protocol);
877 } catch (FileFormatException e)
883 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
885 // extract groovy arguments before anything else.
888 // Once all other stuff is done, execute any groovy scripts (in order)
889 if (groovyscript != null)
891 if (Cache.groovyJarsPresent())
893 System.out.println("Executing script " + groovyscript);
894 executeGroovyScript(groovyscript, startUpAlframe);
899 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
903 // and finally, turn off batch mode indicator - if the desktop still exists
908 desktop.setProgressBar(null, progress);
910 desktop.setInBatchMode(false);
914 private static void showUsage()
917 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
918 + "-nodisplay\tRun Jalview without User Interface.\n"
919 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
920 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
921 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
922 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
923 + "-features FILE\tUse the given file to mark features on the alignment.\n"
924 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
925 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
926 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
927 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
928 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
929 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
930 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
931 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
932 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
933 + "-png FILE\tCreate PNG image FILE from alignment.\n"
934 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
935 + "-html FILE\tCreate HTML file from alignment.\n"
936 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
937 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
938 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
939 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
940 + "-noquestionnaire\tTurn off questionnaire check.\n"
941 + "-nonews\tTurn off check for Jalview news.\n"
942 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
943 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
945 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
946 // after all other properties files have been read\n\t
947 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
948 // passed in correctly)"
949 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
950 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
952 // "-vdoc vamsas-document\tImport vamsas document into new
953 // session or join existing session with same URN\n"
954 // + "-vses vamsas-session\tJoin session with given URN\n"
955 + "-groovy FILE\tExecute groovy script in FILE, after all other arguments have been processed (if FILE is the text 'STDIN' then the file will be read from STDIN)\n"
956 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
959 private static void startUsageStats(final Desktop desktop)
962 * start a User Config prompt asking if we can log usage statistics.
964 PromptUserConfig prompter = new PromptUserConfig(
965 Desktop.getDesktopPane(), "USAGESTATS",
966 "Jalview Usage Statistics",
967 "Do you want to help make Jalview better by enabling "
968 + "the collection of usage statistics with Google Analytics ?"
969 + "\n\n(you can enable or disable usage tracking in the preferences)",
976 "Initialising googletracker for usage stats.");
977 Cache.initGoogleTracker();
978 Cache.log.debug("Tracking enabled.");
985 Cache.log.debug("Not enabling Google Tracking.");
988 desktop.addDialogThread(prompter);
992 * Locate the given string as a file and pass it to the groovy interpreter.
994 * @param groovyscript
995 * the script to execute
996 * @param jalviewContext
997 * the Jalview Desktop object passed in to the groovy binding as the
1000 private void executeGroovyScript(String groovyscript, AlignFrame af)
1003 * for scripts contained in files
1010 if (groovyscript.trim().equals("STDIN"))
1012 // read from stdin into a tempfile and execute it
1015 tfile = File.createTempFile("jalview", "groovy");
1016 PrintWriter outfile = new PrintWriter(
1017 new OutputStreamWriter(new FileOutputStream(tfile)));
1018 BufferedReader br = new BufferedReader(
1019 new InputStreamReader(System.in));
1021 while ((line = br.readLine()) != null)
1023 outfile.write(line + "\n");
1029 } catch (Exception ex)
1031 System.err.println("Failed to read from STDIN into tempfile "
1032 + ((tfile == null) ? "(tempfile wasn't created)"
1033 : tfile.toString()));
1034 ex.printStackTrace();
1039 sfile = tfile.toURI().toURL();
1040 } catch (Exception x)
1043 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1045 x.printStackTrace();
1053 sfile = new URI(groovyscript).toURL();
1054 } catch (Exception x)
1056 tfile = new File(groovyscript);
1057 if (!tfile.exists())
1059 System.err.println("File '" + groovyscript + "' does not exist.");
1062 if (!tfile.canRead())
1064 System.err.println("File '" + groovyscript + "' cannot be read.");
1067 if (tfile.length() < 1)
1069 System.err.println("File '" + groovyscript + "' is empty.");
1074 sfile = tfile.getAbsoluteFile().toURI().toURL();
1075 } catch (Exception ex)
1077 System.err.println("Failed to create a file URL for "
1078 + tfile.getAbsoluteFile());
1085 Map<String, Object> vbinding = new HashMap<>();
1086 vbinding.put("Jalview", this);
1089 vbinding.put("currentAlFrame", af);
1091 Binding gbinding = new Binding(vbinding);
1092 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1093 gse.run(sfile.toString(), gbinding);
1094 if ("STDIN".equals(groovyscript))
1096 // delete temp file that we made -
1097 // only if it was successfully executed
1100 } catch (Exception e)
1102 System.err.println("Exception Whilst trying to execute file " + sfile
1103 + " as a groovy script.");
1104 e.printStackTrace(System.err);
1109 public AlignFrame[] getAlignFrames()
1111 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1112 : Desktop.getAlignFrames();
1117 * Quit method delegates to Desktop.quit - unless running in headless mode
1118 * when it just ends the JVM
1122 if (desktop != null)