Skip to content

Commit 8ada434

Browse files
author
Michael P Schroeder
committed
command line response improvements
1 parent 833b2e8 commit 8ada434

File tree

12 files changed

+88
-47
lines changed

12 files changed

+88
-47
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Gitools 2.2.0
1818
* Layer groups (new)
1919
* Recent files (new)
2020
* .mtabix data file compression (new)
21+
* Parellization: use multiple cores for many tasks
2122
* Many performance improvements
2223
* UI improvements
2324

org.gitools.ui.app/src/main/java/org/gitools/ui/app/Main.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ public class Main {
6666

6767
public static void main(final String[] args) {
6868

69+
// Start CommandListener
70+
boolean portEnabled = Settings.get().isPortEnabled();
71+
String portString = null;
72+
if (portEnabled || portString != null) {
73+
int port = Settings.get().getDefaultPort();
74+
if (portString != null) {
75+
port = Integer.parseInt(portString);
76+
}
77+
CommandListener.start(port, args);
78+
}
6979

7080
// Initialize look and feel
7181
WebLookAndFeel.install();
@@ -132,18 +142,6 @@ public void windowClosed(final WindowEvent e) {
132142
ex.printStackTrace();
133143
}
134144

135-
// Start CommandListener
136-
setProgressText(progress, "Starting command listener");
137-
boolean portEnabled = Settings.get().isPortEnabled();
138-
String portString = null;
139-
if (portEnabled || portString != null) {
140-
int port = Settings.get().getDefaultPort();
141-
if (portString != null) {
142-
port = Integer.parseInt(portString);
143-
}
144-
CommandListener.start(port, args);
145-
}
146-
147145
// Initialize actions
148146
setProgressText(progress, "Loading Gitools actions");
149147
Actions.init();

org.gitools.ui.app/src/main/java/org/gitools/ui/app/batch/CommandExecutor.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
public class CommandExecutor {
3131

32+
boolean noErrors;
33+
3234
public boolean checkArguments(String[] args, PrintWriter out) {
3335

3436
if (args.length == 0) {
@@ -83,7 +85,13 @@ public void execute(String[] args, PrintWriter out) {
8385
}
8486

8587

86-
while (argsList.contains(";")) {
88+
// run all comands
89+
noErrors = true;
90+
while (argsList.contains(";") && noErrors) {
91+
92+
if (!noErrors) {
93+
break;
94+
}
8795

8896
int sepIndex = argsList.indexOf(";");
8997
List<String> sublist = argsList.subList(0, sepIndex);
@@ -132,8 +140,10 @@ private void execute(List<String> args, PrintWriter out) {
132140
out.println("OK");
133141
out.flush();
134142
} else {
143+
out.println(tool.getExitMessage());
135144
out.println("NOT OK");
136145
out.flush();
146+
noErrors = false;
137147
}
138148
}
139149

org.gitools.ui.app/src/main/java/org/gitools/ui/app/batch/CommandListener.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public static synchronized void start(int port, String[] args) {
6060
// Pass the arguments to the other gitools instance
6161
Socket socket = null;
6262
try {
63+
System.out.println("Sending commands to running Gitools application");
64+
6365
socket = new Socket("localhost", port);
6466
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
6567
InputStream in = socket.getInputStream();
@@ -77,8 +79,13 @@ public static synchronized void start(int port, String[] args) {
7779
} catch (Exception ee) {
7880
}
7981
}
82+
83+
// Print command output
8084
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
81-
reader.readLine();
85+
String responseLine;
86+
while (socket.isConnected() && ((responseLine = reader.readLine()) != null)) {
87+
System.out.println(responseLine);
88+
}
8289

8390
} catch (IOException e) {
8491
e.printStackTrace();
@@ -97,6 +104,7 @@ public static synchronized void start(int port, String[] args) {
97104
}
98105
}
99106

107+
System.out.println("Starting command listener on port " + port);
100108
listener = new CommandListener(port);
101109
listener.listenerThread.start();
102110
}
@@ -216,6 +224,8 @@ private void processClientSession(CommandExecutor cmdExe) throws IOException {
216224
} else {
217225
// Port command
218226
cmdExe.execute(inputLine.split(" "), out);
227+
return;
228+
219229
}
220230
}
221231
} catch (IOException e) {

org.gitools.ui.app/src/main/java/org/gitools/ui/app/batch/tools/HelpTool.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ public boolean run(String[] args, PrintWriter out) {
6767
return true;
6868
}
6969

70+
@Override
71+
public String getExitMessage() {
72+
return null;
73+
}
74+
75+
@Override
76+
public int getExitStatus() {
77+
return 0;
78+
}
79+
7080
public static String getVersion() {
7181
return "Gitools " + Main.class.getPackage().getImplementationVersion();
7282
}

org.gitools.ui.app/src/main/java/org/gitools/ui/app/batch/tools/VersionTool.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ public boolean run(String[] args, PrintWriter out) {
4444
return true;
4545
}
4646

47+
@Override
48+
public String getExitMessage() {
49+
return null;
50+
}
51+
52+
@Override
53+
public int getExitStatus() {
54+
return 0;
55+
}
56+
4757
public static String getVersion() {
4858
return "Gitools " + Main.class.getPackage().getImplementationVersion();
4959
}

org.gitools.ui.core/src/main/java/org/gitools/ui/core/commands/AbstractCommand.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ public abstract class AbstractCommand implements Command, JobRunnable, Runnable
3232
public abstract void execute(IProgressMonitor monitor) throws CommandException;
3333

3434
private int exitStatus = -1;
35+
private String exitMessage;
3536

3637
@Override
3738
public void run(IProgressMonitor monitor) {
3839
try {
3940
execute(monitor);
4041
} catch (CommandException e) {
42+
setExitMessage(e.getMessage());
4143
monitor.exception(e);
4244
}
4345
}
@@ -55,4 +57,12 @@ public int getExitStatus() {
5557
protected void setExitStatus(int exitStatus) {
5658
this.exitStatus = exitStatus;
5759
}
60+
61+
public String getExitMessage() {
62+
return exitMessage;
63+
}
64+
65+
public void setExitMessage(String exitMessage) {
66+
this.exitMessage = exitMessage;
67+
}
5868
}

org.gitools.ui.core/src/main/java/org/gitools/ui/core/commands/Command.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ public CommandException(String msg, Throwable cause) {
4444
void execute(IProgressMonitor monitor) throws CommandException;
4545

4646
int getExitStatus();
47+
48+
String getExitMessage();
4749
}

org.gitools.ui.core/src/main/java/org/gitools/ui/core/commands/HeaderCommand.java

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
import org.gitools.api.matrix.SortDirection;
2727
import org.gitools.heatmap.HeatmapDimension;
2828
import org.gitools.heatmap.MatrixViewSorter;
29-
import org.gitools.ui.core.Application;
30-
import org.gitools.ui.platform.dialog.MessageUtils;
31-
32-
import java.util.concurrent.CancellationException;
3329

3430
public abstract class HeaderCommand extends HeatmapCommand {
3531

@@ -59,33 +55,9 @@ public HeaderCommand(String heatmap, MatrixDimensionKey dimension, String sort,
5955
public void execute(IProgressMonitor monitor) throws CommandException {
6056

6157

62-
try {
63-
super.execute(monitor);
64-
65-
if (dimension != null) {
66-
67-
heatmapDimension = heatmap.getDimension(dimension);
68-
} else {
69-
throw new Exception("No valid dimension of heatmap. Choose rows or columns: " + dimension);
70-
71-
}
72-
73-
} catch (Exception e) {
74-
75-
if (!(e.getCause() instanceof CancellationException)) {
76-
String text = "<html>Command error:<br>" +
77-
"<div style='margin: 5px 0px; padding:10px; width:300px; border: 1px solid black;'><strong>" +
78-
e.getLocalizedMessage() +
79-
"</strong></div>" +
80-
"You may find the <strong>'User guide'</strong> at <a href='http://www.gitools.org'>" +
81-
"www.gitools.org</a><br></html>";
82-
MessageUtils.showErrorMessage(Application.get(), text, e);
83-
}
84-
setExitStatus(1);
85-
return;
86-
}
58+
super.execute(monitor);
59+
heatmapDimension = heatmap.getDimension(dimension);
8760

88-
setExitStatus(0);
8961
return;
9062
}
9163

org.gitools.ui.core/src/main/java/org/gitools/ui/core/commands/HeatmapCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected void findHeatmap(IProgressMonitor monitor) throws CommandException {
5252
heatmap = (Heatmap) editor.getModel();
5353
return;
5454
} else {
55-
throw new CommandException("No heatmap selected or open. Indicate name or open and select a heatmap");
55+
throw new CommandException("No heatmap selected or open. Indicate name or open a heatmap (load command)");
5656
}
5757
}
5858

0 commit comments

Comments
 (0)