- Timestamp:
- 2023-04-18T21:36:23+12:00 (12 months ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r37420 r37677 2056 2056 } 2057 2057 } 2058 2059 // Tests if a commandline program is installed 2060 static public class ProgramInstalledTest implements SafeProcess.ExceptionHandler 2061 { 2062 private final String[] command; 2063 private boolean returnValue = false; 2064 2065 public ProgramInstalledTest(String commandOnlyNoArgs) { 2066 this.command = new String[]{ commandOnlyNoArgs, "--version" }; // --help also works for linux open commands 2067 } 2058 2068 2059 2069 public ProgramInstalledTest(String commandOnlyNoArgs, String basicTestParam) { 2070 this.command = new String[]{ commandOnlyNoArgs, basicTestParam }; 2071 } 2072 2073 public boolean found() 2074 { 2075 try { 2076 SafeProcess file_open_test_process = new SafeProcess(command); 2077 file_open_test_process.setExceptionHandler(this); 2078 int exitValue = file_open_test_process.runBasicProcess(); 2079 2080 // returns 0 if program installed and correct params passed in 2081 // like --version/--help. Mostly returns 1 if wrong params passed in/launched wrong 2082 // Both return values indicate the program is installed. 2083 // e.g java --help or --version are wrong, as -help and -version are expected by java command. 2084 // 127 is returned if program not installed 2085 this.returnValue = (exitValue == 0 || exitValue == 1); 2086 } 2087 catch (Exception exception) { 2088 this.returnValue = false; 2089 } 2090 2091 2092 // returnValue could have been set by an exception during SafeProcess.runBasicProcess() 2093 // (see gotException()) so the returnValue is only being returned here at end of function 2094 return this.returnValue; 2095 } 2096 2097 2098 public void gotException(Exception e) { 2099 this.returnValue = false; // default program not found, 2100 // or not working which works out the same for my purposes 2101 2102 if (!(e instanceof IOException)) { 2103 SafeProcess.log("Gatherer.ProgramInstalledTest: got exception" + e.getMessage(), e); 2104 } 2105 } 2106 2107 public String toString() { 2108 return command[0]; 2109 } 2110 } 2111 2060 2112 static public class WebswingAuthenticator 2061 2113 extends GAuthenticator -
main/trunk/gli/src/org/greenstone/gatherer/GathererProg.java
r37341 r37677 114 114 // creating and showing this application's GUI. 115 115 116 117 // Display all Java properties, 118 // https://stackoverflow.com/questions/228477/how-do-i-programmatically-determine-operating-system-in-java 119 //System.getProperties().list(System.out); 120 116 121 SwingUtilities.invokeLater(new Runnable() { 117 122 public void run() { -
main/trunk/gli/src/org/greenstone/gatherer/file/FileAssociationManager.java
r31646 r37677 30 30 import java.util.regex.*; 31 31 import javax.swing.table.*; 32 import org.greenstone.gatherer.Gatherer; 32 33 import org.greenstone.gatherer.Configuration; 33 34 import org.greenstone.gatherer.DebugStream; … … 74 75 XMLTools.setValue(entry, StaticStrings.MAC_OPEN_COMMAND); 75 76 } 76 //else { XMLTools.setValue(entry, StaticStrings.LINUX_OPEN_COMMAND); } // assume linux? 77 else { // On Linux, we need to discover which of a range of possible solutions 78 // works on this machine. If any works, we remember and use that choice 79 // for all file extensions for which no file association has been set yet. 80 81 // If we worked out the default linux file open command in a previous 82 // round of the FileAssociationManager loop, use it for the current file 83 // extension also 84 85 if(StaticStrings.LINUX_OPEN_COMMAND != null && 86 !StaticStrings.LINUX_OPEN_COMMAND.equals("")) { 87 88 XMLTools.setValue(entry, StaticStrings.LINUX_OPEN_COMMAND); 89 } else if(StaticStrings.LINUX_OPEN_COMMAND == null) { 90 // StaticStrings.LINUX_OPEN_COMMAND not set yet: if we never tried to 91 // work out the default linux file launch command yet, then we'll test 92 // whether any known linux open command is available on this linux. 93 94 // xdg-open comes pre-installed on Ubuntu linux, but not on all linux 95 // https://www.cyberciti.biz/faq/unix-linux-command-to-view-file/ 96 // Listing xdg-open 1st as it works on Ubuntu, reducing GLI load time 97 final String[] linux_open_cmds = {"xdg-open", "kde-open", "gnome-open"}; 98 99 for(String open_cmd : linux_open_cmds) { 100 Gatherer.ProgramInstalledTest installTest = new Gatherer.ProgramInstalledTest(open_cmd); 101 if(installTest.found()) { 102 System.err.println("*********** Linux file open command " + installTest + " was found to be installed."); 103 StaticStrings.LINUX_OPEN_COMMAND = open_cmd + " %1"; 104 XMLTools.setValue(entry, StaticStrings.LINUX_OPEN_COMMAND); 105 break; 106 } else { 107 System.err.println("*********** Linux file open command " + installTest + " was not installed."); 108 } 109 } 110 111 // either we have a default linux open command or not 112 // If we don't, set it to empty, so we don't work out 113 // linux value for each file extension (for each time 114 // FileAssociationManager is called) hereafter. 115 if(StaticStrings.LINUX_OPEN_COMMAND == null) { 116 StaticStrings.LINUX_OPEN_COMMAND = ""; 117 } 118 } 119 // else StaticStrings.LINUX_OPEN_COMMAND = ""; which means 120 // we could never work out a feasible file open command on this linux 121 } 77 122 } 78 123 command = null; -
main/trunk/gli/src/org/greenstone/gatherer/util/StaticStrings.java
r37188 r37677 193 193 static final public String LEVELS_STR = "levels"; 194 194 static final public String LIBRARY_URL_ARGUMENT = "-library_url"; 195 static final public String LINUX_OPEN_COMMAND = "xdg-open %1"; 195 static public String LINUX_OPEN_COMMAND; // can't be final, set conditionally in FileAssociationManager 196 // to one of xdg-open/kde-open/gnome-open whichever worked, or "" if none 196 197 static final public String LOCAL_LIBRARY_ARGUMENT = "-local_library"; 197 198 static final public String LOAD_ARGUMENT = "-load";
Note:
See TracChangeset
for help on using the changeset viewer.