Skip to content

Commit 439d55d

Browse files
author
Muhammad Hashim
committed
migrated to IntelliJ IDEA.
1 parent c6d8ae7 commit 439d55d

14 files changed

+367
-336
lines changed

.idea/artifacts/System_Command_Executor_jar.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

System-Command-Executor.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

src/mhashim6/commander/Sample.java

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,34 @@
1414
*/
1515
public class Sample {
1616

17-
public static void main(String[] args) {
18-
19-
Command cmd = new CommandBuilder("ping").withArgs("google.com").build();
20-
ExecutionOutputPrinter eop = new ExecutionOutputPrinter(new Appender() {
21-
22-
@Override
23-
public void appendStdText(String text) {
24-
System.out.println(text);
25-
//or your code to show std output lines.
26-
}
27-
28-
@Override
29-
public void appendErrText(String text) {
30-
System.err.println(text);
31-
//or your code to show error lines.
32-
}
33-
});
34-
35-
try {
36-
ProcessMonitor pMonitor = CommandExecutor.execute(cmd, null, eop); //execute the command, redirect the output to eop.
37-
ExecutionReport report = pMonitor.getExecutionReport(); //blocks until the process finishes or gets aborted.
38-
39-
String commandLine = cmd.string();
40-
int exitCode = report.exitValue();
41-
42-
System.out.printf("command line: %s\nexecution finished with exit code: %d\n\n", commandLine, exitCode);
43-
}
44-
catch (UnrecognisedCmdException e) {
45-
System.err.println(e);
46-
}
47-
}
17+
public static void main(String[] args) {
18+
19+
Command cmd = new CommandBuilder("ping").withArgs("google.com").build();
20+
ExecutionOutputPrinter eop = new ExecutionOutputPrinter(new Appender() {
21+
22+
@Override
23+
public void appendStdText(String text) {
24+
System.out.println(text);
25+
//or your code to show std output lines.
26+
}
27+
28+
@Override
29+
public void appendErrText(String text) {
30+
System.err.println(text);
31+
//or your code to show error lines.
32+
}
33+
});
34+
35+
try {
36+
ProcessMonitor pMonitor = CommandExecutor.execute(cmd, null, eop); //execute the command, redirect the output to eop.
37+
ExecutionReport report = pMonitor.getExecutionReport(); //blocks until the process finishes or gets aborted.
38+
39+
String commandLine = cmd.string();
40+
int exitCode = report.exitValue();
41+
42+
System.out.printf("command line: %s\nexecution finished with exit code: %d\n\n", commandLine, exitCode);
43+
} catch (UnrecognisedCmdException e) {
44+
System.err.println(e);
45+
}
46+
}
4847
}

src/mhashim6/commander/exceptions/UnrecognisedCmdException.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44

55
@SuppressWarnings("serial")
66
public class UnrecognisedCmdException extends IOException {
7-
private String cmd;
7+
private String cmd;
88

9-
/**
10-
* the public constructors that requires the command that caused the error.
11-
*
12-
* @param cmd
13-
*/
14-
public UnrecognisedCmdException(String cmd) {
15-
this.cmd = cmd;
16-
}
9+
/**
10+
* the public constructors that requires the command that caused the error.
11+
*
12+
* @param cmd
13+
*/
14+
public UnrecognisedCmdException(String cmd) {
15+
this.cmd = cmd;
16+
}
1717

18-
@Override
19-
public String toString() {
20-
return "could not recognise " + cmd;
18+
@Override
19+
public String toString() {
20+
return "could not recognise " + cmd;
2121

22-
}
22+
}
2323

2424
}

src/mhashim6/commander/main/Appender.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
/**
44
* @author mhashim6 (Muhammad Hashim)
5-
*
65
*/
76
public interface Appender {
87

9-
void appendStdText(String text);
8+
void appendStdText(String text);
109

11-
void appendErrText(String text);
10+
void appendErrText(String text);
1211
}
1312
// ============================================================

src/mhashim6/commander/main/Command.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
public interface Command {
77

8-
String[] executable();
8+
String[] executable();
99

10-
String string();
10+
String string();
1111

1212
}

0 commit comments

Comments
 (0)