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')
93 Instance.setJalview(this);
98 Platform.getURLCommandArguments();
101 private boolean headless;
103 public static boolean isHeadlessMode()
105 return Instance.getJalview().headless;
108 private Desktop desktop;
110 private AlignFrame currentAlignFrame;
112 public static AlignFrame getCurrentAlignFrame()
114 return Instance.getJalview().currentAlignFrame;
117 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
119 Instance.getJalview().currentAlignFrame = currentAlignFrame;
124 if (!Platform.isJS())
131 // grab all the rights we can for the JVM
132 Policy.setPolicy(new Policy()
135 public PermissionCollection getPermissions(CodeSource codesource)
137 Permissions perms = new Permissions();
138 perms.add(new AllPermission());
143 public void refresh()
151 * keep track of feature fetching tasks.
159 * TODO: generalise to track all jalview events to orchestrate batch
163 private int queued = 0;
165 private int running = 0;
167 public FeatureFetcher()
172 public void addFetcher(final AlignFrame af,
173 final Vector<String> dasSources)
175 final long id = System.currentTimeMillis();
177 final FeatureFetcher us = this;
178 new Thread(new Runnable()
190 af.setProgressBar(MessageManager
191 .getString("status.das_features_being_retrived"), id);
192 af.featureSettings_actionPerformed(null);
193 af.setProgressBar(null, id);
202 public synchronized boolean allFinished()
204 return queued == 0 && running == 0;
210 * main class for Jalview application
213 * open <em>filename</em>
215 public static void main(String[] args)
217 // setLogging(); // BH - for event debugging in JavaScript
218 new Jalview().doMain(args);
221 private static void logClass(String name)
223 // BH - for event debugging in JavaScript
224 ConsoleHandler consoleHandler = new ConsoleHandler();
225 consoleHandler.setLevel(Level.ALL);
226 Logger logger = Logger.getLogger(name);
227 logger.setLevel(Level.ALL);
228 logger.addHandler(consoleHandler);
231 @SuppressWarnings("unused")
232 private static void setLogging()
240 System.out.println("not in js");
243 // BH - for event debugging in JavaScript (Java mode only)
244 if (!Platform.isJS())
251 Logger.getLogger("").setLevel(Level.ALL);
252 logClass("java.awt.EventDispatchThread");
253 logClass("java.awt.EventQueue");
254 logClass("java.awt.Component");
255 logClass("java.awt.focus.Component");
256 logClass("java.awt.focus.DefaultKeyboardFocusManager");
264 void doMain(String[] args)
267 if (!Platform.isJS())
269 System.setSecurityManager(null);
273 .println("Java version: " + System.getProperty("java.version"));
274 System.out.println(System.getProperty("os.arch") + " "
275 + System.getProperty("os.name") + " "
276 + System.getProperty("os.version"));
278 ArgsParser aparser = new ArgsParser(args);
280 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
281 Cache.loadProperties(usrPropsFile);
282 if (usrPropsFile != null)
285 "CMD [-props " + usrPropsFile + "] executed successfully!");
288 if (!Platform.isJS())
295 if (aparser.contains("help") || aparser.contains("h"))
300 if (aparser.contains(ArgsParser.NODISPLAY)
301 || aparser.contains(ArgsParser.NOGUI)
302 || aparser.contains(ArgsParser.HEADLESS)
303 || "true".equals(System.getProperty("java.awt.headless")))
310 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
311 if (jabawsUrl != null)
315 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
317 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
318 } catch (MalformedURLException e)
321 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
326 // check for property setting
327 String defs = aparser.getValue(ArgsParser.SETPROP);
330 int p = defs.indexOf('=');
333 System.err.println("Ignoring invalid setprop argument : " + defs);
337 System.out.println("Executing setprop argument: " + defs);
340 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
343 defs = aparser.getValue(ArgsParser.SETPROP);
345 System.setProperty("http.agent",
346 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
350 } catch (NoClassDefFoundError error)
352 error.printStackTrace();
353 System.out.println("\nEssential logging libraries not found."
354 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
362 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
363 } catch (Exception ex)
365 System.err.println("Unexpected Look and Feel Exception");
366 ex.printStackTrace();
368 if (Platform.isAMacAndNotJS())
371 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
373 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
375 System.setProperty("apple.laf.useScreenMenuBar", "true");
376 if (lookAndFeel != null)
380 UIManager.setLookAndFeel(lookAndFeel);
381 } catch (Throwable e)
384 "Failed to set QuaQua look and feel: " + e.toString());
387 if (lookAndFeel == null
388 || !(lookAndFeel.getClass().isAssignableFrom(
389 UIManager.getLookAndFeel().getClass()))
390 || !UIManager.getLookAndFeel().getClass().toString()
391 .toLowerCase().contains("quaqua"))
396 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
397 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
398 } catch (Throwable e)
401 "Failed to reset look and feel: " + e.toString());
407 * configure 'full' SO model if preferences say to,
408 * else use the default (SO Lite)
410 if (Cache.getDefault("USE_FULL_SO", false))
412 SequenceOntologyFactory.setInstance(new SequenceOntology());
417 desktop = new Desktop();
418 desktop.setInBatchMode(true); // indicate we are starting up
419 desktop.setVisible(true);
421 if (!Platform.isJS())
428 desktop.startServiceDiscovery();
429 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
431 startUsageStats(desktop);
435 System.err.println("CMD [-nousagestats] executed successfully!");
438 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
440 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
443 // Start the desktop questionnaire prompter with the specified
445 Cache.log.debug("Starting questionnaire url at " + url);
446 desktop.checkForQuestionnaire(url);
447 System.out.println("CMD questionnaire[-" + url
448 + "] executed successfully!");
452 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
454 // Start the desktop questionnaire prompter with the specified
457 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
459 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
461 "Starting questionnaire with default url: " + defurl);
462 desktop.checkForQuestionnaire(defurl);
469 .println("CMD [-noquestionnaire] executed successfully!");
472 if (!aparser.contains(ArgsParser.NONEWS))
474 desktop.checkForNews();
477 BioJsHTMLOutput.updateBioJS();
482 FileFormatI format = null;
483 DataSourceType protocol = null;
484 FileLoader fileLoader = new FileLoader(!headless);
486 // script to execute after all loading is
487 // completed one way or another
488 // extract groovy argument and execute if necessary
489 String groovyscript = aparser.getValue(ArgsParser.GROOVY, true);
490 String file = aparser.getValue(ArgsParser.OPEN, true);
492 if (file == null && desktop == null)
494 System.out.println("No files to open!");
497 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
498 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
499 if (vamsasImport != null || vamsasSession != null)
501 if (desktop == null || headless)
504 "Headless vamsas sessions not yet supported. Sorry.");
507 // if we have a file, start a new session and import it.
508 boolean inSession = false;
509 if (vamsasImport != null)
513 DataSourceType viprotocol = AppletFormatAdapter
514 .checkProtocol(vamsasImport);
515 if (viprotocol == DataSourceType.FILE)
517 inSession = desktop.vamsasImport(new File(vamsasImport));
519 else if (viprotocol == DataSourceType.URL)
521 inSession = desktop.vamsasImport(new URL(vamsasImport));
524 } catch (Exception e)
526 System.err.println("Exeption when importing " + vamsasImport
527 + " as a vamsas document.");
532 System.err.println("Failed to import " + vamsasImport
533 + " as a vamsas document.");
537 System.out.println("Imported Successfully into new session "
538 + desktop.getVamsasApplication().getCurrentSession());
541 if (vamsasSession != null)
543 if (vamsasImport != null)
545 // close the newly imported session and import the Jalview specific
546 // remnants into the new session later on.
547 desktop.vamsasStop_actionPerformed(null);
549 // now join the new session
552 if (desktop.joinVamsasSession(vamsasSession))
555 "Successfully joined vamsas session " + vamsasSession);
559 System.err.println("WARNING: Failed to join vamsas session "
562 } catch (Exception e)
565 "ERROR: Failed to join vamsas session " + vamsasSession);
568 if (vamsasImport != null)
570 // the Jalview specific remnants can now be imported into the new
571 // session at the user's leisure.
573 "Skipping Push for import of data into existing vamsas session."); // TODO:
578 // desktop.getVamsasApplication().push_update();
583 // Finally, deal with the remaining input data.
588 desktop.setProgressBar(
590 .getString("status.processing_commandline_args"),
591 progress = System.currentTimeMillis());
593 System.out.println("CMD [-open " + file + "] executed successfully!");
595 if (!Platform.isJS())
597 * ignore in JavaScript -- can't just check file existence - could load
603 if (!file.startsWith("http://") && !file.startsWith("https://"))
604 // BH 2019 added https check for Java
606 if (!(new File(file)).exists())
608 System.out.println("Can't find " + file);
617 protocol = AppletFormatAdapter.checkProtocol(file);
621 format = new IdentifyFile().identify(file, protocol);
622 } catch (FileFormatException e1)
627 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
631 System.out.println("error");
635 setCurrentAlignFrame(af);
636 data = aparser.getValue(ArgsParser.COLOUR, true);
639 data.replaceAll("%20", " ");
641 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
642 af.getViewport(), af.getViewport().getAlignment(), data);
647 "CMD [-color " + data + "] executed successfully!");
652 // Must maintain ability to use the groups flag
653 data = aparser.getValue(ArgsParser.GROUPS, true);
656 af.parseFeaturesFile(data,
657 AppletFormatAdapter.checkProtocol(data));
658 // System.out.println("Added " + data);
660 "CMD groups[-" + data + "] executed successfully!");
662 data = aparser.getValue(ArgsParser.FEATURES, true);
665 af.parseFeaturesFile(data,
666 AppletFormatAdapter.checkProtocol(data));
667 // System.out.println("Added " + data);
669 "CMD [-features " + data + "] executed successfully!");
672 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
675 af.loadJalviewDataFile(data, null, null, null);
676 // System.out.println("Added " + data);
678 "CMD [-annotations " + data + "] executed successfully!");
680 // set or clear the sortbytree flag.
681 if (aparser.contains(ArgsParser.SORTBYTREE))
683 af.getViewport().setSortByTree(true);
684 if (af.getViewport().getSortByTree())
686 System.out.println("CMD [-sortbytree] executed successfully!");
689 if (aparser.contains(ArgsParser.NOANNOTATION)
690 || aparser.contains(ArgsParser.NOANNOTATION2))
692 af.getViewport().setShowAnnotation(false);
693 if (!af.getViewport().isShowAnnotation())
695 System.out.println("CMD no-annotation executed successfully!");
698 if (aparser.contains(ArgsParser.NOSORTBYTREE))
700 af.getViewport().setSortByTree(false);
701 if (!af.getViewport().getSortByTree())
704 .println("CMD [-nosortbytree] executed successfully!");
707 data = aparser.getValue(ArgsParser.TREE, true);
713 "CMD [-tree " + data + "] executed successfully!");
714 NewickFile nf = new NewickFile(data,
715 AppletFormatAdapter.checkProtocol(data));
717 .setCurrentTree(af.showNewickTree(nf, data).getTree());
718 } catch (IOException ex)
720 System.err.println("Couldn't add tree " + data);
721 ex.printStackTrace(System.err);
724 // TODO - load PDB structure(s) to alignment JAL-629
725 // (associate with identical sequence in alignment, or a specified
727 if (groovyscript != null)
729 // Execute the groovy script after we've done all the rendering stuff
730 // and before any images or figures are generated.
731 System.out.println("Executing script " + groovyscript);
732 executeGroovyScript(groovyscript, af);
733 System.out.println("CMD groovy[" + groovyscript
734 + "] executed successfully!");
737 String imageName = "unnamed.png";
738 while (aparser.getSize() > 1)
744 String outputFormat = aparser.nextValue();
745 file = aparser.nextValue();
747 if (outputFormat.equalsIgnoreCase("png"))
749 af.createPNG(new File(file));
750 imageName = (new File(file)).getName();
751 System.out.println("Creating PNG image: " + file);
754 else if (outputFormat.equalsIgnoreCase("svg"))
756 File imageFile = new File(file);
757 imageName = imageFile.getName();
758 af.createSVG(imageFile);
759 System.out.println("Creating SVG image: " + file);
762 else if (outputFormat.equalsIgnoreCase("html"))
764 File imageFile = new File(file);
765 imageName = imageFile.getName();
766 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
767 htmlSVG.exportHTML(file);
769 System.out.println("Creating HTML image: " + file);
772 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
776 System.err.println("The output html file must not be null");
781 BioJsHTMLOutput.refreshVersionInfo(
782 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
783 } catch (URISyntaxException e)
787 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
788 bjs.exportHTML(file);
790 .println("Creating BioJS MSA Viwer HTML file: " + file);
793 else if (outputFormat.equalsIgnoreCase("imgMap"))
795 af.createImageMap(new File(file), imageName);
796 System.out.println("Creating image map: " + file);
799 else if (outputFormat.equalsIgnoreCase("eps"))
801 File outputFile = new File(file);
803 "Creating EPS file: " + outputFile.getAbsolutePath());
804 af.createEPS(outputFile);
808 af.saveAlignment(file, format);
809 if (af.isSaveAlignmentSuccessful())
811 System.out.println("Written alignment in " + format
812 + " format to " + file);
816 System.out.println("Error writing file " + file + " in "
817 + format + " format!!");
822 while (aparser.getSize() > 0)
824 System.out.println("Unknown arg: " + aparser.nextValue());
828 AlignFrame startUpAlframe = null;
829 // We'll only open the default file if the desktop is visible.
831 // ////////////////////
833 if (!Platform.isJS() && !headless && file == null
834 && vamsasImport == null
835 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
842 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
843 jalview.bin.Cache.getDefault("www.jalview.org",
844 "http://www.jalview.org")
845 + "/examples/exampleFile_2_7.jar");
847 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
849 // hardwire upgrade of the startup file
850 file.replace("_2_3.jar", "_2_7.jar");
851 // and remove the stale setting
852 jalview.bin.Cache.removeProperty("STARTUP_FILE");
855 protocol = DataSourceType.FILE;
857 if (file.indexOf("http:") > -1)
859 protocol = DataSourceType.URL;
862 if (file.endsWith(".jar"))
864 format = FileFormat.Jalview;
870 format = new IdentifyFile().identify(file, protocol);
871 } catch (FileFormatException e)
877 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
879 // extract groovy arguments before anything else.
882 // Once all other stuff is done, execute any groovy scripts (in order)
883 if (groovyscript != null)
885 if (Cache.groovyJarsPresent())
887 System.out.println("Executing script " + groovyscript);
888 executeGroovyScript(groovyscript, startUpAlframe);
893 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
897 // and finally, turn off batch mode indicator - if the desktop still exists
902 desktop.setProgressBar(null, progress);
904 desktop.setInBatchMode(false);
908 private static void showUsage()
911 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
912 + "-nodisplay\tRun Jalview without User Interface.\n"
913 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
914 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
915 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
916 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
917 + "-features FILE\tUse the given file to mark features on the alignment.\n"
918 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
919 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
920 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
921 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
922 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
923 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
924 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
925 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
926 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
927 + "-png FILE\tCreate PNG image FILE from alignment.\n"
928 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
929 + "-html FILE\tCreate HTML file from alignment.\n"
930 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
931 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
932 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
933 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
934 + "-noquestionnaire\tTurn off questionnaire check.\n"
935 + "-nonews\tTurn off check for Jalview news.\n"
936 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
937 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
939 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
940 // after all other properties files have been read\n\t
941 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
942 // passed in correctly)"
943 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
944 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
946 // "-vdoc vamsas-document\tImport vamsas document into new
947 // session or join existing session with same URN\n"
948 // + "-vses vamsas-session\tJoin session with given URN\n"
949 + "-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"
950 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
953 private static void startUsageStats(final Desktop desktop)
956 * start a User Config prompt asking if we can log usage statistics.
958 PromptUserConfig prompter = new PromptUserConfig(
959 Desktop.getDesktopPane(), "USAGESTATS",
960 "Jalview Usage Statistics",
961 "Do you want to help make Jalview better by enabling "
962 + "the collection of usage statistics with Google Analytics ?"
963 + "\n\n(you can enable or disable usage tracking in the preferences)",
970 "Initialising googletracker for usage stats.");
971 Cache.initGoogleTracker();
972 Cache.log.debug("Tracking enabled.");
979 Cache.log.debug("Not enabling Google Tracking.");
982 desktop.addDialogThread(prompter);
986 * Locate the given string as a file and pass it to the groovy interpreter.
988 * @param groovyscript
989 * the script to execute
990 * @param jalviewContext
991 * the Jalview Desktop object passed in to the groovy binding as the
994 private void executeGroovyScript(String groovyscript, AlignFrame af)
997 * for scripts contained in files
1004 if (groovyscript.trim().equals("STDIN"))
1006 // read from stdin into a tempfile and execute it
1009 tfile = File.createTempFile("jalview", "groovy");
1010 PrintWriter outfile = new PrintWriter(
1011 new OutputStreamWriter(new FileOutputStream(tfile)));
1012 BufferedReader br = new BufferedReader(
1013 new InputStreamReader(System.in));
1015 while ((line = br.readLine()) != null)
1017 outfile.write(line + "\n");
1023 } catch (Exception ex)
1025 System.err.println("Failed to read from STDIN into tempfile "
1026 + ((tfile == null) ? "(tempfile wasn't created)"
1027 : tfile.toString()));
1028 ex.printStackTrace();
1033 sfile = tfile.toURI().toURL();
1034 } catch (Exception x)
1037 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1039 x.printStackTrace();
1047 sfile = new URI(groovyscript).toURL();
1048 } catch (Exception x)
1050 tfile = new File(groovyscript);
1051 if (!tfile.exists())
1053 System.err.println("File '" + groovyscript + "' does not exist.");
1056 if (!tfile.canRead())
1058 System.err.println("File '" + groovyscript + "' cannot be read.");
1061 if (tfile.length() < 1)
1063 System.err.println("File '" + groovyscript + "' is empty.");
1068 sfile = tfile.getAbsoluteFile().toURI().toURL();
1069 } catch (Exception ex)
1071 System.err.println("Failed to create a file URL for "
1072 + tfile.getAbsoluteFile());
1079 Map<String, Object> vbinding = new HashMap<>();
1080 vbinding.put("Jalview", this);
1083 vbinding.put("currentAlFrame", af);
1085 Binding gbinding = new Binding(vbinding);
1086 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1087 gse.run(sfile.toString(), gbinding);
1088 if ("STDIN".equals(groovyscript))
1090 // delete temp file that we made -
1091 // only if it was successfully executed
1094 } catch (Exception e)
1096 System.err.println("Exception Whilst trying to execute file " + sfile
1097 + " as a groovy script.");
1098 e.printStackTrace(System.err);
1103 public AlignFrame[] getAlignFrames()
1105 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1106 : Desktop.getAlignFrames();
1111 * Quit method delegates to Desktop.quit - unless running in headless mode
1112 * when it just ends the JVM
1116 if (desktop != null)
1126 // BH 2019.05.10 moved here from StructureSelectionManager because this is a
1127 // singleton; allows it to be cleaned up when the application is closed.