MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / sendArguments

Method sendArguments

ij/src/main/java/ij/OtherInstance.java:120–181  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

118 }
119
120 @AstroImageJ(reason = "Replace method of cross-instance communication", modified = true)
121 public static boolean sendArguments(String[] args) {
122 if (!isRMIEnabled())
123 return false;
124
125 var stub = Path.of(getStubPath());
126
127 if (!Files.exists(stub)) {
128 startServer();
129 return false;
130 }
131
132 try (var client = new IPCClient(stub)) {
133 client.sendMessage("user.dir "+System.getProperty("user.dir"));
134 int macros = 0;
135 for (int i=0; i<args.length; i++) {
136 String arg = args[i];
137 if (arg==null) {
138 continue;
139 }
140
141 String cmd = null;
142 if (macros==0 && arg.endsWith(".ijm")) {
143 cmd = "macro " + arg;
144 macros++;
145 } else if (arg.startsWith("-macro") && i+1<args.length) {
146 String macroArg = i+2<args.length?DELIMETER+args[i+2]:"";
147 cmd = "macro " + args[i+1] + macroArg;
148 client.sendMessage(cmd);
149 break;
150 } else if (arg.startsWith("-eval") && i+1<args.length) {
151 cmd = "eval " + args[i+1];
152 args[i+1] = null;
153 } else if (arg.startsWith("-run") && i+1<args.length) {
154 cmd = "run " + args[i+1];
155 args[i+1] = null;
156 } else if (!arg.contains("ij.ImageJ") && !arg.startsWith("-")) {
157 cmd = "open " + arg;
158 }
159
160 if (cmd!=null) {
161 client.sendMessage(cmd);
162 }
163 }
164
165 return true;
166 } catch (IOException e) {
167 e.printStackTrace();
168 } catch (IllegalStateException e) {
169 // The file exists, but is left over from a bad shutdown
170 try {
171 if (Files.deleteIfExists(stub)) {
172 startServer();
173 return false;
174 }
175 } catch (IOException ex) {
176 ex.printStackTrace();
177 }

Callers 1

isRunningMethod · 0.95

Calls 8

isRMIEnabledMethod · 0.95
getStubPathMethod · 0.95
startServerMethod · 0.95
sendMessageMethod · 0.80
startsWithMethod · 0.80
existsMethod · 0.45
getPropertyMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected