Skip to content

Commit

Permalink
Migrate debug plugin to showOutput/showError.
Browse files Browse the repository at this point in the history
  • Loading branch information
csmith committed Feb 16, 2016
1 parent 64262ee commit c94ac4c
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 48 deletions.
24 changes: 17 additions & 7 deletions debug/src/com/dmdirc/addons/debug/Debug.java
Expand Up @@ -102,17 +102,27 @@ public void execute(@Nonnull final WindowModel origin,
}

/**
* Sends a line, if appropriate, to the specified target.
* Shows output, if appropriate, in the specified target.
*
* @param target The command window to send the line to
* @param isSilent Whether this command is being silenced or not
* @param type The type of message to send
* @param args The arguments of the message
* @param message The message to be sent
*/
@Deprecated
public void proxySendLine(final WindowModel target,
final boolean isSilent, final String type, final Object... args) {
sendLine(target, isSilent, type, args);
public void proxyShowOutput(final WindowModel target,
final boolean isSilent, final String message) {
showOutput(target, isSilent, message);
}

/**
* Shows an error, if appropriate, in the specified target.
*
* @param target The command window to send the line to
* @param isSilent Whether this command is being silenced or not
* @param message The message to be sent
*/
public void proxyShowError(final WindowModel target,
final boolean isSilent, final String message) {
showError(target, isSilent, message);
}

/**
Expand Down
21 changes: 15 additions & 6 deletions debug/src/com/dmdirc/addons/debug/DebugCommand.java
Expand Up @@ -86,16 +86,25 @@ public abstract void execute(@Nonnull final WindowModel origin,
final CommandArguments args, final CommandContext context);

/**
* Sends a line, if appropriate, to the specified target.
* Shows output, if appropriate, in the specified target.
*
* @param target The command window to send the line to
* @param isSilent Whether this command is being silenced or not
* @param type The type of message to send
* @param args The arguments of the message
* @param message The message to be sent
*/
public void sendLine(final WindowModel target,
final boolean isSilent, final String type, final Object... args) {
commandProvider.get().proxySendLine(target, isSilent, type, args);
public void showOutput(final WindowModel target, final boolean isSilent, final String message) {
commandProvider.get().proxyShowOutput(target, isSilent, message);
}

/**
* Shows an error, if appropriate, in the specified target.
*
* @param target The command window to send the line to
* @param isSilent Whether this command is being silenced or not
* @param message The message to be sent
*/
public void showError(final WindowModel target, final boolean isSilent, final String message) {
commandProvider.get().proxyShowError(target, isSilent, message);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion debug/src/com/dmdirc/addons/debug/commands/ColourSpam.java
Expand Up @@ -61,7 +61,7 @@ public String getUsage() {
public void execute(@Nonnull final WindowModel origin,
final CommandArguments args, final CommandContext context) {
for (int i = 0; i < 100; i++) {
sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
showOutput(origin, args.isSilent(),
((char) 3) + "5Colour! "
+ ((char) 3) + "6Colour! " + ((char) 3) + "7Colour! "
+ ((char) 3) + "6Colour! " + ((char) 3) + "7Colour! "
Expand Down
2 changes: 1 addition & 1 deletion debug/src/com/dmdirc/addons/debug/commands/ConfigInfo.java
Expand Up @@ -62,7 +62,7 @@ public String getUsage() {
public void execute(@Nonnull final WindowModel origin,
final CommandArguments args, final CommandContext context) {
for (ConfigProvider source : origin.getConfigManager().getSources()) {
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, source.getTarget()
showOutput(origin, args.isSilent(), source.getTarget()
+ " - " + source + "(" + source.getTarget().getOrder()
+ ")");
}
Expand Down
4 changes: 2 additions & 2 deletions debug/src/com/dmdirc/addons/debug/commands/ForceUpdate.java
Expand Up @@ -93,9 +93,9 @@ public void execute(@Nonnull final WindowModel origin,
if (globalConfig.getOptionBool("updater", "enable")) {
UpdateChecker.checkNow(updateManager, identityController, "Forced update checker");
} else {
sendLine(origin, args.isSilent(), FORMAT_ERROR, "Update checking is "
showError(origin, args.isSilent(), "Update checking is "
+ "currently disabled. You can enable it by typing:");
sendLine(origin, args.isSilent(), FORMAT_ERROR, Styliser.CODE_FIXED
showError(origin, args.isSilent(), Styliser.CODE_FIXED
+ " /set updater enable true");
}
}
Expand Down
Expand Up @@ -72,7 +72,7 @@ public String getUsage() {
public void execute(@Nonnull final WindowModel origin,
final CommandArguments args, final CommandContext context) {
for (ConfigProvider source : globalConfig.getSources()) {
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, source.getTarget()
showOutput(origin, args.isSilent(), source.getTarget()
+ " - " + source + "(" + source.getTarget().getOrder()
+ ")");
}
Expand Down
2 changes: 1 addition & 1 deletion debug/src/com/dmdirc/addons/debug/commands/Identities.java
Expand Up @@ -88,7 +88,7 @@ public void execute(@Nonnull final WindowModel origin,
String.valueOf(source.getTarget().getOrder())};
}

sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
showOutput(origin, args.isSilent(),
doTable(new String[]{"Name", "Target", "Data", "Priority"}, data));
}

Expand Down
6 changes: 3 additions & 3 deletions debug/src/com/dmdirc/addons/debug/commands/MemInfo.java
Expand Up @@ -60,11 +60,11 @@ public String getUsage() {
@Override
public void execute(@Nonnull final WindowModel origin,
final CommandArguments args, final CommandContext context) {
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Total Memory: "
showOutput(origin, args.isSilent(), "Total Memory: "
+ Runtime.getRuntime().totalMemory());
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Free Memory: "
showOutput(origin, args.isSilent(), "Free Memory: "
+ Runtime.getRuntime().freeMemory());
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Used Memory: "
showOutput(origin, args.isSilent(), "Used Memory: "
+ (Runtime.getRuntime().totalMemory()
- Runtime.getRuntime().freeMemory()));
}
Expand Down
4 changes: 2 additions & 2 deletions debug/src/com/dmdirc/addons/debug/commands/Notify.java
Expand Up @@ -65,10 +65,10 @@ public void execute(@Nonnull final WindowModel origin,
final CommandArguments args, final CommandContext context) {
final Optional<Colour> colour = origin.getUnreadStatusManager().getNotificationColour();
if (colour.isPresent()) {
sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
showOutput(origin, args.isSilent(),
"Current notification colour is: " + colour.get());
} else {
sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
showOutput(origin, args.isSilent(),
"No current notification colour");
}
}
Expand Down
3 changes: 1 addition & 2 deletions debug/src/com/dmdirc/addons/debug/commands/RunGC.java
Expand Up @@ -61,8 +61,7 @@ public String getUsage() {
public void execute(@Nonnull final WindowModel origin,
final CommandArguments args, final CommandContext context) {
System.gc();
sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
"Invoked garbage collector.");
showOutput(origin, args.isSilent(), "Invoked garbage collector.");
}

}
13 changes: 6 additions & 7 deletions debug/src/com/dmdirc/addons/debug/commands/ServerInfo.java
Expand Up @@ -66,23 +66,22 @@ public void execute(@Nonnull final WindowModel origin,
final Optional<Connection> optionalConnection = origin.getConnection();
if (optionalConnection.isPresent()) {
final Connection connection = optionalConnection.get();
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Server name: "
showOutput(origin, args.isSilent(), "Server name: "
+ connection.getAddress());
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Actual name: "
showOutput(origin, args.isSilent(), "Actual name: "
+ connection.getParser().get().getServerName());
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Network: "
showOutput(origin, args.isSilent(), "Network: "
+ connection.getNetwork());
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "IRCd: "
showOutput(origin, args.isSilent(), "IRCd: "
+ connection.getParser().get().getServerSoftware() + " - "
+ connection.getParser().get().getServerSoftwareType());
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Modes: "
showOutput(origin, args.isSilent(), "Modes: "
+ connection.getParser().get().getBooleanChannelModes() + ' '
+ connection.getParser().get().getListChannelModes() + ' '
+ connection.getParser().get().getParameterChannelModes() + ' '
+ connection.getParser().get().getDoubleParameterChannelModes());
} else {
sendLine(origin, args.isSilent(), FORMAT_ERROR,
"This window isn't connected to a server");
showError(origin, args.isSilent(), "This window isn't connected to a server");
}
}

Expand Down
5 changes: 2 additions & 3 deletions debug/src/com/dmdirc/addons/debug/commands/ServerState.java
Expand Up @@ -65,11 +65,10 @@ public void execute(@Nonnull final WindowModel origin,
final CommandArguments args, final CommandContext context) {
final Optional<Connection> optionalConnection = origin.getConnection();
if (optionalConnection.isPresent()) {
sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
showOutput(origin, args.isSilent(),
optionalConnection.get().getStatus().getTransitionHistory());
} else {
sendLine(origin, args.isSilent(), FORMAT_ERROR,
"This window isn't connected to a server");
showError(origin, args.isSilent(), "This window isn't connected to a server");
}
}

Expand Down
9 changes: 4 additions & 5 deletions debug/src/com/dmdirc/addons/debug/commands/Services.java
Expand Up @@ -72,14 +72,13 @@ public String getUsage() {
@Override
public void execute(@Nonnull final WindowModel origin,
final CommandArguments args, final CommandContext context) {
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Available Services:");
showOutput(origin, args.isSilent(), "Available Services:");
for (Service service : serviceManager.getAllServices()) {
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, " "
+ service.toString());
showOutput(origin, args.isSilent(), " " + service);
if (args.getArguments().length > 0
&& args.getArguments()[0].equals("full")) {
&& "full".equals(args.getArguments()[0])) {
for (ServiceProvider provider : service.getProviders()) {
sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
showOutput(origin, args.isSilent(),
" " + provider.getProviderName()
+ " [Active: " + provider.isActive() + "]");
}
Expand Down
3 changes: 1 addition & 2 deletions debug/src/com/dmdirc/addons/debug/commands/ShowRaw.java
Expand Up @@ -69,8 +69,7 @@ public void execute(@Nonnull final WindowModel origin,
if (connection.isPresent()) {
windowFactory.getRawWindow(connection.get());
} else {
sendLine(origin, args.isSilent(), FORMAT_ERROR,
"Cannot show raw window here.");
showError(origin, args.isSilent(), "Cannot show raw window here.");
}
}

Expand Down
6 changes: 2 additions & 4 deletions debug/src/com/dmdirc/addons/debug/commands/Threads.java
Expand Up @@ -65,12 +65,10 @@ public void execute(@Nonnull final WindowModel origin,
final CommandArguments args, final CommandContext context) {
for (Entry<Thread, StackTraceElement[]> thread
: Thread.getAllStackTraces().entrySet()) {
sendLine(origin, args.isSilent(), FORMAT_OUTPUT, Styliser.CODE_BOLD
+ thread.getKey().getName());
showOutput(origin, args.isSilent(), Styliser.CODE_BOLD + thread.getKey().getName());

for (StackTraceElement element : thread.getValue()) {
sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
Styliser.CODE_FIXED + " " + element.toString());
showOutput(origin, args.isSilent(), Styliser.CODE_FIXED + " " + element);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion debug/src/com/dmdirc/addons/debug/commands/Time.java
Expand Up @@ -83,7 +83,7 @@ private void doTime(final WindowModel origin,
final long start = System.currentTimeMillis();
origin.getCommandParser().parseCommand(origin, args.getArgumentsAsString(0));
final long end = System.currentTimeMillis();
sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
showOutput(origin, args.isSilent(),
"Command executed in " + (end - start) + " milliseconds.");
}
}
Expand Down

0 comments on commit c94ac4c

Please sign in to comment.