Selaa lähdekoodia

Add debug plugin, replace core debug command.

Issue CLIENT-103

Change-Id: Ic046375a8bf417ac84a0a736f64661cbbcdaa08f
Depends-On: I0828dd46c1315a4ae475d23a6152dc8183e1ab09
Reviewed-on: http://gerrit.dmdirc.com/1699
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.5
Greg Holmes 13 vuotta sitten
vanhempi
commit
7326c4e17c

+ 167
- 0
src/com/dmdirc/addons/debug/Debug.java Näytä tiedosto

@@ -0,0 +1,167 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.CommandInfo;
28
+import com.dmdirc.commandparser.CommandType;
29
+import com.dmdirc.commandparser.commands.Command;
30
+import com.dmdirc.commandparser.commands.IntelligentCommand;
31
+import com.dmdirc.commandparser.commands.context.CommandContext;
32
+import com.dmdirc.ui.input.AdditionalTabTargets;
33
+
34
+import java.util.Arrays;
35
+
36
+/**
37
+ * Provides various handy ways to test or debug the client.
38
+ */
39
+public class Debug extends Command implements IntelligentCommand, CommandInfo {
40
+
41
+    /** Parent debug plugin. */
42
+    private final DebugPlugin plugin;
43
+
44
+    /**
45
+     * Creates a new debug command with the specified parent plugin.
46
+     *
47
+     * @param plugin Parent debug plugin
48
+     */
49
+    public Debug(final DebugPlugin plugin) {
50
+        super();
51
+
52
+        this.plugin = plugin;
53
+    }
54
+
55
+    /** {@inheritDoc} */
56
+    @Override
57
+    public void execute(final FrameContainer<?> origin,
58
+            final CommandArguments args, final CommandContext context) {
59
+        if (args.getArguments().length == 0) {
60
+            showUsage(origin, args.isSilent(), "debug",
61
+                    "<debug command> [options]");
62
+        } else {
63
+            final DebugCommand command = plugin.getCommand(
64
+                    args.getArguments()[0]);
65
+            if (command == null) {
66
+                sendLine(origin, args.isSilent(), FORMAT_ERROR,
67
+                        "Unknown debug action.");
68
+            } else {
69
+                final CommandArguments newArgs = new CommandArguments(
70
+                        Arrays.asList(("/" + command.getName() + " "
71
+                        + args.getArgumentsAsString(1)).split(" ")));
72
+                command.execute(origin, newArgs, context);
73
+            }
74
+        }
75
+    }
76
+
77
+    /**
78
+     * Sends a line, if appropriate, to the specified target.
79
+     *
80
+     * @param target The command window to send the line to
81
+     * @param isSilent Whether this command is being silenced or not
82
+     * @param type The type of message to send
83
+     * @param args The arguments of the message
84
+     */
85
+    public void proxySendLine(final FrameContainer<?> target,
86
+            final boolean isSilent, final String type, final Object ... args) {
87
+        sendLine(target, isSilent, type, args);
88
+    }
89
+
90
+    /**
91
+     * Sends a usage line, if appropriate, to the specified target.
92
+     *
93
+     * @param target The command window to send the line to
94
+     * @param isSilent Whether this command is being silenced or not
95
+     * @param name The name of the command that's raising the error
96
+     * @param args The arguments that the command accepts or expects
97
+     */
98
+    public void proxyShowUsage(final FrameContainer<?> target,
99
+            final boolean isSilent, final String name, final String args) {
100
+        showUsage(target, isSilent, getName(), name + " " + args);
101
+    }
102
+
103
+    /**
104
+     * Formats the specified data into a table suitable for output in the
105
+     * textpane. It is expected that each String[] in data has the same number
106
+     * of elements as the headers array.
107
+     *
108
+     * @param headers The headers of the table.
109
+     * @param data The contents of the table.
110
+     * @return A string containing an ASCII table
111
+     */
112
+    public String proxyDoTable(final String[] headers, final String[][] data) {
113
+        return doTable(headers, data);
114
+    }
115
+
116
+    /** {@inheritDoc} */
117
+    @Override
118
+    public String getName() {
119
+        return "debug";
120
+    }
121
+
122
+    /** {@inheritDoc} */
123
+    @Override
124
+    public boolean showInHelp() {
125
+        return false;
126
+    }
127
+
128
+    /** {@inheritDoc} */
129
+    @Override
130
+    public CommandType getType() {
131
+        return CommandType.TYPE_GLOBAL;
132
+    }
133
+
134
+    /** {@inheritDoc} */
135
+    @Override
136
+    public String getHelp() {
137
+        return null;
138
+    }
139
+
140
+    /** {@inheritDoc} */
141
+    @Override
142
+    public AdditionalTabTargets getSuggestions(final int arg,
143
+            final IntelligentCommandContext context) {
144
+        AdditionalTabTargets res = new AdditionalTabTargets();
145
+
146
+        res.excludeAll();
147
+
148
+        if (arg == 0) {
149
+            res.addAll(plugin.getCommandNames());
150
+        } else {
151
+            final DebugCommand command = plugin.getCommand(
152
+                    context.getPreviousArgs().get(0));
153
+            if (command instanceof IntelligentCommand) {
154
+                final IntelligentCommandContext newContext =
155
+                        new IntelligentCommandContext(context.getWindow(),
156
+                        context.getPreviousArgs().subList(1,
157
+                        context.getPreviousArgs().size()),
158
+                        context.getPartial());
159
+                res = ((IntelligentCommand) command).getSuggestions(
160
+                        arg, newContext);
161
+            }
162
+        }
163
+
164
+        return res;
165
+    }
166
+
167
+}

+ 133
- 0
src/com/dmdirc/addons/debug/DebugCommand.java Näytä tiedosto

@@ -0,0 +1,133 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.commands.context.CommandContext;
28
+
29
+/**
30
+ * Debug command, serves as a proxy between debug commands and normal commands.
31
+ */
32
+public abstract class DebugCommand {
33
+    /** The format name used for command output. */
34
+    public static final String FORMAT_OUTPUT = "commandOutput";
35
+    /** The format name used for command errors. */
36
+    public static final String FORMAT_ERROR = "commandError";
37
+    /** Parent debug command. */
38
+    private final Debug command;
39
+
40
+    /**
41
+     * Returns this command's name.
42
+     *
43
+     * @return The name of this command
44
+     */
45
+    public abstract String getName();
46
+
47
+    /**
48
+     * Returns a string representing the help message for this command.
49
+     * <p>
50
+     * The help text should generally be one line, and must start with
51
+     * the name of the command. It should then summarise the arguments of
52
+     * that command, using <code>&lt;angled&gt;</code> brackets for required
53
+     * arguments, and <code>[square]</code> brackets for optional arguments.
54
+     * Where multiple possibilities exist, they are typically separated by a
55
+     * pipe (<code>|</code>), for example: <code>command [--arg1|--arg2]</code>.
56
+     * The usage summary should then be followed by a dash and a brief
57
+     * summary of the purpose of the command.
58
+     * <p>
59
+     * A typical help message would look similar to:
60
+     * <p>
61
+     * <code>command [--arg &lt;param_for_arg&gt;] [someparam] - does x, y and z</code>
62
+     *
63
+     * @return the help message for this command
64
+     */
65
+    public abstract String getUsage();
66
+
67
+
68
+    /**
69
+     * Executes this command.
70
+     *
71
+     * @param origin The container which received the command
72
+     * @param args Arguments passed to this command
73
+     * @param context The context the command was executed in
74
+     */
75
+    public abstract void execute(final FrameContainer<?> origin,
76
+            final CommandArguments args, final CommandContext context);
77
+
78
+    /**
79
+     * Creates a new debug command.
80
+     *
81
+     * @param command Parent debug command
82
+     */
83
+    public DebugCommand(final Debug command) {
84
+        this.command = command;
85
+    }
86
+
87
+
88
+    /**
89
+     * Sends a line, if appropriate, to the specified target.
90
+     *
91
+     * @param target The command window to send the line to
92
+     * @param isSilent Whether this command is being silenced or not
93
+     * @param type The type of message to send
94
+     * @param args The arguments of the message
95
+     */
96
+    public void sendLine(final FrameContainer<?> target,
97
+            final boolean isSilent, final String type, final Object ... args) {
98
+        if (command != null) {
99
+            command.proxySendLine(target, isSilent, type, args);
100
+        }
101
+    }
102
+
103
+    /**
104
+     * Sends a usage line, if appropriate, to the specified target.
105
+     *
106
+     * @param target The command window to send the line to
107
+     * @param isSilent Whether this command is being silenced or not
108
+     * @param name The name of the command that's raising the error
109
+     * @param args The arguments that the command accepts or expects
110
+     */
111
+    public void showUsage(final FrameContainer<?> target,
112
+            final boolean isSilent, final String name, final String args) {
113
+        if (command != null) {
114
+            command.proxyShowUsage(target, isSilent, name, args);
115
+        }
116
+    }
117
+
118
+    /**
119
+     * Formats the specified data into a table suitable for output in the
120
+     * textpane. It is expected that each String[] in data has the same number
121
+     * of elements as the headers array.
122
+     *
123
+     * @param headers The headers of the table.
124
+     * @param data The contents of the table.
125
+     * @return A string containing an ASCII table
126
+     */
127
+    public String doTable(final String[] headers, final String[][] data) {
128
+        if (command != null) {
129
+            return command.proxyDoTable(headers, data);
130
+        }
131
+        return "";
132
+    }
133
+}

+ 132
- 0
src/com/dmdirc/addons/debug/DebugPlugin.java Näytä tiedosto

@@ -0,0 +1,132 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug;
24
+
25
+import com.dmdirc.addons.debug.commands.*; //NOPMD
26
+import com.dmdirc.commandparser.CommandManager;
27
+import com.dmdirc.logger.ErrorLevel;
28
+import com.dmdirc.logger.Logger;
29
+import com.dmdirc.plugins.Plugin;
30
+import java.util.ArrayList;
31
+import java.util.HashMap;
32
+import java.util.List;
33
+import java.util.Map;
34
+
35
+/**
36
+ * Debug plugin providing commands to aid in debugging the client.
37
+ */
38
+public class DebugPlugin extends Plugin {
39
+
40
+    /** List of build in debug commands to load. */
41
+    private static final Class[] CLASSES = {
42
+        Benchmark.class, ColourSpam.class, ConfigInfo.class, ConfigStats.class,
43
+        com.dmdirc.addons.debug.commands.Error.class, FirstRun.class,
44
+        ForceUpdate.class, GlobalConfigInfo.class, MemInfo.class,
45
+        Migration.class, Notify.class, RunGC.class, ServerInfo.class,
46
+        ServerState.class, Services.class, ShowRaw.class, Threads.class,
47
+        Time.class,
48
+    };
49
+    /** List of registered debug commands. */
50
+    private final Map<String, DebugCommand> commands;
51
+    /** Debug command. */
52
+    private final Debug debugCommand;
53
+
54
+    /**
55
+     * Creates a new debug plugin.
56
+     */
57
+    public DebugPlugin() {
58
+        super();
59
+        commands = new HashMap<String, DebugCommand>();
60
+        debugCommand = new Debug(this);
61
+    }
62
+
63
+    /** {@inheritDoc} */
64
+    @Override
65
+    public void onLoad() {
66
+        CommandManager.registerCommand(debugCommand);
67
+        for (Class<DebugCommand> type : CLASSES) {
68
+            try {
69
+                addCommand(type.getConstructor(Debug.class)
70
+                        .newInstance(debugCommand));
71
+            } catch (LinkageError e) {
72
+                Logger.appError(ErrorLevel.HIGH,
73
+                        "Unable to load debug command", e);
74
+            } catch (Exception e) {
75
+                Logger.appError(ErrorLevel.HIGH,
76
+                        "Unable to load debug command", e);
77
+            }
78
+        }
79
+    }
80
+
81
+    /** {@inheritDoc} */
82
+    @Override
83
+    public void onUnload() {
84
+        commands.clear();
85
+        CommandManager.unregisterCommand(debugCommand);
86
+    }
87
+
88
+    /**
89
+     * Adds a command to the list of commands.
90
+     *
91
+     * @param command Command to add
92
+     */
93
+    public void addCommand(final DebugCommand command) {
94
+        commands.put(command.getName(), command);
95
+    }
96
+
97
+    /**
98
+     * Removes a command from the list of commands.
99
+     *
100
+     * @param command Command to remove
101
+     */
102
+    public void removeCommand(final DebugCommand command) {
103
+        commands.remove(command.getName());
104
+    }
105
+
106
+    /**
107
+     * Returns a list of command names.
108
+     *
109
+     * @return List of command names
110
+     */
111
+    public List<String> getCommandNames() {
112
+        final List<String> names = new ArrayList<String>(commands.size());
113
+
114
+        for (DebugCommand command : commands.values()) {
115
+            names.add(command.getName());
116
+        }
117
+
118
+        return names;
119
+    }
120
+
121
+    /**
122
+     * Returns the debug command with the specified name.
123
+     *
124
+     * @param name Name of command to return
125
+     *
126
+     * @return Command with specified name or null if no matches
127
+     */
128
+    public DebugCommand getCommand(final String name) {
129
+        return commands.get(name);
130
+    }
131
+
132
+}

+ 82
- 0
src/com/dmdirc/addons/debug/commands/Benchmark.java Näytä tiedosto

@@ -0,0 +1,82 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+
31
+/**
32
+ * Textpane speed benchmark, outputs a large volume of text and times the amount
33
+ * of time it takes the textpane to draw this.
34
+ */
35
+public class Benchmark extends DebugCommand {
36
+
37
+    /**
38
+     * Creates a new instance of the command.
39
+     *
40
+     * @param command Parent command
41
+     */
42
+    public Benchmark(final Debug command) {
43
+        super(command);
44
+    }
45
+
46
+    /** {@inheritDoc} */
47
+    @Override
48
+    public String getName() {
49
+        return "benchmark";
50
+    }
51
+
52
+    /** {@inheritDoc} */
53
+    @Override
54
+    public String getUsage() {
55
+        return " - Runs a textpane benchmark";
56
+    }
57
+
58
+    /** {@inheritDoc} */
59
+    @Override
60
+    public void execute(final FrameContainer<?> origin,
61
+            final CommandArguments args, final CommandContext context) {
62
+        long[] results = new long[10];
63
+
64
+        for (int i = 0; i < results.length; i++) {
65
+            final long start = System.nanoTime();
66
+
67
+            for (int j = 0; j < 5000; j++) {
68
+                origin.addLine(FORMAT_OUTPUT,
69
+                        "This is a benchmark. Lorem ipsum doler...");
70
+            }
71
+
72
+            final long end = System.nanoTime();
73
+
74
+            results[i] = end - start;
75
+        }
76
+
77
+        for (int i = 0; i < results.length; i++) {
78
+            origin.addLine(FORMAT_OUTPUT, "Iteration " + i + ": " + results[i]
79
+                    + " nanoseconds.");
80
+        }
81
+    }
82
+}

+ 71
- 0
src/com/dmdirc/addons/debug/commands/ColourSpam.java Näytä tiedosto

@@ -0,0 +1,71 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+
31
+/**
32
+ * Outputs a large number of coloured lines.
33
+ */
34
+public class ColourSpam extends DebugCommand {
35
+
36
+    /**
37
+     * Creates a new instance of the command.
38
+     *
39
+     * @param command Parent command
40
+     */
41
+    public ColourSpam(final Debug command) {
42
+        super(command);
43
+    }
44
+
45
+    /** {@inheritDoc} */
46
+    @Override
47
+    public String getName() {
48
+        return "colourspam";
49
+    }
50
+
51
+    /** {@inheritDoc} */
52
+    @Override
53
+    public String getUsage() {
54
+        return " - Spams coloured lines";
55
+    }
56
+
57
+    /** {@inheritDoc} */
58
+    @Override
59
+    public void execute(final FrameContainer<?> origin,
60
+            final CommandArguments args, final CommandContext context) {
61
+        for (int i = 0; i < 100; i++) {
62
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
63
+                    ((char) 3) + "5Colour! "
64
+                    + ((char) 3) + "6Colour! " + ((char) 3) + "7Colour! "
65
+                    + ((char) 3) + "6Colour! " + ((char) 3) + "7Colour! "
66
+                    + ((char) 3) + "6Colour! " + ((char) 3) + "7Colour! "
67
+                    + ((char) 3) + "6Colour! " + ((char) 3) + "7Colour! ");
68
+        }
69
+    }
70
+
71
+}

+ 69
- 0
src/com/dmdirc/addons/debug/commands/ConfigInfo.java Näytä tiedosto

@@ -0,0 +1,69 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+import com.dmdirc.config.Identity;
31
+
32
+/**
33
+ * Outputs the config info related to the current context.
34
+ */
35
+public class ConfigInfo extends DebugCommand {
36
+
37
+    /**
38
+     * Creates a new instance of the command.
39
+     *
40
+     * @param command Parent command
41
+     */
42
+    public ConfigInfo(final Debug command) {
43
+        super(command);
44
+    }
45
+
46
+    /** {@inheritDoc} */
47
+    @Override
48
+    public String getName() {
49
+        return "configinfo";
50
+    }
51
+
52
+    /** {@inheritDoc} */
53
+    @Override
54
+    public String getUsage() {
55
+        return " - Outputs context specific config information";
56
+    }
57
+
58
+    /** {@inheritDoc} */
59
+    @Override
60
+    public void execute(final FrameContainer<?> origin,
61
+            final CommandArguments args, final CommandContext context) {
62
+        for (Identity source : origin.getConfigManager().getSources()) {
63
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, source.getTarget()
64
+                    + " - " + source + "(" + source.getTarget().getOrder()
65
+                    + ")");
66
+        }
67
+    }
68
+
69
+}

+ 204
- 0
src/com/dmdirc/addons/debug/commands/ConfigStats.java Näytä tiedosto

@@ -0,0 +1,204 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+import com.dmdirc.config.ConfigManager;
31
+
32
+import java.io.Serializable;
33
+import java.util.Comparator;
34
+import java.util.Map;
35
+import java.util.Map.Entry;
36
+import java.util.SortedSet;
37
+import java.util.TreeSet;
38
+
39
+/**
40
+ * Outputs usage statistics for config settings.
41
+ */
42
+public class ConfigStats extends DebugCommand {
43
+
44
+    /**
45
+     * Creates a new instance of the command.
46
+     *
47
+     * @param command Parent command
48
+     */
49
+    public ConfigStats(final Debug command) {
50
+        super(command);
51
+    }
52
+
53
+    /** {@inheritDoc} */
54
+    @Override
55
+    public String getName() {
56
+        return "configstats";
57
+    }
58
+
59
+    /** {@inheritDoc} */
60
+    @Override
61
+    public String getUsage() {
62
+        return "[+<X>|<Y>|<regex>] - show config usage stats, optionally "
63
+                + "filtering to the top X entries, entries with at least Y "
64
+                + "usages, or entries matching the specified regex";
65
+    }
66
+
67
+    /** {@inheritDoc} */
68
+    @Override
69
+    public void execute(final FrameContainer<?> origin,
70
+            final CommandArguments args, final CommandContext context) {
71
+        if (args.getArguments().length == 2) {
72
+            if (args.getArguments()[1].startsWith("+")) {
73
+                int arg;
74
+                try {
75
+                    arg = Integer.parseInt(args.getArguments()[1].substring(1));
76
+                } catch (NumberFormatException e) {
77
+                    arg = Integer.MAX_VALUE;
78
+                }
79
+                doConfigStatsTop(origin, args.isSilent(), arg);
80
+            } else if (args.getArguments()[1].matches("^[0-9]+$")) {
81
+                int arg;
82
+                try {
83
+                    arg = Integer.parseInt(args.getArguments()[1]);
84
+                } catch (NumberFormatException e) {
85
+                    arg = -1;
86
+                }
87
+                doConfigStatsCutOff(origin, args.isSilent(), arg);
88
+            } else {
89
+                doConfigStatsOption(origin, args.isSilent(),
90
+                        args.getArguments()[1]);
91
+            }
92
+        } else {
93
+            doConfigStatsCutOff(origin, args.isSilent(), -1);
94
+        }
95
+    }
96
+
97
+
98
+
99
+    /**
100
+     * Shows stats related to the config system, showing any options matching
101
+     * the regex.
102
+     *
103
+     * @param origin The window this command was executed in
104
+     * @param isSilent Whether this command has been silenced or not
105
+     * @param regex Regex to match options against
106
+     */
107
+    private void doConfigStatsOption(final FrameContainer<?> origin,
108
+            final boolean isSilent, final String regex) {
109
+        final SortedSet<Entry<String, Integer>> sortedStats = getSortedStats();
110
+        boolean found = false;
111
+        for (Map.Entry<String, Integer> entry : sortedStats) {
112
+            if (entry.getKey().matches(regex)) {
113
+                sendLine(origin, isSilent, FORMAT_OUTPUT,
114
+                        entry.getKey() + " - " + entry.getValue());
115
+                found = true;
116
+            }
117
+        }
118
+        if (!found) {
119
+            sendLine(origin, isSilent, FORMAT_ERROR,
120
+                    "Unable to locate option.");
121
+        }
122
+    }
123
+
124
+    /**
125
+     * Shows stats related to the config system, listing the top X number of
126
+     * options.
127
+     *
128
+     * @param origin The window this command was executed in
129
+     * @param isSilent Whether this command has been silenced or not
130
+     * @param top Top number of entries to show
131
+     */
132
+    private void doConfigStatsTop(final FrameContainer<?> origin,
133
+            final boolean isSilent, final int top) {
134
+        final SortedSet<Entry<String, Integer>> sortedStats = getSortedStats();
135
+        int i = 0;
136
+        for (Map.Entry<String, Integer> entry : sortedStats) {
137
+            if (i == top) {
138
+                break;
139
+            }
140
+            i++;
141
+            sendLine(origin, isSilent, FORMAT_OUTPUT,
142
+                    entry.getKey() + " - " + entry.getValue());
143
+        }
144
+    }
145
+
146
+    /**
147
+     * Shows stats related to the config system, lists all values with number
148
+     * of usages over the specified value.
149
+     *
150
+     * @param origin The window this command was executed in
151
+     * @param isSilent Whether this command has been silenced or not
152
+     * @param cutoff Cut off value for stats
153
+     */
154
+    private void doConfigStatsCutOff(final FrameContainer<?> origin,
155
+            final boolean isSilent, final int cutoff) {
156
+        final SortedSet<Entry<String, Integer>> sortedStats = getSortedStats();
157
+        for (Map.Entry<String, Integer> entry : sortedStats) {
158
+            if (entry.getValue() <= cutoff) {
159
+                break;
160
+            }
161
+            sendLine(origin, isSilent, FORMAT_OUTPUT,
162
+                    entry.getKey() + " - " + entry.getValue());
163
+        }
164
+    }
165
+
166
+    /**
167
+     * Gets a sorted Set of config options and the number of times they have
168
+     * been called.
169
+     *
170
+     * @return Sorted set of config options and usages
171
+     */
172
+    private static SortedSet<Entry<String, Integer>> getSortedStats() {
173
+        final SortedSet<Entry<String, Integer>> sortedStats =
174
+                new TreeSet<Entry<String, Integer>>(new ValueComparator());
175
+        sortedStats.addAll(ConfigManager.getStats().entrySet());
176
+        return sortedStats;
177
+    }
178
+
179
+    /** Reverse value comparator for a map entry. */
180
+    private static class ValueComparator implements
181
+            Comparator<Entry<String, Integer>>, Serializable {
182
+
183
+        /**
184
+         * A version number for this class. It should be changed whenever the
185
+         * class structure is changed (or anything else that would prevent
186
+         * serialized objects being unserialized with the new class).
187
+         */
188
+        private static final long serialVersionUID = 1;
189
+
190
+        /** {@inheritDoc} */
191
+        @Override
192
+        public int compare(final Entry<String, Integer> o1,
193
+                final Entry<String, Integer> o2) {
194
+            int returnValue = o1.getValue().compareTo(o2.getValue()) * -1;
195
+
196
+            if (returnValue == 0) {
197
+                returnValue = o1.getKey().compareToIgnoreCase(o2.getKey());
198
+            }
199
+
200
+            return returnValue;
201
+        }
202
+    }
203
+
204
+}

+ 132
- 0
src/com/dmdirc/addons/debug/commands/Error.java Näytä tiedosto

@@ -0,0 +1,132 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.IntelligentCommand;
30
+import com.dmdirc.commandparser.commands.context.CommandContext;
31
+import com.dmdirc.logger.ErrorLevel;
32
+import com.dmdirc.logger.Logger;
33
+import com.dmdirc.ui.input.AdditionalTabTargets;
34
+
35
+/**
36
+ * Creates DMDirc errors with the specified parameters.
37
+ */
38
+public class Error extends DebugCommand implements IntelligentCommand {
39
+
40
+    /** Error level to create. */
41
+    private ErrorLevel el = ErrorLevel.HIGH;
42
+
43
+    /**
44
+     * Creates a new instance of the command.
45
+     *
46
+     * @param command Parent command
47
+     */
48
+    public Error(final Debug command) {
49
+        super(command);
50
+    }
51
+
52
+    /** {@inheritDoc} */
53
+    @Override
54
+    public String getName() {
55
+        return "error";
56
+    }
57
+
58
+    /** {@inheritDoc} */
59
+    @Override
60
+    public String getUsage() {
61
+        return "<user|app> [<low|medium|high|fatal|unknown>] - Creates an error"
62
+                + " with the specified parameters, defaults to high priority.";
63
+    }
64
+
65
+    /** {@inheritDoc} */
66
+    @Override
67
+    public void execute(final FrameContainer<?> origin,
68
+            final CommandArguments args, final CommandContext context) {
69
+        if ((args.getArguments().length == 1
70
+                || args.getArguments().length == 2)
71
+                && args.getArguments()[0].equals("user")) {
72
+            Logger.userError(getLevel(args.getArguments()),
73
+                    "Debug error message");
74
+        } else if ((args.getArguments().length == 1
75
+                || args.getArguments().length == 2)
76
+                && args.getArguments()[0].equals("app")) {
77
+            Logger.appError(getLevel(args.getArguments()),
78
+                    "Debug error message", new IllegalArgumentException());
79
+        } else {
80
+            showUsage(origin, args.isSilent(), getName(), getUsage());
81
+        }
82
+    }
83
+
84
+    /**
85
+     * Returns the error level specified by the provided arguments.
86
+     *
87
+     * @param args command arguments
88
+     *
89
+     * @return Error level
90
+     */
91
+    private ErrorLevel getLevel(final String... args) {
92
+        if (args.length >= 2) {
93
+            final String level = args[1];
94
+            if ("low".equals(level)) {
95
+                el = ErrorLevel.LOW;
96
+            } else if ("medium".equals(level)) {
97
+                el = ErrorLevel.MEDIUM;
98
+            } else if ("fatal".equals(level)) {
99
+                el = ErrorLevel.FATAL;
100
+            } else if ("unknown".equals(level)) {
101
+                el = ErrorLevel.UNKNOWN;
102
+            } else {
103
+                el = ErrorLevel.HIGH;
104
+            }
105
+        } else {
106
+            el = ErrorLevel.HIGH;
107
+        }
108
+        return el;
109
+    }
110
+
111
+    /** {@inheritDoc} */
112
+    @Override
113
+    public AdditionalTabTargets getSuggestions(final int arg,
114
+            final IntelligentCommandContext context) {
115
+        final AdditionalTabTargets res = new AdditionalTabTargets();
116
+        res.excludeAll();
117
+
118
+        if (arg == 1) {
119
+            res.add("user");
120
+            res.add("app");
121
+        } else if (arg == 2) {
122
+            res.add("low");
123
+            res.add("medium");
124
+            res.add("high");
125
+            res.add("fatal");
126
+            res.add("unknown");
127
+        }
128
+
129
+        return res;
130
+    }
131
+
132
+}

+ 64
- 0
src/com/dmdirc/addons/debug/commands/FirstRun.java Näytä tiedosto

@@ -0,0 +1,64 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+
31
+/**
32
+ * Opens the DMDirc first run wizard.
33
+ */
34
+public class FirstRun extends DebugCommand {
35
+
36
+    /**
37
+     * Creates a new instance of the command.
38
+     *
39
+     * @param command Parent command
40
+     */
41
+    public FirstRun(final Debug command) {
42
+        super(command);
43
+    }
44
+
45
+    /** {@inheritDoc} */
46
+    @Override
47
+    public String getName() {
48
+        return "firstrun";
49
+    }
50
+
51
+    /** {@inheritDoc} */
52
+    @Override
53
+    public String getUsage() {
54
+        return " - shows the first run wizard";
55
+    }
56
+
57
+    /** {@inheritDoc} */
58
+    @Override
59
+    public void execute(final FrameContainer<?> origin,
60
+            final CommandArguments args, final CommandContext context) {
61
+        context.getSource().getController().showFirstRunWizard();
62
+    }
63
+
64
+}

+ 75
- 0
src/com/dmdirc/addons/debug/commands/ForceUpdate.java Näytä tiedosto

@@ -0,0 +1,75 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+import com.dmdirc.config.IdentityManager;
31
+import com.dmdirc.ui.messages.Styliser;
32
+import com.dmdirc.updater.UpdateChecker;
33
+
34
+/**
35
+ * Forces the client to check for an update.
36
+ */
37
+public class ForceUpdate extends DebugCommand {
38
+
39
+    /**
40
+     * Creates a new instance of the command.
41
+     *
42
+     * @param command Parent command
43
+     */
44
+    public ForceUpdate(final Debug command) {
45
+        super(command);
46
+    }
47
+
48
+    /** {@inheritDoc} */
49
+    @Override
50
+    public String getName() {
51
+        return "forceupdate";
52
+    }
53
+
54
+    /** {@inheritDoc} */
55
+    @Override
56
+    public String getUsage() {
57
+        return " - Forces a client update check";
58
+    }
59
+
60
+    /** {@inheritDoc} */
61
+    @Override
62
+    public void execute(final FrameContainer<?> origin,
63
+            final CommandArguments args, final CommandContext context) {
64
+        if (IdentityManager.getGlobalConfig().getOptionBool("updater",
65
+                "enable")) {
66
+            new Thread(new UpdateChecker(), "Forced update checker").start();
67
+        } else {
68
+            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Update checking is "
69
+                    + "currenty disabled.  You can enable it by typing:");
70
+            sendLine(origin, args.isSilent(), FORMAT_ERROR, Styliser.CODE_FIXED
71
+                    + "    /set updater enable true");
72
+        }
73
+    }
74
+
75
+}

+ 70
- 0
src/com/dmdirc/addons/debug/commands/GlobalConfigInfo.java Näytä tiedosto

@@ -0,0 +1,70 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+import com.dmdirc.config.Identity;
31
+import com.dmdirc.config.IdentityManager;
32
+
33
+/**
34
+ * Outputs information about the global config sources.
35
+ */
36
+public class GlobalConfigInfo extends DebugCommand {
37
+
38
+    /**
39
+     * Creates a new instance of the command.
40
+     *
41
+     * @param command Parent command
42
+     */
43
+    public GlobalConfigInfo(final Debug command) {
44
+        super(command);
45
+    }
46
+
47
+    /** {@inheritDoc} */
48
+    @Override
49
+    public String getName() {
50
+        return "globalconfiginfo";
51
+    }
52
+
53
+    /** {@inheritDoc} */
54
+    @Override
55
+    public String getUsage() {
56
+        return " - Outputs global config information";
57
+    }
58
+
59
+    /** {@inheritDoc} */
60
+    @Override
61
+    public void execute(final FrameContainer<?> origin,
62
+            final CommandArguments args, final CommandContext context) {
63
+        for (Identity source : IdentityManager.getGlobalConfig().getSources()) {
64
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, source.getTarget()
65
+                    + " - " + source + "(" + source.getTarget().getOrder()
66
+                    + ")");
67
+        }
68
+    }
69
+
70
+}

+ 70
- 0
src/com/dmdirc/addons/debug/commands/MemInfo.java Näytä tiedosto

@@ -0,0 +1,70 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+
31
+/**
32
+ * Outputs the total, free and used memory for the JVM.
33
+ */
34
+public class MemInfo extends DebugCommand {
35
+
36
+    /**
37
+     * Creates a new instance of the command.
38
+     *
39
+     * @param command Parent command
40
+     */
41
+    public MemInfo(final Debug command) {
42
+        super(command);
43
+    }
44
+
45
+    /** {@inheritDoc} */
46
+    @Override
47
+    public String getName() {
48
+        return "meminfo";
49
+    }
50
+
51
+    /** {@inheritDoc} */
52
+    @Override
53
+    public String getUsage() {
54
+        return " - shows JVM memory information";
55
+    }
56
+
57
+    /** {@inheritDoc} */
58
+    @Override
59
+    public void execute(final FrameContainer<?> origin,
60
+            final CommandArguments args, final CommandContext context) {
61
+        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Total Memory: "
62
+                + Runtime.getRuntime().totalMemory());
63
+        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Free Memory: "
64
+                + Runtime.getRuntime().freeMemory());
65
+        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Used Memory: "
66
+                + (Runtime.getRuntime().totalMemory()
67
+                - Runtime.getRuntime().freeMemory()));
68
+    }
69
+
70
+}

+ 64
- 0
src/com/dmdirc/addons/debug/commands/Migration.java Näytä tiedosto

@@ -0,0 +1,64 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+
31
+/**
32
+ * Opens the DMDirc migration wizard.
33
+ */
34
+public class Migration extends DebugCommand {
35
+
36
+    /**
37
+     * Creates a new instance of the command.
38
+     *
39
+     * @param command Parent command
40
+     */
41
+    public Migration(final Debug command) {
42
+        super(command);
43
+    }
44
+
45
+    /** {@inheritDoc} */
46
+    @Override
47
+    public String getName() {
48
+        return "migration";
49
+    }
50
+
51
+    /** {@inheritDoc} */
52
+    @Override
53
+    public String getUsage() {
54
+        return " - Shows the migration wizard";
55
+    }
56
+
57
+    /** {@inheritDoc} */
58
+    @Override
59
+    public void execute(final FrameContainer<?> origin,
60
+            final CommandArguments args, final CommandContext context) {
61
+        context.getSource().getController().showMigrationWizard();
62
+    }
63
+
64
+}

+ 65
- 0
src/com/dmdirc/addons/debug/commands/Notify.java Näytä tiedosto

@@ -0,0 +1,65 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+
31
+/**
32
+ * Outputs the current notification colour for a window.
33
+ */
34
+public class Notify extends DebugCommand {
35
+
36
+    /**
37
+     * Creates a new instance of the command.
38
+     *
39
+     * @param command Parent command
40
+     */
41
+    public Notify(final Debug command) {
42
+        super(command);
43
+    }
44
+
45
+    /** {@inheritDoc} */
46
+    @Override
47
+    public String getName() {
48
+        return "notify";
49
+    }
50
+
51
+    /** {@inheritDoc} */
52
+    @Override
53
+    public String getUsage() {
54
+        return " - Shows the current notification colour for a window";
55
+    }
56
+
57
+    /** {@inheritDoc} */
58
+    @Override
59
+    public void execute(final FrameContainer<?> origin,
60
+            final CommandArguments args, final CommandContext context) {
61
+        sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
62
+                "Current notification colour is: " + origin.getNotification());
63
+    }
64
+
65
+}

+ 66
- 0
src/com/dmdirc/addons/debug/commands/RunGC.java Näytä tiedosto

@@ -0,0 +1,66 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+
31
+/**
32
+ * Starts a manual GC run for the JVM.
33
+ */
34
+public class RunGC extends DebugCommand {
35
+
36
+    /**
37
+     * Creates a new instance of the command.
38
+     *
39
+     * @param command Parent command
40
+     */
41
+    public RunGC(final Debug command) {
42
+        super(command);
43
+    }
44
+
45
+    /** {@inheritDoc} */
46
+    @Override
47
+    public String getName() {
48
+        return "rungc";
49
+    }
50
+
51
+    /** {@inheritDoc} */
52
+    @Override
53
+    public String getUsage() {
54
+        return " - Runs the JVM garbage collector";
55
+    }
56
+
57
+    /** {@inheritDoc} */
58
+    @Override
59
+    public void execute(final FrameContainer<?> origin,
60
+            final CommandArguments args, final CommandContext context) {
61
+        System.gc();
62
+        sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
63
+                "Invoked garbage collector.");
64
+    }
65
+
66
+}

+ 84
- 0
src/com/dmdirc/addons/debug/commands/ServerInfo.java Näytä tiedosto

@@ -0,0 +1,84 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.Server;
27
+import com.dmdirc.addons.debug.Debug;
28
+import com.dmdirc.addons.debug.DebugCommand;
29
+import com.dmdirc.commandparser.CommandArguments;
30
+import com.dmdirc.commandparser.commands.context.CommandContext;
31
+
32
+/**
33
+ * Outputs general information about a connected server.
34
+ */
35
+public class ServerInfo extends DebugCommand {
36
+
37
+    /**
38
+     * Creates a new instance of the command.
39
+     *
40
+     * @param command Parent command
41
+     */
42
+    public ServerInfo(final Debug command) {
43
+        super(command);
44
+    }
45
+
46
+    /** {@inheritDoc} */
47
+    @Override
48
+    public String getName() {
49
+        return "serverinfo";
50
+    }
51
+
52
+    /** {@inheritDoc} */
53
+    @Override
54
+    public String getUsage() {
55
+        return " - Outputs information about the server";
56
+    }
57
+
58
+    /** {@inheritDoc} */
59
+    @Override
60
+    public void execute(final FrameContainer<?> origin,
61
+            final CommandArguments args, final CommandContext context) {
62
+        if (origin.getServer() == null) {
63
+            sendLine(origin, args.isSilent(), FORMAT_ERROR,
64
+                    "This window isn't connected to a server");
65
+        } else {
66
+            final Server server = origin.getServer();
67
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Server name: "
68
+                    + server.getName());
69
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Actual name: "
70
+                    + server.getParser().getServerName());
71
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Network: "
72
+                    + server.getNetwork());
73
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "IRCd: "
74
+                    + server.getParser().getServerSoftware() + " - "
75
+                    + server.getParser().getServerSoftwareType());
76
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Modes: "
77
+                    + server.getParser().getBooleanChannelModes() + " "
78
+                    + server.getParser().getListChannelModes() + " "
79
+                    + server.getParser().getParameterChannelModes() + " "
80
+                    + server.getParser().getDoubleParameterChannelModes());
81
+        }
82
+    }
83
+
84
+}

+ 72
- 0
src/com/dmdirc/addons/debug/commands/ServerState.java Näytä tiedosto

@@ -0,0 +1,72 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.Server;
27
+import com.dmdirc.addons.debug.Debug;
28
+import com.dmdirc.addons.debug.DebugCommand;
29
+import com.dmdirc.commandparser.CommandArguments;
30
+import com.dmdirc.commandparser.commands.context.CommandContext;
31
+
32
+/**
33
+ * Outputs server state information.
34
+ */
35
+public class ServerState extends DebugCommand {
36
+
37
+    /**
38
+     * Creates a new instance of the command.
39
+     *
40
+     * @param command Parent command
41
+     */
42
+    public ServerState(final Debug command) {
43
+        super(command);
44
+    }
45
+
46
+    /** {@inheritDoc} */
47
+    @Override
48
+    public String getName() {
49
+        return "serverstate";
50
+    }
51
+
52
+    /** {@inheritDoc} */
53
+    @Override
54
+    public String getUsage() {
55
+        return " - Outputs server state information";
56
+    }
57
+
58
+    /** {@inheritDoc} */
59
+    @Override
60
+    public void execute(final FrameContainer<?> origin,
61
+            final CommandArguments args, final CommandContext context) {
62
+        if (origin.getServer() == null) {
63
+            sendLine(origin, args.isSilent(), FORMAT_ERROR,
64
+                    "This window isn't connected to a server");
65
+        } else {
66
+            final Server server = origin.getServer();
67
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
68
+                    server.getStatus().getTransitionHistory());
69
+        }
70
+    }
71
+
72
+}

+ 97
- 0
src/com/dmdirc/addons/debug/commands/Services.java Näytä tiedosto

@@ -0,0 +1,97 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.IntelligentCommand;
30
+import com.dmdirc.commandparser.commands.context.CommandContext;
31
+import com.dmdirc.plugins.PluginManager;
32
+import com.dmdirc.plugins.Service;
33
+import com.dmdirc.plugins.ServiceProvider;
34
+import com.dmdirc.ui.input.AdditionalTabTargets;
35
+
36
+/**
37
+ * Outputs information regarding available services.
38
+ */
39
+public class Services extends DebugCommand implements IntelligentCommand {
40
+
41
+    /**
42
+     * Creates a new instance of the command.
43
+     *
44
+     * @param command Parent command
45
+     */
46
+    public Services(final Debug command) {
47
+        super(command);
48
+    }
49
+
50
+    /** {@inheritDoc} */
51
+    @Override
52
+    public String getName() {
53
+        return "services";
54
+    }
55
+
56
+    /** {@inheritDoc} */
57
+    @Override
58
+    public String getUsage() {
59
+        return "[full] - Outputs available servers, optionally showing which"
60
+                + " are active and which are not";
61
+    }
62
+
63
+    /** {@inheritDoc} */
64
+    @Override
65
+    public void execute(final FrameContainer<?> origin,
66
+            final CommandArguments args, final CommandContext context) {
67
+        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Available Services:");
68
+        for (Service service : PluginManager.getPluginManager()
69
+                .getAllServices()) {
70
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "    "
71
+                    + service.toString());
72
+            if (args.getArguments().length > 0
73
+                    && args.getArguments()[0].equals("full")) {
74
+                for (ServiceProvider provider : service.getProviders()) {
75
+                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
76
+                            "            " + provider.getProviderName()
77
+                            + " [Active: " + provider.isActive() + "]");
78
+                }
79
+            }
80
+        }
81
+    }
82
+
83
+    /** {@inheritDoc} */
84
+    @Override
85
+    public AdditionalTabTargets getSuggestions(final int arg,
86
+            final IntelligentCommandContext context) {
87
+        final AdditionalTabTargets res = new AdditionalTabTargets();
88
+        res.excludeAll();
89
+
90
+        if (arg == 1) {
91
+            res.add("full");
92
+        }
93
+
94
+        return res;
95
+    }
96
+
97
+}

+ 68
- 0
src/com/dmdirc/addons/debug/commands/ShowRaw.java Näytä tiedosto

@@ -0,0 +1,68 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+
31
+/**
32
+ * Adds a raw window to a given server.
33
+ */
34
+public class ShowRaw extends DebugCommand {
35
+
36
+    /**
37
+     * Creates a new instance of the command.
38
+     *
39
+     * @param command Parent command
40
+     */
41
+    public ShowRaw(final Debug command) {
42
+        super(command);
43
+    }
44
+
45
+    @Override
46
+    public String getName() {
47
+        return "showraw";
48
+    }
49
+
50
+    /** {@inheritDoc} */
51
+    @Override
52
+    public String getUsage() {
53
+        return " - Adds a raw window to the current server or parent server";
54
+    }
55
+
56
+    /** {@inheritDoc} */
57
+    @Override
58
+    public void execute(final FrameContainer<?> origin,
59
+            final CommandArguments args, final CommandContext context) {
60
+        if (origin == null || origin.getServer() == null) {
61
+            sendLine(origin, args.isSilent(), FORMAT_ERROR,
62
+                    "Cannot show raw window here.");
63
+        } else {
64
+            origin.getServer().addRaw();
65
+        }
66
+    }
67
+
68
+}

+ 75
- 0
src/com/dmdirc/addons/debug/commands/Threads.java Näytä tiedosto

@@ -0,0 +1,75 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+import com.dmdirc.ui.messages.Styliser;
31
+import java.util.Map.Entry;
32
+
33
+/**
34
+ * Outputs a thread dump.
35
+ */
36
+public class Threads extends DebugCommand {
37
+
38
+    /**
39
+     * Creates a new instance of the command.
40
+     *
41
+     * @param command Parent command
42
+     */
43
+    public Threads(final Debug command) {
44
+        super(command);
45
+    }
46
+
47
+    /** {@inheritDoc} */
48
+    @Override
49
+    public String getName() {
50
+        return "threads";
51
+    }
52
+
53
+    /** {@inheritDoc} */
54
+    @Override
55
+    public String getUsage() {
56
+        return " - Shows a thread dump for the running JVM";
57
+    }
58
+
59
+    /** {@inheritDoc} */
60
+    @Override
61
+    public void execute(final FrameContainer<?> origin,
62
+            final CommandArguments args, final CommandContext context) {
63
+        for (Entry<Thread, StackTraceElement[]> thread
64
+                : Thread.getAllStackTraces().entrySet()) {
65
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, Styliser.CODE_BOLD
66
+                    + thread.getKey().getName());
67
+
68
+            for (StackTraceElement element : thread.getValue()) {
69
+                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
70
+                        Styliser.CODE_FIXED + "    " + element.toString());
71
+            }
72
+        }
73
+    }
74
+
75
+}

+ 109
- 0
src/com/dmdirc/addons/debug/commands/Time.java Näytä tiedosto

@@ -0,0 +1,109 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.WritableFrameContainer;
27
+import com.dmdirc.addons.debug.Debug;
28
+import com.dmdirc.addons.debug.DebugCommand;
29
+import com.dmdirc.commandparser.CommandArguments;
30
+import com.dmdirc.commandparser.commands.IntelligentCommand;
31
+import com.dmdirc.commandparser.commands.context.CommandContext;
32
+import com.dmdirc.ui.input.AdditionalTabTargets;
33
+import com.dmdirc.ui.input.TabCompletionType;
34
+import com.dmdirc.ui.interfaces.Window;
35
+
36
+/**
37
+ * Times how long it takes to execute commands.
38
+ */
39
+public class Time extends DebugCommand implements IntelligentCommand {
40
+
41
+    /**
42
+     * Creates a new instance of the command.
43
+     *
44
+     * @param command Parent command
45
+     */
46
+    public Time(final Debug command) {
47
+        super(command);
48
+    }
49
+
50
+    /** {@inheritDoc} */
51
+    @Override
52
+    public String getName() {
53
+        return "time";
54
+    }
55
+
56
+    /** {@inheritDoc} */
57
+    @Override
58
+    public String getUsage() {
59
+        return "<command to time> - times the specified command";
60
+    }
61
+
62
+    /** {@inheritDoc} */
63
+    @Override
64
+    public void execute(final FrameContainer<?> origin,
65
+            final CommandArguments args, final CommandContext context) {
66
+        doTime(origin, context.getSource(), args);
67
+    }
68
+
69
+    /**
70
+     * Facilitates timing of a command.
71
+     *
72
+     * @param origin The origin of the command
73
+     * @param window The window to be passed on to the timed command, if any
74
+     * @param args The arguments that were passed to the command
75
+     */
76
+    private void doTime(final FrameContainer<?> origin, final Window window,
77
+            final CommandArguments args) {
78
+        if (args.getArguments().length == 0) {
79
+            showUsage(origin, args.isSilent(), getName(), getUsage());
80
+            return;
81
+        }
82
+
83
+        if (origin instanceof WritableFrameContainer<?>) {
84
+            final WritableFrameContainer<?> container
85
+                    = (WritableFrameContainer<?>) origin;
86
+            final long start = System.currentTimeMillis();
87
+            container.getCommandParser().parseCommand(origin, window,
88
+                    args.getArgumentsAsString(0));
89
+            final long end = System.currentTimeMillis();
90
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
91
+                    "Command executed in " + (end - start) + " milliseconds.");
92
+        }
93
+    }
94
+
95
+    /** {@inheritDoc} */
96
+    @Override
97
+    public AdditionalTabTargets getSuggestions(final int arg,
98
+            final IntelligentCommandContext context) {
99
+        final AdditionalTabTargets res = new AdditionalTabTargets();
100
+        res.excludeAll();
101
+
102
+        if (arg == 1) {
103
+            res.include(TabCompletionType.COMMAND);
104
+        }
105
+
106
+        return res;
107
+    }
108
+
109
+}

+ 26
- 0
src/com/dmdirc/addons/debug/plugin.config Näytä tiedosto

@@ -0,0 +1,26 @@
1
+# This is a DMDirc configuration file.
2
+
3
+# This section indicates which sections below take key/value
4
+# pairs, rather than a simple list. It should be placed above
5
+# any sections that take key/values.
6
+keysections:
7
+  metadata
8
+  updates
9
+  version
10
+  defaults
11
+
12
+metadata:
13
+  author=Greg <greg@dmdirc.com>
14
+  mainclass=com.dmdirc.addons.debug.DebugPlugin
15
+  description=Provides some useful debug commands, mostly to aid in development of the client.
16
+  name=debug
17
+  nicename=Debug
18
+  unloadable=yes
19
+
20
+updates:
21
+  id=62
22
+
23
+version:
24
+  friendly=0.1
25
+
26
+defaults:

Loading…
Peruuta
Tallenna