Browse Source

Remove actions. Entirely.

"Death is nothing, but to live defeated and inglorious is to die daily."

Happy new year! :)
pull/326/head
Chris Smith 9 years ago
parent
commit
ac931ead7f
84 changed files with 1 additions and 9573 deletions
  1. 0
    20
      res/com/dmdirc/actions/defaults/umodes/ohv
  2. 0
    27
      res/com/dmdirc/actions/defaults/umodes/ov
  3. 0
    20
      res/com/dmdirc/actions/defaults/umodes/qaohv
  4. 0
    20
      res/com/dmdirc/actions/defaults/umodes/qaov
  5. 0
    7
      src/com/dmdirc/ClientModule.java
  6. 0
    12
      src/com/dmdirc/Main.java
  7. 0
    639
      src/com/dmdirc/actions/Action.java
  8. 0
    163
      src/com/dmdirc/actions/ActionComponentChain.java
  9. 0
    212
      src/com/dmdirc/actions/ActionCondition.java
  10. 0
    43
      src/com/dmdirc/actions/ActionErrorType.java
  11. 0
    135
      src/com/dmdirc/actions/ActionFactory.java
  12. 0
    239
      src/com/dmdirc/actions/ActionGroup.java
  13. 0
    628
      src/com/dmdirc/actions/ActionManager.java
  14. 0
    442
      src/com/dmdirc/actions/ActionModel.java
  15. 0
    39
      src/com/dmdirc/actions/ActionStatus.java
  16. 0
    361
      src/com/dmdirc/actions/ActionSubstitutor.java
  17. 0
    59
      src/com/dmdirc/actions/ActionSubstitutorFactory.java
  18. 0
    43
      src/com/dmdirc/actions/ActionTypeComparator.java
  19. 0
    116
      src/com/dmdirc/actions/ColourActionComparison.java
  20. 0
    388
      src/com/dmdirc/actions/ConditionTree.java
  21. 0
    144
      src/com/dmdirc/actions/ConditionTreeFactory.java
  22. 0
    226
      src/com/dmdirc/actions/CoreActionComparison.java
  23. 0
    721
      src/com/dmdirc/actions/CoreActionComponent.java
  24. 0
    82
      src/com/dmdirc/actions/CoreActionExtractor.java
  25. 0
    319
      src/com/dmdirc/actions/CoreActionType.java
  26. 0
    20
      src/com/dmdirc/actions/defaults/umodes/ohv
  27. 0
    27
      src/com/dmdirc/actions/defaults/umodes/ov
  28. 0
    20
      src/com/dmdirc/actions/defaults/umodes/qaohv
  29. 0
    20
      src/com/dmdirc/actions/defaults/umodes/qaov
  30. 0
    74
      src/com/dmdirc/actions/metatypes/ActionEvents.java
  31. 0
    98
      src/com/dmdirc/actions/metatypes/ChannelEvents.java
  32. 0
    103
      src/com/dmdirc/actions/metatypes/ClientEvents.java
  33. 0
    75
      src/com/dmdirc/actions/metatypes/LinkEvents.java
  34. 0
    71
      src/com/dmdirc/actions/metatypes/PluginEvents.java
  35. 0
    77
      src/com/dmdirc/actions/metatypes/QueryEvents.java
  36. 0
    94
      src/com/dmdirc/actions/metatypes/ServerEvents.java
  37. 0
    111
      src/com/dmdirc/actions/package-info.java
  38. 0
    69
      src/com/dmdirc/actions/validators/ActionNameValidator.java
  39. 0
    70
      src/com/dmdirc/actions/validators/ConditionRuleValidator.java
  40. 0
    53
      src/com/dmdirc/actions/wrappers/PerformType.java
  41. 0
    342
      src/com/dmdirc/actions/wrappers/PerformWrapper.java
  42. 0
    26
      src/com/dmdirc/actions/wrappers/package-info.java
  43. 0
    13
      src/com/dmdirc/commandparser/commands/CommandModule.java
  44. 0
    79
      src/com/dmdirc/commandparser/commands/global/ReloadActions.java
  45. 0
    36
      src/com/dmdirc/events/ActionCreatedEvent.java
  46. 0
    47
      src/com/dmdirc/events/ActionDeletedEvent.java
  47. 0
    42
      src/com/dmdirc/events/ActionEvent.java
  48. 0
    36
      src/com/dmdirc/events/ActionUpdatedEvent.java
  49. 0
    248
      src/com/dmdirc/interfaces/ActionController.java
  50. 0
    63
      src/com/dmdirc/interfaces/actions/ActionComparison.java
  51. 0
    95
      src/com/dmdirc/interfaces/actions/ActionComponent.java
  52. 0
    58
      src/com/dmdirc/interfaces/actions/ActionMetaType.java
  53. 0
    52
      src/com/dmdirc/interfaces/actions/ActionType.java
  54. 0
    3
      src/com/dmdirc/interfaces/ui/FirstRunWizard.java
  55. 1
    15
      src/com/dmdirc/plugins/PluginInjectorInitialiser.java
  56. 0
    89
      src/com/dmdirc/updater/components/ActionGroupComponent.java
  57. 0
    30
      test-res/com/dmdirc/actions/action1
  58. 0
    29
      test-res/com/dmdirc/actions/action_multisettings
  59. 0
    30
      test-res/com/dmdirc/actions/defaults/action1
  60. 0
    24
      test-res/com/dmdirc/actions/defaults/action2
  61. 0
    63
      test/com/dmdirc/actions/ActionComparisonNamesTest.java
  62. 0
    161
      test/com/dmdirc/actions/ActionComponentChainTest.java
  63. 0
    154
      test/com/dmdirc/actions/ActionConditionTest.java
  64. 0
    124
      test/com/dmdirc/actions/ActionGroupTest.java
  65. 0
    190
      test/com/dmdirc/actions/ActionModelTest.java
  66. 0
    165
      test/com/dmdirc/actions/ActionSubstitutorTest.java
  67. 0
    201
      test/com/dmdirc/actions/ActionTest.java
  68. 0
    39
      test/com/dmdirc/actions/ActionTypeComparatorTest.java
  69. 0
    95
      test/com/dmdirc/actions/ConditionTreeEvaluatorTest.java
  70. 0
    73
      test/com/dmdirc/actions/ConditionTreeParserTest.java
  71. 0
    150
      test/com/dmdirc/actions/ConditionTreeTest.java
  72. 0
    104
      test/com/dmdirc/actions/CoreActionComparisonTest.java
  73. 0
    77
      test/com/dmdirc/actions/CoreActionExtractorTest.java
  74. 0
    42
      test/com/dmdirc/actions/CoreActionTypeTest.java
  75. 0
    86
      test/com/dmdirc/actions/StringComponentsTest.java
  76. 0
    42
      test/com/dmdirc/actions/metatypes/ActionEventsTest.java
  77. 0
    38
      test/com/dmdirc/actions/metatypes/ChannelEventsTest.java
  78. 0
    38
      test/com/dmdirc/actions/metatypes/ClientEventsTest.java
  79. 0
    42
      test/com/dmdirc/actions/metatypes/LinkEventsTest.java
  80. 0
    38
      test/com/dmdirc/actions/metatypes/PluginEventsTest.java
  81. 0
    38
      test/com/dmdirc/actions/metatypes/QueryEventsTest.java
  82. 0
    38
      test/com/dmdirc/actions/metatypes/ServerEventsTest.java
  83. 0
    72
      test/com/dmdirc/actions/validators/ActionNameValidatorTest.java
  84. 0
    59
      test/com/dmdirc/actions/validators/ConditionRuleValidatorTest.java

+ 0
- 20
res/com/dmdirc/actions/defaults/umodes/ohv View File

@@ -1,20 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-# Written on: Mon Dec 17 23:32:19 GMT 2007
3
-
4
-# This section indicates which sections below take key/value
5
-# pairs, rather than a simple list. It should be placed above
6
-# any sections that take key/values.
7
-keysections:
8
-  condition 0
9
-
10
-triggers:
11
-  SERVER_CONNECTED
12
-
13
-response:
14
-  /.set --server popup umodes <umodes-op\n<umodes-hop\n<umodes-voice
15
-
16
-condition 0:
17
-  argument=0
18
-  component=SERVER_CHANNELUMODES
19
-  target=ohv
20
-  comparison=STRING_EQUALS

+ 0
- 27
res/com/dmdirc/actions/defaults/umodes/ov View File

@@ -1,27 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-# Written on: Mon Dec 17 23:32:19 GMT 2007
3
-
4
-# This section indicates which sections below take key/value
5
-# pairs, rather than a simple list. It should be placed above
6
-# any sections that take key/values.
7
-keysections:
8
-  condition 0
9
-  metadata
10
-
11
-triggers:
12
-  SERVER_CONNECTED
13
-
14
-response:
15
-  /.set --server popup umodes <umodes-op\n<umodes-voice
16
-
17
-condition 0:
18
-  argument=0
19
-  component=SERVER_CHANNELUMODES
20
-  target=ov
21
-  comparison=STRING_EQUALS
22
-
23
-metadata:
24
-  description=Automatically sets the popup.umodes setting when connecting to a server, so that the correct user modes appear in the nicklist popup.
25
-  author=Chris <chris@dmdirc.com>
26
-  version=2
27
-  component=19

+ 0
- 20
res/com/dmdirc/actions/defaults/umodes/qaohv View File

@@ -1,20 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-# Written on: Mon Dec 17 23:32:19 GMT 2007
3
-
4
-# This section indicates which sections below take key/value
5
-# pairs, rather than a simple list. It should be placed above
6
-# any sections that take key/values.
7
-keysections:
8
-  condition 0
9
-
10
-triggers:
11
-  SERVER_CONNECTED
12
-
13
-response:
14
-  /.set --server popup umodes <umodes-op\n<umodes-hop\n<umodes-voice\n-\n<umodes-admin\n<umodes-owner
15
-
16
-condition 0:
17
-  argument=0
18
-  component=SERVER_CHANNELUMODES
19
-  target=qaohv
20
-  comparison=STRING_EQUALS

+ 0
- 20
res/com/dmdirc/actions/defaults/umodes/qaov View File

@@ -1,20 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-# Written on: Mon Dec 17 23:32:19 GMT 2007
3
-
4
-# This section indicates which sections below take key/value
5
-# pairs, rather than a simple list. It should be placed above
6
-# any sections that take key/values.
7
-keysections:
8
-  condition 0
9
-
10
-triggers:
11
-  SERVER_CONNECTED
12
-
13
-response:
14
-  /.set --server popup umodes <umodes-op\n<umodes-voice\n-\n<umodes-admin\n<umodes-owner
15
-
16
-condition 0:
17
-  argument=0
18
-  component=SERVER_CHANNELUMODES
19
-  target=qaov
20
-  comparison=STRING_EQUALS

+ 0
- 7
src/com/dmdirc/ClientModule.java View File

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
-import com.dmdirc.actions.ActionManager;
26 25
 import com.dmdirc.commandline.CommandLineOptionsModule;
27 26
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
28 27
 import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
@@ -33,7 +32,6 @@ import com.dmdirc.commandparser.auto.AutoCommandModule;
33 32
 import com.dmdirc.commandparser.commands.CommandModule;
34 33
 import com.dmdirc.config.ConfigModule;
35 34
 import com.dmdirc.config.profiles.ProfilesModule;
36
-import com.dmdirc.interfaces.ActionController;
37 35
 import com.dmdirc.interfaces.CommandController;
38 36
 import com.dmdirc.interfaces.ConnectionFactory;
39 37
 import com.dmdirc.interfaces.ConnectionManager;
@@ -120,11 +118,6 @@ public class ClientModule {
120 118
         return new IconManager(globalConfig, urlBuilder);
121 119
     }
122 120
 
123
-    @Provides
124
-    public ActionController getActionController(final ActionManager actionManager) {
125
-        return actionManager;
126
-    }
127
-
128 121
     @Provides
129 122
     public LifecycleController getLifecycleController(final SystemLifecycleController controller) {
130 123
         return controller;

+ 0
- 12
src/com/dmdirc/Main.java View File

@@ -23,8 +23,6 @@
23 23
 package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.GlobalWindow.GlobalWindowManager;
26
-import com.dmdirc.actions.ActionManager;
27
-import com.dmdirc.actions.ColourActionComparison;
28 26
 import com.dmdirc.commandline.CommandLineParser;
29 27
 import com.dmdirc.commandparser.CommandManager;
30 28
 import com.dmdirc.events.ClientClosedEvent;
@@ -71,8 +69,6 @@ public class Main {
71 69
     private final IdentityController identityManager;
72 70
     /** The server manager the client will use. */
73 71
     private final ConnectionManager connectionManager;
74
-    /** The action manager the client will use. */
75
-    private final ActionManager actionManager;
76 72
     /** The command-line parser used for this instance. */
77 73
     private final CommandLineParser commandLineParser;
78 74
     /** The plugin manager the client will use. */
@@ -83,8 +79,6 @@ public class Main {
83 79
     private final CommandManager commandManager;
84 80
     /** The global window manager to use. */
85 81
     private final GlobalWindowManager globalWindowManager;
86
-    /** The colour-based action comparisons. */
87
-    private final ColourActionComparison colourActionComparison;
88 82
     /** The set of known lifecycle components. */
89 83
     private final Set<SystemLifecycleComponent> lifecycleComponents;
90 84
     /** The set of migrators to execute on startup. */
@@ -103,13 +97,11 @@ public class Main {
103 97
     public Main(
104 98
             final IdentityController identityManager,
105 99
             final ConnectionManager connectionManager,
106
-            final ActionManager actionManager,
107 100
             final CommandLineParser commandLineParser,
108 101
             final PluginManager pluginManager,
109 102
             final CommandManager commandManager,
110 103
             final CorePluginExtractor corePluginExtractor,
111 104
             final GlobalWindowManager globalWindowManager,
112
-            final ColourActionComparison colourActionComparison,
113 105
             final Set<SystemLifecycleComponent> lifecycleComponents,
114 106
             final Set<Migrator> migrators,
115 107
             final DMDircMBassador eventBus,
@@ -117,13 +109,11 @@ public class Main {
117 109
             final ModeAliasReporter reporter) {
118 110
         this.identityManager = identityManager;
119 111
         this.connectionManager = connectionManager;
120
-        this.actionManager = actionManager;
121 112
         this.commandLineParser = commandLineParser;
122 113
         this.pluginManager = pluginManager;
123 114
         this.corePluginExtractor = corePluginExtractor;
124 115
         this.commandManager = commandManager;
125 116
         this.globalWindowManager = globalWindowManager;
126
-        this.colourActionComparison = colourActionComparison;
127 117
         this.lifecycleComponents = lifecycleComponents;
128 118
         this.migrators = migrators;
129 119
         this.eventBus = eventBus;
@@ -177,9 +167,7 @@ public class Main {
177 167
 
178 168
         lifecycleComponents.forEach(SystemLifecycleComponent::startUp);
179 169
 
180
-        actionManager.initialise(colourActionComparison);
181 170
         pluginManager.doAutoLoad();
182
-        actionManager.loadUserActions();
183 171
 
184 172
         eventBus.publishAsync(new ClientOpenedEvent());
185 173
         eventBus.subscribe(reporter);

+ 0
- 639
src/com/dmdirc/actions/Action.java View File

@@ -1,639 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.GlobalWindow;
27
-import com.dmdirc.config.prefs.PreferencesSetting;
28
-import com.dmdirc.config.prefs.PreferencesType;
29
-import com.dmdirc.events.ActionCreatedEvent;
30
-import com.dmdirc.events.ActionDeletedEvent;
31
-import com.dmdirc.events.ActionUpdatedEvent;
32
-import com.dmdirc.events.AppErrorEvent;
33
-import com.dmdirc.events.UserErrorEvent;
34
-import com.dmdirc.interfaces.ActionController;
35
-import com.dmdirc.interfaces.actions.ActionComparison;
36
-import com.dmdirc.interfaces.actions.ActionComponent;
37
-import com.dmdirc.interfaces.actions.ActionType;
38
-import com.dmdirc.interfaces.config.ConfigChangeListener;
39
-import com.dmdirc.interfaces.config.IdentityController;
40
-import com.dmdirc.logger.ErrorLevel;
41
-import com.dmdirc.updater.Version;
42
-import com.dmdirc.util.io.ConfigFile;
43
-import com.dmdirc.util.io.InvalidConfigFileException;
44
-
45
-import java.io.IOException;
46
-import java.nio.file.Files;
47
-import java.nio.file.Path;
48
-import java.util.ArrayList;
49
-import java.util.Arrays;
50
-import java.util.HashMap;
51
-import java.util.List;
52
-import java.util.Map;
53
-
54
-import javax.inject.Provider;
55
-
56
-/**
57
- * Describes a single action.
58
- */
59
-public class Action extends ActionModel implements ConfigChangeListener {
60
-
61
-    /** The domain name for condition trees. */
62
-    private static final String DOMAIN_CONDITIONTREE = "conditiontree";
63
-    /** The domain name for format changes. */
64
-    private static final String DOMAIN_FORMAT = "format";
65
-    /** The domain name for meta-data. */
66
-    private static final String DOMAIN_METADATA = "metadata";
67
-    /** The domain name for response information. */
68
-    private static final String DOMAIN_RESPONSE = "response";
69
-    /** The domain name for triggers. */
70
-    private static final String DOMAIN_TRIGGERS = "triggers";
71
-    /** The domain name for concurrency. */
72
-    private static final String DOMAIN_CONCURRENCY = "concurrency";
73
-    /** The domain name for misc settings. */
74
-    private static final String DOMAIN_MISC = "misc";
75
-    /** The base directory to save actions in. */
76
-    private final Path actionsDirectory;
77
-    /** The controller to use to read and update settings. */
78
-    private final IdentityController identityController;
79
-    /** The controller to use to retrieve components, comparisons, etc. */
80
-    private final ActionController actionController;
81
-    /** Event bus to post events to. */
82
-    private final DMDircMBassador eventBus;
83
-    /** The config file we're using. */
84
-    protected ConfigFile config;
85
-    /** The location of the file we're reading/saving. */
86
-    private Path location;
87
-
88
-    /**
89
-     * Creates a new instance of Action. The group and name specified must be the group and name of
90
-     * a valid action already saved to disk.
91
-     *
92
-     * @param eventBus                    Event bus to post events to
93
-     * @param globalWindowProvider        Provider of global windows for triggering actions.
94
-     * @param substitutorFactory          Factory to use to create action substitutors.
95
-     * @param actionController            The controller that owns this action.
96
-     * @param identityController          The controller to use to retrieve and update settings.
97
-     * @param actionsDirectory            The base directory to store actions in.
98
-     * @param group                       The group the action belongs to
99
-     * @param name                        The name of the action
100
-     */
101
-    public Action(final DMDircMBassador eventBus,
102
-            final Provider<GlobalWindow> globalWindowProvider,
103
-            final ActionSubstitutorFactory substitutorFactory,
104
-            final ActionController actionController, final IdentityController identityController,
105
-            final Path actionsDirectory, final String group, final String name) {
106
-        super(globalWindowProvider, substitutorFactory, group, name);
107
-
108
-        this.eventBus = eventBus;
109
-        this.actionController = actionController;
110
-        this.identityController = identityController;
111
-        this.actionsDirectory = actionsDirectory;
112
-        this.location = actionsDirectory.resolve(group).resolve(name);
113
-
114
-        try {
115
-            config = new ConfigFile(location);
116
-            config.read();
117
-            loadActionFromConfig();
118
-            actionController.addAction(this);
119
-        } catch (InvalidConfigFileException ex) {
120
-            error(ActionErrorType.FILE, "Unable to parse action file: " + ex.getMessage());
121
-        } catch (IOException ex) {
122
-            error(ActionErrorType.FILE, "I/O error when loading action: " + ex.getMessage());
123
-        }
124
-
125
-        identityController.getGlobalConfiguration().addChangeListener("disable_action",
126
-                (group + "/" + name).replace(' ', '.'), this);
127
-        checkDisabled();
128
-    }
129
-
130
-    /**
131
-     * Creates a new instance of Action with the specified properties and saves it to disk.
132
-     *
133
-     * @param eventBus                    Event bus to post events to
134
-     * @param globalWindowProvider        Provider of global windows for triggering actions.
135
-     * @param substitutorFactory          Factory to use to create action substitutors.
136
-     * @param actionController            The controller that owns this action.
137
-     * @param identityController          The controller to use to retrieve and update settings.
138
-     * @param actionsDirectory            The base directory to store actions in.
139
-     * @param group                       The group the action belongs to
140
-     * @param name                        The name of the action
141
-     * @param triggers                    The triggers to use
142
-     * @param response                    The response to use
143
-     * @param conditions                  The conditions to use
144
-     * @param conditionTree               The condition tree to use
145
-     * @param newFormat                   The new formatter to use
146
-     */
147
-    public Action(final DMDircMBassador eventBus,
148
-            final Provider<GlobalWindow> globalWindowProvider,
149
-            final ActionSubstitutorFactory substitutorFactory,
150
-            final ActionController actionController, final IdentityController identityController,
151
-            final Path actionsDirectory, final String group, final String name,
152
-            final ActionType[] triggers, final String[] response,
153
-            final List<ActionCondition> conditions, final ConditionTree conditionTree,
154
-            final String newFormat) {
155
-        super(globalWindowProvider, substitutorFactory, group, name,
156
-                triggers, response, conditions, conditionTree, newFormat);
157
-
158
-        this.eventBus = eventBus;
159
-        this.actionController = actionController;
160
-        this.identityController = identityController;
161
-        this.actionsDirectory = actionsDirectory;
162
-        this.location = actionsDirectory.resolve(group)
163
-                .resolve(name.replaceAll("[^A-Za-z0-9\\-_]", "_"));
164
-
165
-        try {
166
-            Files.createDirectories(location.getParent());
167
-        } catch (IOException ex) {
168
-            //TODO we don't handle the error now, but we should
169
-        }
170
-
171
-        save();
172
-
173
-        identityController.getGlobalConfiguration().addChangeListener("disable_action",
174
-                (group + "/" + name).replace(' ', '.'), this);
175
-        checkDisabled();
176
-
177
-        actionController.addAction(this);
178
-        //TODO This needs to be done somewhere else, remove eventbus when it is.
179
-        eventBus.publishAsync(new ActionCreatedEvent(this));
180
-    }
181
-
182
-    /**
183
-     * Loads this action from the config instance.
184
-     */
185
-    protected void loadActionFromConfig() {
186
-        if (config.isFlatDomain(DOMAIN_TRIGGERS)) {
187
-            if (!loadTriggers(config.getFlatDomain(DOMAIN_TRIGGERS))) {
188
-                return;
189
-            }
190
-        } else {
191
-            error(ActionErrorType.TRIGGERS, "No trigger specified");
192
-            return;
193
-        }
194
-
195
-        if (config.isFlatDomain(DOMAIN_RESPONSE)) {
196
-            response = new String[config.getFlatDomain(DOMAIN_RESPONSE).size()];
197
-
198
-            int i = 0;
199
-            for (String line : config.getFlatDomain(DOMAIN_RESPONSE)) {
200
-                response[i++] = line;
201
-            }
202
-        } else {
203
-            error(ActionErrorType.RESPONSE, "No response specified");
204
-            return;
205
-        }
206
-
207
-        if (config.isFlatDomain(DOMAIN_FORMAT)) {
208
-            newFormat = config.getFlatDomain(DOMAIN_FORMAT).isEmpty() ? ""
209
-                    : config.getFlatDomain(DOMAIN_FORMAT).get(0);
210
-        }
211
-
212
-        for (int cond = 0; config.isKeyDomain("condition " + cond); cond++) {
213
-            if (!readCondition(config.getKeyDomain("condition " + cond))) {
214
-                return;
215
-            }
216
-        }
217
-
218
-        if (config.isFlatDomain(DOMAIN_CONDITIONTREE)
219
-                && !config.getFlatDomain(DOMAIN_CONDITIONTREE).isEmpty()) {
220
-            conditionTree = ConditionTree.parseString(
221
-                    config.getFlatDomain(DOMAIN_CONDITIONTREE).get(0));
222
-
223
-            if (conditionTree == null) {
224
-                error(ActionErrorType.CONDITION_TREE, "Unable to parse condition tree");
225
-                return;
226
-            }
227
-
228
-            if (conditionTree.getMaximumArgument() >= conditions.size()) {
229
-                error(ActionErrorType.CONDITION_TREE, "Condition tree references condition "
230
-                        + conditionTree.getMaximumArgument() + " but there are"
231
-                        + " only " + conditions.size() + " conditions");
232
-                return;
233
-            }
234
-        }
235
-
236
-        if (config.isKeyDomain(DOMAIN_CONCURRENCY)
237
-                && config.getKeyDomain(DOMAIN_CONCURRENCY).containsKey("group")) {
238
-            setConcurrencyGroup(config.getKeyDomain(DOMAIN_CONCURRENCY).get("group"));
239
-        }
240
-
241
-        if (config.isKeyDomain(DOMAIN_MISC)
242
-                && config.getKeyDomain(DOMAIN_MISC).containsKey("stopping")) {
243
-            setStopping(Boolean.parseBoolean(config.getKeyDomain(DOMAIN_MISC).get("stopping")));
244
-        }
245
-
246
-        if (status == ActionStatus.DISABLED) {
247
-            status = ActionStatus.ACTIVE;
248
-        }
249
-
250
-        checkMetaData();
251
-    }
252
-
253
-    /**
254
-     * Checks to see if this action contains group meta-data, and adds it to the group as
255
-     * appropriate.
256
-     */
257
-    private void checkMetaData() {
258
-        if (config.isKeyDomain(DOMAIN_METADATA)) {
259
-            final ActionGroup myGroup = actionController.getOrCreateGroup(group);
260
-            final Map<String, String> data = config.getKeyDomain(DOMAIN_METADATA);
261
-
262
-            if (data.containsKey("description")) {
263
-                myGroup.setDescription(data.get("description"));
264
-            }
265
-
266
-            if (data.containsKey("author")) {
267
-                myGroup.setAuthor(data.get("author"));
268
-            }
269
-
270
-            if (data.containsKey("version")) {
271
-                myGroup.setVersion(new Version(data.get("version")));
272
-            }
273
-
274
-            if (data.containsKey("component")) {
275
-                try {
276
-                    myGroup.setComponent(Integer.parseInt(data.get("component")));
277
-                } catch (NumberFormatException ex) {
278
-                    // Do nothing
279
-                }
280
-            }
281
-        }
282
-
283
-        for (int i = 0; config.isKeyDomain("setting " + i); i++) {
284
-            final ActionGroup myGroup = actionController.getOrCreateGroup(group);
285
-            final Map<String, String> data = config.getKeyDomain("setting " + i);
286
-
287
-            if (data.containsKey("type") && data.containsKey("setting")
288
-                    && data.containsKey("title") && data.containsKey("default")
289
-                    && data.containsKey("tooltip")) {
290
-                actionController.registerSetting(data.get("setting"), data.get("default"));
291
-                myGroup.getSettings().put(data.get("setting"), new PreferencesSetting(
292
-                        PreferencesType.valueOf(data.get("type")), "actions",
293
-                        data.get("setting"), data.get("title"), data.get("tooltip"),
294
-                        identityController.getGlobalConfiguration(),
295
-                        identityController.getUserSettings()));
296
-            }
297
-        }
298
-    }
299
-
300
-    /**
301
-     * Loads a list of triggers with the specified names.
302
-     *
303
-     * @param newTriggers A list of trigger names
304
-     *
305
-     * @return True if all triggers are valid and compatible, false otherwise.
306
-     */
307
-    private boolean loadTriggers(final List<String> newTriggers) {
308
-        triggers = new ActionType[newTriggers.size()];
309
-
310
-        for (int i = 0; i < triggers.length; i++) {
311
-            triggers[i] = actionController.getType(newTriggers.get(i));
312
-
313
-            if (triggers[i] == null) {
314
-                error(ActionErrorType.TRIGGERS, "Invalid trigger specified: " + newTriggers.get(i));
315
-                return false;
316
-            } else if (i != 0 && !triggers[i].getType().equals(triggers[0].getType())) {
317
-                error(ActionErrorType.TRIGGERS, "Triggers are not compatible");
318
-                return false;
319
-            }
320
-        }
321
-
322
-        return true;
323
-    }
324
-
325
-    /**
326
-     * Called to save the action.
327
-     */
328
-    public void save() {
329
-        if (!isModified()) {
330
-            return;
331
-        }
332
-
333
-        final ConfigFile newConfig = new ConfigFile(location);
334
-
335
-        final List<String> triggerNames = new ArrayList<>();
336
-        final List<String> responseLines = new ArrayList<>();
337
-        responseLines.addAll(Arrays.asList(response));
338
-
339
-        for (ActionType trigger : triggers) {
340
-            if (trigger == null) {
341
-                eventBus.publish(new AppErrorEvent(ErrorLevel.LOW,
342
-                        new IllegalArgumentException("Triggers: "+ Arrays.toString(triggers)),
343
-                        "ActionType was null", ""));
344
-                continue;
345
-            }
346
-
347
-            triggerNames.add(trigger.toString());
348
-        }
349
-
350
-        newConfig.addDomain(DOMAIN_TRIGGERS, triggerNames);
351
-        newConfig.addDomain(DOMAIN_RESPONSE, responseLines);
352
-
353
-        if (conditionTree != null) {
354
-            newConfig.addDomain(DOMAIN_CONDITIONTREE, new ArrayList<>());
355
-            newConfig.getFlatDomain(DOMAIN_CONDITIONTREE).add(conditionTree.toString());
356
-        }
357
-
358
-        if (newFormat != null) {
359
-            newConfig.addDomain(DOMAIN_FORMAT, new ArrayList<>());
360
-            newConfig.getFlatDomain(DOMAIN_FORMAT).add(newFormat);
361
-        }
362
-
363
-        if (concurrencyGroup != null) {
364
-            newConfig.addDomain(DOMAIN_CONCURRENCY, new HashMap<>());
365
-            newConfig.getKeyDomain(DOMAIN_CONCURRENCY).put("group", concurrencyGroup);
366
-        }
367
-
368
-        if (stop) {
369
-            newConfig.addDomain(DOMAIN_MISC, new HashMap<>());
370
-            newConfig.getKeyDomain(DOMAIN_MISC).put("stopping", "true");
371
-        }
372
-
373
-        int i = 0;
374
-        for (ActionCondition condition : conditions) {
375
-            final Map<String, String> data = new HashMap<>();
376
-
377
-            data.put("argument", String.valueOf(condition.getArg()));
378
-
379
-            if (condition.getArg() == -1) {
380
-                data.put("starget", condition.getStarget());
381
-            } else {
382
-                data.put("component", condition.getComponent().toString());
383
-            }
384
-
385
-            data.put("comparison", condition.getComparison().toString());
386
-            data.put("target", condition.getTarget());
387
-
388
-            newConfig.addDomain("condition " + i, data);
389
-            i++;
390
-        }
391
-
392
-        if (config != null) {
393
-            // Preserve any meta-data
394
-            if (config.isKeyDomain(DOMAIN_METADATA)) {
395
-                newConfig.addDomain(DOMAIN_METADATA, config.getKeyDomain(DOMAIN_METADATA));
396
-            }
397
-
398
-            for (i = 0; config.isKeyDomain("setting " + i); i++) {
399
-                newConfig.addDomain("setting " + i, config.getKeyDomain("setting " + i));
400
-            }
401
-        }
402
-
403
-        try {
404
-            newConfig.write();
405
-
406
-            resetModified();
407
-        } catch (IOException ex) {
408
-            eventBus.publish(new UserErrorEvent(ErrorLevel.HIGH, ex,
409
-                    "I/O error when saving action: " + group + '/' + name + ": " + ex.getMessage(),
410
-                    ""));
411
-        }
412
-
413
-        eventBus.publishAsync(new ActionUpdatedEvent(this));
414
-    }
415
-
416
-    /**
417
-     * Reads a condition from the specified configuration section.
418
-     *
419
-     * @param data The relevant section of the action configuration
420
-     *
421
-     * @return True if the condition is valid, false otherwise
422
-     */
423
-    private boolean readCondition(final Map<String, String> data) {
424
-        final int arg;
425
-        ActionComponent component = null;
426
-        final ActionComparison comparison;
427
-        final String target;
428
-        String starget = null;
429
-
430
-        // ------ Read the argument
431
-        try {
432
-            arg = Integer.parseInt(data.get("argument"));
433
-        } catch (NumberFormatException ex) {
434
-            error(ActionErrorType.CONDITIONS,
435
-                    "Invalid argument number specified: " + data.get("argument"));
436
-            return false;
437
-        }
438
-
439
-        if (arg < -1 || arg >= triggers[0].getType().getArity()) {
440
-            error(ActionErrorType.CONDITIONS, "Invalid argument number specified: " + arg);
441
-            return false;
442
-        }
443
-
444
-        // ------ Read the component or the source
445
-        if (arg == -1) {
446
-            starget = data.get("starget");
447
-
448
-            if (starget == null) {
449
-                error(ActionErrorType.CONDITIONS, "No starget specified");
450
-                return false;
451
-            }
452
-        } else {
453
-            component = readComponent(data, arg);
454
-            if (component == null) {
455
-                return false;
456
-            }
457
-        }
458
-
459
-        // ------ Read the comparison
460
-        comparison = actionController.getComparison(data.get("comparison"));
461
-        if (comparison == null) {
462
-            error(ActionErrorType.CONDITIONS, "Invalid comparison specified: "
463
-                    + data.get("comparison"));
464
-            return false;
465
-        }
466
-
467
-        if ((arg != -1 && !comparison.appliesTo().equals(component.getType()))
468
-                || (arg == -1 && !comparison.appliesTo().equals(String.class))) {
469
-            error(ActionErrorType.CONDITIONS,
470
-                    "Comparison cannot be applied to specified component: " + data.get("comparison"));
471
-            return false;
472
-        }
473
-
474
-        // ------ Read the target
475
-        target = data.get("target");
476
-
477
-        if (target == null) {
478
-            error(ActionErrorType.CONDITIONS, "No target specified for condition");
479
-            return false;
480
-        }
481
-
482
-        if (arg == -1) {
483
-            conditions.add(new ActionCondition(starget, comparison, target));
484
-        } else {
485
-            conditions.add(new ActionCondition(arg, component, comparison, target));
486
-        }
487
-
488
-        return true;
489
-    }
490
-
491
-    /**
492
-     * Reads a component from the specified data section for the specified argument.
493
-     *
494
-     * @param data The relevant section of the action configuration
495
-     * @param arg  The argument number that the component should apply to
496
-     *
497
-     * @return The corresponding ActionComponent, or null if the specified component is invalid.
498
-     */
499
-    private ActionComponent readComponent(final Map<String, String> data, final int arg) {
500
-        final String componentName = data.get("component");
501
-        final ActionComponent component;
502
-
503
-        if (componentName.indexOf('.') == -1) {
504
-            component = actionController.getComponent(componentName);
505
-        } else {
506
-            try {
507
-                component = new ActionComponentChain(triggers[0].getType().getArgTypes()[arg],
508
-                        componentName, actionController);
509
-            } catch (IllegalArgumentException iae) {
510
-                error(ActionErrorType.CONDITIONS, iae.getMessage());
511
-                return null;
512
-            }
513
-        }
514
-
515
-        if (component == null) {
516
-            error(ActionErrorType.CONDITIONS, "Unknown component: " + componentName);
517
-            return null;
518
-        }
519
-
520
-        if (!component.appliesTo().equals(triggers[0].getType().getArgTypes()[arg])) {
521
-            error(ActionErrorType.CONDITIONS,
522
-                    "Component cannot be applied to specified arg in condition: " + componentName);
523
-            return null;
524
-        }
525
-
526
-        return component;
527
-    }
528
-
529
-    /**
530
-     * Raises a trivial error, informing the user of the problem.
531
-     *
532
-     * @param type    The type of error that occurred.
533
-     * @param message The message to be raised
534
-     */
535
-    private void error(final ActionErrorType type, final String message) {
536
-        this.error = message;
537
-        this.errorType = type;
538
-        this.status = ActionStatus.FAILED;
539
-
540
-        eventBus.publish(new UserErrorEvent(ErrorLevel.LOW,
541
-                new IllegalStateException("Error when parsing action: " + group + '/' + name + ": "
542
-                        + message),
543
-                "Error when parsing action" + group + '/' + name + ": " + message, ""));
544
-    }
545
-
546
-    @Override
547
-    public void setName(final String newName) {
548
-        super.setName(newName);
549
-
550
-        try {
551
-            Files.delete(location);
552
-        } catch (IOException ex) {
553
-            //TODO we don't handle the error now, but we should
554
-        }
555
-        location = actionsDirectory.resolve(group).resolve(newName);
556
-
557
-        save();
558
-    }
559
-
560
-    @Override
561
-    public void setGroup(final String newGroup) {
562
-        super.setGroup(newGroup);
563
-
564
-        try {
565
-            Files.delete(location);
566
-        } catch (IOException ex) {
567
-            //TODO we don't handle the error now, but we should
568
-        }
569
-
570
-        location = actionsDirectory.resolve(group).resolve(name);
571
-
572
-        try {
573
-            Files.createDirectories(location);
574
-        } catch (IOException ex) {
575
-            //TODO we don't handle the error now, but we should
576
-        }
577
-
578
-
579
-        save();
580
-    }
581
-
582
-    /**
583
-     * Deletes this action.
584
-     */
585
-    public void delete() {
586
-        eventBus.publishAsync(new ActionDeletedEvent(actionController.getOrCreateGroup(getGroup()), this));
587
-        try {
588
-            Files.delete(location);
589
-        } catch (IOException ex) {
590
-            //TODO we don't handle the error now, but we should
591
-        }
592
-    }
593
-
594
-    @Override
595
-    public String toString() {
596
-        final String parent = super.toString();
597
-
598
-        return parent.substring(0, parent.length() - 1) + ",location=" + location + "]";
599
-    }
600
-
601
-    @Override
602
-    public void configChanged(final String domain, final String key) {
603
-        checkDisabled();
604
-    }
605
-
606
-    /**
607
-     * Checks if this action is disabled or not.
608
-     *
609
-     * @since 0.6.3
610
-     */
611
-    protected void checkDisabled() {
612
-        final String key = (group + "/" + name).replace(' ', '.');
613
-        final boolean disabled = identityController.getGlobalConfiguration().hasOptionBool(
614
-                "disable_action", key)
615
-                && identityController.getGlobalConfiguration().getOptionBool("disable_action", key);
616
-
617
-        if (disabled && status == ActionStatus.ACTIVE) {
618
-            status = ActionStatus.DISABLED;
619
-        } else if (!disabled && status == ActionStatus.DISABLED) {
620
-            status = ActionStatus.ACTIVE;
621
-        }
622
-    }
623
-
624
-    /**
625
-     * Sets whether this action is enabled or not.
626
-     *
627
-     * @param enabled true to enable, false to disable
628
-     */
629
-    public void setEnabled(final boolean enabled) {
630
-        if (enabled) {
631
-            identityController.getUserSettings().unsetOption("disable_action",
632
-                    (group + "/" + name).replace(' ', '.'));
633
-        } else {
634
-            identityController.getUserSettings().setOption("disable_action",
635
-                    (group + "/" + name).replace(' ', '.'), true);
636
-        }
637
-    }
638
-
639
-}

+ 0
- 163
src/com/dmdirc/actions/ActionComponentChain.java View File

@@ -1,163 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.Precondition;
26
-import com.dmdirc.interfaces.ActionController;
27
-import com.dmdirc.interfaces.actions.ActionComponent;
28
-
29
-import java.util.ArrayList;
30
-import java.util.List;
31
-
32
-import static com.google.common.base.Preconditions.checkArgument;
33
-
34
-/**
35
- * An action component chain supports chaining of multiple action components together.
36
- */
37
-public class ActionComponentChain implements ActionComponent {
38
-
39
-    /**
40
-     * A list of components in this chain.
41
-     */
42
-    private final List<ActionComponent> components = new ArrayList<>();
43
-
44
-    /**
45
-     * Creates a new component chain from the specified text representation. Chains are separated
46
-     * with full stops (.).
47
-     *
48
-     * @param source  The class that this chain needs to start with
49
-     * @param chain   The textual representation of the chain
50
-     * @param manager The action manager to use to look up components
51
-     */
52
-    public ActionComponentChain(final Class<?> source, final String chain,
53
-            final ActionController manager) {
54
-        Class<?> current = source;
55
-
56
-        for (String componentName : chain.split("\\.")) {
57
-            final ActionComponent component = manager.getComponent(componentName);
58
-
59
-            if (component == null) {
60
-                throw new IllegalArgumentException("Component " + componentName
61
-                        + " not found");
62
-            } else if (component.appliesTo().isAssignableFrom(current)) {
63
-                components.add(component);
64
-                current = component.getType();
65
-            } else {
66
-                throw new IllegalArgumentException("Component " + componentName
67
-                        + " cannot be applied to " + current.getName());
68
-            }
69
-        }
70
-    }
71
-
72
-    @Override
73
-    public Object get(final Object arg) {
74
-        Object res = arg;
75
-
76
-        for (ActionComponent component : components) {
77
-            if (res == null) {
78
-                return null;
79
-            }
80
-
81
-            res = component.get(res);
82
-        }
83
-
84
-        return res;
85
-    }
86
-
87
-    @Precondition("This component chain has one or more components")
88
-    @Override
89
-    public Class<?> appliesTo() {
90
-        checkArgument(!components.isEmpty());
91
-
92
-        return components.get(0).appliesTo();
93
-    }
94
-
95
-    @Precondition("This component chain has one or more components")
96
-    @Override
97
-    public Class<?> getType() {
98
-        checkArgument(!components.isEmpty());
99
-
100
-        return components.get(components.size() - 1).getType();
101
-    }
102
-
103
-    @Precondition("This component chain has one or more components")
104
-    @Override
105
-    public String getName() {
106
-        checkArgument(!components.isEmpty());
107
-
108
-        final StringBuilder name = new StringBuilder();
109
-
110
-        for (ActionComponent component : components) {
111
-            name.append("'s ");
112
-            name.append(component.getName());
113
-        }
114
-
115
-        return name.substring(3);
116
-    }
117
-
118
-    @Override
119
-    @Precondition("This component chain has one or more components")
120
-    public String toString() {
121
-        checkArgument(!components.isEmpty());
122
-
123
-        final StringBuilder name = new StringBuilder();
124
-
125
-        for (ActionComponent component : components) {
126
-            name.append('.');
127
-            name.append(component.toString());
128
-        }
129
-
130
-        return name.substring(1);
131
-    }
132
-
133
-    @Override
134
-    public String name() {
135
-        return toString();
136
-    }
137
-
138
-    /**
139
-     * Determines if any components in this chain require a server to have an established connection
140
-     * in order to function.
141
-     *
142
-     * @since 0.6.4
143
-     * @return True iff at least one component requires a connection
144
-     */
145
-    public boolean requiresConnection() {
146
-        boolean res = false;
147
-
148
-        for (ActionComponent component : components) {
149
-            try {
150
-                final ComponentOptions options = component.getClass()
151
-                        .getMethod("get", Object.class).getAnnotation(ComponentOptions.class);
152
-                if (options != null) {
153
-                    res |= options.requireConnected();
154
-                }
155
-            } catch (NoSuchMethodException ex) {
156
-                // Do nothing
157
-            }
158
-        }
159
-
160
-        return res;
161
-    }
162
-
163
-}

+ 0
- 212
src/com/dmdirc/actions/ActionCondition.java View File

@@ -1,212 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.interfaces.actions.ActionComparison;
26
-import com.dmdirc.interfaces.actions.ActionComponent;
27
-
28
-/**
29
- * An action condition represents one condition within an action.
30
- */
31
-public class ActionCondition {
32
-
33
-    /** The argument number that this action condition applies to. */
34
-    private int arg;
35
-    /** The component that this action condition applies to. */
36
-    private ActionComponent component;
37
-    /** The comparison that should be used for this condition. */
38
-    private ActionComparison comparison;
39
-    /** The target of the comparison for this condition. */
40
-    private String target = "";
41
-    /** The source target for this comparison. */
42
-    private String starget = "";
43
-
44
-    /**
45
-     * Creates a new instance of ActionCondition that compares the output of a component to a
46
-     * string.
47
-     *
48
-     * @param arg        The argument number to be tested
49
-     * @param component  The component to be tested
50
-     * @param comparison The comparison to be used
51
-     * @param target     The target of the comparison
52
-     */
53
-    public ActionCondition(final int arg, final ActionComponent component,
54
-            final ActionComparison comparison, final String target) {
55
-
56
-        this.arg = arg;
57
-        this.component = component;
58
-        this.comparison = comparison;
59
-        this.target = target;
60
-    }
61
-
62
-    /**
63
-     * Creates a new instance of ActionCondition that compares two strings.
64
-     *
65
-     * @param starget    The first target for comparison.
66
-     * @param comparison The comparison to be used
67
-     * @param target     The second target for the comparison
68
-     */
69
-    public ActionCondition(final String starget, final ActionComparison comparison,
70
-            final String target) {
71
-
72
-        this.arg = -1;
73
-        this.starget = starget;
74
-        this.comparison = comparison;
75
-        this.target = target;
76
-    }
77
-
78
-    /**
79
-     * Tests to see if this condition holds.
80
-     *
81
-     * @param sub  The substitutor to use for this
82
-     * @param args The event arguments to be tested
83
-     *
84
-     * @return True if the condition holds, false otherwise
85
-     */
86
-    public boolean test(final ActionSubstitutor sub, final Object... args) {
87
-        final String thisTarget = sub.doSubstitution(getTarget(), args);
88
-
89
-        if (arg == -1) {
90
-            final String thisStarget = sub.doSubstitution(starget, args);
91
-            return getComparison().test(thisStarget, thisTarget);
92
-        } else {
93
-            return getComparison().test(getComponent().get(args[getArg()]), thisTarget);
94
-        }
95
-    }
96
-
97
-    /**
98
-     * Returns the argument number this condition applies to.
99
-     *
100
-     * @return Argument number
101
-     */
102
-    public int getArg() {
103
-        return arg;
104
-    }
105
-
106
-    /**
107
-     * Returns the component this condition applies to.
108
-     *
109
-     * @return Component to apply condition to
110
-     */
111
-    public ActionComponent getComponent() {
112
-        return component;
113
-    }
114
-
115
-    /**
116
-     * Returns the comparison this condition applies to.
117
-     *
118
-     * @return Comparison to be used
119
-     */
120
-    public ActionComparison getComparison() {
121
-        return comparison;
122
-    }
123
-
124
-    /**
125
-     * Returns the target of the comparison for this condition.
126
-     *
127
-     * @return Target for comparison
128
-     */
129
-    public String getTarget() {
130
-        return target;
131
-    }
132
-
133
-    /**
134
-     * Sets the argument number this condition applies to.
135
-     *
136
-     * @param arg Argument number
137
-     */
138
-    public void setArg(final int arg) {
139
-        this.arg = arg;
140
-    }
141
-
142
-    /**
143
-     * Sets the component this condition applies to.
144
-     *
145
-     * @param component Component to apply condition to
146
-     */
147
-    public void setComponent(final ActionComponent component) {
148
-        this.component = component;
149
-    }
150
-
151
-    /**
152
-     * Sets the comparison this condition applies to.
153
-     *
154
-     * @param comparison Comparison to be used
155
-     */
156
-    public void setComparison(final ActionComparison comparison) {
157
-        this.comparison = comparison;
158
-    }
159
-
160
-    /**
161
-     * Sets the target of the comparison for this condition.
162
-     *
163
-     * @param target Target for comparison
164
-     */
165
-    public void setTarget(final String target) {
166
-        this.target = target;
167
-    }
168
-
169
-    /**
170
-     * Retrieves the starget of this condition.
171
-     *
172
-     * @return This condition's starget, or null if none was set.
173
-     */
174
-    public String getStarget() {
175
-        return starget;
176
-    }
177
-
178
-    /**
179
-     * Sets the starget for this condition.
180
-     *
181
-     * @param starget The new starget for this condition.
182
-     */
183
-    public void setStarget(final String starget) {
184
-        this.starget = starget;
185
-    }
186
-
187
-    @Override
188
-    public String toString() {
189
-        return "[ arg=" + arg + ", component=" + component + ", comparison="
190
-                + comparison + ", target=" + target + ", starget=" + starget + " ]";
191
-    }
192
-
193
-    @Override
194
-    public boolean equals(final Object obj) {
195
-        if (!(obj instanceof ActionCondition)) {
196
-            return false;
197
-        }
198
-
199
-        final ActionCondition o = (ActionCondition) obj;
200
-
201
-        return arg == o.getArg() && component == o.getComponent()
202
-                && comparison == o.getComparison() && target.equals(o.getTarget())
203
-                && starget.equals(o.getStarget());
204
-    }
205
-
206
-    @Override
207
-    public int hashCode() {
208
-        return arg + 100 * (arg == -1 ? starget.hashCode() : component.hashCode())
209
-                + 10000 * comparison.hashCode() + 100000 * target.hashCode();
210
-    }
211
-
212
-}

+ 0
- 43
src/com/dmdirc/actions/ActionErrorType.java View File

@@ -1,43 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-/**
26
- * An enumeration of possible types of error an action may encounter.
27
- *
28
- * @since 0.6.6
29
- */
30
-public enum ActionErrorType {
31
-
32
-    /** A low-level problem occurred trying to read the action's file. */
33
-    FILE,
34
-    /** A problem with the action's triggers. */
35
-    TRIGGERS,
36
-    /** A problem with the action's response. */
37
-    RESPONSE,
38
-    /** A problem with the action's condition tree. */
39
-    CONDITION_TREE,
40
-    /** A problem with the action's conditions. */
41
-    CONDITIONS
42
-
43
-}

+ 0
- 135
src/com/dmdirc/actions/ActionFactory.java View File

@@ -1,135 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.GlobalWindow;
27
-import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
28
-import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
29
-import com.dmdirc.interfaces.ActionController;
30
-import com.dmdirc.interfaces.actions.ActionType;
31
-import com.dmdirc.interfaces.config.IdentityController;
32
-
33
-import java.nio.file.Path;
34
-import java.util.List;
35
-
36
-import javax.inject.Inject;
37
-import javax.inject.Provider;
38
-import javax.inject.Singleton;
39
-
40
-/**
41
- * Factory for creating {@link Action}s.
42
- */
43
-@Singleton
44
-public class ActionFactory {
45
-
46
-    /** The controller that will own actions. */
47
-    private final Provider<ActionController> actionController;
48
-    /** The controller to use to retrieve and update settings. */
49
-    private final Provider<IdentityController> identityController;
50
-    /** The global window to use for actions without windows. */
51
-    private final Provider<GlobalWindow> globalWindowProvider;
52
-    /** The factory to use to create substitutors. */
53
-    private final ActionSubstitutorFactory substitutorFactory;
54
-    /** The base directory to store actions in. */
55
-    private final Path actionsDirectory;
56
-    /** Event bus to post events on. */
57
-    private final DMDircMBassador eventBus;
58
-
59
-    /**
60
-     * Creates a new instance of {@link ActionFactory}.
61
-     *
62
-     * @param eventBus                    The event bus to post events on.
63
-     * @param actionController            The controller that will own actions.
64
-     * @param identityController          The controller to use to retrieve and update settings.
65
-     * @param globalWindowProvider        The global window to use for actions without windows.
66
-     * @param substitutorFactory          The factory to use to create substitutors.
67
-     * @param actionsDirectory            The base directory to store actions in.
68
-     */
69
-    @Inject
70
-    public ActionFactory(final DMDircMBassador eventBus, final Provider<ActionController> actionController,
71
-            final Provider<IdentityController> identityController,
72
-            final Provider<GlobalWindow> globalWindowProvider,
73
-            final ActionSubstitutorFactory substitutorFactory,
74
-            @Directory(DirectoryType.ACTIONS) final Path actionsDirectory) {
75
-        this.eventBus = eventBus;
76
-        this.actionController = actionController;
77
-        this.identityController = identityController;
78
-        this.globalWindowProvider = globalWindowProvider;
79
-        this.substitutorFactory = substitutorFactory;
80
-        this.actionsDirectory = actionsDirectory;
81
-    }
82
-
83
-    /**
84
-     * Creates a new instance of Action. The group and name specified must be the group and name of
85
-     * a valid action already saved to disk.
86
-     *
87
-     * @param group The group the action belongs to
88
-     * @param name  The name of the action
89
-     *
90
-     * @return A relevant action.
91
-     */
92
-    public Action getAction(final String group, final String name) {
93
-        return new Action(
94
-                eventBus, globalWindowProvider,
95
-                substitutorFactory,
96
-                actionController.get(),
97
-                identityController.get(),
98
-                actionsDirectory,
99
-                group,
100
-                name);
101
-    }
102
-
103
-    /**
104
-     * Creates a new instance of Action with the specified properties and saves it to disk.
105
-     *
106
-     * @param group         The group the action belongs to
107
-     * @param name          The name of the action
108
-     * @param triggers      The triggers to use
109
-     * @param response      The response to use
110
-     * @param conditions    The conditions to use
111
-     * @param conditionTree The condition tree to use
112
-     * @param newFormat     The new formatter to use
113
-     *
114
-     * @return A relevant action.
115
-     */
116
-    public Action getAction(final String group, final String name,
117
-            final ActionType[] triggers, final String[] response,
118
-            final List<ActionCondition> conditions,
119
-            final ConditionTree conditionTree, final String newFormat) {
120
-        return new Action(
121
-                eventBus, globalWindowProvider,
122
-                substitutorFactory,
123
-                actionController.get(),
124
-                identityController.get(),
125
-                actionsDirectory,
126
-                group,
127
-                name,
128
-                triggers,
129
-                response,
130
-                conditions,
131
-                conditionTree,
132
-                newFormat);
133
-    }
134
-
135
-}

+ 0
- 239
src/com/dmdirc/actions/ActionGroup.java View File

@@ -1,239 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.Precondition;
26
-import com.dmdirc.config.prefs.PreferencesSetting;
27
-import com.dmdirc.updater.Version;
28
-
29
-import java.util.ArrayList;
30
-import java.util.HashMap;
31
-import java.util.Iterator;
32
-import java.util.List;
33
-import java.util.Map;
34
-
35
-import static com.google.common.base.Preconditions.checkArgument;
36
-import static com.google.common.base.Preconditions.checkNotNull;
37
-
38
-/**
39
- * Represents a group of actions, along with their meta-data.
40
- */
41
-public class ActionGroup implements Iterable<Action> {
42
-
43
-    /** The actions in this group. */
44
-    private final List<Action> actions = new ArrayList<>();
45
-    /** The name of this action group. */
46
-    private final String name;
47
-    /** The description of this action group. */
48
-    private String description;
49
-    /** The author of this action group. */
50
-    private String author;
51
-    /** The component number of this action group (for updating). */
52
-    private int component = -1;
53
-    /** The version of this action group. */
54
-    private Version version;
55
-    /** A list of settings used by this action group. */
56
-    private final Map<String, PreferencesSetting> settings = new HashMap<>();
57
-    /** Action manager. */
58
-    private final ActionManager actionManager;
59
-
60
-    /**
61
-     * Creates a new instance of ActionGroup.
62
-     *
63
-     * @param actionManager The action manager used to manager this group.
64
-     * @param name          The name of this action group
65
-     */
66
-    public ActionGroup(final ActionManager actionManager, final String name) {
67
-        this.actionManager = actionManager;
68
-        this.name = name;
69
-    }
70
-
71
-    /**
72
-     * Retrieves the author of this ActionGroup.
73
-     *
74
-     * @return This action group's author, or null if the author isn't specified
75
-     */
76
-    public String getAuthor() {
77
-        return author;
78
-    }
79
-
80
-    /**
81
-     * Sets the author of this ActionGroup.
82
-     *
83
-     * @param author The new author for this action group
84
-     */
85
-    public void setAuthor(final String author) {
86
-        this.author = author;
87
-    }
88
-
89
-    /**
90
-     * Retrieves the description of this action group.
91
-     *
92
-     * @return This action group's description, or null if none is specified
93
-     */
94
-    public String getDescription() {
95
-        return description;
96
-    }
97
-
98
-    /**
99
-     * Sets the description for this action group.
100
-     *
101
-     * @param description The new description for this action group
102
-     */
103
-    public void setDescription(final String description) {
104
-        this.description = description;
105
-    }
106
-
107
-    /**
108
-     * Retrieves the name of this action group.
109
-     *
110
-     * @return This action group's name
111
-     */
112
-    public String getName() {
113
-        return name;
114
-    }
115
-
116
-    /**
117
-     * Retrieves a map settings used by this action group.
118
-     *
119
-     * @return A map of setting names to values
120
-     */
121
-    public Map<String, PreferencesSetting> getSettings() {
122
-        return settings;
123
-    }
124
-
125
-    /**
126
-     * Retrieves the version number of this action group.
127
-     *
128
-     * @return This action group's version number, or null if none is specified.
129
-     *
130
-     * @since 0.6.4
131
-     */
132
-    public Version getVersion() {
133
-        return version;
134
-    }
135
-
136
-    /**
137
-     * Sets the version of this action group.
138
-     *
139
-     * @param version This action group's new version.
140
-     *
141
-     * @since 0.6.4
142
-     */
143
-    public void setVersion(final Version version) {
144
-        this.version = version;
145
-    }
146
-
147
-    /**
148
-     * Retrieves the addon site component number for this action group.
149
-     *
150
-     * @return The component number for this action group, or -1 if none is specified.
151
-     */
152
-    public int getComponent() {
153
-        return component;
154
-    }
155
-
156
-    /**
157
-     * Sets the addon site component number for this action group.
158
-     *
159
-     * @param component The component number for this action group
160
-     */
161
-    public void setComponent(final int component) {
162
-        this.component = component;
163
-    }
164
-
165
-    /**
166
-     * Removes the specified action from this group.
167
-     *
168
-     * @param action The action to be removed
169
-     */
170
-    public void remove(final Action action) {
171
-        actions.remove(action);
172
-    }
173
-
174
-    @Override
175
-    public Iterator<Action> iterator() {
176
-        return actions.iterator();
177
-    }
178
-
179
-    /**
180
-     * Removes all actions from this group, and removes all meta-data.
181
-     */
182
-    public void clear() {
183
-        new ArrayList<>(actions).forEach(this::remove);
184
-
185
-        settings.clear();
186
-        description = null;
187
-        author = null;
188
-        version = null;
189
-        component = -1;
190
-    }
191
-
192
-    /**
193
-     * Adds the specified action to this group.
194
-     *
195
-     * @param action The action to be added
196
-     */
197
-    public void add(final Action action) {
198
-        actions.add(action);
199
-    }
200
-
201
-    /**
202
-     * Retrieves a copy of the list of all actions in this group.
203
-     *
204
-     * @return A list of actions in this group
205
-     */
206
-    public List<Action> getActions() {
207
-        return new ArrayList<>(actions);
208
-    }
209
-
210
-    /**
211
-     * Deletes an action from this group.
212
-     *
213
-     * @param action The action to be deleted
214
-     *
215
-     * @since 0.6.3
216
-     */
217
-    @Precondition({
218
-        "The specified action is non-null",
219
-        "The specified action exists in this group"
220
-    })
221
-    @SuppressWarnings("deprecation")
222
-    public void deleteAction(final Action action) {
223
-        checkNotNull(action);
224
-        checkArgument(actions.contains(action));
225
-
226
-        actionManager.removeAction(action);
227
-        action.delete();
228
-    }
229
-
230
-    /**
231
-     * Determines if this action group is delible or not.
232
-     *
233
-     * @return True if the group may be deleted, false if it may not.
234
-     */
235
-    public boolean isDelible() {
236
-        return true;
237
-    }
238
-
239
-}

+ 0
- 628
src/com/dmdirc/actions/ActionManager.java View File

@@ -1,628 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.Precondition;
27
-import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
28
-import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
29
-import com.dmdirc.config.ConfigBinding;
30
-import com.dmdirc.events.AppErrorEvent;
31
-import com.dmdirc.events.ClientClosedEvent;
32
-import com.dmdirc.events.DMDircEvent;
33
-import com.dmdirc.events.DisplayableEvent;
34
-import com.dmdirc.events.UserErrorEvent;
35
-import com.dmdirc.interfaces.ActionController;
36
-import com.dmdirc.interfaces.actions.ActionComparison;
37
-import com.dmdirc.interfaces.actions.ActionComponent;
38
-import com.dmdirc.interfaces.actions.ActionType;
39
-import com.dmdirc.interfaces.config.IdentityController;
40
-import com.dmdirc.logger.ErrorLevel;
41
-import com.dmdirc.updater.components.ActionGroupComponent;
42
-import com.dmdirc.updater.manager.UpdateManager;
43
-import com.dmdirc.util.collections.MapList;
44
-import com.dmdirc.util.io.FileUtils;
45
-
46
-import java.io.File;
47
-import java.io.IOException;
48
-import java.lang.reflect.Method;
49
-import java.nio.file.Files;
50
-import java.nio.file.Path;
51
-import java.nio.file.Paths;
52
-import java.util.ArrayList;
53
-import java.util.Collection;
54
-import java.util.Collections;
55
-import java.util.HashMap;
56
-import java.util.List;
57
-import java.util.Map;
58
-import java.util.stream.Collectors;
59
-
60
-import javax.inject.Inject;
61
-import javax.inject.Provider;
62
-import javax.inject.Singleton;
63
-
64
-import org.slf4j.Logger;
65
-import org.slf4j.LoggerFactory;
66
-
67
-import net.engio.mbassy.listener.Handler;
68
-
69
-import static com.google.common.base.Preconditions.checkArgument;
70
-import static com.google.common.base.Preconditions.checkNotNull;
71
-
72
-/**
73
- * Manages all actions for the client.
74
- */
75
-@Singleton
76
-public class ActionManager implements ActionController {
77
-
78
-    private static final Logger LOG = LoggerFactory.getLogger(ActionManager.class);
79
-    /** The identity manager to load configuration from. */
80
-    private final IdentityController identityManager;
81
-    /** The factory to use to create actions. */
82
-    private final ActionFactory factory;
83
-    /** Provider of an update manager. */
84
-    private final Provider<UpdateManager> updateManagerProvider;
85
-    /** A list of registered action types. */
86
-    private final Collection<ActionType> types = new ArrayList<>();
87
-    /** A list of registered action components. */
88
-    private final Collection<ActionComponent> components = new ArrayList<>();
89
-    /** A list of registered action comparisons. */
90
-    private final Collection<ActionComparison> comparisons = new ArrayList<>();
91
-    /** A map linking types and a list of actions that're registered for them. */
92
-    private final MapList<ActionType, Action> actions = new MapList<>();
93
-    /** A map linking groups and a list of actions that're in them. */
94
-    private final Map<String, ActionGroup> groups = new HashMap<>();
95
-    /** A map of objects to synchronise on for concurrency groups. */
96
-    private final Map<String, Object> locks = new HashMap<>();
97
-    /** A map of the action type groups to the action types within. */
98
-    private final MapList<String, ActionType> typeGroups = new MapList<>();
99
-    /** The global event bus to monitor. */
100
-    private final DMDircMBassador eventBus;
101
-    /** The directory to load and save actions in. */
102
-    private final String directory;
103
-    /** Indicates whether or not user actions should be killed (not processed). */
104
-    @ConfigBinding(domain = "actions", key = "killswitch")
105
-    private boolean killSwitch;
106
-
107
-    /**
108
-     * Creates a new instance of ActionManager.
109
-     *
110
-     * @param identityManager        The IdentityManager to load configuration from.
111
-     * @param factory                The factory to use to create new actions.
112
-     * @param updateManagerProvider  Provider of an update manager, to register components.
113
-     * @param eventBus               The global event bus to monitor.
114
-     * @param directory              The directory to load and save actions in.
115
-     */
116
-    @Inject
117
-    public ActionManager(
118
-            final IdentityController identityManager,
119
-            final ActionFactory factory,
120
-            final Provider<UpdateManager> updateManagerProvider,
121
-            final DMDircMBassador eventBus,
122
-            @Directory(DirectoryType.ACTIONS) final String directory) {
123
-        this.identityManager = identityManager;
124
-        this.factory = factory;
125
-        this.updateManagerProvider = updateManagerProvider;
126
-        this.eventBus = eventBus;
127
-        this.directory = directory;
128
-    }
129
-
130
-    /**
131
-     * Initialiases the actions manager.
132
-     *
133
-     * @param colourComparisons The colour comparisons to use.
134
-     */
135
-    // TODO: Refactor to take a list of comparisons/sources.
136
-    public void initialise(final ColourActionComparison colourComparisons) {
137
-        LOG.info("Initialising the actions manager");
138
-
139
-        identityManager.getGlobalConfiguration().getBinder().bind(this, ActionManager.class);
140
-
141
-        registerTypes(CoreActionType.values());
142
-        registerComparisons(CoreActionComparison.values());
143
-        registerComparisons(colourComparisons.getComparisons());
144
-        registerComponents(CoreActionComponent.values());
145
-
146
-        eventBus.subscribe(this);
147
-    }
148
-
149
-    @Override
150
-    public void saveAllActions() {
151
-        for (ActionGroup group : groups.values()) {
152
-            for (Action action : group) {
153
-                action.save();
154
-            }
155
-        }
156
-    }
157
-
158
-    /**
159
-     * Saves all actions when the client is being closed.
160
-     *
161
-     * @param event The event that was raised.
162
-     */
163
-    @Handler
164
-    public void handleClientClosed(final ClientClosedEvent event) {
165
-        LOG.debug("Client closed - saving all actions");
166
-        saveAllActions();
167
-    }
168
-
169
-    @Override
170
-    public void registerSetting(final String name, final String value) {
171
-        LOG.debug("Registering new action setting: {} = {}", name, value);
172
-        identityManager.getAddonSettings().setOption("actions", name, value);
173
-    }
174
-
175
-    @Override
176
-    public void addGroup(final ActionGroup group) {
177
-        groups.put(group.getName(), group);
178
-    }
179
-
180
-    @Override
181
-    public void registerTypes(final ActionType[] newTypes) {
182
-        for (ActionType type : newTypes) {
183
-            checkNotNull(type);
184
-
185
-            if (!types.contains(type)) {
186
-                LOG.debug("Registering action type: {}", type);
187
-                types.add(type);
188
-                typeGroups.add(type.getType().getGroup(), type);
189
-            }
190
-        }
191
-    }
192
-
193
-    @Override
194
-    public void registerComponents(final ActionComponent[] comps) {
195
-        for (ActionComponent comp : comps) {
196
-            checkNotNull(comp);
197
-
198
-            LOG.debug("Registering action component: {}", comp);
199
-            components.add(comp);
200
-        }
201
-    }
202
-
203
-    @Override
204
-    public void registerComparisons(final ActionComparison[] comps) {
205
-        for (ActionComparison comp : comps) {
206
-            checkNotNull(comp);
207
-
208
-            LOG.debug("Registering action comparison: {}", comp);
209
-            comparisons.add(comp);
210
-        }
211
-    }
212
-
213
-    @Override
214
-    public Map<String, ActionGroup> getGroupsMap() {
215
-        return Collections.unmodifiableMap(groups);
216
-    }
217
-
218
-    @Override
219
-    public MapList<String, ActionType> getGroupedTypes() {
220
-        return new MapList<>(typeGroups);
221
-    }
222
-
223
-    @Override
224
-    public void loadUserActions() {
225
-        actions.clear();
226
-
227
-        groups.values().forEach(ActionGroup::clear);
228
-
229
-        final File dir = new File(directory);
230
-
231
-        if (!dir.exists()) {
232
-            try {
233
-                dir.mkdirs();
234
-                dir.createNewFile();
235
-            } catch (IOException ex) {
236
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.HIGH, null,
237
-                        "I/O error when creating actions directory: " + ex.getMessage(), ""));
238
-            }
239
-        }
240
-
241
-        if (dir.listFiles() == null) {
242
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
243
-                    "Unable to load user action files", ""));
244
-        } else {
245
-            for (File file : dir.listFiles()) {
246
-                if (file.isDirectory()) {
247
-                    loadActions(file);
248
-                }
249
-            }
250
-        }
251
-
252
-        registerComponents(updateManagerProvider.get());
253
-    }
254
-
255
-    /**
256
-     * Creates new ActionGroupComponents for each action group.
257
-     *
258
-     * @param updateManager The update manager to register components with
259
-     */
260
-    private void registerComponents(final UpdateManager updateManager) {
261
-        groups.values().stream()
262
-                .filter(group -> group.getComponent() != -1 && group.getVersion() != null)
263
-                .forEach(group -> updateManager.addComponent(
264
-                        new ActionGroupComponent(this, group)));
265
-    }
266
-
267
-    /**
268
-     * Loads action files from a specified group directory.
269
-     *
270
-     * @param dir The directory to scan.
271
-     */
272
-    @Precondition("The specified File is not null and represents a directory")
273
-    private void loadActions(final File dir) {
274
-        checkNotNull(dir);
275
-        checkArgument(dir.isDirectory());
276
-
277
-        LOG.debug("Loading actions from directory: {}", dir.getAbsolutePath());
278
-
279
-        if (!groups.containsKey(dir.getName())) {
280
-            groups.put(dir.getName(), new ActionGroup(this, dir.getName()));
281
-        }
282
-
283
-        for (File file : dir.listFiles()) {
284
-            factory.getAction(dir.getName(), file.getName());
285
-        }
286
-    }
287
-
288
-    @Override
289
-    public void addAction(final Action action) {
290
-        checkNotNull(action);
291
-
292
-        LOG.debug("Registering action: {}/{} (status: {})", action.getGroup(), action.getName(),
293
-                action.getStatus());
294
-
295
-        if (action.getStatus() != ActionStatus.FAILED) {
296
-            for (ActionType trigger : action.getTriggers()) {
297
-                LOG.trace("Action has trigger {}", trigger);
298
-                actions.add(trigger, action);
299
-            }
300
-        }
301
-
302
-        getOrCreateGroup(action.getGroup()).add(action);
303
-    }
304
-
305
-    @Override
306
-    public ActionGroup getOrCreateGroup(final String name) {
307
-        if (!groups.containsKey(name)) {
308
-            groups.put(name, new ActionGroup(this, name));
309
-        }
310
-
311
-        return groups.get(name);
312
-    }
313
-
314
-    @Override
315
-    public void removeAction(final Action action) {
316
-        checkNotNull(action);
317
-
318
-        actions.removeFromAll(action);
319
-        getOrCreateGroup(action.getGroup()).remove(action);
320
-    }
321
-
322
-    @Override
323
-    public void reregisterAction(final Action action) {
324
-        removeAction(action);
325
-        addAction(action);
326
-    }
327
-
328
-    @Override
329
-    public boolean triggerEvent(final ActionType type,
330
-            final StringBuffer format, final Object... arguments) {
331
-        checkNotNull(type);
332
-        checkNotNull(type.getType());
333
-        checkArgument(type.getType().getArity() == arguments.length);
334
-
335
-        LOG.trace("Calling listeners for event of type {}", type);
336
-
337
-        return killSwitch || !triggerActions(type, format, arguments);
338
-    }
339
-
340
-    /**
341
-     * Triggers actions that respond to the specified type.
342
-     *
343
-     * @param type      The type of the event to process
344
-     * @param format    The format of the message that's going to be displayed for the event.
345
-     *                  Actions may change this format.
346
-     * @param arguments The arguments for the event
347
-     *
348
-     * @return True if the event should be skipped, or false if it can continue
349
-     */
350
-    @Precondition("The specified ActionType is not null")
351
-    private boolean triggerActions(final ActionType type,
352
-            final StringBuffer format, final Object... arguments) {
353
-        checkNotNull(type);
354
-
355
-        LOG.trace("Executing actions for event of type {}", type);
356
-
357
-        boolean res = false;
358
-        if (actions.containsKey(type)) {
359
-            for (Action action : new ArrayList<>(actions.get(type))) {
360
-                try {
361
-                    if (action.getConcurrencyGroup() == null) {
362
-                        res |= action.trigger(format, arguments);
363
-                    } else {
364
-                        synchronized (locks) {
365
-                            if (!locks.containsKey(action.getConcurrencyGroup())) {
366
-                                locks.put(action.getConcurrencyGroup(), new Object());
367
-                            }
368
-                        }
369
-
370
-                        synchronized (locks.get(action.getConcurrencyGroup())) {
371
-                            res |= action.trigger(format, arguments);
372
-                        }
373
-                    }
374
-                } catch (LinkageError | Exception e) {
375
-                    eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e,
376
-                            "Error processing action: " + e.getMessage(), ""));
377
-                }
378
-            }
379
-        }
380
-
381
-        return res;
382
-    }
383
-
384
-    /**
385
-     * Processes an event from the event bus.
386
-     *
387
-     * @param event The event that was raised.
388
-     */
389
-    @Handler
390
-    public void processEvent(final DMDircEvent event) {
391
-        final ActionType type = getType(getLegacyActionTypeName(event));
392
-        if (type == null) {
393
-            LOG.warn("Unable to locate legacy type for event {}", event.getClass().getName());
394
-            return;
395
-        }
396
-
397
-        final Class<?>[] argTypes = type.getType().getArgTypes();
398
-        final Object[] arguments = getLegacyArguments(event, argTypes);
399
-
400
-        if (event instanceof DisplayableEvent) {
401
-            final DisplayableEvent displayable = (DisplayableEvent) event;
402
-            final StringBuffer buffer = new StringBuffer(displayable.getDisplayFormat());
403
-            triggerEvent(type, buffer, arguments);
404
-            displayable.setDisplayFormat(buffer.toString());
405
-        } else {
406
-            triggerEvent(type, null, arguments);
407
-        }
408
-    }
409
-
410
-    /**
411
-     * Gets the name of the legacy {@link ActionType} to which the given event corresponds.
412
-     *
413
-     * @param event The event to obtain the name of.
414
-     *
415
-     * @return The legacy action type name.
416
-     */
417
-    private static String getLegacyActionTypeName(final DMDircEvent event) {
418
-        return event.getClass().getSimpleName()
419
-                .replaceAll("Event$", "")
420
-                .replaceAll("(.)([A-Z])", "$1_$2")
421
-                .toUpperCase();
422
-    }
423
-
424
-    /**
425
-     * Attempts to obtain a legacy arguments array from the given event. Arguments will be matched
426
-     * based on their expected classes. Where an event provides multiple getters of the same type,
427
-     * the one closest in index to the argument index will be used.
428
-     *
429
-     * @param event    The event to get legacy arguments for.
430
-     * @param argTypes The type of arguments expected for the action type.
431
-     *
432
-     * @return An array of objects containing the legacy arguments.
433
-     */
434
-    private static Object[] getLegacyArguments(final DMDircEvent event, final Class<?>[] argTypes) {
435
-        final Object[] arguments = new Object[argTypes.length];
436
-        final Method[] methods = event.getClass().getMethods();
437
-
438
-        for (int i = 0; i < argTypes.length; i++) {
439
-            final Class<?> target = argTypes[i];
440
-            Method best = null;
441
-            int bestDistance = Integer.MAX_VALUE;
442
-
443
-            for (int j = 0; j < methods.length; j++) {
444
-                final Method method = methods[j];
445
-                if (method.getParameterTypes().length == 0
446
-                        && method.getName().startsWith("get")
447
-                        && !"getDisplayFormat".equals(method.getName())
448
-                        && method.getReturnType().equals(target)
449
-                        && Math.abs(j - i) < bestDistance) {
450
-                    bestDistance = Math.abs(j - i);
451
-                    best = method;
452
-                }
453
-            }
454
-
455
-            if (best == null) {
456
-                LOG.error("Unable to find method on event {} to satisfy argument #{} of class {}",
457
-                        event.getClass().getName(), i, target.getName());
458
-                arguments[i] = null;
459
-            } else {
460
-                try {
461
-                    arguments[i] = best.invoke(event);
462
-                } catch (ReflectiveOperationException ex) {
463
-                    LOG.error("Unable to invoke method {} on {} to get action argument",
464
-                            best.getName(), event.getClass().getName(), ex);
465
-                }
466
-            }
467
-        }
468
-
469
-        return arguments;
470
-    }
471
-
472
-    @Override
473
-    public ActionGroup createGroup(final String group) {
474
-        checkNotNull(group);
475
-        checkArgument(!group.isEmpty());
476
-        checkArgument(!groups.containsKey(group));
477
-
478
-        final File file = new File(directory + group);
479
-        if (file.isDirectory() || file.mkdir()) {
480
-            final ActionGroup actionGroup = new ActionGroup(this, group);
481
-            groups.put(group, actionGroup);
482
-            return actionGroup;
483
-        } else {
484
-            throw new IllegalArgumentException("Unable to create action group directory"
485
-                    + "\n\nDir: " + directory + group);
486
-        }
487
-    }
488
-
489
-    @Override
490
-    public void deleteGroup(final String group) {
491
-        checkNotNull(group);
492
-        checkArgument(!group.isEmpty());
493
-        checkArgument(groups.containsKey(group));
494
-
495
-        groups.get(group).getActions().forEach(this::removeAction);
496
-
497
-        final File dir = new File(directory + group);
498
-
499
-        if (dir.isDirectory()) {
500
-            for (File file : dir.listFiles()) {
501
-                if (!file.delete()) {
502
-                    eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
503
-                            "Unable to remove file: " + file.getAbsolutePath(), ""));
504
-                    return;
505
-                }
506
-            }
507
-        }
508
-
509
-        if (!dir.delete()) {
510
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
511
-                    "Unable to remove directory: " + dir.getAbsolutePath(), ""));
512
-            return;
513
-        }
514
-
515
-        groups.remove(group);
516
-    }
517
-
518
-    @Override
519
-    public void changeGroupName(final String oldName, final String newName) {
520
-        checkNotNull(oldName);
521
-        checkArgument(!oldName.isEmpty());
522
-        checkNotNull(newName);
523
-        checkArgument(!newName.isEmpty());
524
-        checkArgument(groups.containsKey(oldName));
525
-        checkArgument(!groups.containsKey(newName));
526
-        checkArgument(!newName.equals(oldName));
527
-
528
-        createGroup(newName);
529
-
530
-        for (Action action : groups.get(oldName).getActions()) {
531
-            action.setGroup(newName);
532
-            getOrCreateGroup(oldName).remove(action);
533
-            getOrCreateGroup(newName).add(action);
534
-        }
535
-
536
-        deleteGroup(oldName);
537
-    }
538
-
539
-    @Override
540
-    public ActionType getType(final String type) {
541
-        if (type == null || type.isEmpty()) {
542
-            return null;
543
-        }
544
-
545
-        for (ActionType target : types) {
546
-            if (target.name().equals(type)) {
547
-                return target;
548
-            }
549
-        }
550
-
551
-        return null;
552
-    }
553
-
554
-    @Override
555
-    public List<ActionType> findCompatibleTypes(final ActionType type) {
556
-        checkNotNull(type);
557
-
558
-        final List<ActionType> res = types.stream()
559
-                .filter(target -> !target.equals(type) && target.getType().equals(type.getType()))
560
-                .collect(Collectors.toList());
561
-
562
-        return res;
563
-    }
564
-
565
-    @Override
566
-    public List<ActionComponent> findCompatibleComponents(final Class<?> target) {
567
-        checkNotNull(target);
568
-
569
-        final List<ActionComponent> res =
570
-                components.stream().filter(subject -> subject.appliesTo().equals(target))
571
-                        .collect(Collectors.toList());
572
-
573
-        return res;
574
-    }
575
-
576
-    @Override
577
-    public List<ActionComparison> findCompatibleComparisons(final Class<?> target) {
578
-        checkNotNull(target);
579
-
580
-        final List<ActionComparison> res =
581
-                comparisons.stream().filter(subject -> subject.appliesTo().equals(target))
582
-                        .collect(Collectors.toList());
583
-
584
-        return res;
585
-    }
586
-
587
-    @Override
588
-    public ActionComponent getComponent(final String type) {
589
-        checkNotNull(type);
590
-        checkArgument(!type.isEmpty());
591
-
592
-        for (ActionComponent target : components) {
593
-            if (target.name().equals(type)) {
594
-                return target;
595
-            }
596
-        }
597
-
598
-        return null;
599
-    }
600
-
601
-    @Override
602
-    public ActionComparison getComparison(final String type) {
603
-        checkNotNull(type);
604
-        checkArgument(!type.isEmpty());
605
-
606
-        for (ActionComparison target : comparisons) {
607
-            if (target.name().equals(type)) {
608
-                return target;
609
-            }
610
-        }
611
-
612
-        return null;
613
-    }
614
-
615
-    /**
616
-     * Installs an action pack located at the specified path.
617
-     *
618
-     * @param path The full path of the action pack .zip.
619
-     *
620
-     * @throws IOException If the zip cannot be extracted
621
-     */
622
-    public void installActionPack(final Path path) throws IOException {
623
-        FileUtils.copyRecursively(path, Paths.get(directory));
624
-        loadUserActions();
625
-        Files.delete(path);
626
-    }
627
-
628
-}

+ 0
- 442
src/com/dmdirc/actions/ActionModel.java View File

@@ -1,442 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.FrameContainer;
26
-import com.dmdirc.GlobalWindow;
27
-import com.dmdirc.Precondition;
28
-import com.dmdirc.commandparser.parsers.CommandParser;
29
-import com.dmdirc.interfaces.actions.ActionType;
30
-
31
-import java.util.ArrayList;
32
-import java.util.Arrays;
33
-import java.util.List;
34
-
35
-import javax.inject.Provider;
36
-
37
-/**
38
- * Represents the basic model of an action, and its triggering mechanism. Saving and loading are
39
- * handled by the Action class.
40
- */
41
-public class ActionModel {
42
-
43
-    // TODO: Sort out the mess of protected fields here.
44
-
45
-    /** Provider of global windows for global actions. */
46
-    private final Provider<GlobalWindow> globalWindowProvider;
47
-    /** Factory to use to creator substitutors. */
48
-    private final ActionSubstitutorFactory substitutorFactory;
49
-    /** The group this action belongs to. */
50
-    protected String group;
51
-    /** The name of this action. */
52
-    protected String name;
53
-    /** The ActionTypes that trigger this action. */
54
-    protected ActionType[] triggers;
55
-    /** The commands to execute if this action is triggered. */
56
-    protected String[] response;
57
-    /** The change that should be made to the format string, if any. */
58
-    protected String newFormat;
59
-    /** The conditions for this action. */
60
-    protected List<ActionCondition> conditions = new ArrayList<>();
61
-    /** The condition tree used for evaluating conditions. */
62
-    protected ConditionTree conditionTree;
63
-    /** Whether this action has been modified or not. */
64
-    protected boolean modified;
65
-    /** Whether this action wishes the event to be stopped. */
66
-    protected boolean stop;
67
-    /** The concurrency group this action belongs to, if any. */
68
-    protected String concurrencyGroup;
69
-    /** The status of this action. */
70
-    protected ActionStatus status = ActionStatus.ACTIVE;
71
-    /** A description of any error that occurs while creating the action. */
72
-    protected String error;
73
-    /** The type of error that occurred, if any. */
74
-    protected ActionErrorType errorType;
75
-
76
-    /**
77
-     * Creates a new instance of ActionModel with the specified properties.
78
-     *
79
-     * @param globalWindowProvider        Provider of global windows for global actions.
80
-     * @param substitutorFactory          Factory to use to create action substitutors.
81
-     * @param group                       The group the action belongs to
82
-     * @param name                        The name of the action
83
-     */
84
-    public ActionModel(
85
-            final Provider<GlobalWindow> globalWindowProvider,
86
-            final ActionSubstitutorFactory substitutorFactory,
87
-            final String group,
88
-            final String name) {
89
-        this.globalWindowProvider = globalWindowProvider;
90
-        this.substitutorFactory = substitutorFactory;
91
-        this.group = group;
92
-        this.name = name;
93
-    }
94
-
95
-    /**
96
-     * Creates a new instance of ActionModel with the specified properties.
97
-     *  @param globalWindowProvider        Provider of global windows for global actions.
98
-     * @param substitutorFactory          Factory to use to create action substitutors.
99
-     * @param group                       The group the action belongs to
100
-     * @param name                        The name of the action
101
-     * @param triggers                    The triggers to use
102
-     * @param response                    The response to use
103
-     * @param conditions                  The conditions to use
104
-     * @param conditionTree               The condition tree to use
105
-     * @param newFormat                   The new formatter to use
106
-     */
107
-    public ActionModel(
108
-            final Provider<GlobalWindow> globalWindowProvider,
109
-            final ActionSubstitutorFactory substitutorFactory,
110
-            final String group, final String name,
111
-            final ActionType[] triggers, final String[] response,
112
-            final List<ActionCondition> conditions,
113
-            final ConditionTree conditionTree, final String newFormat) {
114
-        this(globalWindowProvider, substitutorFactory, group, name);
115
-        this.triggers = triggers.clone();
116
-        this.response = response.clone();
117
-        this.conditions = conditions;
118
-        this.conditionTree = conditionTree;
119
-        this.newFormat = newFormat;
120
-        this.modified = true;
121
-    }
122
-
123
-    /**
124
-     * Triggers this action.
125
-     *
126
-     * @param format        The format of the message that's going to be displayed.
127
-     * @param arguments     The arguments from the action that caused this trigger.
128
-     *
129
-     * @return True if the execution of the event should be stopped, or false if the event may
130
-     *         continue
131
-     */
132
-    @Precondition({
133
-        "This action has at least one trigger",
134
-        "This action's primary trigger is non-null"
135
-    })
136
-    public boolean trigger(final StringBuffer format, final Object... arguments) {
137
-        assert triggers.length > 0;
138
-        assert triggers[0] != null;
139
-
140
-        if (status != ActionStatus.ACTIVE) {
141
-            return false;
142
-        }
143
-
144
-        final ActionSubstitutor sub = substitutorFactory.getActionSubstitutor(triggers[0]);
145
-
146
-        if (!test(sub, arguments)) {
147
-            return false;
148
-        }
149
-
150
-        final FrameContainer container;
151
-        if (arguments.length > 0 && arguments[0] instanceof FrameContainer
152
-                && ((FrameContainer) arguments[0]).isWritable()) {
153
-            container = (FrameContainer) arguments[0];
154
-        } else {
155
-            container = globalWindowProvider.get();
156
-        }
157
-
158
-        final CommandParser cp = container.getCommandParser();
159
-        for (String command : response) {
160
-            cp.parseCommand(container, sub.doSubstitution(command, arguments));
161
-        }
162
-
163
-        if (newFormat != null && format != null) {
164
-            format.setLength(0);
165
-            format.append(newFormat);
166
-        }
167
-
168
-        return stop;
169
-    }
170
-
171
-    /**
172
-     * Tests to see if this action should be triggered or not.
173
-     *
174
-     * @param sub       The ActionsSubstitutor to use to substitute args
175
-     * @param arguments The arguments for the action event
176
-     *
177
-     * @return True if the action should be executed, false otherwise
178
-     */
179
-    public boolean test(final ActionSubstitutor sub,
180
-            final Object... arguments) {
181
-        final boolean[] results = new boolean[conditions.size()];
182
-
183
-        int i = 0;
184
-        for (ActionCondition condition : conditions) {
185
-            results[i++] = condition.test(sub, arguments);
186
-        }
187
-
188
-        return getRealConditionTree().evaluate(results);
189
-    }
190
-
191
-    /**
192
-     * Retrieves a list of this action's conditions.
193
-     *
194
-     * @return A list of this action's conditions
195
-     */
196
-    public List<ActionCondition> getConditions() {
197
-        return conditions;
198
-    }
199
-
200
-    /**
201
-     * Sets this action's conditions.
202
-     *
203
-     * @param conditions A list of conditions to use
204
-     */
205
-    public void setConditions(final List<ActionCondition> conditions) {
206
-        this.conditions = conditions;
207
-        this.modified = true;
208
-    }
209
-
210
-    /**
211
-     * Retrieves the status of this action.
212
-     *
213
-     * @since 0.6.5
214
-     * @return This action's current status
215
-     */
216
-    public ActionStatus getStatus() {
217
-        return status;
218
-    }
219
-
220
-    /**
221
-     * Retrieves a plain text description of any error that occurred while loading this action.
222
-     *
223
-     * @since 0.6.5
224
-     * @return This action's error message, or null if no error was encountered
225
-     */
226
-    public String getError() {
227
-        return error;
228
-    }
229
-
230
-    /**
231
-     * Retrieves the type of the error that occurred while loading this action.
232
-     *
233
-     * @since 0.6.5
234
-     * @return This action's error's type, or null if no error was encountered
235
-     */
236
-    public ActionErrorType getErrorType() {
237
-        return errorType;
238
-    }
239
-
240
-    /**
241
-     * Retrieves this action's triggers.
242
-     *
243
-     * @return The triggers used by this action
244
-     */
245
-    public ActionType[] getTriggers() {
246
-        return triggers == null ? null : triggers.clone();
247
-    }
248
-
249
-    /**
250
-     * Sets this action's triggers.
251
-     *
252
-     * @param triggers The new triggers to use
253
-     */
254
-    public void setTriggers(final ActionType[] triggers) {
255
-        this.triggers = triggers.clone();
256
-        this.modified = true;
257
-    }
258
-
259
-    /**
260
-     * Retrieves this action's new format setting.
261
-     *
262
-     * @return The format that this action will use, or null if no change
263
-     */
264
-    public String getNewFormat() {
265
-        return newFormat;
266
-    }
267
-
268
-    /**
269
-     * Sets this action's new format setting.
270
-     *
271
-     * @param newFormat The new 'new format' setting
272
-     */
273
-    public void setNewFormat(final String newFormat) {
274
-        this.newFormat = newFormat;
275
-        this.modified = true;
276
-    }
277
-
278
-    /**
279
-     * Retrieves this action's response.
280
-     *
281
-     * @return The commands that will be executed if this action is triggered
282
-     */
283
-    public String[] getResponse() {
284
-        return response == null ? null : response.clone();
285
-    }
286
-
287
-    /**
288
-     * Sets this action's response.
289
-     *
290
-     * @param response The new response to use
291
-     */
292
-    public void setResponse(final String[] response) {
293
-        this.response = response.clone();
294
-        this.modified = true;
295
-    }
296
-
297
-    /**
298
-     * Retrieves this action's group name.
299
-     *
300
-     * @return This action's group name
301
-     */
302
-    public String getGroup() {
303
-        return group;
304
-    }
305
-
306
-    /**
307
-     * Sets the group of this action.
308
-     *
309
-     * @param newGroup The new group for this action
310
-     */
311
-    public void setGroup(final String newGroup) {
312
-        this.group = newGroup;
313
-        this.modified = true;
314
-    }
315
-
316
-    /**
317
-     * Retrieves this action's name.
318
-     *
319
-     * @return This action's name
320
-     */
321
-    public String getName() {
322
-        return name;
323
-    }
324
-
325
-    /**
326
-     * Sets the name of this action.
327
-     *
328
-     * @param newName The new name for this action
329
-     */
330
-    public void setName(final String newName) {
331
-        this.name = newName;
332
-        this.modified = true;
333
-    }
334
-
335
-    /**
336
-     * Retrieves the condition tree used for this action. Condition trees may be null, in which case
337
-     * the arguments are conjoined together.
338
-     *
339
-     * @return This action's condition tree
340
-     */
341
-    public ConditionTree getConditionTree() {
342
-        return conditionTree;
343
-    }
344
-
345
-    /**
346
-     * Retrieves a concrete condition tree used for this action. If there is no condition tree
347
-     * defined for this action, returns a conjunction tree for the arguments.
348
-     *
349
-     * @since 0.6
350
-     * @return A {@link ConditionTree} object for this action
351
-     */
352
-    public ConditionTree getRealConditionTree() {
353
-        return conditionTree == null ? ConditionTree.createConjunction(
354
-                conditions.size()) : conditionTree;
355
-    }
356
-
357
-    /**
358
-     * Sets the condition tree used for this action.
359
-     *
360
-     * @param conditionTree The new condition tree to be used
361
-     */
362
-    public void setConditionTree(final ConditionTree conditionTree) {
363
-        this.conditionTree = conditionTree;
364
-        this.modified = true;
365
-    }
366
-
367
-    /**
368
-     * Retrieves the concurrency group of this action.
369
-     *
370
-     * @return This action's concurrency group
371
-     *
372
-     * @since 0.6.3
373
-     */
374
-    public String getConcurrencyGroup() {
375
-        return concurrencyGroup;
376
-    }
377
-
378
-    /**
379
-     * Sets the concurrency group of this action.
380
-     *
381
-     * @param concurrencyGroup This action's new concurrency group
382
-     *
383
-     * @since 0.6.3
384
-     */
385
-    public void setConcurrencyGroup(final String concurrencyGroup) {
386
-        this.concurrencyGroup = (concurrencyGroup == null
387
-                || concurrencyGroup.isEmpty()) ? null : concurrencyGroup;
388
-    }
389
-
390
-    /**
391
-     * Determines whether or not this action will stop the event execution if it is triggered.
392
-     *
393
-     * @return The stopping preference of this action
394
-     *
395
-     * @see #setStopping(boolean)
396
-     * @since 0.6.4
397
-     */
398
-    public boolean isStopping() {
399
-        return stop;
400
-    }
401
-
402
-    /**
403
-     * Sets the stopping preference of this action. If the stopping preference is {@code true} then
404
-     * when this action is successfully triggered,it will request that execution of the event is
405
-     * stopped. This will prevent the default behaviour of the callee being executed.
406
-     *
407
-     * @param stop The new stopping preference of this action
408
-     *
409
-     * @see #isStopping()
410
-     * @since 0.6.4
411
-     */
412
-    public void setStopping(final boolean stop) {
413
-        this.stop = stop;
414
-    }
415
-
416
-    /**
417
-     * Determine if this model has been modified since it was constructed or its modified status was
418
-     * reset.
419
-     *
420
-     * @return True if this model has been modified, false otherwise
421
-     */
422
-    public boolean isModified() {
423
-        return modified;
424
-    }
425
-
426
-    /**
427
-     * Resets the modified status of this model. After a call to resetModified(), this model will
428
-     * report that it has not been modified, until one of the set* methods is used.
429
-     */
430
-    public void resetModified() {
431
-        this.modified = false;
432
-    }
433
-
434
-    @Override
435
-    public String toString() {
436
-        return "[name=" + group + "/" + name + ", triggers="
437
-                + Arrays.toString(triggers) + ", response="
438
-                + Arrays.toString(response) + ", "
439
-                + conditions + ", format='" + newFormat + "']";
440
-    }
441
-
442
-}

+ 0
- 39
src/com/dmdirc/actions/ActionStatus.java View File

@@ -1,39 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-/**
26
- * An enumeration of possible statuses for actions.
27
- *
28
- * @since 0.6.6
29
- */
30
-public enum ActionStatus {
31
-
32
-    /** The action is active and will run if triggered. */
33
-    ACTIVE,
34
-    /** The action is disabled by the user. */
35
-    DISABLED,
36
-    /** The action has failed to load. */
37
-    FAILED
38
-
39
-}

+ 0
- 361
src/com/dmdirc/actions/ActionSubstitutor.java View File

@@ -1,361 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.FrameContainer;
26
-import com.dmdirc.Precondition;
27
-import com.dmdirc.ServerState;
28
-import com.dmdirc.commandparser.CommandArguments;
29
-import com.dmdirc.interfaces.ActionController;
30
-import com.dmdirc.interfaces.CommandController;
31
-import com.dmdirc.interfaces.Connection;
32
-import com.dmdirc.interfaces.actions.ActionComponent;
33
-import com.dmdirc.interfaces.actions.ActionType;
34
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
35
-import com.dmdirc.interfaces.ui.Window;
36
-
37
-import java.util.Arrays;
38
-import java.util.HashMap;
39
-import java.util.Map;
40
-import java.util.Optional;
41
-import java.util.Set;
42
-import java.util.regex.Matcher;
43
-import java.util.regex.Pattern;
44
-
45
-/**
46
- * Handles the substitution of variables into action targets and responses.
47
- */
48
-public class ActionSubstitutor {
49
-
50
-    /** Substitution to use when a component requires a connected server. */
51
-    private static final String ERR_NOT_CONNECTED = "not_connected";
52
-    /** Substitution to use to replace an unknown substitution. */
53
-    private static final String ERR_NOT_DEFINED = "not_defined";
54
-    /** Substitution to use to replace a chain that evaluates to null. */
55
-    private static final String ERR_NULL_CHAIN = "null_component";
56
-    /** Substitution to use to replace subs with illegal components. */
57
-    private static final String ERR_ILLEGAL_COMPONENT = "illegal_component";
58
-    /** Pattern used to match braced substitutions. */
59
-    private static final Pattern BRACES_PATTERN = Pattern.compile("(?<!\\\\)((?:\\\\\\\\)*)"
60
-            + "(\\$\\{([^{}]*?)\\})");
61
-    /** Pattern used to match all other substitutions. */
62
-    private static final Pattern OTHER_PATTERN = Pattern.compile("(?<!\\\\)((?:\\\\\\\\)*)(\\$("
63
-            + "[0-9]+(-([0-9]+)?)?|" // Word subs - $1, $1-, $1-2
64
-            + "[0-9]+(\\.([A-Z_]+))+|" // Component subs - 2.FOO_BAR
65
-            + "[a-z0-9A-Z_\\.]+" // Config/server subs
66
-            + "))");
67
-    /** Pattern to determine if a substitution is a word number type. */
68
-    private static final Pattern NUMBER_PATTERN = Pattern.compile("([0-9]+)(-([0-9]+)?)?");
69
-    /** Pattern to determine if a substitution is an argument+component type. */
70
-    private static final Pattern COMP_PATTERN = Pattern.compile("([0-9]+)\\.([A-Z_]+(\\.[A-Z_]+)*)");
71
-    /** Pattern to determine if a substitution is a server component type. */
72
-    private static final Pattern SERVER_PATTERN = Pattern.compile("[A-Z_]+(\\.[A-Z_]+)*");
73
-    /** The action controller to use to find components. */
74
-    private final ActionController actionController;
75
-    /** The global config to read settings from. */
76
-    private final AggregateConfigProvider globalConfig;
77
-    /** The command controller to use when building command arguments. */
78
-    private final CommandController commandController;
79
-    /** The action type this substitutor is for. */
80
-    private final ActionType type;
81
-
82
-    /**
83
-     * Creates a new substitutor for the specified action type.
84
-     *
85
-     * @param actionController  The action controller to use to find components.
86
-     * @param commandController The command controller to use when building command arguments.
87
-     * @param globalConfig      The global config to read settings from.
88
-     * @param type              The action type this substitutor is for
89
-     */
90
-    public ActionSubstitutor(
91
-            final ActionController actionController,
92
-            final CommandController commandController,
93
-            final AggregateConfigProvider globalConfig,
94
-            final ActionType type) {
95
-        this.actionController = actionController;
96
-        this.globalConfig = globalConfig;
97
-        this.commandController = commandController;
98
-        this.type = type;
99
-    }
100
-
101
-    /**
102
-     * Retrieves a list of global config variables that will be substituted. Note: does not include
103
-     * initial $.
104
-     *
105
-     * @return A list of global variable names that will be substituted
106
-     */
107
-    public Set<String> getConfigSubstitutions() {
108
-        return globalConfig.getOptions("actions").keySet();
109
-    }
110
-
111
-    /**
112
-     * Retrieves a list of substitutions derived from argument and component combinations, along
113
-     * with a corresponding friendly name for them. Note: does not include initial $.
114
-     *
115
-     * @return A map of component substitution names and their descriptions
116
-     */
117
-    public Map<String, String> getComponentSubstitutions() {
118
-        final Map<String, String> res = new HashMap<>();
119
-
120
-        int i = 0;
121
-        for (Class<?> myClass : type.getType().getArgTypes()) {
122
-            for (ActionComponent comp : actionController.findCompatibleComponents(myClass)) {
123
-                final String key = "{" + i + "." + comp.toString() + "}";
124
-                final String desc = type.getType().getArgNames()[i] + "'s " + comp.getName();
125
-
126
-                res.put(key, desc);
127
-            }
128
-
129
-            i++;
130
-        }
131
-
132
-        return res;
133
-    }
134
-
135
-    /**
136
-     * Retrieves a list of server substitutions, if this action type supports them. Note: does not
137
-     * include initial $.
138
-     *
139
-     * @return A map of server substitution names and their descriptions.
140
-     */
141
-    public Map<String, String> getServerSubstitutions() {
142
-        final Map<String, String> res = new HashMap<>();
143
-
144
-        if (hasFrameContainer()) {
145
-            for (ActionComponent comp : actionController
146
-                    .findCompatibleComponents(Connection.class)) {
147
-                final String key = "{" + comp.toString() + "}";
148
-                final String desc = "The connection's " + comp.getName();
149
-
150
-                res.put(key, desc);
151
-            }
152
-        }
153
-
154
-        return res;
155
-    }
156
-
157
-    /**
158
-     * Returns true if this action type's first argument is a frame container, or descendant of one.
159
-     *
160
-     * @return True if this action type's first arg extends or is a FrameContainer
161
-     */
162
-    private boolean hasFrameContainer() {
163
-        Class<?> target = null;
164
-
165
-        if (type.getType().getArgTypes().length > 0) {
166
-            target = type.getType().getArgTypes()[0];
167
-
168
-            while (target != null && target != FrameContainer.class) {
169
-                target = target.getSuperclass();
170
-            }
171
-        }
172
-
173
-        return target == FrameContainer.class;
174
-    }
175
-
176
-    /**
177
-     * Determines whether or not word substitutions will work for this action type. Word
178
-     * substitutions take the form $1, $1-5, $6-, etc.
179
-     *
180
-     * @return True if word substitutions are supported, false otherwise.
181
-     */
182
-    public boolean usesWordSubstitutions() {
183
-        return type.getType().getArgTypes().length > 2
184
-                && (type.getType().getArgTypes()[2] == String[].class
185
-                || type.getType().getArgTypes()[2] == String.class);
186
-    }
187
-
188
-    /**
189
-     * Performs all applicable substitutions on the specified string, with the specified arguments.
190
-     *
191
-     * @param target The string to be altered
192
-     * @param args   The arguments for the action type
193
-     *
194
-     * @return The substituted string
195
-     */
196
-    @Precondition("Number of arguments given equals the number of arguments "
197
-            + "required by this substitutor's type")
198
-    public String doSubstitution(final String target, final Object... args) {
199
-        if (type.getType().getArity() != args.length) {
200
-            throw new IllegalArgumentException("Invalid number of arguments "
201
-                    + "for doSubstitution: expected " + type.getType().getArity() + ", got "
202
-                    + args.length + ". Type: " + type.getName());
203
-        }
204
-
205
-        final StringBuilder res = new StringBuilder(target);
206
-
207
-        Matcher bracesMatcher = BRACES_PATTERN.matcher(res);
208
-        Matcher otherMatcher = OTHER_PATTERN.matcher(res);
209
-
210
-        boolean first;
211
-
212
-        while ((first = bracesMatcher.find()) || otherMatcher.find()) {
213
-            final Matcher matcher = first ? bracesMatcher : otherMatcher;
214
-
215
-            final String group = matcher.group(3);
216
-            final int start = matcher.start() + matcher.group(1).length();
217
-            final int end = matcher.end();
218
-
219
-            res.delete(start, end);
220
-            res.insert(start, getSubstitution(doSubstitution(group, args), args));
221
-
222
-            bracesMatcher = BRACES_PATTERN.matcher(res);
223
-            otherMatcher = OTHER_PATTERN.matcher(res);
224
-        }
225
-
226
-        return res.toString().replaceAll("\\\\(.)", "$1");
227
-    }
228
-
229
-    /**
230
-     * Retrieves the value which should be used for the specified substitution.
231
-     *
232
-     * @param substitution The substitution, without leading $
233
-     * @param args         The arguments for the action
234
-     *
235
-     * @return The substitution to be used
236
-     */
237
-    private String getSubstitution(final String substitution, final Object... args) {
238
-        final Matcher numberMatcher = NUMBER_PATTERN.matcher(substitution);
239
-        final Matcher compMatcher = COMP_PATTERN.matcher(substitution);
240
-        final Matcher serverMatcher = SERVER_PATTERN.matcher(substitution);
241
-
242
-        if (usesWordSubstitutions() && numberMatcher.matches()) {
243
-            final CommandArguments words = args[2] instanceof String
244
-                    ? new CommandArguments(commandController, (String) args[2])
245
-                    : new CommandArguments(commandController, Arrays.asList((String[]) args[2]));
246
-
247
-            final int start;
248
-            int end;
249
-
250
-            start = end = Integer.parseInt(numberMatcher.group(1)) - 1;
251
-
252
-            if (numberMatcher.group(3) != null) {
253
-                end = Integer.parseInt(numberMatcher.group(3)) - 1;
254
-            } else if (numberMatcher.group(2) != null) {
255
-                end = words.getWords().length - 1;
256
-            }
257
-
258
-            return words.getWordsAsString(start, end);
259
-        }
260
-
261
-        if (compMatcher.matches()) {
262
-            final int argument = Integer.parseInt(compMatcher.group(1));
263
-
264
-            try {
265
-                final ActionComponentChain chain = new ActionComponentChain(
266
-                        type.getType().getArgTypes()[argument], compMatcher.group(2),
267
-                        actionController);
268
-                return escape(checkConnection(chain, args, args[argument]));
269
-            } catch (IllegalArgumentException ex) {
270
-                return ERR_ILLEGAL_COMPONENT;
271
-            }
272
-        }
273
-
274
-        final AggregateConfigProvider manager = getConfigManager(args);
275
-
276
-        if (manager.hasOptionString("actions", substitution)) {
277
-            return manager.getOption("actions", substitution);
278
-        }
279
-
280
-        if (hasFrameContainer() && serverMatcher.matches()) {
281
-            final Optional<Connection> connection =
282
-                    ((FrameContainer) args[0]).getConnection();
283
-
284
-            if (connection.isPresent()) {
285
-                try {
286
-                    final ActionComponentChain chain = new ActionComponentChain(
287
-                            Connection.class, substitution, actionController);
288
-                    return escape(checkConnection(chain, args, connection.get()));
289
-                } catch (IllegalArgumentException ex) {
290
-                    return ERR_ILLEGAL_COMPONENT;
291
-                }
292
-            }
293
-        }
294
-
295
-        return ERR_NOT_DEFINED;
296
-    }
297
-
298
-    /**
299
-     * Checks the connection status of any server associated with the specified arguments. If the
300
-     * specified component chain requires a server with an established connection and no such server
301
-     * is present, this method returns the string {@code not_connected} without attempting to
302
-     * evaluate any components in the chain.
303
-     *
304
-     * @since 0.6.4
305
-     * @param chain    The chain to be checked
306
-     * @param args     The arguments for this invocation
307
-     * @param argument The argument used as a base for the chain
308
-     *
309
-     * @return The value of the evaluated chain, or <code>not_connected</code>
310
-     */
311
-    protected String checkConnection(final ActionComponentChain chain,
312
-            final Object[] args, final Object argument) {
313
-        if ((chain.requiresConnection() && args[0] instanceof FrameContainer
314
-                && ((FrameContainer) args[0]).getConnection().get().getState()
315
-                == ServerState.CONNECTED) || !chain.requiresConnection()) {
316
-            final Object res = chain.get(argument);
317
-            return res == null ? ERR_NULL_CHAIN : res.toString();
318
-        }
319
-
320
-        return ERR_NOT_CONNECTED;
321
-    }
322
-
323
-    /**
324
-     * Tries to retrieve an appropriate configuration manager from the specified set of arguments.
325
-     * If any of the arguments is an instance of {@link FrameContainer} or {@link Window}, the
326
-     * config manager is requested from them. Otherwise, the global config is returned.
327
-     *
328
-     * @param args The arguments to be tested
329
-     *
330
-     * @return The best config manager to use for those arguments
331
-     *
332
-     * @since 0.6.3m2
333
-     */
334
-    protected AggregateConfigProvider getConfigManager(final Object... args) {
335
-        for (Object arg : args) {
336
-            if (arg instanceof FrameContainer) {
337
-                return ((FrameContainer) arg).getConfigManager();
338
-            } else if (arg instanceof Window) {
339
-                return ((Window) arg).getContainer().getConfigManager();
340
-            }
341
-        }
342
-
343
-        return globalConfig;
344
-    }
345
-
346
-    /**
347
-     * Escapes all special characters in the specified input. This will result in the input being
348
-     * treated as a plain string when passed through the substitutor (i.e., no substitutions will
349
-     * occur).
350
-     *
351
-     * @param input The string to be escaped
352
-     *
353
-     * @return An escaped version of the specified string
354
-     *
355
-     * @since 0.6.4
356
-     */
357
-    protected static String escape(final String input) {
358
-        return input.replace("\\", "\\\\").replace("$", "\\$");
359
-    }
360
-
361
-}

+ 0
- 59
src/com/dmdirc/actions/ActionSubstitutorFactory.java View File

@@ -1,59 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.ClientModule;
26
-import com.dmdirc.interfaces.ActionController;
27
-import com.dmdirc.interfaces.CommandController;
28
-import com.dmdirc.interfaces.actions.ActionType;
29
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
30
-
31
-import javax.inject.Inject;
32
-import javax.inject.Provider;
33
-import javax.inject.Singleton;
34
-
35
-/**
36
- * Factory for {@link ActionSubstitutor}s.
37
- */
38
-@Singleton
39
-public class ActionSubstitutorFactory {
40
-
41
-    private final Provider<ActionController> actionController;
42
-    private final CommandController commandController;
43
-    private final AggregateConfigProvider globalConfig;
44
-
45
-    @Inject
46
-    public ActionSubstitutorFactory(
47
-            final Provider<ActionController> actionController,
48
-            final CommandController commandController,
49
-            @ClientModule.GlobalConfig final AggregateConfigProvider globalConfig) {
50
-        this.actionController = actionController;
51
-        this.commandController = commandController;
52
-        this.globalConfig = globalConfig;
53
-    }
54
-
55
-    public ActionSubstitutor getActionSubstitutor(final ActionType type) {
56
-        return new ActionSubstitutor(actionController.get(), commandController, globalConfig, type);
57
-    }
58
-
59
-}

+ 0
- 43
src/com/dmdirc/actions/ActionTypeComparator.java View File

@@ -1,43 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.interfaces.actions.ActionType;
26
-
27
-import java.io.Serializable;
28
-import java.util.Comparator;
29
-
30
-/**
31
- * Implements a comparator for action types that compares their names.
32
- */
33
-public final class ActionTypeComparator implements Comparator<ActionType>, Serializable {
34
-
35
-    /** A version number for this class. */
36
-    private static final long serialVersionUID = 1;
37
-
38
-    @Override
39
-    public int compare(final ActionType o1, final ActionType o2) {
40
-        return o1.getName().compareTo(o2.getName());
41
-    }
42
-
43
-}

+ 0
- 116
src/com/dmdirc/actions/ColourActionComparison.java View File

@@ -1,116 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.ClientModule;
26
-import com.dmdirc.interfaces.actions.ActionComparison;
27
-import com.dmdirc.ui.messages.ColourManager;
28
-import com.dmdirc.util.colours.Colour;
29
-
30
-import javax.inject.Inject;
31
-import javax.inject.Provider;
32
-
33
-/**
34
- * Core action comparisons dependent on a colour manager.
35
- */
36
-public class ColourActionComparison {
37
-
38
-    /** Instance of the equals comparison. */
39
-    private final Equals equalsComparison;
40
-    /** Instance of the not equals comparison. */
41
-    private final NotEquals notEqualsComparison;
42
-    /** Colour manager to use to parse colours. */
43
-    private final Provider<ColourManager> colourManager;
44
-
45
-    /**
46
-     * Creates a new instance of {@link ColourActionComparison}.
47
-     *
48
-     * @param colourManager The colour manager to use.
49
-     */
50
-    @Inject
51
-    public ColourActionComparison(@ClientModule.GlobalConfig final Provider<ColourManager> colourManager) {
52
-        this.equalsComparison = new Equals();
53
-        this.notEqualsComparison = new NotEquals();
54
-        this.colourManager = colourManager;
55
-    }
56
-
57
-    /**
58
-     * Gets the available colour comparisons.
59
-     *
60
-     * @return The available comparisons.
61
-     */
62
-    public ActionComparison[] getComparisons() {
63
-        return new ActionComparison[]{equalsComparison, notEqualsComparison};
64
-    }
65
-
66
-    /** Checks if the colour is the same as another colour. */
67
-    private class Equals implements ActionComparison {
68
-
69
-        @Override
70
-        public boolean test(final Object arg1, final Object arg2) {
71
-            return arg1.equals(colourManager.get().getColourFromString((String) arg2, null));
72
-        }
73
-
74
-        @Override
75
-        public Class<?> appliesTo() {
76
-            return Colour.class;
77
-        }
78
-
79
-        @Override
80
-        public String getName() {
81
-            return "equals";
82
-        }
83
-
84
-        @Override
85
-        public String name() {
86
-            return "COLOUR_EQUALS";
87
-        }
88
-
89
-    }
90
-
91
-    /** Checks if the colour is not the same as another colour. */
92
-    private class NotEquals implements ActionComparison {
93
-
94
-        @Override
95
-        public boolean test(final Object arg1, final Object arg2) {
96
-            return !equalsComparison.test(arg1, arg2);
97
-        }
98
-
99
-        @Override
100
-        public Class<?> appliesTo() {
101
-            return Colour.class;
102
-        }
103
-
104
-        @Override
105
-        public String getName() {
106
-            return "does not equal";
107
-        }
108
-
109
-        @Override
110
-        public String name() {
111
-            return "COLOUR_NEQUALS";
112
-        }
113
-
114
-    }
115
-
116
-}

+ 0
- 388
src/com/dmdirc/actions/ConditionTree.java View File

@@ -1,388 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import java.util.ArrayDeque;
26
-import java.util.Deque;
27
-
28
-/**
29
- * A condition tree specifies in which order a group of conditions will be executed.
30
- */
31
-public final class ConditionTree {
32
-
33
-    /** The possible operations on a condition tree. */
34
-    public enum OPERATION {
35
-
36
-        /** Only passes if both subtrees are true. */
37
-        AND,
38
-        /** Passes if either of the subtrees are true. */
39
-        OR,
40
-        /** Passes if the specified argument is true. */
41
-        VAR,
42
-        /** Only passes iof the left subtree fails to pass. */
43
-        NOT,
44
-        /** Doesn't do anything (an empty tree). */
45
-        NOOP
46
-
47
-    }
48
-    /** The left subtree of this tree. */
49
-    private ConditionTree leftArg;
50
-    /** The right subtree of this tree. */
51
-    private ConditionTree rightArg;
52
-    /** The argument of this tree (only used for VAR ops). */
53
-    private int argument = -1;
54
-    /** The operation that this tree performs. */
55
-    private final OPERATION op;
56
-
57
-    /**
58
-     * Creates a new ConditionTree for a binary operation.
59
-     *
60
-     * @param op       The binary operation to perform
61
-     * @param leftArg  The left argument/subtree
62
-     * @param rightArg The right argument/subtree
63
-     */
64
-    private ConditionTree(final OPERATION op, final ConditionTree leftArg,
65
-            final ConditionTree rightArg) {
66
-        this.op = op;
67
-        this.leftArg = leftArg;
68
-        this.rightArg = rightArg;
69
-    }
70
-
71
-    /**
72
-     * Creates a new ConditionTree for a unary operation.
73
-     *
74
-     * @param op       The unary operation to perform.
75
-     * @param argument The argument/subtree to perform it on.
76
-     */
77
-    private ConditionTree(final OPERATION op, final ConditionTree argument) {
78
-        this.op = op;
79
-        this.leftArg = argument;
80
-    }
81
-
82
-    /**
83
-     * Creates a new ConditionTree for a VAR operation with the specified argument number.
84
-     *
85
-     * @param argument The number of the argument that's to be tested.
86
-     */
87
-    private ConditionTree(final int argument) {
88
-        this.op = OPERATION.VAR;
89
-        this.argument = argument;
90
-    }
91
-
92
-    /**
93
-     * Creates a new ConditionTree for a NOOP operation.
94
-     */
95
-    private ConditionTree() {
96
-        this.op = OPERATION.NOOP;
97
-    }
98
-
99
-    /**
100
-     * Retrieves the highest argument number that is used in this condition tree.
101
-     *
102
-     * @return The highest argument number used in this tree
103
-     */
104
-    public int getMaximumArgument() {
105
-        if (this.op == OPERATION.NOOP) {
106
-            return 0;
107
-        } else if (this.op == OPERATION.VAR) {
108
-            return argument;
109
-        } else if (this.op == OPERATION.NOT) {
110
-            return leftArg.getMaximumArgument();
111
-        } else {
112
-            return Math.max(leftArg.getMaximumArgument(), rightArg.getMaximumArgument());
113
-        }
114
-    }
115
-
116
-    /**
117
-     * Evaluates this tree with the specified conditions. Returns the result of the evaluation.
118
-     *
119
-     * @param conditions The binary values of each of the conditions used in this three
120
-     *
121
-     * @return The result of the evaluation of this tree
122
-     */
123
-    public boolean evaluate(final boolean[] conditions) {
124
-        switch (op) {
125
-            case VAR:
126
-                return conditions[argument];
127
-            case NOT:
128
-                return !leftArg.evaluate(conditions);
129
-            case AND:
130
-                return leftArg.evaluate(conditions) && rightArg.evaluate(conditions);
131
-            case OR:
132
-                return leftArg.evaluate(conditions) || rightArg.evaluate(conditions);
133
-            default:
134
-                return true;
135
-        }
136
-    }
137
-
138
-    @Override
139
-    public boolean equals(final Object obj) {
140
-        return obj instanceof ConditionTree
141
-                && toString().equals(obj.toString());
142
-    }
143
-
144
-    @Override
145
-    public int hashCode() {
146
-        return toString().hashCode();
147
-    }
148
-
149
-    /**
150
-     * Retrieves a String representation of this ConditionTree. The string representation is a
151
-     * normalised formula describing this tree and all of its children. The output of this method
152
-     * will generate an identical tree if passed to parseString.
153
-     *
154
-     * @return A string representation of this tree
155
-     */
156
-    @Override
157
-    public String toString() {
158
-        switch (op) {
159
-            case VAR:
160
-                return String.valueOf(argument);
161
-            case NOT:
162
-                return "!" + leftArg;
163
-            case AND:
164
-                return "(" + leftArg + "&" + rightArg + ")";
165
-            case OR:
166
-                return "(" + leftArg + "|" + rightArg + ")";
167
-            default:
168
-                return "";
169
-        }
170
-    }
171
-
172
-    /**
173
-     * Parses the specified string into a condition tree.
174
-     *
175
-     * @param string The string to be parsed
176
-     *
177
-     * @return The corresponding condition tree, or null if there was an error while parsing the
178
-     *         data
179
-     */
180
-    public static ConditionTree parseString(final String string) {
181
-        final Deque<Object> stack = new ArrayDeque<>();
182
-
183
-        for (int i = 0; i < string.length(); i++) {
184
-            final char m = string.charAt(i);
185
-
186
-            if (isInt(m)) {
187
-                final StringBuilder temp = new StringBuilder(String.valueOf(m));
188
-
189
-                while (i + 1 < string.length() && isInt(string.charAt(i + 1))) {
190
-                    temp.append(string.charAt(i + 1));
191
-                    i++;
192
-                }
193
-
194
-                try {
195
-                    stack.add(new ConditionTree(Integer.parseInt(temp.toString())));
196
-                } catch (NumberFormatException ex) {
197
-                    return null;
198
-                }
199
-            } else if (m != ' ' && m != '\t' && m != '\n' && m != '\r') {
200
-                stack.add(m);
201
-            }
202
-        }
203
-
204
-        return parseStack(stack);
205
-    }
206
-
207
-    /**
208
-     * Parses the specified stack of elements, and returns a corresponding ConditionTree.
209
-     *
210
-     * @param stack The stack to be read.
211
-     *
212
-     * @return The corresponding condition tree, or null if there was an error while parsing the
213
-     *         data.
214
-     */
215
-    private static ConditionTree parseStack(final Deque<Object> stack) {
216
-        final Deque<Object> myStack = new ArrayDeque<>();
217
-
218
-        while (!stack.isEmpty()) {
219
-            final Object object = stack.poll();
220
-
221
-            if (object instanceof Character && ((Character) object) == ')') {
222
-                final ConditionTree bracket = readBracket(myStack);
223
-
224
-                if (bracket == null) {
225
-                    return null;
226
-                } else {
227
-                    myStack.add(bracket);
228
-                }
229
-            } else {
230
-                myStack.add(object);
231
-            }
232
-        }
233
-
234
-        while (!myStack.isEmpty()) {
235
-            if (myStack.size() == 1) {
236
-                final Object first = myStack.pollFirst();
237
-                if (first instanceof ConditionTree) {
238
-                    return (ConditionTree) first;
239
-                } else {
240
-                    return null;
241
-                }
242
-            }
243
-
244
-            final ConditionTree first = readTerm(myStack);
245
-
246
-            if (first == null) {
247
-                return null;
248
-            } else if (myStack.isEmpty()) {
249
-                return first;
250
-            }
251
-
252
-            final Object second = myStack.pollFirst();
253
-
254
-            if (myStack.isEmpty()) {
255
-                return null;
256
-            } else {
257
-                final ConditionTree third = readTerm(myStack);
258
-
259
-                if (third != null && second instanceof Character) {
260
-                    final OPERATION op;
261
-
262
-                    if ((Character) second == '&') {
263
-                        op = OPERATION.AND;
264
-                    } else if ((Character) second == '|') {
265
-                        op = OPERATION.OR;
266
-                    } else {
267
-                        return null;
268
-                    }
269
-
270
-                    myStack.addFirst(new ConditionTree(op, first, third));
271
-                } else {
272
-                    return null;
273
-                }
274
-            }
275
-        }
276
-
277
-        return new ConditionTree();
278
-    }
279
-
280
-    /**
281
-     * Reads and returns a single term from the specified stack.
282
-     *
283
-     * @param stack The stack to be read
284
-     *
285
-     * @return The ConditionTree representing the last element on the stack, or null if it was not
286
-     *         possible to create one.
287
-     */
288
-    private static ConditionTree readTerm(final Deque<Object> stack) {
289
-        final Object first = stack.pollFirst();
290
-
291
-        if (first instanceof Character && (Character) first == '!') {
292
-            if (stack.isEmpty()) {
293
-                return null;
294
-            }
295
-
296
-            return new ConditionTree(OPERATION.NOT, readTerm(stack));
297
-        } else {
298
-            if (!(first instanceof ConditionTree)) {
299
-                return null;
300
-            }
301
-
302
-            return (ConditionTree) first;
303
-        }
304
-    }
305
-
306
-    /**
307
-     * Pops elements off of the end of the specified stack until an opening bracket is reached, and
308
-     * then returns the parsed content of the bracket.
309
-     *
310
-     * @param stack The stack to be read for the bracket
311
-     *
312
-     * @return The parsed contents of the bracket, or null if the brackets were mismatched.
313
-     */
314
-    private static ConditionTree readBracket(final Deque<Object> stack) {
315
-        final Deque<Object> tempStack = new ArrayDeque<>();
316
-        boolean found = false;
317
-
318
-        while (!found && !stack.isEmpty()) {
319
-            final Object object = stack.pollLast();
320
-
321
-            if (object instanceof Character && ((Character) object) == '(') {
322
-                found = true;
323
-            } else {
324
-                tempStack.addFirst(object);
325
-            }
326
-        }
327
-
328
-        if (found) {
329
-            return parseStack(tempStack);
330
-        } else {
331
-            return null;
332
-        }
333
-    }
334
-
335
-    /**
336
-     * Determines if the specified character represents a single digit.
337
-     *
338
-     * @param target The character to be tested
339
-     *
340
-     * @return True if the character is a digit, false otherwise
341
-     */
342
-    private static boolean isInt(final char target) {
343
-        return target >= '0' && target <= '9';
344
-    }
345
-
346
-    /**
347
-     * Creates a condition tree by disjointing the specified number of arguments together.
348
-     *
349
-     * @param numArgs The number of arguments to be disjointed
350
-     *
351
-     * @return The corresponding condition tree
352
-     */
353
-    public static ConditionTree createDisjunction(final int numArgs) {
354
-        final StringBuilder builder = new StringBuilder();
355
-
356
-        for (int i = 0; i < numArgs; i++) {
357
-            if (builder.length() != 0) {
358
-                builder.append('|');
359
-            }
360
-
361
-            builder.append(i);
362
-        }
363
-
364
-        return parseString(builder.toString());
365
-    }
366
-
367
-    /**
368
-     * Creates a condition tree by conjoining the specified number of arguments together.
369
-     *
370
-     * @param numArgs The number of arguments to be conjoined
371
-     *
372
-     * @return The corresponding condition tree
373
-     */
374
-    public static ConditionTree createConjunction(final int numArgs) {
375
-        final StringBuilder builder = new StringBuilder();
376
-
377
-        for (int i = 0; i < numArgs; i++) {
378
-            if (builder.length() != 0) {
379
-                builder.append('&');
380
-            }
381
-
382
-            builder.append(i);
383
-        }
384
-
385
-        return parseString(builder.toString());
386
-    }
387
-
388
-}

+ 0
- 144
src/com/dmdirc/actions/ConditionTreeFactory.java View File

@@ -1,144 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-/**
26
- * Provides methods to automatically generated condition tree for a specified number of arguments.
27
- *
28
- * @since 0.6
29
- */
30
-public abstract class ConditionTreeFactory {
31
-
32
-    /**
33
-     * Retrieves a condition tree for the specified number of arguments.
34
-     *
35
-     * @param args The number of arguments in the {@link Action}
36
-     *
37
-     * @return A ConditionTree for the specified number of args
38
-     */
39
-    public abstract ConditionTree getConditionTree(final int args);
40
-
41
-    /**
42
-     * Retrieves the type this of factory.
43
-     *
44
-     * @return This factory's type
45
-     */
46
-    public abstract ConditionTreeFactoryType getType();
47
-
48
-    /**
49
-     * The possible types of ConditionTreeFactories.
50
-     */
51
-    public enum ConditionTreeFactoryType {
52
-
53
-        /** Factories that produce disjunction (OR) trees. */
54
-        DISJUNCTION,
55
-        /** Factories that produce conjunction (AND) trees. */
56
-        CONJUNCTION,
57
-        /** Factories that produce custom trees. */
58
-        CUSTOM,
59
-
60
-    }
61
-
62
-    /**
63
-     * Retrieves a factory that will extrapolate the specified {@link ConditionTree} for different
64
-     * number of arguments, if applicable.
65
-     *
66
-     * @param tree The {@link ConditionTree} that's in use
67
-     * @param args The number of conditions currently in use
68
-     *
69
-     * @return A {@link ConditionTreeFactory} that will create relevant {@link ConditionTree}s
70
-     */
71
-    public static ConditionTreeFactory getFactory(final ConditionTree tree, final int args) {
72
-        if (tree.equals(ConditionTree.createConjunction(args))) {
73
-            return new ConjunctionFactory();
74
-        } else if (tree.equals(ConditionTree.createDisjunction(args))) {
75
-            return new DisjunctionFactory();
76
-        } else {
77
-            return new CustomFactory(tree);
78
-        }
79
-    }
80
-
81
-    /**
82
-     * Creates condition trees where the arguments are conjoined together.
83
-     */
84
-    public static class ConjunctionFactory extends ConditionTreeFactory {
85
-
86
-        @Override
87
-        public ConditionTree getConditionTree(final int args) {
88
-            return ConditionTree.createConjunction(args);
89
-        }
90
-
91
-        @Override
92
-        public ConditionTreeFactoryType getType() {
93
-            return ConditionTreeFactoryType.CONJUNCTION;
94
-        }
95
-
96
-    }
97
-
98
-    /**
99
-     * Creates condition trees where the arguments are disjointed together.
100
-     */
101
-    public static class DisjunctionFactory extends ConditionTreeFactory {
102
-
103
-        @Override
104
-        public ConditionTree getConditionTree(final int args) {
105
-            return ConditionTree.createDisjunction(args);
106
-        }
107
-
108
-        @Override
109
-        public ConditionTreeFactoryType getType() {
110
-            return ConditionTreeFactoryType.DISJUNCTION;
111
-        }
112
-
113
-    }
114
-
115
-    /**
116
-     * Creates condition trees with a custom structure.
117
-     */
118
-    public static class CustomFactory extends ConditionTreeFactory {
119
-
120
-        /** The condition tree to use. */
121
-        protected final ConditionTree tree;
122
-
123
-        /**
124
-         * Creates a new CustomFactory for the specified tree.
125
-         *
126
-         * @param tree The tree to use
127
-         */
128
-        public CustomFactory(final ConditionTree tree) {
129
-            this.tree = tree;
130
-        }
131
-
132
-        @Override
133
-        public ConditionTree getConditionTree(final int args) {
134
-            return tree;
135
-        }
136
-
137
-        @Override
138
-        public ConditionTreeFactoryType getType() {
139
-            return ConditionTreeFactoryType.CUSTOM;
140
-        }
141
-
142
-    }
143
-
144
-}

+ 0
- 226
src/com/dmdirc/actions/CoreActionComparison.java View File

@@ -1,226 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.interfaces.actions.ActionComparison;
26
-
27
-import java.util.regex.PatternSyntaxException;
28
-
29
-/**
30
- * A CoreActionComparison represents a possible comparison between two types of data used in an
31
- * action condition.
32
- */
33
-public enum CoreActionComparison implements ActionComparison {
34
-
35
-    /** Compares a string to another using a regular expression. */
36
-    STRING_REGEX {
37
-        @Override
38
-        public boolean test(final Object arg1, final Object arg2) {
39
-            try {
40
-                return ((String) arg1).matches((String) arg2);
41
-            } catch (PatternSyntaxException pse) {
42
-                return false;
43
-            }
44
-        }
45
-
46
-        @Override
47
-        public Class<?> appliesTo() {
48
-            return String.class;
49
-        }
50
-
51
-        @Override
52
-        public String getName() {
53
-            return "matches regex";
54
-        }
55
-    },
56
-    /**
57
-     * Compares if two strings content are the same, case insensitive.
58
-     */
59
-    STRING_EQUALS {
60
-        @Override
61
-        public boolean test(final Object arg1, final Object arg2) {
62
-            return ((String) arg1).equalsIgnoreCase((String) arg2);
63
-        }
64
-
65
-        @Override
66
-        public Class<?> appliesTo() {
67
-            return String.class;
68
-        }
69
-
70
-        @Override
71
-        public String getName() {
72
-            return "equals";
73
-        }
74
-    },
75
-    /**
76
-     * Compares if two strings content aren't the same, case insensitive.
77
-     */
78
-    STRING_NEQUALS {
79
-        @Override
80
-        public boolean test(final Object arg1, final Object arg2) {
81
-            return !STRING_EQUALS.test(arg1, arg2);
82
-        }
83
-
84
-        @Override
85
-        public Class<?> appliesTo() {
86
-            return String.class;
87
-        }
88
-
89
-        @Override
90
-        public String getName() {
91
-            return "does not equal";
92
-        }
93
-    },
94
-    /** Checks if the string starts with another strings. */
95
-    STRING_STARTSWITH {
96
-        @Override
97
-        public boolean test(final Object arg1, final Object arg2) {
98
-            return ((String) arg1).startsWith((String) arg2);
99
-        }
100
-
101
-        @Override
102
-        public Class<?> appliesTo() {
103
-            return String.class;
104
-        }
105
-
106
-        @Override
107
-        public String getName() {
108
-            return "starts with";
109
-        }
110
-    },
111
-    /** Checks if the string contains another string. */
112
-    STRING_CONTAINS {
113
-        @Override
114
-        public boolean test(final Object arg1, final Object arg2) {
115
-            return ((String) arg1).contains((CharSequence) arg2);
116
-        }
117
-
118
-        @Override
119
-        public Class<?> appliesTo() {
120
-            return String.class;
121
-        }
122
-
123
-        @Override
124
-        public String getName() {
125
-            return "contains";
126
-        }
127
-    },
128
-    /** Checks if the string doesn't contain another string. */
129
-    STRING_NCONTAINS {
130
-        @Override
131
-        public boolean test(final Object arg1, final Object arg2) {
132
-            return !((String) arg1).contains((CharSequence) arg2);
133
-        }
134
-
135
-        @Override
136
-        public Class<?> appliesTo() {
137
-            return String.class;
138
-        }
139
-
140
-        @Override
141
-        public String getName() {
142
-            return "doesn't contain";
143
-        }
144
-    },
145
-    /** Checks if two boolean values are equal. */
146
-    BOOL_IS {
147
-        @Override
148
-        public boolean test(final Object arg1, final Object arg2) {
149
-            return arg1.equals(Boolean.valueOf((String) arg2));
150
-        }
151
-
152
-        @Override
153
-        public Class<?> appliesTo() {
154
-            return Boolean.class;
155
-        }
156
-
157
-        @Override
158
-        public String getName() {
159
-            return "is";
160
-        }
161
-    },
162
-    /** Checks if the int is equals to another int. */
163
-    INT_EQUALS {
164
-        @Override
165
-        public boolean test(final Object arg1, final Object arg2) {
166
-            try {
167
-                return 0 == ((Integer) arg1).compareTo(Integer.parseInt((String) arg2));
168
-            } catch (NumberFormatException ex) {
169
-                return false;
170
-            }
171
-        }
172
-
173
-        @Override
174
-        public Class<?> appliesTo() {
175
-            return Integer.class;
176
-        }
177
-
178
-        @Override
179
-        public String getName() {
180
-            return "equals";
181
-        }
182
-    },
183
-    /** Checks if the int is larger than another int. */
184
-    INT_GREATER {
185
-        @Override
186
-        public boolean test(final Object arg1, final Object arg2) {
187
-            try {
188
-                return 0 < ((Integer) arg1).compareTo(Integer.parseInt((String) arg2));
189
-            } catch (NumberFormatException ex) {
190
-                return false;
191
-            }
192
-        }
193
-
194
-        @Override
195
-        public Class<?> appliesTo() {
196
-            return Integer.class;
197
-        }
198
-
199
-        @Override
200
-        public String getName() {
201
-            return "is greater than";
202
-        }
203
-    },
204
-    /** Checks if the int is smaller than another int. */
205
-    INT_LESS {
206
-        @Override
207
-        public boolean test(final Object arg1, final Object arg2) {
208
-            try {
209
-                return 0 > ((Integer) arg1).compareTo(Integer.parseInt((String) arg2));
210
-            } catch (NumberFormatException ex) {
211
-                return false;
212
-            }
213
-        }
214
-
215
-        @Override
216
-        public Class<?> appliesTo() {
217
-            return Integer.class;
218
-        }
219
-
220
-        @Override
221
-        public String getName() {
222
-            return "is less than";
223
-        }
224
-    }
225
-
226
-}

+ 0
- 721
src/com/dmdirc/actions/CoreActionComponent.java View File

@@ -1,721 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.Channel;
26
-import com.dmdirc.FrameContainer;
27
-import com.dmdirc.Query;
28
-import com.dmdirc.interfaces.Connection;
29
-import com.dmdirc.interfaces.PrivateChat;
30
-import com.dmdirc.interfaces.actions.ActionComponent;
31
-import com.dmdirc.interfaces.config.ConfigProvider;
32
-import com.dmdirc.interfaces.ui.Window;
33
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
34
-import com.dmdirc.parser.interfaces.ClientInfo;
35
-import com.dmdirc.parser.interfaces.LocalClientInfo;
36
-import com.dmdirc.parser.interfaces.Parser;
37
-import com.dmdirc.ui.messages.Styliser;
38
-
39
-import java.awt.AWTKeyStroke;
40
-import java.awt.event.InputEvent;
41
-import java.awt.event.KeyEvent;
42
-import java.util.Calendar;
43
-import java.util.Optional;
44
-
45
-import javax.swing.KeyStroke;
46
-
47
-/**
48
- * A CoreActionComponent represents a component of some object that the user can use as the subject
49
- * of a condition within an action.
50
- */
51
-public enum CoreActionComponent implements ActionComponent {
52
-
53
-    /** Returns the name of the server. */
54
-    SERVER_NAME {
55
-        @Override
56
-        public Object get(final Object arg) {
57
-            return ((Connection) arg).getAddress();
58
-        }
59
-
60
-        @Override
61
-        public Class<?> appliesTo() {
62
-            return Connection.class;
63
-        }
64
-
65
-        @Override
66
-        public Class<?> getType() {
67
-            return String.class;
68
-        }
69
-
70
-        @Override
71
-        public String getName() {
72
-            return "name";
73
-        }
74
-    },
75
-    /** Returns the network of the server. */
76
-    SERVER_NETWORK {
77
-        @Override
78
-        @ComponentOptions(requireConnected = true)
79
-        public Object get(final Object arg) {
80
-            return ((Connection) arg).getNetwork();
81
-        }
82
-
83
-        @Override
84
-        public Class<?> appliesTo() {
85
-            return Connection.class;
86
-        }
87
-
88
-        @Override
89
-        public Class<?> getType() {
90
-            return String.class;
91
-        }
92
-
93
-        @Override
94
-        public String getName() {
95
-            return "network";
96
-        }
97
-    },
98
-    /**
99
-     * Returns the protocol of the server.
100
-     *
101
-     * @since 0.6.4
102
-     */
103
-    SERVER_PROTOCOL {
104
-        @Override
105
-        public Object get(final Object arg) {
106
-            return ((Connection) arg).getProtocol();
107
-        }
108
-
109
-        @Override
110
-        public Class<?> appliesTo() {
111
-            return Connection.class;
112
-        }
113
-
114
-        @Override
115
-        public Class<?> getType() {
116
-            return String.class;
117
-        }
118
-
119
-        @Override
120
-        public String getName() {
121
-            return "protocol";
122
-        }
123
-    },
124
-    /** Returns the away reason for the server. */
125
-    SERVER_MYAWAYREASON {
126
-        @Override
127
-        public Object get(final Object arg) {
128
-            return ((Connection) arg).getAwayMessage();
129
-        }
130
-
131
-        @Override
132
-        public Class<?> appliesTo() {
133
-            return Connection.class;
134
-        }
135
-
136
-        @Override
137
-        public Class<?> getType() {
138
-            return String.class;
139
-        }
140
-
141
-        @Override
142
-        public String getName() {
143
-            return "away reason";
144
-        }
145
-    },
146
-    /** Returns the channel umodes for the server. */
147
-    SERVER_CHANNELUMODES {
148
-        @Override
149
-        @ComponentOptions(requireConnected = true)
150
-        public Object get(final Object arg) {
151
-            return ((Connection) arg).getParser().get().getChannelUserModes();
152
-        }
153
-
154
-        @Override
155
-        public Class<?> appliesTo() {
156
-            return Connection.class;
157
-        }
158
-
159
-        @Override
160
-        public Class<?> getType() {
161
-            return String.class;
162
-        }
163
-
164
-        @Override
165
-        public String getName() {
166
-            return "list of channel usermodes";
167
-        }
168
-    },
169
-    /** Returns the nickname for the server. */
170
-    SERVER_MYNICKNAME {
171
-        @Override
172
-        @ComponentOptions(requireConnected = true)
173
-        public Object get(final Object arg) {
174
-            return Optional.ofNullable((Connection) arg)
175
-                    .flatMap(Connection::getParser)
176
-                    .map(Parser::getLocalClient)
177
-                    .map(LocalClientInfo::getNickname)
178
-                    .orElse("null");
179
-        }
180
-
181
-        @Override
182
-        public Class<?> appliesTo() {
183
-            return Connection.class;
184
-        }
185
-
186
-        @Override
187
-        public Class<?> getType() {
188
-            return String.class;
189
-        }
190
-
191
-        @Override
192
-        public String getName() {
193
-            return "nickname";
194
-        }
195
-    },
196
-    /** Returns the name of the server. */
197
-    SERVER_PROFILE {
198
-        @Override
199
-        public Object get(final Object arg) {
200
-            return ((Connection) arg).getProfile();
201
-        }
202
-
203
-        @Override
204
-        public Class<?> appliesTo() {
205
-            return Connection.class;
206
-        }
207
-
208
-        @Override
209
-        public Class<?> getType() {
210
-            return ConfigProvider.class;
211
-        }
212
-
213
-        @Override
214
-        public String getName() {
215
-            return "profile";
216
-        }
217
-    },
218
-    /** Returns the name of the channel. */
219
-    CHANNEL_NAME {
220
-        @Override
221
-        public Object get(final Object arg) {
222
-            return ((Channel) arg).getChannelInfo().getName();
223
-        }
224
-
225
-        @Override
226
-        public Class<?> appliesTo() {
227
-            return Channel.class;
228
-        }
229
-
230
-        @Override
231
-        public Class<?> getType() {
232
-            return String.class;
233
-        }
234
-
235
-        @Override
236
-        public String getName() {
237
-            return "name";
238
-        }
239
-    },
240
-    /** Returns the name of a client. */
241
-    CLIENT_NAME {
242
-        @Override
243
-        public Object get(final Object arg) {
244
-            return ((ClientInfo) arg).getNickname();
245
-        }
246
-
247
-        @Override
248
-        public Class<?> appliesTo() {
249
-            return ClientInfo.class;
250
-        }
251
-
252
-        @Override
253
-        public Class<?> getType() {
254
-            return String.class;
255
-        }
256
-
257
-        @Override
258
-        public String getName() {
259
-            return "nickname";
260
-        }
261
-    },
262
-    /** Returns the host of a client. */
263
-    CLIENT_HOST {
264
-        @Override
265
-        public Object get(final Object arg) {
266
-            return ((ClientInfo) arg).getHostname();
267
-        }
268
-
269
-        @Override
270
-        public Class<?> appliesTo() {
271
-            return ClientInfo.class;
272
-        }
273
-
274
-        @Override
275
-        public Class<?> getType() {
276
-            return String.class;
277
-        }
278
-
279
-        @Override
280
-        public String getName() {
281
-            return "host";
282
-        }
283
-    },
284
-    /** Returns the name of a client. */
285
-    USER_NAME {
286
-        @Override
287
-        public Object get(final Object arg) {
288
-            return ((ChannelClientInfo) arg).getClient().getNickname();
289
-        }
290
-
291
-        @Override
292
-        public Class<?> appliesTo() {
293
-            return ChannelClientInfo.class;
294
-        }
295
-
296
-        @Override
297
-        public Class<?> getType() {
298
-            return String.class;
299
-        }
300
-
301
-        @Override
302
-        public String getName() {
303
-            return "nickname";
304
-        }
305
-    },
306
-    /** Returns the modes of a client. */
307
-    USER_MODES {
308
-        @Override
309
-        public Object get(final Object arg) {
310
-            return ((ChannelClientInfo) arg).getAllModes();
311
-        }
312
-
313
-        @Override
314
-        public Class<?> appliesTo() {
315
-            return ChannelClientInfo.class;
316
-        }
317
-
318
-        @Override
319
-        public Class<?> getType() {
320
-            return String.class;
321
-        }
322
-
323
-        @Override
324
-        public String getName() {
325
-            return "modes";
326
-        }
327
-    },
328
-    /** Returns the host of a client. */
329
-    USER_HOST {
330
-        @Override
331
-        public Object get(final Object arg) {
332
-            return ((ChannelClientInfo) arg).getClient().getHostname();
333
-        }
334
-
335
-        @Override
336
-        public Class<?> appliesTo() {
337
-            return ChannelClientInfo.class;
338
-        }
339
-
340
-        @Override
341
-        public Class<?> getType() {
342
-            return String.class;
343
-        }
344
-
345
-        @Override
346
-        public String getName() {
347
-            return "host";
348
-        }
349
-    },
350
-    /**
351
-     * Returns the number of common channels the client is on.
352
-     */
353
-    USER_COMCHANS {
354
-        @Override
355
-        public Object get(final Object arg) {
356
-            return ((ChannelClientInfo) arg).getClient().getChannelCount();
357
-        }
358
-
359
-        @Override
360
-        public Class<?> appliesTo() {
361
-            return ChannelClientInfo.class;
362
-        }
363
-
364
-        @Override
365
-        public Class<?> getType() {
366
-            return Integer.class;
367
-        }
368
-
369
-        @Override
370
-        public String getName() {
371
-            return "number of common channels";
372
-        }
373
-    },
374
-    /** Returns the content of a string. */
375
-    STRING_STRING {
376
-        @Override
377
-        public Object get(final Object arg) {
378
-            return arg;
379
-        }
380
-
381
-        @Override
382
-        public Class<?> appliesTo() {
383
-            return String.class;
384
-        }
385
-
386
-        @Override
387
-        public Class<?> getType() {
388
-            return String.class;
389
-        }
390
-
391
-        @Override
392
-        public String getName() {
393
-            return "content";
394
-        }
395
-    },
396
-    /**
397
-     * Returns the content of a string, stripped of formatting.
398
-     */
399
-    STRING_STRIPPED {
400
-        @Override
401
-        public Object get(final Object arg) {
402
-            return Styliser.stipControlCodes((String) arg);
403
-        }
404
-
405
-        @Override
406
-        public Class<?> appliesTo() {
407
-            return String.class;
408
-        }
409
-
410
-        @Override
411
-        public Class<?> getType() {
412
-            return String.class;
413
-        }
414
-
415
-        @Override
416
-        public String getName() {
417
-            return "content (without formatting)";
418
-        }
419
-    },
420
-    /** Returns the length of a string. */
421
-    STRING_LENGTH {
422
-        @Override
423
-        public Object get(final Object arg) {
424
-            return ((CharSequence) arg).length();
425
-        }
426
-
427
-        @Override
428
-        public Class<?> appliesTo() {
429
-            return String.class;
430
-        }
431
-
432
-        @Override
433
-        public Class<?> getType() {
434
-            return Integer.class;
435
-        }
436
-
437
-        @Override
438
-        public String getName() {
439
-            return "length";
440
-        }
441
-    },
442
-    /** Returns the size of a string array. */
443
-    STRINGARRAY_LENGTH {
444
-        @Override
445
-        public Object get(final Object arg) {
446
-            return ((String[]) arg).length;
447
-        }
448
-
449
-        @Override
450
-        public Class<?> appliesTo() {
451
-            return String[].class;
452
-        }
453
-
454
-        @Override
455
-        public Class<?> getType() {
456
-            return Integer.class;
457
-        }
458
-
459
-        @Override
460
-        public String getName() {
461
-            return "size";
462
-        }
463
-    },
464
-    /**
465
-     * Returns the readable representation of a date.
466
-     */
467
-    CALENDAR_FULLSTRING {
468
-        @Override
469
-        public Object get(final Object arg) {
470
-            return ((Calendar) arg).getTime().toString();
471
-        }
472
-
473
-        @Override
474
-        public Class<?> appliesTo() {
475
-            return Calendar.class;
476
-        }
477
-
478
-        @Override
479
-        public Class<?> getType() {
480
-            return String.class;
481
-        }
482
-
483
-        @Override
484
-        public String getName() {
485
-            return "full date";
486
-        }
487
-    },
488
-    /**
489
-     * Returns the name of the key that was pressed.
490
-     */
491
-    KEYEVENT_KEYNAME {
492
-        @Override
493
-        public Object get(final Object arg) {
494
-            return KeyEvent.getKeyText(((AWTKeyStroke) arg).getKeyCode());
495
-        }
496
-
497
-        @Override
498
-        public Class<?> appliesTo() {
499
-            return KeyStroke.class;
500
-        }
501
-
502
-        @Override
503
-        public Class<?> getType() {
504
-            return String.class;
505
-        }
506
-
507
-        @Override
508
-        public String getName() {
509
-            return "key name";
510
-        }
511
-    },
512
-    /**
513
-     * Returns the state of the control key for a key press event.
514
-     */
515
-    KEYEVENT_CTRLSTATE {
516
-        @Override
517
-        public Object get(final Object arg) {
518
-            return (((AWTKeyStroke) arg).getModifiers() & InputEvent.CTRL_DOWN_MASK) != 0;
519
-        }
520
-
521
-        @Override
522
-        public Class<?> appliesTo() {
523
-            return KeyStroke.class;
524
-        }
525
-
526
-        @Override
527
-        public Class<?> getType() {
528
-            return Boolean.class;
529
-        }
530
-
531
-        @Override
532
-        public String getName() {
533
-            return "control key state";
534
-        }
535
-    },
536
-    /**
537
-     * Returns the state of the shift key for a key press event.
538
-     */
539
-    KEYEVENT_SHIFTSTATE {
540
-        @Override
541
-        public Object get(final Object arg) {
542
-            return (((AWTKeyStroke) arg).getModifiers() & InputEvent.SHIFT_DOWN_MASK) != 0;
543
-        }
544
-
545
-        @Override
546
-        public Class<?> appliesTo() {
547
-            return KeyStroke.class;
548
-        }
549
-
550
-        @Override
551
-        public Class<?> getType() {
552
-            return Boolean.class;
553
-        }
554
-
555
-        @Override
556
-        public String getName() {
557
-            return "shift key state";
558
-        }
559
-    },
560
-    /**
561
-     * Returns the state of the shift key for a key press event.
562
-     */
563
-    KEYEVENT_ALTSTATE {
564
-        @Override
565
-        public Object get(final Object arg) {
566
-            return (((AWTKeyStroke) arg).getModifiers() & InputEvent.ALT_DOWN_MASK) != 0;
567
-        }
568
-
569
-        @Override
570
-        public Class<?> appliesTo() {
571
-            return KeyStroke.class;
572
-        }
573
-
574
-        @Override
575
-        public Class<?> getType() {
576
-            return Boolean.class;
577
-        }
578
-
579
-        @Override
580
-        public String getName() {
581
-            return "alt key state";
582
-        }
583
-    },
584
-    /** Returns the host of the query. */
585
-    QUERY_HOST {
586
-        @Override
587
-        public Object get(final Object arg) {
588
-            return ((PrivateChat) arg).getHost();
589
-        }
590
-
591
-        @Override
592
-        public Class<?> appliesTo() {
593
-            return Query.class;
594
-        }
595
-
596
-        @Override
597
-        public Class<?> getType() {
598
-            return String.class;
599
-        }
600
-
601
-        @Override
602
-        public String getName() {
603
-            return "host";
604
-        }
605
-    },
606
-    /** Returns the host of the query. */
607
-    QUERY_NICK {
608
-        @Override
609
-        public Object get(final Object arg) {
610
-            return ((FrameContainer) arg).getName();
611
-        }
612
-
613
-        @Override
614
-        public Class<?> appliesTo() {
615
-            return Query.class;
616
-        }
617
-
618
-        @Override
619
-        public Class<?> getType() {
620
-            return String.class;
621
-        }
622
-
623
-        @Override
624
-        public String getName() {
625
-            return "nick";
626
-        }
627
-    },
628
-    /** The name of a window. */
629
-    WINDOW_NAME {
630
-        @Override
631
-        public Object get(final Object arg) {
632
-            return ((FrameContainer) arg).getName();
633
-        }
634
-
635
-        @Override
636
-        public Class<?> appliesTo() {
637
-            return FrameContainer.class;
638
-        }
639
-
640
-        @Override
641
-        public Class<?> getType() {
642
-            return String.class;
643
-        }
644
-
645
-        @Override
646
-        public String getName() {
647
-            return "name";
648
-        }
649
-    },
650
-    /**
651
-     * Returns the server of the window.
652
-     *
653
-     * @since 0.6.4
654
-     */
655
-    WINDOW_SERVER {
656
-        @Override
657
-        public Object get(final Object arg) {
658
-            return ((Window) arg).getContainer().getConnection().orElse(null);
659
-        }
660
-
661
-        @Override
662
-        public Class<?> appliesTo() {
663
-            return Window.class;
664
-        }
665
-
666
-        @Override
667
-        public Class<?> getType() {
668
-            return Connection.class;
669
-        }
670
-
671
-        @Override
672
-        public String getName() {
673
-            return "server";
674
-        }
675
-    },
676
-    /** Returns the name of an identity. */
677
-    IDENTITY_NAME {
678
-        @Override
679
-        public Object get(final Object arg) {
680
-            return ((ConfigProvider) arg).getName();
681
-        }
682
-
683
-        @Override
684
-        public Class<?> appliesTo() {
685
-            return ConfigProvider.class;
686
-        }
687
-
688
-        @Override
689
-        public Class<?> getType() {
690
-            return String.class;
691
-        }
692
-
693
-        @Override
694
-        public String getName() {
695
-            return "name";
696
-        }
697
-    },
698
-    /** Returns the value of an integer. */
699
-    INTEGER_VALUE {
700
-        @Override
701
-        public Object get(final Object arg) {
702
-            return arg;
703
-        }
704
-
705
-        @Override
706
-        public Class<?> appliesTo() {
707
-            return Integer.class;
708
-        }
709
-
710
-        @Override
711
-        public Class<?> getType() {
712
-            return Integer.class;
713
-        }
714
-
715
-        @Override
716
-        public String getName() {
717
-            return "value";
718
-        }
719
-    }
720
-
721
-}

+ 0
- 82
src/com/dmdirc/actions/CoreActionExtractor.java View File

@@ -1,82 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
27
-import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
28
-import com.dmdirc.events.UserErrorEvent;
29
-import com.dmdirc.interfaces.ActionController;
30
-import com.dmdirc.logger.ErrorLevel;
31
-import com.dmdirc.util.io.FileUtils;
32
-
33
-import java.io.IOException;
34
-import java.nio.file.Path;
35
-
36
-import javax.inject.Inject;
37
-import javax.inject.Singleton;
38
-
39
-/**
40
- * Utility class that can extract bundled actions.
41
- */
42
-@Singleton
43
-public class CoreActionExtractor {
44
-
45
-    /** The action manager to inform when actions are updated. */
46
-    private final ActionController actionManager;
47
-    /** The directory to extract actions to. */
48
-    private final Path actionsDir;
49
-    /** The event bus to post events to. */
50
-    private final DMDircMBassador eventBus;
51
-
52
-    /**
53
-     * Creates a new instance of {@link CoreActionExtractor}.
54
-     *
55
-     * @param actionManager  The action manager to inform when actions are updated.
56
-     * @param actionsDir     The directory to extract actions to.
57
-     * @param eventBus       The event bus to post events to.
58
-     */
59
-    @Inject
60
-    public CoreActionExtractor(final ActionController actionManager,
61
-            @Directory(DirectoryType.ACTIONS) final Path actionsDir,
62
-            final DMDircMBassador eventBus) {
63
-        this.actionManager = actionManager;
64
-        this.actionsDir = actionsDir;
65
-        this.eventBus = eventBus;
66
-    }
67
-
68
-    /**
69
-     * Extracts actions bundled with DMDirc to the user's profile's actions directory.
70
-     */
71
-    public void extractCoreActions() {
72
-        try {
73
-            FileUtils.copyResourcesContents(getClass().getResource("/com/dmdirc/actions/defaults/"),
74
-                    actionsDir);
75
-            actionManager.loadUserActions();
76
-        } catch (IOException ex) {
77
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex,
78
-                    "Failed to extract actions: " + ex.getMessage(), ""));
79
-        }
80
-    }
81
-
82
-}

+ 0
- 319
src/com/dmdirc/actions/CoreActionType.java View File

@@ -1,319 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.actions.metatypes.ActionEvents;
26
-import com.dmdirc.actions.metatypes.ChannelEvents;
27
-import com.dmdirc.actions.metatypes.ClientEvents;
28
-import com.dmdirc.actions.metatypes.LinkEvents;
29
-import com.dmdirc.actions.metatypes.PluginEvents;
30
-import com.dmdirc.actions.metatypes.QueryEvents;
31
-import com.dmdirc.actions.metatypes.ServerEvents;
32
-import com.dmdirc.interfaces.actions.ActionMetaType;
33
-import com.dmdirc.interfaces.actions.ActionType;
34
-
35
-/**
36
- * An enumeration of actions that are raised by the core.
37
- */
38
-public enum CoreActionType implements ActionType {
39
-
40
-    /** Client opened. */
41
-    @Deprecated
42
-    CLIENT_OPENED(ClientEvents.CLIENT_EVENT, "Client opened"),
43
-    /** Client closed. */
44
-    @Deprecated
45
-    CLIENT_CLOSED(ClientEvents.CLIENT_EVENT, "Client closed"),
46
-    /** Client closing. */
47
-    @Deprecated
48
-    CLIENT_CLOSING(ClientEvents.CLIENT_EVENT, "Client closing"),
49
-    /** Client minimised. */
50
-    @Deprecated
51
-    CLIENT_MINIMISED(ClientEvents.CLIENT_EVENT, "Client minimised"),
52
-    /** Client unminimised. */
53
-    @Deprecated
54
-    CLIENT_UNMINIMISED(ClientEvents.CLIENT_EVENT, "Client unminimised"),
55
-    /** Client lost focus. */
56
-    @Deprecated
57
-    CLIENT_FOCUS_LOST(ClientEvents.CLIENT_EVENT, "Client lost focus"),
58
-    /** Client gained focus. */
59
-    @Deprecated
60
-    CLIENT_FOCUS_GAINED(ClientEvents.CLIENT_EVENT, "Client gained focus"),
61
-    /** Function key pressed. */
62
-    @Deprecated
63
-    CLIENT_KEY_PRESSED(ClientEvents.CLIENT_EVENT_WITH_KEY, "Function key pressed"),
64
-    /** Frame changed. */
65
-    @Deprecated
66
-    CLIENT_FRAME_CHANGED(ClientEvents.WINDOW_EVENT, "Frame changed"),
67
-    /** User input. */
68
-    @Deprecated
69
-    CLIENT_USER_INPUT(ClientEvents.CLIENT_EVENT_WITH_BUFFER, "User input"),
70
-    /** Line added. */
71
-    @Deprecated
72
-    CLIENT_LINE_ADDED(ClientEvents.WINDOW_EVENT_WITH_MESSAGE, "Line added to a window"),
73
-    /** Popup generated. */
74
-    @Deprecated
75
-    CLIENT_POPUP_GENERATED(ClientEvents.POPUP_EVENT, "Popup menu generated"),
76
-    /** Prefs dialog opened. */
77
-    @Deprecated
78
-    CLIENT_PREFS_OPENED(ClientEvents.CLIENT_EVENT_WITH_PREFS, "Preferences dialog opened"),
79
-    /** Context-specific prefs requested. */
80
-    @Deprecated
81
-    CLIENT_PREFS_REQUESTED(ClientEvents.CLIENT_EVENT_WITH_PREFS_CAT, "Preferences requested"),
82
-    /** Prefs dialog closed. */
83
-    @Deprecated
84
-    CLIENT_PREFS_CLOSED(ClientEvents.CLIENT_EVENT, "Preferences dialog opened"),
85
-    /** Unknown command. */
86
-    @Deprecated
87
-    UNKNOWN_COMMAND(ClientEvents.UNKNOWN_COMMAND, "Unknown command entered"),
88
-    /** Server numeric received. */
89
-    @Deprecated
90
-    SERVER_NUMERIC(ServerEvents.SERVER_NUMERIC, "Numeric event received"),
91
-    /** Server connected. */
92
-    @Deprecated
93
-    SERVER_CONNECTED(ServerEvents.SERVER_EVENT, "Server connected"),
94
-    /** Server connecting. */
95
-    @Deprecated
96
-    SERVER_CONNECTING(ServerEvents.SERVER_EVENT, "Server connecting"),
97
-    /** Server connection error. */
98
-    @Deprecated
99
-    SERVER_CONNECTERROR(ServerEvents.SERVER_EVENT_WITH_ARG, "Server connection error"),
100
-    /** Server disconnected. */
101
-    @Deprecated
102
-    SERVER_DISCONNECTED(ServerEvents.SERVER_EVENT, "Server disconnected"),
103
-    /** Marked as away. */
104
-    @Deprecated
105
-    SERVER_BACK(ServerEvents.SERVER_EVENT, "Marked as 'back'"),
106
-    /** Marked as back. */
107
-    @Deprecated
108
-    SERVER_AWAY(ServerEvents.SERVER_EVENT_WITH_ARG, "Marked as 'away'"),
109
-    /** Error. */
110
-    @Deprecated
111
-    SERVER_ERROR(ServerEvents.SERVER_EVENT_WITH_ARG, "Server error"),
112
-    /** Auth notice received. */
113
-    @Deprecated
114
-    SERVER_AUTHNOTICE(ServerEvents.SERVER_EVENT_WITH_ARG, "Received auth notice"),
115
-    /** Unknown action received. */
116
-    @Deprecated
117
-    SERVER_UNKNOWNACTION(ServerEvents.SERVER_UNKNOWN_EVENT, "Received unknown action"),
118
-    /** Unknown notice received. */
119
-    @Deprecated
120
-    SERVER_UNKNOWNNOTICE(ServerEvents.SERVER_UNKNOWN_EVENT, "Received unknown notice"),
121
-    /** Unknown message received. */
122
-    @Deprecated
123
-    SERVER_UNKNOWNMESSAGE(ServerEvents.SERVER_UNKNOWN_EVENT, "Received unknown message"),
124
-    /** User modes changed. */
125
-    @Deprecated
126
-    SERVER_USERMODES(ServerEvents.SERVER_SOURCED_EVENT_WITH_ARG, "User modes changed"),
127
-    /** Private CTCP received. */
128
-    @Deprecated
129
-    SERVER_CTCP(ServerEvents.SERVER_CTCP_EVENT, "CTCP received"),
130
-    /** Private CTCPR received. */
131
-    @Deprecated
132
-    SERVER_CTCPR(ServerEvents.SERVER_CTCP_EVENT, "CTCP reply received"),
133
-    /** Private notice received. */
134
-    @Deprecated
135
-    SERVER_NOTICE(ServerEvents.SERVER_SOURCED_EVENT_WITH_ARG, "Notice received"),
136
-    /** Private server notice received. */
137
-    @Deprecated
138
-    SERVER_SERVERNOTICE(ServerEvents.SERVER_SOURCED_EVENT_WITH_ARG, "Server notice received"),
139
-    /** MOTD starting. */
140
-    @Deprecated
141
-    SERVER_MOTDSTART(ServerEvents.SERVER_EVENT_WITH_ARG, "Start of MOTD received"),
142
-    /** MOTD ended. */
143
-    @Deprecated
144
-    SERVER_MOTDEND(ServerEvents.SERVER_EVENT_WITH_ARG, "End of MOTD received"),
145
-    /** MOTD line. */
146
-    @Deprecated
147
-    SERVER_MOTDLINE(ServerEvents.SERVER_EVENT_WITH_ARG, "MOTD line received"),
148
-    /** Ping reply received. */
149
-    @Deprecated
150
-    SERVER_GOTPING(ServerEvents.SERVER_PING, "Received server ping reply"),
151
-    /** Missed server ping reply. */
152
-    @Deprecated
153
-    SERVER_NOPING(ServerEvents.SERVER_PING, "Missed server ping reply"),
154
-    /** Ping sent. */
155
-    @Deprecated
156
-    SERVER_PINGSENT(ServerEvents.SERVER_EVENT, "Ping request sent"),
157
-    /** Invite received. */
158
-    @Deprecated
159
-    SERVER_INVITERECEIVED(ServerEvents.SERVER_INVITE, "Invite received"),
160
-    /** Wallops. */
161
-    @Deprecated
162
-    SERVER_WALLOPS(ServerEvents.SERVER_SOURCED_EVENT_WITH_ARG, "Wallop received"),
163
-    /** Wallusers. */
164
-    @Deprecated
165
-    SERVER_WALLUSERS(ServerEvents.SERVER_SOURCED_EVENT_WITH_ARG, "Walluser received"),
166
-    /** Walldesync. */
167
-    @Deprecated
168
-    SERVER_WALLDESYNC(ServerEvents.SERVER_SOURCED_EVENT_WITH_ARG, "Walldesync received"),
169
-    /** Nick change. */
170
-    @Deprecated
171
-    SERVER_NICKCHANGE(ServerEvents.SERVER_NICKCHANGE, "My nickname changed"),
172
-    /** Names reply received. */
173
-    @Deprecated
174
-    CHANNEL_GOTNAMES(ChannelEvents.CHANNEL_EVENT, "Channel names reply received"),
175
-    /** Channel topic is not set. */
176
-    @Deprecated
177
-    CHANNEL_NOTOPIC(ChannelEvents.CHANNEL_EVENT, "Channel topic is not set"),
178
-    /** Channel topic received. */
179
-    @Deprecated
180
-    CHANNEL_GOTTOPIC(ChannelEvents.CHANNEL_TOPICEVENT, "Channel topic received"),
181
-    /** Channel message sent. */
182
-    @Deprecated
183
-    CHANNEL_SELF_MESSAGE(ChannelEvents.CHANNEL_SOURCED_EVENT_WITH_ARG, "Channel message sent"),
184
-    /** Channel action sent. */
185
-    @Deprecated
186
-    CHANNEL_SELF_ACTION(ChannelEvents.CHANNEL_SOURCED_EVENT_WITH_ARG, "Channel action sent"),
187
-    /** Channel message received. */
188
-    @Deprecated
189
-    CHANNEL_MESSAGE(ChannelEvents.CHANNEL_SOURCED_EVENT_WITH_ARG, "Channel message received"),
190
-    /** Channel actions received. */
191
-    @Deprecated
192
-    CHANNEL_ACTION(ChannelEvents.CHANNEL_SOURCED_EVENT_WITH_ARG, "Channel action received"),
193
-    /** Channel notice received. */
194
-    @Deprecated
195
-    CHANNEL_NOTICE(ChannelEvents.CHANNEL_SOURCED_EVENT_WITH_ARG, "Channel notice received"),
196
-    /** Channel mode notice received. */
197
-    @Deprecated
198
-    CHANNEL_MODE_NOTICE(ChannelEvents.CHANNEL_SOURCED_EVENT_WITH_CHARARG,
199
-            "Channel mode notice received"),
200
-    /** Channel CTCP received. */
201
-    @Deprecated
202
-    CHANNEL_CTCP(ChannelEvents.CHANNEL_CTCP, "Channel CTCP received"),
203
-    /** Someone joined a channel. */
204
-    @Deprecated
205
-    CHANNEL_JOIN(ChannelEvents.CHANNEL_SOURCED_EVENT, "Someone joined a channel"),
206
-    /** Someone left a channel. */
207
-    @Deprecated
208
-    CHANNEL_PART(ChannelEvents.CHANNEL_SOURCED_EVENT_WITH_ARG, "Someone left a channel"),
209
-    /** Someone quit. */
210
-    @Deprecated
211
-    CHANNEL_QUIT(ChannelEvents.CHANNEL_SOURCED_EVENT_WITH_ARG, "Someone quit IRC"),
212
-    /** Someone was kicked. */
213
-    @Deprecated
214
-    CHANNEL_KICK(ChannelEvents.CHANNEL_SOURCED_EVENT_WITH_VICTIM, "Someone kicked someone"),
215
-    /** Someone marked as away. */
216
-    @Deprecated
217
-    CHANNEL_USERAWAY(ChannelEvents.CHANNEL_SOURCED_EVENT, "Someone is marked as 'away'"),
218
-    /** Someone marked as back. */
219
-    @Deprecated
220
-    CHANNEL_USERBACK(ChannelEvents.CHANNEL_SOURCED_EVENT, "Someone is marked as 'back'"),
221
-    /** Channel list mode retrieved. */
222
-    @Deprecated
223
-    CHANNEL_LISTMODERETRIEVED(ChannelEvents.CHANNEL_LISTMODEEVENT,
224
-            "Channel list mode value retrieved"),
225
-    /** Channel mode discovered. */
226
-    @Deprecated
227
-    CHANNEL_MODESDISCOVERED(ChannelEvents.CHANNEL_MODEEVENT, "Channel modes discovered"),
228
-    /** Channel mode changes. */
229
-    @Deprecated
230
-    CHANNEL_MODECHANGE(ChannelEvents.CHANNEL_SOURCED_EVENT_WITH_ARG, "Someone changed channel modes"),
231
-    /** Someone changed someone else's user modes. */
232
-    @Deprecated
233
-    CHANNEL_USERMODECHANGE(ChannelEvents.CHANNEL_SOURCED_EVENT_WITH_VICTIM,
234
-            "Someone changed someone else's modes"),
235
-    /** Someone changed nickname. */
236
-    @Deprecated
237
-    CHANNEL_NICKCHANGE(ChannelEvents.CHANNEL_NICKEVENT, "Someone changed nicknames"),
238
-    /** Someone changed a topic. */
239
-    @Deprecated
240
-    CHANNEL_TOPICCHANGE(ChannelEvents.CHANNEL_SOURCED_EVENT_WITH_ARG,
241
-            "Someone changed channel topic"),
242
-    /** Query opened. */
243
-    @Deprecated
244
-    QUERY_OPENED(QueryEvents.QUERY_EVENT, "Query window opened"),
245
-    /** Query closed. */
246
-    @Deprecated
247
-    QUERY_CLOSED(QueryEvents.QUERY_EVENT, "Query window closed"),
248
-    /** Query message received. */
249
-    @Deprecated
250
-    QUERY_MESSAGE(QueryEvents.QUERY_SOURCED_EVENT_WITH_ARG, "Private message received"),
251
-    /** Query action received. */
252
-    @Deprecated
253
-    QUERY_ACTION(QueryEvents.QUERY_SOURCED_EVENT_WITH_ARG, "Private action received"),
254
-    /** Query message sent. */
255
-    @Deprecated
256
-    QUERY_SELF_MESSAGE(QueryEvents.QUERY_SOURCED_EVENT_WITH_ARG, "Private message sent"),
257
-    /** Query action sent. */
258
-    @Deprecated
259
-    QUERY_SELF_ACTION(QueryEvents.QUERY_SOURCED_EVENT_WITH_ARG, "Private action sent"),
260
-    /** Query quit event. */
261
-    @Deprecated
262
-    QUERY_QUIT(QueryEvents.QUERY_EVENT_WITH_ARG, "Query: user quit"),
263
-    /** Query nick change. */
264
-    @Deprecated
265
-    QUERY_NICKCHANGE(QueryEvents.QUERY_EVENT_WITH_ARG, "Query: user changed nicks"),
266
-    /** Plugin loaded. */
267
-    @Deprecated
268
-    PLUGIN_LOADED(PluginEvents.PLUGIN_EVENT, "Plugin loaded"),
269
-    /** Plugin unloaded. */
270
-    @Deprecated
271
-    PLUGIN_UNLOADED(PluginEvents.PLUGIN_EVENT, "Plugin unloaded"),
272
-    /** Plugins have been refreshed. */
273
-    @Deprecated
274
-    PLUGIN_REFRESH(PluginEvents.PLUGIN_EVENT, "Plugins refreshed"),
275
-    /** Action created. */
276
-    @Deprecated
277
-    ACTION_CREATED(ActionEvents.ACTION_EVENT, "Action created"),
278
-    /** Action updated. */
279
-    @Deprecated
280
-    ACTION_UPDATED(ActionEvents.ACTION_EVENT, "Action updated"),
281
-    /** Action deleted. */
282
-    @Deprecated
283
-    ACTION_DELETED(ActionEvents.ACTION_DELETED, "Action deleted"),
284
-    /** Channel clicked. */
285
-    @Deprecated
286
-    LINK_CHANNEL_CLICKED(LinkEvents.CHANNEL_CLICKED, "A channel link was clicked"),
287
-    /** Channel clicked. */
288
-    @Deprecated
289
-    LINK_NICKNAME_CLICKED(LinkEvents.NICKNAME_CLICKED, "A nickname link was clicked"),
290
-    /** Link clicked. */
291
-    @Deprecated
292
-    LINK_URL_CLICKED(LinkEvents.LINK_CLICKED, "A Link was clicked");
293
-    /** The type of this action. */
294
-    private final ActionMetaType type;
295
-    /** The name of this action. */
296
-    private final String name;
297
-
298
-    /**
299
-     * Constructs a new core action.
300
-     *
301
-     * @param type The type of this action
302
-     * @param name The name of this action
303
-     */
304
-    CoreActionType(final ActionMetaType type, final String name) {
305
-        this.type = type;
306
-        this.name = name;
307
-    }
308
-
309
-    @Override
310
-    public ActionMetaType getType() {
311
-        return type;
312
-    }
313
-
314
-    @Override
315
-    public String getName() {
316
-        return name;
317
-    }
318
-
319
-}

+ 0
- 20
src/com/dmdirc/actions/defaults/umodes/ohv View File

@@ -1,20 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-# Written on: Mon Dec 17 23:32:19 GMT 2007
3
-
4
-# This section indicates which sections below take key/value
5
-# pairs, rather than a simple list. It should be placed above
6
-# any sections that take key/values.
7
-keysections:
8
-  condition 0
9
-
10
-triggers:
11
-  SERVER_CONNECTED
12
-
13
-response:
14
-  /.set --server popup umodes <umodes-op\n<umodes-hop\n<umodes-voice
15
-
16
-condition 0:
17
-  argument=0
18
-  component=SERVER_CHANNELUMODES
19
-  target=ohv
20
-  comparison=STRING_EQUALS

+ 0
- 27
src/com/dmdirc/actions/defaults/umodes/ov View File

@@ -1,27 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-# Written on: Mon Dec 17 23:32:19 GMT 2007
3
-
4
-# This section indicates which sections below take key/value
5
-# pairs, rather than a simple list. It should be placed above
6
-# any sections that take key/values.
7
-keysections:
8
-  condition 0
9
-  metadata
10
-
11
-triggers:
12
-  SERVER_CONNECTED
13
-
14
-response:
15
-  /.set --server popup umodes <umodes-op\n<umodes-voice
16
-
17
-condition 0:
18
-  argument=0
19
-  component=SERVER_CHANNELUMODES
20
-  target=ov
21
-  comparison=STRING_EQUALS
22
-
23
-metadata:
24
-  description=Automatically sets the popup.umodes setting when connecting to a server, so that the correct user modes appear in the nicklist popup.
25
-  author=Chris <chris@dmdirc.com>
26
-  version=2
27
-  component=19

+ 0
- 20
src/com/dmdirc/actions/defaults/umodes/qaohv View File

@@ -1,20 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-# Written on: Mon Dec 17 23:32:19 GMT 2007
3
-
4
-# This section indicates which sections below take key/value
5
-# pairs, rather than a simple list. It should be placed above
6
-# any sections that take key/values.
7
-keysections:
8
-  condition 0
9
-
10
-triggers:
11
-  SERVER_CONNECTED
12
-
13
-response:
14
-  /.set --server popup umodes <umodes-op\n<umodes-hop\n<umodes-voice\n-\n<umodes-admin\n<umodes-owner
15
-
16
-condition 0:
17
-  argument=0
18
-  component=SERVER_CHANNELUMODES
19
-  target=qaohv
20
-  comparison=STRING_EQUALS

+ 0
- 20
src/com/dmdirc/actions/defaults/umodes/qaov View File

@@ -1,20 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-# Written on: Mon Dec 17 23:32:19 GMT 2007
3
-
4
-# This section indicates which sections below take key/value
5
-# pairs, rather than a simple list. It should be placed above
6
-# any sections that take key/values.
7
-keysections:
8
-  condition 0
9
-
10
-triggers:
11
-  SERVER_CONNECTED
12
-
13
-response:
14
-  /.set --server popup umodes <umodes-op\n<umodes-voice\n-\n<umodes-admin\n<umodes-owner
15
-
16
-condition 0:
17
-  argument=0
18
-  component=SERVER_CHANNELUMODES
19
-  target=qaov
20
-  comparison=STRING_EQUALS

+ 0
- 74
src/com/dmdirc/actions/metatypes/ActionEvents.java View File

@@ -1,74 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions.metatypes;
24
-
25
-import com.dmdirc.actions.Action;
26
-import com.dmdirc.actions.ActionGroup;
27
-import com.dmdirc.interfaces.actions.ActionMetaType;
28
-
29
-/**
30
- * Defines action-related events.
31
- */
32
-public enum ActionEvents implements ActionMetaType {
33
-
34
-    /** Action event type. */
35
-    ACTION_EVENT(new String[]{"action"}, Action.class),
36
-    /** Action event type. */
37
-    ACTION_DELETED(new String[]{"Action group", "Action name"}, ActionGroup.class, String.class);
38
-    /** The names of the arguments for this meta type. */
39
-    private final String[] argNames;
40
-    /** The classes of the arguments for this meta type. */
41
-    private final Class<?>[] argTypes;
42
-
43
-    /**
44
-     * Creates a new instance of this meta-type.
45
-     *
46
-     * @param argNames The names of the meta-type's arguments
47
-     * @param argTypes The types of the meta-type's arguments
48
-     */
49
-    ActionEvents(final String[] argNames, final Class<?>... argTypes) {
50
-        this.argNames = argNames;
51
-        this.argTypes = argTypes;
52
-    }
53
-
54
-    @Override
55
-    public int getArity() {
56
-        return argNames.length;
57
-    }
58
-
59
-    @Override
60
-    public Class<?>[] getArgTypes() {
61
-        return argTypes;
62
-    }
63
-
64
-    @Override
65
-    public String[] getArgNames() {
66
-        return argNames;
67
-    }
68
-
69
-    @Override
70
-    public String getGroup() {
71
-        return "Action Events";
72
-    }
73
-
74
-}

+ 0
- 98
src/com/dmdirc/actions/metatypes/ChannelEvents.java View File

@@ -1,98 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions.metatypes;
24
-
25
-import com.dmdirc.Channel;
26
-import com.dmdirc.Topic;
27
-import com.dmdirc.interfaces.actions.ActionMetaType;
28
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
29
-
30
-/**
31
- * Defines channel-related events.
32
- */
33
-public enum ChannelEvents implements ActionMetaType {
34
-
35
-    /** Channel event type. */
36
-    CHANNEL_EVENT(new String[]{"channel"}, Channel.class),
37
-    /** Channel mode event. */
38
-    CHANNEL_MODEEVENT(new String[]{"channel", "modes"}, Channel.class, String.class),
39
-    /** Channel list mode event. */
40
-    CHANNEL_LISTMODEEVENT(new String[]{"channel", "mode"}, Channel.class, Character.class),
41
-    /** Channel topic event type. */
42
-    CHANNEL_TOPICEVENT(new String[]{"channel", "topic"}, Channel.class, Topic.class),
43
-    /** Channel CTCP type. */
44
-    CHANNEL_CTCP(new String[]{"channel", "user", "type", "content"}, Channel.class,
45
-            ChannelClientInfo.class, String.class, String.class),
46
-    /** Channel event with source. */
47
-    CHANNEL_SOURCED_EVENT(new String[]{"channel", "user"}, Channel.class, ChannelClientInfo.class),
48
-    /** Chanel event with source and argument. */
49
-    CHANNEL_SOURCED_EVENT_WITH_ARG(new String[]{"channel", "user", "message"}, Channel.class,
50
-            ChannelClientInfo.class, String.class),
51
-    /** Chanel event with source and nickname. */
52
-    CHANNEL_NICKEVENT(new String[]{"channel", "user", "old nickname"}, Channel.class,
53
-            ChannelClientInfo.class, String.class),
54
-    /** Chanel event with source, message and mode character argument.
55
-     *
56
-     * @since 0.6.3m2 */
57
-    CHANNEL_SOURCED_EVENT_WITH_CHARARG(new String[]{"channel", "user", "mode", "message"},
58
-            Channel.class, ChannelClientInfo.class, String.class, String.class),
59
-    /** Channel event with source and victim. */
60
-    CHANNEL_SOURCED_EVENT_WITH_VICTIM(new String[]{"channel", "user", "victim", "message"},
61
-            Channel.class, ChannelClientInfo.class, ChannelClientInfo.class, String.class);
62
-    /** The names of the arguments for this meta type. */
63
-    private final String[] argNames;
64
-    /** The classes of the arguments for this meta type. */
65
-    private final Class<?>[] argTypes;
66
-
67
-    /**
68
-     * Creates a new instance of this meta-type.
69
-     *
70
-     * @param argNames The names of the meta-type's arguments
71
-     * @param argTypes The types of the meta-type's arguments
72
-     */
73
-    ChannelEvents(final String[] argNames, final Class<?>... argTypes) {
74
-        this.argNames = argNames;
75
-        this.argTypes = argTypes;
76
-    }
77
-
78
-    @Override
79
-    public int getArity() {
80
-        return argNames.length;
81
-    }
82
-
83
-    @Override
84
-    public Class<?>[] getArgTypes() {
85
-        return argTypes;
86
-    }
87
-
88
-    @Override
89
-    public String[] getArgNames() {
90
-        return argNames;
91
-    }
92
-
93
-    @Override
94
-    public String getGroup() {
95
-        return "Channel Events";
96
-    }
97
-
98
-}

+ 0
- 103
src/com/dmdirc/actions/metatypes/ClientEvents.java View File

@@ -1,103 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions.metatypes;
24
-
25
-import com.dmdirc.FrameContainer;
26
-import com.dmdirc.commandparser.PopupMenu;
27
-import com.dmdirc.commandparser.PopupType;
28
-import com.dmdirc.config.prefs.PreferencesCategory;
29
-import com.dmdirc.config.prefs.PreferencesDialogModel;
30
-import com.dmdirc.interfaces.actions.ActionMetaType;
31
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
32
-
33
-import javax.swing.KeyStroke;
34
-import javax.swing.text.StyledDocument;
35
-
36
-/**
37
- * Defines client-wide events.
38
- */
39
-public enum ClientEvents implements ActionMetaType {
40
-
41
-    /** Client event type. */
42
-    CLIENT_EVENT(new String[]{}),
43
-    /** Client event type, with a frame argument. */
44
-    WINDOW_EVENT(new String[]{"window"}, FrameContainer.class),
45
-    /** Client event with frame and message. */
46
-    WINDOW_EVENT_WITH_MESSAGE(new String[]{"window", "message"}, FrameContainer.class, String.class),
47
-    /** A popup-related event. */
48
-    POPUP_EVENT(new String[]{"popup type", "popup", "configuration provider"}, PopupType.class,
49
-            PopupMenu.class, AggregateConfigProvider.class),
50
-    /** Client event type, with a key argument. */
51
-    CLIENT_EVENT_WITH_KEY(new String[]{"key event"}, KeyStroke.class),
52
-    /** Client event with an origin and
53
-     * editable buffer. */
54
-    CLIENT_EVENT_WITH_BUFFER(new String[]{"origin", "buffer"}, FrameContainer.class,
55
-            StringBuffer.class),
56
-    /** Client event with preferences manager. */
57
-    CLIENT_EVENT_WITH_PREFS(new String[]{"preferences manager"}, PreferencesDialogModel.class),
58
-    /** Client event with preferences category. */
59
-    CLIENT_EVENT_WITH_PREFS_CAT(new String[]{"preferences category", "is server"},
60
-            PreferencesCategory.class, Boolean.class),
61
-    /** Client event with a styled doc. */
62
-    CLIENT_EVENT_WITH_STYLE(new String[]{"styled document", "start offset", "length"},
63
-            StyledDocument.class, Integer.class, Integer.class),
64
-    /** Unknown command event type. */
65
-    UNKNOWN_COMMAND(new String[]{"source", "command", "arguments"}, FrameContainer.class,
66
-            String.class, String[].class);
67
-    /** The names of the arguments for this meta type. */
68
-    private final String[] argNames;
69
-    /** The classes of the arguments for this meta type. */
70
-    private final Class<?>[] argTypes;
71
-
72
-    /**
73
-     * Creates a new instance of this meta-type.
74
-     *
75
-     * @param argNames The names of the meta-type's arguments
76
-     * @param argTypes The types of the meta-type's arguments
77
-     */
78
-    ClientEvents(final String[] argNames, final Class<?>... argTypes) {
79
-        this.argNames = argNames;
80
-        this.argTypes = argTypes;
81
-    }
82
-
83
-    @Override
84
-    public int getArity() {
85
-        return argNames.length;
86
-    }
87
-
88
-    @Override
89
-    public Class<?>[] getArgTypes() {
90
-        return argTypes;
91
-    }
92
-
93
-    @Override
94
-    public String[] getArgNames() {
95
-        return argNames;
96
-    }
97
-
98
-    @Override
99
-    public String getGroup() {
100
-        return "General Events";
101
-    }
102
-
103
-}

+ 0
- 75
src/com/dmdirc/actions/metatypes/LinkEvents.java View File

@@ -1,75 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions.metatypes;
24
-
25
-import com.dmdirc.interfaces.actions.ActionMetaType;
26
-import com.dmdirc.interfaces.ui.Window;
27
-
28
-/**
29
- * Defines link-related events.
30
- */
31
-public enum LinkEvents implements ActionMetaType {
32
-
33
-    /** URL Link clicked. */
34
-    LINK_CLICKED(new String[]{"Window", "URL"}, Window.class, String.class),
35
-    /** Channel link clicked. */
36
-    CHANNEL_CLICKED(new String[]{"Window", "Channel"}, Window.class, String.class),
37
-    /** Nickname link clicked. */
38
-    NICKNAME_CLICKED(new String[]{"Window", "Nickname"}, Window.class, String.class);
39
-    /** The names of the arguments for this meta type. */
40
-    private final String[] argNames;
41
-    /** The classes of the arguments for this meta type. */
42
-    private final Class<?>[] argTypes;
43
-
44
-    /**
45
-     * Creates a new instance of this meta-type.
46
-     *
47
-     * @param argNames The names of the meta-type's arguments
48
-     * @param argTypes The types of the meta-type's arguments
49
-     */
50
-    LinkEvents(final String[] argNames, final Class<?>... argTypes) {
51
-        this.argNames = argNames;
52
-        this.argTypes = argTypes;
53
-    }
54
-
55
-    @Override
56
-    public int getArity() {
57
-        return argNames.length;
58
-    }
59
-
60
-    @Override
61
-    public Class<?>[] getArgTypes() {
62
-        return argTypes;
63
-    }
64
-
65
-    @Override
66
-    public String[] getArgNames() {
67
-        return argNames;
68
-    }
69
-
70
-    @Override
71
-    public String getGroup() {
72
-        return "Link Events";
73
-    }
74
-
75
-}

+ 0
- 71
src/com/dmdirc/actions/metatypes/PluginEvents.java View File

@@ -1,71 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions.metatypes;
24
-
25
-import com.dmdirc.interfaces.actions.ActionMetaType;
26
-import com.dmdirc.plugins.PluginInfo;
27
-
28
-/**
29
- * Defines plugin-related events.
30
- */
31
-public enum PluginEvents implements ActionMetaType {
32
-
33
-    /** Plugin event type. */
34
-    PLUGIN_EVENT(new String[]{"plugin"}, PluginInfo.class);
35
-    /** The names of the arguments for this meta type. */
36
-    private final String[] argNames;
37
-    /** The classes of the arguments for this meta type. */
38
-    private final Class<?>[] argTypes;
39
-
40
-    /**
41
-     * Creates a new instance of this meta-type.
42
-     *
43
-     * @param argNames The names of the meta-type's arguments
44
-     * @param argTypes The types of the meta-type's arguments
45
-     */
46
-    PluginEvents(final String[] argNames, final Class<?>... argTypes) {
47
-        this.argNames = argNames;
48
-        this.argTypes = argTypes;
49
-    }
50
-
51
-    @Override
52
-    public int getArity() {
53
-        return argNames.length;
54
-    }
55
-
56
-    @Override
57
-    public Class<?>[] getArgTypes() {
58
-        return argTypes;
59
-    }
60
-
61
-    @Override
62
-    public String[] getArgNames() {
63
-        return argNames;
64
-    }
65
-
66
-    @Override
67
-    public String getGroup() {
68
-        return "Plugin Events";
69
-    }
70
-
71
-}

+ 0
- 77
src/com/dmdirc/actions/metatypes/QueryEvents.java View File

@@ -1,77 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions.metatypes;
24
-
25
-import com.dmdirc.Query;
26
-import com.dmdirc.interfaces.actions.ActionMetaType;
27
-import com.dmdirc.parser.interfaces.ClientInfo;
28
-
29
-/**
30
- * Defines query-related events.
31
- */
32
-public enum QueryEvents implements ActionMetaType {
33
-
34
-    /** Query event type. */
35
-    QUERY_EVENT(new String[]{"query"}, Query.class),
36
-    /** Query event with argument. */
37
-    QUERY_EVENT_WITH_ARG(new String[]{"query", "message"}, Query.class, String.class),
38
-    /** Query event with argument and source. */
39
-    QUERY_SOURCED_EVENT_WITH_ARG(new String[]{"query", "source", "message"}, Query.class,
40
-            ClientInfo.class, String.class);
41
-    /** The names of the arguments for this meta type. */
42
-    private final String[] argNames;
43
-    /** The classes of the arguments for this meta type. */
44
-    private final Class<?>[] argTypes;
45
-
46
-    /**
47
-     * Creates a new instance of this meta-type.
48
-     *
49
-     * @param argNames The names of the meta-type's arguments
50
-     * @param argTypes The types of the meta-type's arguments
51
-     */
52
-    QueryEvents(final String[] argNames, final Class<?>... argTypes) {
53
-        this.argNames = argNames;
54
-        this.argTypes = argTypes;
55
-    }
56
-
57
-    @Override
58
-    public int getArity() {
59
-        return argNames.length;
60
-    }
61
-
62
-    @Override
63
-    public Class<?>[] getArgTypes() {
64
-        return argTypes;
65
-    }
66
-
67
-    @Override
68
-    public String[] getArgNames() {
69
-        return argNames;
70
-    }
71
-
72
-    @Override
73
-    public String getGroup() {
74
-        return "Query Events";
75
-    }
76
-
77
-}

+ 0
- 94
src/com/dmdirc/actions/metatypes/ServerEvents.java View File

@@ -1,94 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions.metatypes;
24
-
25
-import com.dmdirc.interfaces.Connection;
26
-import com.dmdirc.interfaces.actions.ActionMetaType;
27
-import com.dmdirc.parser.interfaces.ClientInfo;
28
-
29
-/**
30
- * Defines server-related events.
31
- */
32
-public enum ServerEvents implements ActionMetaType {
33
-
34
-    /** Server ping event type. */
35
-    SERVER_PING(new String[]{"server", "ping"}, Connection.class, Long.class),
36
-    /** Server numeric event type. */
37
-    SERVER_NUMERIC(new String[]{"server", "numeric", "arguments"}, Connection.class, Integer.class,
38
-            String[].class),
39
-    /** Server event with argument. */
40
-    SERVER_EVENT_WITH_ARG(new String[]{"server", "message"}, Connection.class, String.class),
41
-    /** Server nick change. */
42
-    SERVER_NICKCHANGE(new String[]{"server", "old nickname", "new nickname"}, Connection.class,
43
-            String.class, String.class),
44
-    /** Server event, with source and argument. */
45
-    SERVER_SOURCED_EVENT_WITH_ARG(new String[]{"server", "user", "message"}, Connection.class,
46
-            ClientInfo.class, String.class),
47
-    /** Server CTCP event. */
48
-    SERVER_CTCP_EVENT(new String[]{"server", "user", "type", "content"}, Connection.class,
49
-            ClientInfo.class, String.class, String.class),
50
-    /** Server event with argument. */
51
-    SERVER_UNKNOWN_EVENT(new String[]{"server", "source", "target", "message"}, Connection.class,
52
-            String.class, String.class, String.class),
53
-    /** Server invite event. */
54
-    SERVER_INVITE(new String[]{"server", "source", "channel"}, Connection.class, ClientInfo.class,
55
-            String.class),
56
-    /** Server event type. */
57
-    SERVER_EVENT(new String[]{"server"}, Connection.class);
58
-    /** The names of the arguments for this meta type. */
59
-    private final String[] argNames;
60
-    /** The classes of the arguments for this meta type. */
61
-    private final Class<?>[] argTypes;
62
-
63
-    /**
64
-     * Creates a new instance of this meta-type.
65
-     *
66
-     * @param argNames The names of the meta-type's arguments
67
-     * @param argTypes The types of the meta-type's arguments
68
-     */
69
-    ServerEvents(final String[] argNames, final Class<?>... argTypes) {
70
-        this.argNames = argNames;
71
-        this.argTypes = argTypes;
72
-    }
73
-
74
-    @Override
75
-    public int getArity() {
76
-        return argNames.length;
77
-    }
78
-
79
-    @Override
80
-    public Class<?>[] getArgTypes() {
81
-        return argTypes;
82
-    }
83
-
84
-    @Override
85
-    public String[] getArgNames() {
86
-        return argNames;
87
-    }
88
-
89
-    @Override
90
-    public String getGroup() {
91
-        return "Server/Private Events";
92
-    }
93
-
94
-}

+ 0
- 111
src/com/dmdirc/actions/package-info.java View File

@@ -1,111 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-/**
24
- * 'Actions' provide a way for users to execute commands in response to certain events.
25
- *
26
- * <h2>Action types and meta-types</h2>
27
- *
28
- * Actions are executed in response to events in the client. Each event has a corresponding
29
- * {@link com.dmdirc.interfaces.actions.ActionType}, which has both a user-friendly name and an
30
- * internal name, as well as a meta-type which describes the arguments it takes.
31
- *
32
- * <p>
33
- * For example, when a message on a channel is received, the client looks for actions that respond
34
- * to the {@link com.dmdirc.actions.CoreActionType#CHANNEL_MESSAGE} action type. The channel message
35
- * type has a meta-type of
36
- * {@link com.dmdirc.actions.metatypes.ChannelEvents#CHANNEL_SOURCED_EVENT_WITH_ARG} which says that
37
- * the event will come with three arguments: a channel, a user, and a message. It also defines the
38
- * types of those arguments ({@link com.dmdirc.Channel},
39
- * {@link com.dmdirc.parser.interfaces.ChannelClientInfo}, and {@link java.lang.String}
40
- * respectively).
41
- *
42
- * <h2>Conditions</h2>
43
- *
44
- * Before an action is executed, its 'conditions' are checked. These are a simple collection of
45
- * rules concerning the state of the client, or the event's arguments. There are two types of
46
- * condition: component-based and string-based.
47
- *
48
- * <p>
49
- * Component-based conditions start off with one of the action's arguments, and then apply one or
50
- * more components to it to get some useful property. Components all implement
51
- * {@link com.dmdirc.interfaces.actions.ActionComponent} and essentially transform one object into
52
- * another, somehow. A component may take a {@link com.dmdirc.Channel} object and return that
53
- * channel's name as a string, or could take a string and return the length of it as an integer
54
- * (these components are implemented in {@link com.dmdirc.actions.CoreActionComponent#CHANNEL_NAME}
55
- * and {@link com.dmdirc.actions.CoreActionComponent#STRING_LENGTH}).
56
- *
57
- * <p>
58
- * A component based action could be as simple as "the message's content", or as complicated as "the
59
- * channel's server's network name's length". These chains of components are handled by an
60
- * {@link ActionComponentChain}.
61
- *
62
- * <p>
63
- * String-based conditions simply start off with a plain string, which is subject to substitution as
64
- * described below.
65
- *
66
- * <p>
67
- * Action conditions also specify a comparison. These define various methods of comparing objects,
68
- * such as checking two strings are equal
69
- * ({@link com.dmdirc.actions.CoreActionComparison#STRING_EQUALS}) or that an integer is greater
70
- * than a pre-defined value ({@link com.dmdirc.actions.CoreActionComparison#INT_GREATER}). All
71
- * comparisons implement {@link com.dmdirc.interfaces.actions.ActionComparison}. The second argument
72
- * is always a string provided by the user.
73
- *
74
- * <p>
75
- * Finally, if more than one condition is present the user can decide how they are matched. The two
76
- * most common and straight-forward options are a conjunction (where all the conditions must be
77
- * true) and a disjunction (where one of the conditions must be true). Users can also specify their
78
- * own, more complicated, rules such as "condition 1 AND (condition 2 OR condition 3)". These are
79
- * all expressed as a {@link ConditionTree}.
80
- *
81
- * <h2>Commands and substitutions</h2>
82
- *
83
- * When an action is triggered and its conditions are satisfied, it will execute a set of user
84
- * specified commands. These are executed on the relevant
85
- * {@link com.dmdirc.commandparser.parsers.CommandParser}, so are interpreted as though the user
86
- * typed them in the window where the event occurred. For example if in response to a channel
87
- * message the user had entered the command {@code /part}, then the client would part the channel
88
- * where the message was received.
89
- *
90
- * <p>
91
- * Commands and condition arguments are subject to action substitutions. This allows users to
92
- * include various dynamic properties in their responses or conditions. Substitutions are prefixed
93
- * with a {@code $} character, and come in several varieties:
94
- *
95
- * <ul>
96
- * <li>Configuration keys. Any setting in the 'actions' domain with the key 'key' can be substituted
97
- * using {@code $key}.</li>
98
- * <li>Words. Events that include a message allow substitution of individual words in the form
99
- * {@code $n} or ranges in the form {@code $n-} or {@code $n-m}, for some indices n and m.</li>
100
- * <li>Argument components. Any argument that is part of the action may be substituted in using the
101
- * format {@code ${n.component}}, where 'n' is the index of the argument and 'component' is the name
102
- * of the component to apply to it. Multiple components may be chained together:
103
- * {@code ${n.component1.component2}}.</li>
104
- * <li>Connection components. For convenience, any event that is triggered within the context of a
105
- * connection allows a shorthand form for connection-based substitutions. This is the same as an
106
- * argument-based substitution, but without the argument number. The substituter locates an
107
- * appropriate argument it can obtain a {@link com.dmdirc.interfaces.Connection} from and applies
108
- * the component to the relevant connection directly.</li>
109
- * </ul>
110
- */
111
-package com.dmdirc.actions;

+ 0
- 69
src/com/dmdirc/actions/validators/ActionNameValidator.java View File

@@ -1,69 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions.validators;
24
-
25
-import com.dmdirc.actions.Action;
26
-import com.dmdirc.actions.ActionGroup;
27
-import com.dmdirc.util.validators.ValidationResponse;
28
-import com.dmdirc.util.validators.Validator;
29
-
30
-import java.util.List;
31
-
32
-/**
33
- * Validates action names.
34
- *
35
- * @since 0.6.3
36
- */
37
-public class ActionNameValidator implements Validator<String> {
38
-
39
-    /** Failure reason for duplicates. */
40
-    private static final String FAILURE_EXISTS = "Name must not already exist.";
41
-    /** Associated action group. */
42
-    private final ActionGroup group;
43
-    /** Original name. */
44
-    private final String originalName;
45
-
46
-    /**
47
-     * Instantiates a new action name validator for an existing action.
48
-     *
49
-     * @param group        Associated action group
50
-     * @param originalName Existing action name
51
-     */
52
-    public ActionNameValidator(final ActionGroup group,
53
-            final String originalName) {
54
-        this.group = group;
55
-        this.originalName = originalName;
56
-    }
57
-
58
-    @Override
59
-    public ValidationResponse validate(final String object) {
60
-        final List<Action> actions = group.getActions();
61
-        for (Action action : actions) {
62
-            if (action.getName().equals(object) && !action.getName().equals(originalName)) {
63
-                return new ValidationResponse(FAILURE_EXISTS);
64
-            }
65
-        }
66
-        return new ValidationResponse();
67
-    }
68
-
69
-}

+ 0
- 70
src/com/dmdirc/actions/validators/ConditionRuleValidator.java View File

@@ -1,70 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions.validators;
24
-
25
-import com.dmdirc.actions.ConditionTree;
26
-import com.dmdirc.util.validators.ValidationResponse;
27
-import com.dmdirc.util.validators.Validator;
28
-
29
-/**
30
- * Validates a condition tree.
31
- */
32
-public class ConditionRuleValidator implements Validator<String> {
33
-
34
-    /** The number of arguments to the tree. */
35
-    private int args;
36
-
37
-    /**
38
-     * Creates a new ConditionRuleValidator.
39
-     *
40
-     * @param args The number of arguments allowed in the ConditionTree (i.e., the number of
41
-     *             ActionConditions)
42
-     */
43
-    public ConditionRuleValidator(final int args) {
44
-        this.args = args;
45
-    }
46
-
47
-    /**
48
-     * Updates the number of arguments used to validate the condition tree.
49
-     *
50
-     * @param args New number of arguments
51
-     */
52
-    public void setArgs(final int args) {
53
-        this.args = args;
54
-    }
55
-
56
-    @Override
57
-    public ValidationResponse validate(final String object) {
58
-        final ConditionTree tree = ConditionTree.parseString(object);
59
-
60
-        if (tree == null) {
61
-            return new ValidationResponse("Invalid rule.");
62
-        } else if (tree.getMaximumArgument() >= args) {
63
-            return new ValidationResponse("Condition "
64
-                    + tree.getMaximumArgument() + " does not exist");
65
-        } else {
66
-            return new ValidationResponse();
67
-        }
68
-    }
69
-
70
-}

+ 0
- 53
src/com/dmdirc/actions/wrappers/PerformType.java View File

@@ -1,53 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions.wrappers;
24
-
25
-/**
26
- * Describes the type of perform.
27
- *
28
- * @since 0.6.4
29
- */
30
-public enum PerformType {
31
-
32
-    /** A perform targeting a server. */
33
-    SERVER("Server"),
34
-    /** A perform targeting a network. */
35
-    NETWORK("Network");
36
-    /** Friendly name. */
37
-    private final String friendlyName;
38
-
39
-    /**
40
-     * Instantiates a new perform type.
41
-     *
42
-     * @param name Friendly name for the perform type
43
-     */
44
-    PerformType(final String name) {
45
-        friendlyName = name;
46
-    }
47
-
48
-    @Override
49
-    public String toString() {
50
-        return friendlyName;
51
-    }
52
-
53
-}

+ 0
- 342
src/com/dmdirc/actions/wrappers/PerformWrapper.java View File

@@ -1,342 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions.wrappers;
24
-
25
-import com.dmdirc.actions.Action;
26
-import com.dmdirc.actions.ActionComponentChain;
27
-import com.dmdirc.actions.ActionCondition;
28
-import com.dmdirc.actions.ActionFactory;
29
-import com.dmdirc.actions.ActionGroup;
30
-import com.dmdirc.actions.ActionManager;
31
-import com.dmdirc.actions.ConditionTree;
32
-import com.dmdirc.actions.CoreActionComparison;
33
-import com.dmdirc.actions.CoreActionComponent;
34
-import com.dmdirc.actions.CoreActionType;
35
-import com.dmdirc.commandparser.auto.AutoCommand;
36
-import com.dmdirc.commandparser.auto.AutoCommandManager;
37
-import com.dmdirc.interfaces.Connection;
38
-import com.dmdirc.interfaces.actions.ActionComponent;
39
-import com.dmdirc.interfaces.actions.ActionType;
40
-
41
-import java.util.ArrayList;
42
-import java.util.List;
43
-
44
-import javax.inject.Inject;
45
-import javax.inject.Singleton;
46
-
47
-/**
48
- * An action wrapper for performs.
49
- *
50
- * @deprecated Use {@link AutoCommandManager}
51
- */
52
-@Singleton
53
-@Deprecated
54
-public class PerformWrapper extends ActionGroup {
55
-
56
-    /** The component name for per-profile perform conditions. */
57
-    private static final String PP_COMP_NAME = "SERVER_PROFILE.IDENTITY_NAME";
58
-    /** Factory to use for actions. */
59
-    private final ActionFactory actionFactory;
60
-    /** Action manager. */
61
-    private final ActionManager actionManager;
62
-
63
-    /**
64
-     * Creates a new instance of PerformWrapper.
65
-     *
66
-     * @param actionFactory Factory to use to create actions.
67
-     */
68
-    @Inject
69
-    public PerformWrapper(final ActionManager actionManager, final ActionFactory actionFactory) {
70
-        super(actionManager, "performs");
71
-        this.actionManager = actionManager;
72
-        this.actionFactory = actionFactory;
73
-    }
74
-
75
-    /**
76
-     * Sets the perform for the specified target of the specified type. If the specified perform is
77
-     * empty - that is, any non-null elements are empty Strings - then the perform is removed. If a
78
-     * profile is specified, the perform will only be executed for that profile.
79
-     *
80
-     * @param perform The perform to be set
81
-     * @param content The new content of that perform
82
-     *
83
-     * @since 0.6.4
84
-     */
85
-    public void setPerform(final PerformDescription perform, final String... content) {
86
-        synchronized (this) {
87
-            Action action = getAction(perform.getType() == PerformType.NETWORK
88
-                    ? CoreActionComponent.SERVER_NETWORK : CoreActionComponent.SERVER_NAME,
89
-                    perform.getTarget(), perform.getProfile());
90
-
91
-            final boolean empty = isEmpty(content);
92
-
93
-            if (action == null && !empty) {
94
-                // They want to set a perform but we don't have an action
95
-                action = createAction(
96
-                        perform.getType() == PerformType.SERVER ? perform.getTarget() : "",
97
-                        perform.getType() == PerformType.NETWORK ? perform.getTarget() : "",
98
-                        perform.getProfile());
99
-                action.setResponse(content);
100
-                action.save();
101
-            }
102
-
103
-            if (action != null) {
104
-                if (empty) {
105
-                    // They want to clear the perform but we have an action
106
-                    deleteAction(action);
107
-                } else {
108
-                    // They want to set a perform and we have an action
109
-                    action.setResponse(content);
110
-                    action.save();
111
-                }
112
-            }
113
-        }
114
-    }
115
-
116
-    /**
117
-     * Retrieves the perform for the relevant target. If no such perform exists, a zero-length array
118
-     * is returned.
119
-     *
120
-     * @param perform The perform to be retrieved
121
-     *
122
-     * @return The corresponding perform, or a zero-length array if none set
123
-     *
124
-     * @since 0.6.4
125
-     */
126
-    public String[] getPerform(final PerformDescription perform) {
127
-        final Action action = getAction(perform.getType() == PerformType.NETWORK
128
-                ? CoreActionComponent.SERVER_NETWORK : CoreActionComponent.SERVER_NAME,
129
-                perform.getTarget(), perform.getProfile());
130
-
131
-        if (action == null || action.getResponse() == null) {
132
-            return new String[0];
133
-        } else {
134
-            return action.getResponse();
135
-        }
136
-    }
137
-
138
-    /**
139
-     * Determines if the specified perform is "empty". An empty perform is one that does not contain
140
-     * any non-empty Strings.
141
-     *
142
-     * @param perform The perform to test
143
-     *
144
-     * @return True if the perform is empty, false otherwise
145
-     *
146
-     * @since 0.6.4
147
-     */
148
-    private static boolean isEmpty(final String... perform) {
149
-        for (String part : perform) {
150
-            if (part != null && !part.isEmpty()) {
151
-                return false;
152
-            }
153
-        }
154
-
155
-        return true;
156
-    }
157
-
158
-    /**
159
-     * Creates a new, empty, perform wrapper for the specified server or network. Note that both
160
-     * server and network must be specified, and exactly one of them must be empty.
161
-     *
162
-     * @param server  The server to create the action for
163
-     * @param network The network to create the action for
164
-     * @param profile The profile the action is for (or null if "global")
165
-     *
166
-     * @since 0.6.3
167
-     * @return The new perform wrapper action
168
-     */
169
-    private Action createAction(final String server, final String network,
170
-            final String profile) {
171
-        final List<ActionCondition> conditions = new ArrayList<>();
172
-        final CoreActionComponent component = server.isEmpty() ? CoreActionComponent.SERVER_NETWORK
173
-                : CoreActionComponent.SERVER_NAME;
174
-
175
-        conditions.add(new ActionCondition(0, component,
176
-                CoreActionComparison.STRING_EQUALS, server + network));
177
-
178
-        if (profile != null) {
179
-            conditions.add(new ActionCondition(0,
180
-                    new ActionComponentChain(Connection.class, PP_COMP_NAME, actionManager),
181
-                    CoreActionComparison.STRING_EQUALS, profile));
182
-        }
183
-
184
-        return actionFactory.getAction(getName(), server + network
185
-                + (profile == null ? "" : " - " + profile),
186
-                new ActionType[]{CoreActionType.SERVER_CONNECTED},
187
-                new String[0], conditions,
188
-                ConditionTree.createConjunction(conditions.size()), null);
189
-    }
190
-
191
-    /**
192
-     * Retrieve an action with a condition that checks the specified component, and matches it
193
-     * against the specified target.
194
-     *
195
-     * @param component The action component to look for
196
-     * @param target    The string the component is matched against
197
-     * @param profile   The name of the profile that the action must target, or null for a
198
-     *                  non-profile specific action
199
-     *
200
-     * @since 0.6.3
201
-     * @return The matching action if one exists, or null
202
-     */
203
-    private Action getAction(final ActionComponent component, final String target,
204
-            final String profile) {
205
-        for (Action action : this) {
206
-            int matches = profile == null ? 1 : 2;
207
-
208
-            for (ActionCondition condition : action.getConditions()) {
209
-                if (condition.getComponent() == component
210
-                        && condition.getTarget().equalsIgnoreCase(target)) {
211
-                    matches--;
212
-                } else if (profile != null
213
-                        && PP_COMP_NAME.equals(condition.getComponent().toString())
214
-                        && condition.getTarget().equalsIgnoreCase(profile)) {
215
-                    matches--;
216
-                }
217
-            }
218
-
219
-            if (matches == 0) {
220
-                return action;
221
-            }
222
-        }
223
-
224
-        return null;
225
-    }
226
-
227
-    @Override
228
-    public boolean isDelible() {
229
-        return false;
230
-    }
231
-
232
-    @Override
233
-    public String getDescription() {
234
-        return "Performs allow you to automatically execute commands when"
235
-                + " you connect to a specific server or network. You can edit"
236
-                + " the perform for the current server or network in the "
237
-                + "\"Server Settings\" dialog, which can be accessed through "
238
-                + "the Settings menu.";
239
-    }
240
-
241
-    /**
242
-     * Describes one specific perform.
243
-     *
244
-     * @since 0.6.4
245
-     * @deprecated See {@link AutoCommand}
246
-     */
247
-    @Deprecated
248
-    public static class PerformDescription {
249
-
250
-        /** The type of the perform being described. */
251
-        private final PerformType type;
252
-        /** The target of the perform. */
253
-        private final String target;
254
-        /** The profile (if any) of the perform. */
255
-        private final String profile;
256
-
257
-        /**
258
-         * Creates a new perform description with the specified arguments.
259
-         *
260
-         * @param type    The type of the perform in question
261
-         * @param target  The target of the perform
262
-         * @param profile The profile of the perform (or null)
263
-         */
264
-        public PerformDescription(final PerformType type, final String target,
265
-                final String profile) {
266
-            this.type = type;
267
-            this.target = target;
268
-            this.profile = profile;
269
-
270
-            if (target == null) {
271
-                throw new NullPointerException("Target may not be null");
272
-            }
273
-        }
274
-
275
-        /**
276
-         * Creates a new perform description with the specified arguments.
277
-         *
278
-         * @param type   The type of the perform in question
279
-         * @param target The target of the perform
280
-         */
281
-        public PerformDescription(final PerformType type, final String target) {
282
-            this.type = type;
283
-            this.target = target;
284
-            this.profile = null;
285
-
286
-            if (target == null) {
287
-                throw new NullPointerException("Target may not be null");
288
-            }
289
-        }
290
-
291
-        /**
292
-         * Retrieves the profile of this perform.
293
-         *
294
-         * @return This perform's profile
295
-         */
296
-        public String getProfile() {
297
-            return profile;
298
-        }
299
-
300
-        /**
301
-         * Retrieves the target of this perform.
302
-         *
303
-         * @return This perform's target
304
-         */
305
-        public String getTarget() {
306
-            return target;
307
-        }
308
-
309
-        /**
310
-         * Retrieves the type of this perform.
311
-         *
312
-         * @return This perform's type
313
-         */
314
-        public PerformType getType() {
315
-            return type;
316
-        }
317
-
318
-        @Override
319
-        public boolean equals(final Object obj) {
320
-            if (obj == null || getClass() != obj.getClass()) {
321
-                return false;
322
-            }
323
-
324
-            final PerformDescription other = (PerformDescription) obj;
325
-
326
-            return !(type != other.type || !target.equals(other.target)) &&
327
-                    (profile == null ? other.profile == null : profile.equals(other.profile));
328
-
329
-        }
330
-
331
-        @Override
332
-        public int hashCode() {
333
-            int hash = 7;
334
-            hash = 89 * hash + (type != null ? type.hashCode() : 0);
335
-            hash = 89 * hash + target.hashCode();
336
-            hash = 89 * hash + (profile != null ? profile.hashCode() : 0);
337
-            return hash;
338
-        }
339
-
340
-    }
341
-
342
-}

+ 0
- 26
src/com/dmdirc/actions/wrappers/package-info.java View File

@@ -1,26 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-/**
24
- * Action wrappers.
25
- */
26
-package com.dmdirc.actions.wrappers;

+ 0
- 13
src/com/dmdirc/commandparser/commands/CommandModule.java View File

@@ -43,7 +43,6 @@ import com.dmdirc.commandparser.commands.global.Ifplugin;
43 43
 import com.dmdirc.commandparser.commands.global.LoadPlugin;
44 44
 import com.dmdirc.commandparser.commands.global.NewServer;
45 45
 import com.dmdirc.commandparser.commands.global.OpenWindow;
46
-import com.dmdirc.commandparser.commands.global.ReloadActions;
47 46
 import com.dmdirc.commandparser.commands.global.ReloadIdentities;
48 47
 import com.dmdirc.commandparser.commands.global.ReloadPlugin;
49 48
 import com.dmdirc.commandparser.commands.global.SaveConfig;
@@ -529,18 +528,6 @@ public class CommandModule {
529 528
         return new SimpleCommandDetails(command, OpenWindow.INFO);
530 529
     }
531 530
 
532
-    /**
533
-     * Provides the /reloadactions command.
534
-     *
535
-     * @param command The instantiated command.
536
-     *
537
-     * @return The command's details.
538
-     */
539
-    @Provides(type = Provides.Type.SET)
540
-    public CommandDetails getCommand(final ReloadActions command) {
541
-        return new SimpleCommandDetails(command, ReloadActions.INFO);
542
-    }
543
-
544 531
     /**
545 532
      * Provides the /reloadidentities command.
546 533
      *

+ 0
- 79
src/com/dmdirc/commandparser/commands/global/ReloadActions.java View File

@@ -1,79 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.commandparser.commands.global;
24
-
25
-import com.dmdirc.FrameContainer;
26
-import com.dmdirc.commandparser.BaseCommandInfo;
27
-import com.dmdirc.commandparser.CommandArguments;
28
-import com.dmdirc.commandparser.CommandInfo;
29
-import com.dmdirc.commandparser.CommandType;
30
-import com.dmdirc.commandparser.commands.Command;
31
-import com.dmdirc.commandparser.commands.IntelligentCommand;
32
-import com.dmdirc.commandparser.commands.context.CommandContext;
33
-import com.dmdirc.interfaces.ActionController;
34
-import com.dmdirc.interfaces.CommandController;
35
-import com.dmdirc.ui.input.AdditionalTabTargets;
36
-
37
-import javax.annotation.Nonnull;
38
-import javax.inject.Inject;
39
-
40
-/**
41
- * Allows the user to reload actions.
42
- */
43
-public final class ReloadActions extends Command implements IntelligentCommand {
44
-
45
-    /** A command info object for this command. */
46
-    public static final CommandInfo INFO = new BaseCommandInfo("reloadactions",
47
-            "reloadactions - reloads actions from disk",
48
-            CommandType.TYPE_GLOBAL);
49
-    /** The action controller to use to reload actions. */
50
-    private final ActionController actionController;
51
-
52
-    /**
53
-     * Creates a new instance of this command.
54
-     *
55
-     * @param controller The controller to use for command information.
56
-     * @param actionController The action controller to use to reload actions.
57
-     */
58
-    @Inject
59
-    public ReloadActions(
60
-            final CommandController controller,
61
-            final ActionController actionController) {
62
-        super(controller);
63
-        this.actionController = actionController;
64
-    }
65
-
66
-    @Override
67
-    public void execute(@Nonnull final FrameContainer origin,
68
-            final CommandArguments args, final CommandContext context) {
69
-        actionController.loadUserActions();
70
-        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Actions reloaded.");
71
-    }
72
-
73
-    @Override
74
-    public AdditionalTabTargets getSuggestions(final int arg,
75
-            final IntelligentCommandContext context) {
76
-        return new AdditionalTabTargets().excludeAll();
77
-    }
78
-
79
-}

+ 0
- 36
src/com/dmdirc/events/ActionCreatedEvent.java View File

@@ -1,36 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.events;
24
-
25
-import com.dmdirc.actions.Action;
26
-
27
-/**
28
- * Fired on the creation of an action.
29
- */
30
-public class ActionCreatedEvent extends ActionEvent {
31
-
32
-    public ActionCreatedEvent(final Action action) {
33
-        super(action);
34
-    }
35
-
36
-}

+ 0
- 47
src/com/dmdirc/events/ActionDeletedEvent.java View File

@@ -1,47 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.events;
24
-
25
-import com.dmdirc.actions.Action;
26
-import com.dmdirc.actions.ActionGroup;
27
-
28
-/**
29
- * Fired when an action is deleted.
30
- */
31
-public class ActionDeletedEvent extends ActionEvent {
32
-
33
-    private final ActionGroup group;
34
-
35
-    public ActionDeletedEvent(final ActionGroup group, final Action action) {
36
-        super(action);
37
-        this.group = group;
38
-    }
39
-
40
-    public ActionGroup getGroup() {
41
-        return group;
42
-    }
43
-
44
-    public String getName() {
45
-        return getAction().getName();
46
-    }
47
-}

+ 0
- 42
src/com/dmdirc/events/ActionEvent.java View File

@@ -1,42 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.events;
24
-
25
-import com.dmdirc.actions.Action;
26
-
27
-/**
28
- * Base class for all action events.
29
- */
30
-public abstract class ActionEvent extends DMDircEvent {
31
-
32
-    private final Action action;
33
-
34
-    public ActionEvent(final Action action) {
35
-        this.action = action;
36
-    }
37
-
38
-    public Action getAction() {
39
-        return action;
40
-    }
41
-
42
-}

+ 0
- 36
src/com/dmdirc/events/ActionUpdatedEvent.java View File

@@ -1,36 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.events;
24
-
25
-import com.dmdirc.actions.Action;
26
-
27
-/**
28
- * Fired when an action is updated.
29
- */
30
-public class ActionUpdatedEvent extends ActionEvent {
31
-
32
-    public ActionUpdatedEvent(final Action action) {
33
-        super(action);
34
-    }
35
-
36
-}

+ 0
- 248
src/com/dmdirc/interfaces/ActionController.java View File

@@ -1,248 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.interfaces;
24
-
25
-import com.dmdirc.Precondition;
26
-import com.dmdirc.actions.Action;
27
-import com.dmdirc.actions.ActionGroup;
28
-import com.dmdirc.interfaces.actions.ActionComparison;
29
-import com.dmdirc.interfaces.actions.ActionComponent;
30
-import com.dmdirc.interfaces.actions.ActionType;
31
-import com.dmdirc.util.collections.MapList;
32
-
33
-import java.util.List;
34
-import java.util.Map;
35
-
36
-/**
37
- * Manages all known actions, action types, comparisons, components, etc, and facilitates loading
38
- * and triggering of actions.
39
- */
40
-public interface ActionController {
41
-
42
-    /**
43
-     * Registers an action with the manager.
44
-     *
45
-     * @param action The action to be registered
46
-     */
47
-    @Precondition("The specified action is not null")
48
-    void addAction(final Action action);
49
-
50
-    /**
51
-     * Registers the specified group of actions with the manager.
52
-     *
53
-     * @param group The group of actions to be registered
54
-     */
55
-    void addGroup(final ActionGroup group);
56
-
57
-    /**
58
-     * Renames the specified group.
59
-     *
60
-     * @param oldName The old name of the group
61
-     * @param newName The new name of the group
62
-     */
63
-    @Precondition({"The old name is non-null and not empty", "The old name is an existing group",
64
-            "The new name is non-null and not empty", "The new name is not an existing group",
65
-            "The old name does not equal the new name"})
66
-    void changeGroupName(final String oldName, final String newName);
67
-
68
-    /**
69
-     * Creates a new group with the specified name.
70
-     *
71
-     * @param group The group to be created
72
-     *
73
-     * @return The newly created group
74
-     */
75
-    @Precondition({"The specified group is non-null and not empty",
76
-            "The specified group is not an existing group"})
77
-    ActionGroup createGroup(final String group);
78
-
79
-    /**
80
-     * Removes the group with the specified name.
81
-     *
82
-     * @param group The group to be removed
83
-     */
84
-    @Precondition({"The specified group is non-null and not empty",
85
-            "The specified group is an existing group"})
86
-    void deleteGroup(final String group);
87
-
88
-    /**
89
-     * Returns a list of action comparisons that are compatible with the specified class.
90
-     *
91
-     * @param target The class to be tested
92
-     *
93
-     * @return A list of compatible action comparisons
94
-     */
95
-    @Precondition("The specified target is not null")
96
-    List<ActionComparison> findCompatibleComparisons(final Class<?> target);
97
-
98
-    /**
99
-     * Returns a list of action components that are compatible with the specified class.
100
-     *
101
-     * @param target The class to be tested
102
-     *
103
-     * @return A list of compatible action components
104
-     */
105
-    @Precondition("The specified target is not null")
106
-    List<ActionComponent> findCompatibleComponents(final Class<?> target);
107
-
108
-    /**
109
-     * Returns a list of action types that are compatible with the one specified.
110
-     *
111
-     * @param type The type to be checked against
112
-     *
113
-     * @return A list of compatible action types
114
-     */
115
-    @Precondition("The specified type is not null")
116
-    List<ActionType> findCompatibleTypes(final ActionType type);
117
-
118
-    /**
119
-     * Returns the action type specified by the given string, or null if it doesn't match a valid
120
-     * registered action type.
121
-     *
122
-     * @param type The name of the action type to try and find
123
-     *
124
-     * @return The actiontype with the specified name, or null on failure
125
-     */
126
-    @Precondition("The specified type is non-null and not empty")
127
-    ActionComparison getComparison(final String type);
128
-
129
-    /**
130
-     * Returns the action component specified by the given string, or null if it doesn't match a
131
-     * valid registered action component.
132
-     *
133
-     * @param type The name of the action component to try and find
134
-     *
135
-     * @return The actioncomponent with the specified name, or null on failure
136
-     */
137
-    @Precondition("The specified type is non-null and not empty")
138
-    ActionComponent getComponent(final String type);
139
-
140
-    /**
141
-     * Returns a map of type groups to types.
142
-     *
143
-     * @return A map of type groups to types
144
-     */
145
-    MapList<String, ActionType> getGroupedTypes();
146
-
147
-    /**
148
-     * Returns a map of groups to action lists.
149
-     *
150
-     * @return a map of groups to action lists
151
-     */
152
-    Map<String, ActionGroup> getGroupsMap();
153
-
154
-    /**
155
-     * Retrieves the action group with the specified name. A new group is created if it doesn't
156
-     * already exist.
157
-     *
158
-     * @param name The name of the group to retrieve
159
-     *
160
-     * @return The corresponding ActionGroup
161
-     */
162
-    ActionGroup getOrCreateGroup(final String name);
163
-
164
-    /**
165
-     * Returns the action comparison specified by the given string, or null if it doesn't match a
166
-     * valid registered action comparison.
167
-     *
168
-     * @param type The name of the action comparison to try and find
169
-     *
170
-     * @return The type with the specified name, or null on failure
171
-     */
172
-    ActionType getType(final String type);
173
-
174
-    /**
175
-     * Loads actions from the user's directory.
176
-     */
177
-    void loadUserActions();
178
-
179
-    /**
180
-     * Registers a set of action comparisons with the manager.
181
-     *
182
-     * @param comps An array of ActionComparisons to be registered
183
-     */
184
-    @Precondition("None of the specified ActionComparisons are null")
185
-    void registerComparisons(final ActionComparison[] comps);
186
-
187
-    /**
188
-     * Registers a set of action components with the manager.
189
-     *
190
-     * @param comps An array of ActionComponents to be registered
191
-     */
192
-    @Precondition("None of the specified ActionComponents are null")
193
-    void registerComponents(final ActionComponent[] comps);
194
-
195
-    /**
196
-     * Registers the specified default setting for actions.
197
-     *
198
-     * @param name  The name of the setting to be registered
199
-     * @param value The default value for the setting
200
-     */
201
-    void registerSetting(final String name, final String value);
202
-
203
-    /**
204
-     * Registers a set of action types with the manager.
205
-     *
206
-     * @param newTypes An array of ActionTypes to be registered
207
-     */
208
-    @Precondition("None of the specified ActionTypes are null")
209
-    void registerTypes(final ActionType[] newTypes);
210
-
211
-    /**
212
-     * Unregisters an action with the manager.
213
-     *
214
-     * @param action The action to be unregistered
215
-     */
216
-    @Precondition("The specified action is not null")
217
-    void removeAction(final Action action);
218
-
219
-    /**
220
-     * Reregisters the specified action. Should be used when the action's triggers change.
221
-     *
222
-     * @param action The action to be reregistered
223
-     */
224
-    void reregisterAction(final Action action);
225
-
226
-    /**
227
-     * Saves all actions.
228
-     */
229
-    void saveAllActions();
230
-
231
-    /**
232
-     * Processes an event of the specified type.
233
-     *
234
-     * @param type      The type of the event to process
235
-     * @param format    The format of the message that's going to be displayed for the event.
236
-     *                  Actions may change this format.
237
-     * @param arguments The arguments for the event
238
-     *
239
-     * @return True if the event should be processed, or false if an action listener has requested
240
-     *         the event be skipped.
241
-     */
242
-    @Precondition({"The specified ActionType is not null",
243
-            "The specified ActionType has a valid ActionMetaType",
244
-            "The length of the arguments array equals the arity of the ActionType's " +
245
-                    "ActionMetaType"})
246
-    boolean triggerEvent(final ActionType type, final StringBuffer format, final Object... arguments);
247
-
248
-}

+ 0
- 63
src/com/dmdirc/interfaces/actions/ActionComparison.java View File

@@ -1,63 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.interfaces.actions;
24
-
25
-/**
26
- * Describes the methods that must be implemented by an action comparison. Action comparisons allow
27
- * the user to compare an action component to a string they entered.
28
- */
29
-public interface ActionComparison {
30
-
31
-    /**
32
-     * Tests the specified arguments against each other.
33
-     *
34
-     * @param arg1 The first argument
35
-     * @param arg2 The second argument
36
-     *
37
-     * @return True iff the comparison between the args succeeds, false otherwise
38
-     */
39
-    boolean test(final Object arg1, final Object arg2);
40
-
41
-    /**
42
-     * Returns the class that this comparison deals with.
43
-     *
44
-     * @return The Class that this comparison can compare
45
-     */
46
-    Class<?> appliesTo();
47
-
48
-    /**
49
-     * Returns a friendly name for this comparison.
50
-     *
51
-     * @return This comparison's friendly name
52
-     */
53
-    String getName();
54
-
55
-    /**
56
-     * Returns the internal name of this comparison.
57
-     *
58
-     * @since 0.6.4
59
-     * @return This comparison's internal name
60
-     */
61
-    String name();
62
-
63
-}

+ 0
- 95
src/com/dmdirc/interfaces/actions/ActionComponent.java View File

@@ -1,95 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.interfaces.actions;
24
-
25
-import java.lang.annotation.ElementType;
26
-import java.lang.annotation.Retention;
27
-import java.lang.annotation.RetentionPolicy;
28
-import java.lang.annotation.Target;
29
-
30
-/**
31
- * The ActionComponent interface describes the methods that action components are required to
32
- * implement. Components are objects that allow the user to pull a specific piece of information
33
- * from a certain type of argument.
34
- */
35
-public interface ActionComponent {
36
-
37
-    /**
38
-     * An annotation which allows action components to specify options relating to their use. The
39
-     * annotation should be applied to the {@link #get(java.lang.Object)} method of implementing
40
-     * classes.
41
-     *
42
-     * @since 0.6.4
43
-     */
44
-    @Retention(RetentionPolicy.RUNTIME)
45
-    @Target(ElementType.METHOD)
46
-    @interface ComponentOptions {
47
-
48
-        /**
49
-         * Whether or not the component requires a connected server.
50
-         *
51
-         * @return true if component requires a connected server
52
-         */
53
-        boolean requireConnected() default false;
54
-
55
-    }
56
-
57
-    /**
58
-     * Retrieves the component of the specified argument that this component represents.
59
-     *
60
-     * @param arg The object to retrieve the component from
61
-     *
62
-     * @return The relevant component of the object
63
-     */
64
-    Object get(Object arg);
65
-
66
-    /**
67
-     * Retrieves the type of class that this component applies to.
68
-     *
69
-     * @return The Class that this component can be applied to
70
-     */
71
-    Class<?> appliesTo();
72
-
73
-    /**
74
-     * Retrieves the type of this component.
75
-     *
76
-     * @return The Class of this component.
77
-     */
78
-    Class<?> getType();
79
-
80
-    /**
81
-     * Retrieves a friendly name for this component.
82
-     *
83
-     * @return This component's friendly name
84
-     */
85
-    String getName();
86
-
87
-    /**
88
-     * Retrieves the internal name of this action component.
89
-     *
90
-     * @since 0.6.4
91
-     * @return The internal name of this component
92
-     */
93
-    String name();
94
-
95
-}

+ 0
- 58
src/com/dmdirc/interfaces/actions/ActionMetaType.java View File

@@ -1,58 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.interfaces.actions;
24
-
25
-/**
26
- * Encapsulates the methods that all action types are required to implement.
27
- */
28
-public interface ActionMetaType {
29
-
30
-    /**
31
-     * Retrieves the arity of this type.
32
-     *
33
-     * @return The arity of this action type
34
-     */
35
-    int getArity();
36
-
37
-    /**
38
-     * Retrieves the type of arguments that actions of this type should expect.
39
-     *
40
-     * @return The type of arguments expected
41
-     */
42
-    Class<?>[] getArgTypes();
43
-
44
-    /**
45
-     * Retrieves the names of the arguments that actions of this type should expect.
46
-     *
47
-     * @return The names of the expected arguments
48
-     */
49
-    String[] getArgNames();
50
-
51
-    /**
52
-     * Retrieves the name of a logical group for this meta-type to be put into.
53
-     *
54
-     * @return The meta-type's group name
55
-     */
56
-    String getGroup();
57
-
58
-}

+ 0
- 52
src/com/dmdirc/interfaces/actions/ActionType.java View File

@@ -1,52 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.interfaces.actions;
24
-
25
-/**
26
- * Encapsulates the methods that all actions are required to implement.
27
- */
28
-public interface ActionType {
29
-
30
-    /**
31
-     * Retrieves the type of this action.
32
-     *
33
-     * @return This action's type
34
-     */
35
-    ActionMetaType getType();
36
-
37
-    /**
38
-     * Retrieves this type's friendly name.
39
-     *
40
-     * @return The friendly name of this type
41
-     */
42
-    String getName();
43
-
44
-    /**
45
-     * Retrieves this type's internal name.
46
-     *
47
-     * @since 0.6.4
48
-     * @return The internal name of this type
49
-     */
50
-    String name();
51
-
52
-}

+ 0
- 3
src/com/dmdirc/interfaces/ui/FirstRunWizard.java View File

@@ -28,9 +28,6 @@ public interface FirstRunWizard {
28 28
     /** Extracts the core plugins. */
29 29
     void extractPlugins();
30 30
 
31
-    /** Extracts the core actions. */
32
-    void extractActions();
33
-
34 31
     /** Displays the First run wizard. */
35 32
     void display();
36 33
 

+ 1
- 15
src/com/dmdirc/plugins/PluginInjectorInitialiser.java View File

@@ -24,9 +24,6 @@ package com.dmdirc.plugins;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26 26
 import com.dmdirc.DMDircMBassador;
27
-import com.dmdirc.actions.ActionFactory;
28
-import com.dmdirc.actions.ActionManager;
29
-import com.dmdirc.actions.ActionSubstitutorFactory;
30 27
 import com.dmdirc.commandparser.CommandManager;
31 28
 import com.dmdirc.config.prefs.PreferencesManager;
32 29
 import com.dmdirc.interfaces.ConnectionManager;
@@ -49,8 +46,6 @@ import javax.inject.Inject;
49 46
  */
50 47
 public class PluginInjectorInitialiser {
51 48
 
52
-    private final ActionManager actionManager;
53
-    private final ActionFactory actionFactory;
54 49
     private final PluginManager pluginManager;
55 50
     private final IdentityController identityController;
56 51
     private final ConnectionManager connectionManager;
@@ -63,13 +58,11 @@ public class PluginInjectorInitialiser {
63 58
     private final CorePluginExtractor corePluginExtractor;
64 59
     private final URLBuilder urlBuilder;
65 60
     private final ColourManager colourManager;
66
-    private final ActionSubstitutorFactory actionSubstitutorFactory;
67 61
     private final DMDircMBassador eventBus;
68 62
     private final IconManager iconManager;
69 63
 
70 64
     @Inject
71
-    public PluginInjectorInitialiser(final ActionManager actionManager,
72
-            final ActionFactory actionFactory,
65
+    public PluginInjectorInitialiser(
73 66
             final PluginManager pluginManager,
74 67
             final IdentityController identityController,
75 68
             final ConnectionManager connectionManager,
@@ -82,11 +75,8 @@ public class PluginInjectorInitialiser {
82 75
             final CorePluginExtractor corePluginExtractor,
83 76
             final URLBuilder urlBuilder,
84 77
             @GlobalConfig final ColourManager colourManager,
85
-            final ActionSubstitutorFactory actionSubstitutorFactory,
86 78
             final DMDircMBassador eventBus,
87 79
             @GlobalConfig final IconManager iconManager) {
88
-        this.actionManager = actionManager;
89
-        this.actionFactory = actionFactory;
90 80
         this.pluginManager = pluginManager;
91 81
         this.identityController = identityController;
92 82
         this.connectionManager = connectionManager;
@@ -99,7 +89,6 @@ public class PluginInjectorInitialiser {
99 89
         this.corePluginExtractor = corePluginExtractor;
100 90
         this.urlBuilder = urlBuilder;
101 91
         this.colourManager = colourManager;
102
-        this.actionSubstitutorFactory = actionSubstitutorFactory;
103 92
         this.eventBus = eventBus;
104 93
         this.iconManager = iconManager;
105 94
     }
@@ -110,7 +99,6 @@ public class PluginInjectorInitialiser {
110 99
      * @param injector The injector to be initialised
111 100
      */
112 101
     public void initialise(final SimpleInjector injector) {
113
-        injector.addParameter(actionManager);
114 102
         injector.addParameter(PluginManager.class, pluginManager);
115 103
         injector.addParameter(identityController);
116 104
         injector.addParameter(ConnectionManager.class, connectionManager);
@@ -120,11 +108,9 @@ public class PluginInjectorInitialiser {
120 108
         injector.addParameter(PreferencesManager.class, preferencesManager);
121 109
         injector.addParameter(LifecycleController.class, lifecycleController);
122 110
         injector.addParameter(corePluginExtractor);
123
-        injector.addParameter(actionFactory);
124 111
         injector.addParameter(themeManager);
125 112
         injector.addParameter(urlBuilder);
126 113
         injector.addParameter(colourManager);
127
-        injector.addParameter(actionSubstitutorFactory);
128 114
         injector.addParameter(eventBus);
129 115
         injector.addParameter(iconManager);
130 116
     }

+ 0
- 89
src/com/dmdirc/updater/components/ActionGroupComponent.java View File

@@ -1,89 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.updater.components;
24
-
25
-import com.dmdirc.actions.ActionGroup;
26
-import com.dmdirc.actions.ActionManager;
27
-import com.dmdirc.updater.UpdateComponent;
28
-import com.dmdirc.updater.Version;
29
-
30
-import java.io.IOException;
31
-import java.nio.file.Path;
32
-
33
-/**
34
- * Update component for action groups.
35
- */
36
-public class ActionGroupComponent implements UpdateComponent {
37
-
38
-    private final ActionManager actionManager;
39
-
40
-    public ActionGroupComponent(final ActionManager actionManager,
41
-            final ActionGroup group) {
42
-        this.actionManager = actionManager;
43
-        this.group = group;
44
-    }
45
-    /** The group that this component represents. */
46
-    private final ActionGroup group;
47
-
48
-    @Override
49
-    public String getName() {
50
-        return "addon-" + group.getComponent();
51
-    }
52
-
53
-    @Override
54
-    public String getFriendlyName() {
55
-        return "Action pack: " + group.getName();
56
-    }
57
-
58
-    @Override
59
-    public Version getVersion() {
60
-        return group.getVersion();
61
-    }
62
-
63
-    @Override
64
-    public String getFriendlyVersion() {
65
-        return String.valueOf(getVersion());
66
-    }
67
-
68
-    @Override
69
-    public boolean requiresRestart() {
70
-        return false;
71
-    }
72
-
73
-    @Override
74
-    public boolean requiresManualInstall() {
75
-        return false;
76
-    }
77
-
78
-    @Override
79
-    public String getManualInstructions(final Path path) {
80
-        return "";
81
-    }
82
-
83
-    @Override
84
-    public boolean doInstall(final Path path) throws IOException {
85
-        actionManager.installActionPack(path);
86
-        return false;
87
-    }
88
-
89
-}

+ 0
- 30
test-res/com/dmdirc/actions/action1 View File

@@ -1,30 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-# Written on: Mon Jan 14 06:19:51 GMT 2008
3
-
4
-# This section indicates which sections below take key/value
5
-# pairs, rather than a simple list. It should be placed above
6
-# any sections that take key/values.
7
-keysections:
8
-  condition 0
9
-  condition 1
10
-
11
-triggers:
12
-  SERVER_AWAY
13
-
14
-response:
15
-  /away
16
-
17
-conditiontree:
18
-  (0&1)
19
-
20
-condition 0:
21
-  argument=1
22
-  component=STRING_LENGTH
23
-  target=0
24
-  comparison=INT_EQUALS
25
-
26
-condition 1:
27
-  argument=-1
28
-  starget=foo
29
-  target=bar
30
-  comparison=STRING_CONTAINS

+ 0
- 29
test-res/com/dmdirc/actions/action_multisettings View File

@@ -1,29 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-# Written on: Mon Jan 14 06:19:51 GMT 2008
3
-
4
-# This section indicates which sections below take key/value
5
-# pairs, rather than a simple list. It should be placed above
6
-# any sections that take key/values.
7
-keysections:
8
-  setting 0
9
-  setting 1
10
-
11
-triggers:
12
-  SERVER_AWAY
13
-
14
-response:
15
-  /away
16
-
17
-setting 0:
18
-  type=TEXT
19
-  setting=highlightregex
20
-  title=Highlight Regex
21
-  tooltip=Regex to use to detect a highlight
22
-  default=(?i).*(shane|dataforce|Q${SERVER_MYNICKNAME}E|(?<![#A-Z])DF).*
23
-
24
-setting 1:
25
-  type=TEXT
26
-  setting=highlightregex
27
-  title=Highlight Regex
28
-  tooltip=Regex to use to detect a highlight
29
-  default=(?i).*(shane|dataforce|Q${SERVER_MYNICKNAME}E|(?<![#A-Z])DF).*

+ 0
- 30
test-res/com/dmdirc/actions/defaults/action1 View File

@@ -1,30 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-# Written on: Mon Jan 14 06:19:51 GMT 2008
3
-
4
-# This section indicates which sections below take key/value
5
-# pairs, rather than a simple list. It should be placed above
6
-# any sections that take key/values.
7
-keysections:
8
-  condition 0
9
-  condition 1
10
-
11
-triggers:
12
-  SERVER_AWAY
13
-
14
-response:
15
-  /away
16
-
17
-conditiontree:
18
-  (0&1)
19
-
20
-condition 0:
21
-  argument=1
22
-  component=STRING_LENGTH
23
-  target=0
24
-  comparison=INT_EQUALS
25
-
26
-condition 1:
27
-  argument=-1
28
-  starget=foo
29
-  target=bar
30
-  comparison=STRING_CONTAINS

+ 0
- 24
test-res/com/dmdirc/actions/defaults/action2 View File

@@ -1,24 +0,0 @@
1
-# This is a DMDirc configuration file.
2
-# Written on: Mon Jan 14 06:19:51 GMT 2008
3
-
4
-# This section indicates which sections below take key/value
5
-# pairs, rather than a simple list. It should be placed above
6
-# any sections that take key/values.
7
-keysections:
8
-  condition 0
9
-  condition 1
10
-
11
-triggers:
12
-  SERVER_AWAY
13
-
14
-response:
15
-  /away
16
-
17
-conditiontree:
18
-  (0)
19
-
20
-condition 0:
21
-  argument=1
22
-  component=STRING_LENGTH
23
-  target=0
24
-  comparison=INT_EQUALS

+ 0
- 63
test/com/dmdirc/actions/ActionComparisonNamesTest.java View File

@@ -1,63 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.interfaces.actions.ActionComparison;
26
-
27
-import java.util.LinkedList;
28
-import java.util.List;
29
-
30
-import org.junit.Test;
31
-import org.junit.runner.RunWith;
32
-import org.junit.runners.Parameterized;
33
-
34
-import static org.junit.Assert.*;
35
-
36
-@RunWith(Parameterized.class)
37
-public class ActionComparisonNamesTest {
38
-
39
-    private final ActionComparison comparison;
40
-
41
-    public ActionComparisonNamesTest(final ActionComparison comparison) {
42
-        this.comparison = comparison;
43
-    }
44
-
45
-    @Test
46
-    public void testName() {
47
-        assertNotNull(comparison.getName());
48
-        assertFalse(comparison.getName().isEmpty());
49
-        assertTrue(comparison.getName().matches(".*?s(n't)?( .*?)?"));
50
-    }
51
-
52
-    @Parameterized.Parameters
53
-    public static List<Object[]> data() {
54
-        final List<Object[]> res = new LinkedList<>();
55
-
56
-        for (ActionComparison comp : CoreActionComparison.values()) {
57
-            res.add(new Object[]{comp});
58
-        }
59
-
60
-        return res;
61
-    }
62
-
63
-}

+ 0
- 161
test/com/dmdirc/actions/ActionComponentChainTest.java View File

@@ -1,161 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.Server;
26
-import com.dmdirc.interfaces.actions.ActionComponent;
27
-
28
-import org.junit.Before;
29
-import org.junit.Test;
30
-import org.junit.runner.RunWith;
31
-import org.mockito.Mock;
32
-import org.mockito.runners.MockitoJUnitRunner;
33
-
34
-import static org.junit.Assert.*;
35
-import static org.mockito.Mockito.*;
36
-
37
-@RunWith(MockitoJUnitRunner.class)
38
-public class ActionComponentChainTest {
39
-
40
-    @Mock private ActionManager actionManager;
41
-
42
-    @Before
43
-    public void setUp() throws Exception {
44
-        when(actionManager.getComponent("SERVER_NAME"))
45
-                .thenReturn(CoreActionComponent.SERVER_NAME);
46
-        when(actionManager.getComponent("SERVER_NETWORK"))
47
-                .thenReturn(CoreActionComponent.SERVER_NETWORK);
48
-        when(actionManager.getComponent("STRING_LENGTH"))
49
-                .thenReturn(CoreActionComponent.STRING_LENGTH);
50
-        when(actionManager.getComponent("STRING_STRING"))
51
-                .thenReturn(CoreActionComponent.STRING_STRING);
52
-        when(actionManager.getComponent("USER_MODES"))
53
-                .thenReturn(CoreActionComponent.USER_MODES);
54
-
55
-        // TODO: Testing for this behaviour here is odd - ActionComponentChain
56
-        //       should probably do its own validation and throw a more
57
-        //       appropriate exception.
58
-        when(actionManager.getComponent(""))
59
-                .thenThrow(new AssertionError());
60
-    }
61
-
62
-    @Test
63
-    public void testSingle() {
64
-        final ActionComponentChain chain = new ActionComponentChain(String.class, "STRING_STRING", actionManager);
65
-        assertEquals("foo bar baz", chain.get("foo bar baz"));
66
-        assertEquals("STRING_STRING", chain.toString());
67
-    }
68
-
69
-    @Test
70
-    public void testDouble() {
71
-        final ActionComponentChain chain = new ActionComponentChain(String.class,
72
-                "STRING_STRING.STRING_STRING", actionManager);
73
-        assertEquals("foo bar baz", chain.get("foo bar baz"));
74
-        assertEquals("STRING_STRING.STRING_STRING", chain.toString());
75
-    }
76
-
77
-    @Test(expected=IllegalArgumentException.class)
78
-    public void testInvalidName() {
79
-        new ActionComponentChain(String.class, "STRONG_STRING", actionManager);
80
-    }
81
-
82
-    @Test(expected=IllegalArgumentException.class)
83
-    public void testInvalidType() {
84
-        new ActionComponentChain(String.class, "USER_MODES.STRING_STRING", actionManager);
85
-    }
86
-
87
-    @Test(expected=IllegalArgumentException.class)
88
-    public void testInvalidLink() {
89
-        new ActionComponentChain(String.class, "STRING_STRING.USER_MODES", actionManager);
90
-    }
91
-
92
-    @Test
93
-    public void testAppliesTo() {
94
-        final ActionComponent chain = new ActionComponentChain(String.class,
95
-                "STRING_STRING.STRING_STRING.STRING_LENGTH", actionManager);
96
-        assertSame(String.class, chain.appliesTo());
97
-    }
98
-
99
-    @Test
100
-    public void testGetType() {
101
-        final ActionComponent chain = new ActionComponentChain(String.class,
102
-                "STRING_STRING.STRING_STRING.STRING_LENGTH", actionManager);
103
-        assertSame(Integer.class, chain.getType());
104
-    }
105
-
106
-    @Test
107
-    public void testGetName() {
108
-        final ActionComponent chain = new ActionComponentChain(String.class,
109
-                "STRING_STRING.STRING_STRING.STRING_LENGTH", actionManager);
110
-
111
-        assertTrue(chain.getName().contains(CoreActionComponent.STRING_STRING.getName()));
112
-        assertTrue(chain.getName().contains(CoreActionComponent.STRING_LENGTH.getName()));
113
-    }
114
-
115
-    @Test(expected=AssertionError.class)
116
-    public void testEmptyAppliesTo() {
117
-        final ActionComponent chain = new ActionComponentChain(String.class, "", actionManager);
118
-        chain.appliesTo();
119
-    }
120
-
121
-    @Test(expected=AssertionError.class)
122
-    public void testEmptyGetType() {
123
-        final ActionComponent chain = new ActionComponentChain(String.class, "", actionManager);
124
-        chain.getType();
125
-    }
126
-
127
-    @Test(expected=AssertionError.class)
128
-    public void testEmptyGetName() {
129
-        final ActionComponent chain = new ActionComponentChain(String.class, "", actionManager);
130
-        chain.getName();
131
-    }
132
-
133
-    @SuppressWarnings("ResultOfMethodCallIgnored")
134
-    @Test(expected=AssertionError.class)
135
-    public void testEmptyToString() {
136
-        final ActionComponentChain chain = new ActionComponentChain(String.class, "", actionManager);
137
-        chain.toString();
138
-    }
139
-
140
-    @Test
141
-    public void testRequiresConnection1() {
142
-        final ActionComponentChain chain = new ActionComponentChain(Server.class,
143
-                "SERVER_NETWORK", actionManager);
144
-        assertTrue(chain.requiresConnection());
145
-    }
146
-
147
-    @Test
148
-    public void testRequiresConnection2() {
149
-        final ActionComponentChain chain = new ActionComponentChain(Server.class,
150
-                "SERVER_NETWORK.STRING_LENGTH", actionManager);
151
-        assertTrue(chain.requiresConnection());
152
-    }
153
-
154
-    @Test
155
-    public void testRequiresConnection3() {
156
-        final ActionComponentChain chain = new ActionComponentChain(Server.class,
157
-                "SERVER_NAME.STRING_LENGTH", actionManager);
158
-        assertFalse(chain.requiresConnection());
159
-    }
160
-
161
-}

+ 0
- 154
test/com/dmdirc/actions/ActionConditionTest.java View File

@@ -1,154 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.interfaces.ActionController;
26
-import com.dmdirc.interfaces.CommandController;
27
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
28
-
29
-import org.junit.Test;
30
-import org.junit.runner.RunWith;
31
-import org.mockito.Mock;
32
-import org.mockito.runners.MockitoJUnitRunner;
33
-
34
-import static org.junit.Assert.*;
35
-
36
-@RunWith(MockitoJUnitRunner.class)
37
-public class ActionConditionTest {
38
-
39
-    @Mock private ActionController actionController;
40
-    @Mock private CommandController commandController;
41
-    @Mock private AggregateConfigProvider configProvider;
42
-
43
-    @Test
44
-    public void testConstructor1() {
45
-        final ActionCondition ac = new ActionCondition(1, CoreActionComponent.STRING_STRING,
46
-            CoreActionComparison.STRING_STARTSWITH, "foo");
47
-        assertEquals(1, ac.getArg());
48
-        assertEquals(CoreActionComponent.STRING_STRING, ac.getComponent());
49
-        assertEquals(CoreActionComparison.STRING_STARTSWITH, ac.getComparison());
50
-        assertEquals("foo", ac.getTarget());
51
-    }
52
-
53
-    @Test
54
-    public void testConstructor2() {
55
-        final ActionCondition ac = new ActionCondition("foobarbaz",
56
-            CoreActionComparison.STRING_STARTSWITH, "foo");
57
-        assertEquals("foobarbaz", ac.getStarget());
58
-        assertEquals(CoreActionComparison.STRING_STARTSWITH, ac.getComparison());
59
-        assertEquals("foo", ac.getTarget());
60
-    }
61
-
62
-    @Test
63
-    public void testTest1() {
64
-        final ActionCondition ac = new ActionCondition(1, CoreActionComponent.STRING_STRING,
65
-            CoreActionComparison.STRING_STARTSWITH, "foo");
66
-        assertTrue(ac.test(new ActionSubstitutor(actionController, commandController,
67
-                configProvider, CoreActionType.CLIENT_USER_INPUT), null, "foo bar"));
68
-    }
69
-
70
-    @Test
71
-    public void testTest2() {
72
-        final ActionCondition ac = new ActionCondition("foobarbaz",
73
-            CoreActionComparison.STRING_STARTSWITH, "foo");
74
-        assertTrue(ac.test(new ActionSubstitutor(actionController, commandController,
75
-                configProvider, CoreActionType.CLIENT_CLOSED)));
76
-    }
77
-
78
-    @Test
79
-    public void testSetters() {
80
-        final ActionCondition ac = new ActionCondition("foobarbaz",
81
-            CoreActionComparison.STRING_STARTSWITH, "foo");
82
-        assertEquals("foo", ac.getTarget());
83
-        ac.setTarget("bar");
84
-        assertEquals("bar", ac.getTarget());
85
-
86
-        assertEquals("foobarbaz", ac.getStarget());
87
-        ac.setStarget("bar");
88
-        assertEquals("bar", ac.getStarget());
89
-
90
-        assertEquals(CoreActionComparison.STRING_STARTSWITH, ac.getComparison());
91
-        ac.setComparison(CoreActionComparison.STRING_EQUALS);
92
-        assertEquals(CoreActionComparison.STRING_EQUALS, ac.getComparison());
93
-
94
-        ac.setComponent(CoreActionComponent.STRING_STRING);
95
-        assertEquals(CoreActionComponent.STRING_STRING, ac.getComponent());
96
-
97
-        ac.setArg(0);
98
-        assertEquals(0, ac.getArg());
99
-    }
100
-
101
-    @Test
102
-    public void testToString() {
103
-        final ActionCondition ac1 = new ActionCondition("foobarbaz",
104
-            CoreActionComparison.STRING_STARTSWITH, "foo");
105
-        assertTrue(ac1.toString().contains("foo"));
106
-        assertTrue(ac1.toString().contains("foobarbaz"));
107
-        assertTrue(ac1.toString().contains(CoreActionComparison.STRING_STARTSWITH.toString()));
108
-    }
109
-
110
-    @Test
111
-    public void testEquals() {
112
-        final ActionCondition ac1 = new ActionCondition("foobarbaz",
113
-            CoreActionComparison.STRING_STARTSWITH, "foo");
114
-        final ActionCondition ac2 = new ActionCondition("foobarbaz",
115
-            CoreActionComparison.STRING_STARTSWITH, "foo");
116
-
117
-        assertTrue(ac1.equals(ac2));
118
-        assertTrue(ac2.equals(ac1));
119
-        assertFalse(ac1.equals(null)); // NOPMD
120
-        assertFalse(ac1.equals("foo"));
121
-        assertEquals(ac1.hashCode(), ac2.hashCode());
122
-
123
-        ac2.setStarget("bar");
124
-        assertFalse(ac2.equals(ac1));
125
-        assertFalse(ac1.equals(ac2));
126
-
127
-        ac2.setStarget("foobarbaz");
128
-        ac2.setComponent(CoreActionComponent.STRING_STRING);
129
-        ac2.setArg(1);
130
-        assertFalse(ac2.equals(ac1));
131
-        assertFalse(ac1.equals(ac2));
132
-
133
-        ac1.setComponent(CoreActionComponent.STRING_STRING);
134
-        ac1.setArg(1);
135
-        assertTrue(ac1.equals(ac2));
136
-        assertTrue(ac2.equals(ac1));
137
-        assertEquals(ac1.hashCode(), ac2.hashCode());
138
-
139
-        ac1.setComponent(CoreActionComponent.STRING_LENGTH);
140
-        assertFalse(ac2.equals(ac1));
141
-        assertFalse(ac1.equals(ac2));
142
-
143
-        ac1.setComponent(CoreActionComponent.STRING_STRING);
144
-        ac1.setComparison(CoreActionComparison.STRING_NCONTAINS);
145
-        assertFalse(ac2.equals(ac1));
146
-        assertFalse(ac1.equals(ac2));
147
-
148
-        ac1.setComparison(CoreActionComparison.STRING_STARTSWITH);
149
-        ac1.setTarget("flub");
150
-        assertFalse(ac2.equals(ac1));
151
-        assertFalse(ac1.equals(ac2));
152
-    }
153
-
154
-}

+ 0
- 124
test/com/dmdirc/actions/ActionGroupTest.java View File

@@ -1,124 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-package com.dmdirc.actions;
23
-
24
-import com.dmdirc.config.prefs.PreferencesSetting;
25
-import com.dmdirc.updater.Version;
26
-
27
-import org.junit.Test;
28
-import org.junit.runner.RunWith;
29
-import org.mockito.Mock;
30
-import org.mockito.runners.MockitoJUnitRunner;
31
-
32
-import static org.junit.Assert.assertEquals;
33
-import static org.junit.Assert.assertFalse;
34
-import static org.junit.Assert.assertTrue;
35
-import static org.mockito.Mockito.mock;
36
-
37
-@RunWith(MockitoJUnitRunner.class)
38
-public class ActionGroupTest {
39
-
40
-    @Mock private ActionManager actionManager;
41
-
42
-    @Test
43
-    public void testGetAuthor() {
44
-        final ActionGroup instance = new ActionGroup(actionManager, "moo");
45
-        instance.setAuthor("foo");
46
-
47
-        final String expResult = "foo";
48
-        final String result = instance.getAuthor();
49
-        assertEquals(expResult, result);
50
-    }
51
-
52
-    @Test
53
-    public void testGetDescription() {
54
-        final ActionGroup instance = new ActionGroup(actionManager, "bar");
55
-        instance.setDescription("Tra-la-la-la-la");
56
-
57
-        final String expResult = "Tra-la-la-la-la";
58
-        final String result = instance.getDescription();
59
-        assertEquals(expResult, result);
60
-    }
61
-
62
-    @Test
63
-    public void testGetName() {
64
-        final ActionGroup instance = new ActionGroup(actionManager, "foobar");
65
-
66
-        final String expResult = "foobar";
67
-        final String result = instance.getName();
68
-        assertEquals(expResult, result);
69
-    }
70
-
71
-    @Test
72
-    public void testGetSettings() {
73
-        final ActionGroup instance = new ActionGroup(actionManager, "foo");
74
-
75
-        assertTrue(instance.getSettings().isEmpty());
76
-
77
-        instance.getSettings().put("", mock(PreferencesSetting.class));
78
-        assertEquals(1, instance.getSettings().size());
79
-    }
80
-
81
-    @Test
82
-    public void testGetVersion() {
83
-        final ActionGroup instance = new ActionGroup(actionManager, "vtest");
84
-        instance.setVersion(new Version(73));
85
-
86
-        final Version expResult = new Version(73);
87
-        final Version result = instance.getVersion();
88
-        assertEquals(expResult, result);
89
-    }
90
-
91
-    @Test
92
-    public void testGetComponent() {
93
-        final ActionGroup instance = new ActionGroup(actionManager, "zzz");
94
-        instance.setComponent(69);
95
-
96
-        final int expResult = 69;
97
-        final int result = instance.getComponent();
98
-        assertEquals(expResult, result);
99
-    }
100
-
101
-    @Test
102
-    public void testClear() {
103
-        final ActionGroup instance = new ActionGroup(actionManager, "zzz");
104
-        instance.add(null);
105
-        assertTrue(instance.iterator().hasNext());
106
-        instance.clear();
107
-        assertFalse(instance.iterator().hasNext());
108
-    }
109
-
110
-    @Test
111
-    public void testRemove() {
112
-        final ActionGroup instance = new ActionGroup(actionManager, "zzz");
113
-        instance.add(null);
114
-        assertTrue(instance.iterator().hasNext());
115
-        instance.remove(null);
116
-        assertFalse(instance.iterator().hasNext());
117
-    }
118
-
119
-    @Test
120
-    public void testIsDelible() {
121
-        assertTrue(new ActionGroup(actionManager, "foo").isDelible());
122
-    }
123
-
124
-}

+ 0
- 190
test/com/dmdirc/actions/ActionModelTest.java View File

@@ -1,190 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.GlobalWindow;
26
-import com.dmdirc.interfaces.ActionController;
27
-import com.dmdirc.interfaces.CommandController;
28
-import com.dmdirc.interfaces.actions.ActionType;
29
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
30
-
31
-import java.util.ArrayList;
32
-import java.util.Arrays;
33
-import java.util.List;
34
-
35
-import javax.inject.Provider;
36
-
37
-import org.junit.Test;
38
-import org.junit.runner.RunWith;
39
-import org.mockito.Mock;
40
-import org.mockito.runners.MockitoJUnitRunner;
41
-
42
-import static org.junit.Assert.assertEquals;
43
-import static org.junit.Assert.assertFalse;
44
-import static org.junit.Assert.assertNull;
45
-import static org.junit.Assert.assertTrue;
46
-
47
-@RunWith(MockitoJUnitRunner.class)
48
-public class ActionModelTest {
49
-
50
-    @Mock private Provider<GlobalWindow> gwProvider;
51
-    @Mock private ActionSubstitutorFactory substitutorFactory;
52
-    @Mock private ActionController actionController;
53
-    @Mock private CommandController commandController;
54
-    @Mock private AggregateConfigProvider configProvider;
55
-
56
-    @Test
57
-    public void testConditions() {
58
-        final ActionModel model = new ActionModel(gwProvider, substitutorFactory,
59
-                "group", "name");
60
-
61
-        assertTrue("ActionModel must start with no conditions",
62
-                model.getConditions().isEmpty());
63
-
64
-        final List<ActionCondition> conds = new ArrayList<>();
65
-
66
-        model.setConditions(conds);
67
-
68
-        assertEquals("setConditions must set conditions",
69
-                conds, model.getConditions());
70
-    }
71
-
72
-    @Test
73
-    public void testTriggers() {
74
-        final ActionModel model = new ActionModel(gwProvider, substitutorFactory,
75
-                "group", "name");
76
-
77
-        assertNull("ActionModel must start with null triggers",
78
-                model.getTriggers());
79
-
80
-        final ActionType[] triggers = {CoreActionType.CHANNEL_ACTION};
81
-
82
-        model.setTriggers(triggers);
83
-
84
-        assertEquals("setTriggers must set triggers",
85
-                Arrays.asList(triggers), Arrays.asList(model.getTriggers()));
86
-    }
87
-
88
-    @Test
89
-    public void testNewFormat() {
90
-        final ActionModel model = new ActionModel(gwProvider, substitutorFactory,
91
-                "group", "name");
92
-
93
-        assertNull("ActionModel must start with null format",
94
-                model.getNewFormat());
95
-
96
-        model.setNewFormat("");
97
-
98
-        assertEquals("setNewFormat must set format (empty string)",
99
-                "", model.getNewFormat());
100
-
101
-        model.setNewFormat("newformat");
102
-
103
-        assertEquals("setNewFormat must set format (non-empty string)",
104
-                "newformat", model.getNewFormat());
105
-    }
106
-
107
-    @Test
108
-    public void testResponse() {
109
-        final ActionModel model = new ActionModel(gwProvider, substitutorFactory,
110
-                "group", "name");
111
-
112
-        assertNull("ActionModel must start with null response",
113
-                model.getResponse());
114
-
115
-        final String[] newResponse = {"a", "b", "c"};
116
-
117
-        model.setResponse(newResponse);
118
-
119
-        assertEquals("setResponse must set response",
120
-                Arrays.asList(newResponse), Arrays.asList(model.getResponse()));
121
-    }
122
-
123
-    @Test
124
-    public void testGroup() {
125
-        final ActionModel model = new ActionModel(gwProvider, substitutorFactory,
126
-                "group", "name");
127
-
128
-        assertEquals("ActionModel constructor must set group",
129
-                "group", model.getGroup());
130
-
131
-        model.setGroup("group2");
132
-
133
-        assertEquals("setGroup must set group",
134
-                "group2", model.getGroup());
135
-    }
136
-
137
-    @Test
138
-    public void testName() {
139
-        final ActionModel model = new ActionModel(gwProvider, substitutorFactory,
140
-                "group", "name");
141
-
142
-        assertEquals("ActionModel constructor must set name",
143
-                "name", model.getName());
144
-
145
-        model.setName("name2");
146
-
147
-        assertEquals("setName must set name",
148
-                "name2", model.getName());
149
-    }
150
-
151
-    @Test
152
-    public void testTest() {
153
-        final ActionModel model = new ActionModel(gwProvider, substitutorFactory,
154
-                "group", "name",
155
-                new ActionType[]{CoreActionType.CHANNEL_ACTION},
156
-                new String[0], Arrays.asList(new ActionCondition(2, CoreActionComponent.STRING_STRING,
157
-                        CoreActionComparison.STRING_REGEX, ".*e{5}.*"),
158
-                new ActionCondition(2, CoreActionComponent.STRING_STRING,
159
-                        CoreActionComparison.STRING_STARTSWITH, "abc")), ConditionTree.parseString("0|1"), null);
160
-        final ActionSubstitutor sub = new ActionSubstitutor(actionController,
161
-                commandController, configProvider, CoreActionType.CHANNEL_ACTION);
162
-
163
-        assertTrue("test must pass if one condition in disjunction passes (cond 1)",
164
-                model.test(sub, null, null, "abcdef"));
165
-        assertTrue("test must pass if one condition in disjunction passes (cond 2)",
166
-                model.test(sub, null, null, "bcdeeeeeeeeef"));
167
-        assertFalse("test must fail if all conditions fail",
168
-                model.test(sub, null, null, "abeeef"));
169
-    }
170
-
171
-    @Test
172
-    public void testTestNoCondTree() {
173
-        final ActionModel model = new ActionModel(gwProvider, substitutorFactory,
174
-                "group", "name",
175
-                new ActionType[]{CoreActionType.CHANNEL_ACTION},
176
-                new String[0], Arrays.asList(new ActionCondition(2, CoreActionComponent.STRING_STRING,
177
-                        CoreActionComparison.STRING_REGEX, ".*e{5}.*"),
178
-                new ActionCondition(2, CoreActionComponent.STRING_STRING,
179
-                        CoreActionComparison.STRING_STARTSWITH, "abc")), null, null);
180
-        final ActionSubstitutor sub = new ActionSubstitutor(actionController, commandController,
181
-                configProvider, CoreActionType.CHANNEL_ACTION);
182
-
183
-        assertFalse("test must fail if one condition in conjunction fails (cond 1)",
184
-                model.test(sub, null, null, "abcdef"));
185
-        assertFalse("test must fail if one condition in conjunction fails (cond 2)",
186
-                model.test(sub, null, null, "abdeeeeeeeeef"));
187
-        assertTrue("test must pass if both conditions in conjunction pass",
188
-                model.test(sub, null, null, "abcdeeeeeeeeef"));
189
-    }
190
-}

+ 0
- 165
test/com/dmdirc/actions/ActionSubstitutorTest.java View File

@@ -1,165 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.Channel;
26
-import com.dmdirc.Server;
27
-import com.dmdirc.ServerState;
28
-import com.dmdirc.config.InvalidIdentityFileException;
29
-import com.dmdirc.interfaces.ActionController;
30
-import com.dmdirc.interfaces.CommandController;
31
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
32
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
33
-
34
-import java.util.Arrays;
35
-import java.util.HashMap;
36
-import java.util.List;
37
-import java.util.Map;
38
-import java.util.Optional;
39
-
40
-import org.junit.BeforeClass;
41
-import org.junit.Test;
42
-import org.junit.runner.RunWith;
43
-import org.junit.runners.Parameterized;
44
-
45
-import static org.junit.Assert.*;
46
-import static org.mockito.Mockito.*;
47
-
48
-@RunWith(Parameterized.class)
49
-public class ActionSubstitutorTest {
50
-
51
-    private static final Map<String, String> SETTINGS = new HashMap<>();
52
-
53
-    private final String input, expected;
54
-    private final Channel channel;
55
-    private final ActionSubstitutor substitutor;
56
-    private final Object[] args;
57
-
58
-    @BeforeClass
59
-    public static void setup() throws InvalidIdentityFileException {
60
-        SETTINGS.put("alpha", "A");
61
-        SETTINGS.put("bravo", "$alpha");
62
-        SETTINGS.put("charlie", "${bravo}");
63
-        SETTINGS.put("delta", "${${bravo}${bravo}}");
64
-        SETTINGS.put("AA", "win!");
65
-    }
66
-
67
-    public ActionSubstitutorTest(final String input, final String expected) {
68
-        this.input = input;
69
-        this.expected = expected;
70
-
71
-        this.channel = mock(Channel.class);
72
-
73
-        final AggregateConfigProvider manager = mock(AggregateConfigProvider.class);
74
-        final Server server = mock(Server.class);
75
-
76
-        final ChannelClientInfo clientInfo = mock(ChannelClientInfo.class);
77
-
78
-        when(channel.getConnection()).thenReturn(Optional.of(server));
79
-        when(channel.getConfigManager()).thenReturn(manager);
80
-        when(server.getState()).thenReturn(ServerState.DISCONNECTED);
81
-        when(server.getAwayMessage()).thenReturn("foo");
82
-        when(server.getProtocol()).thenReturn("$alpha");
83
-
84
-        when(manager.getOptions(eq("actions"))).thenReturn(SETTINGS);
85
-        for (Map.Entry<String, String> entry : SETTINGS.entrySet()) {
86
-            when(manager.hasOptionString("actions", entry.getKey())).thenReturn(true);
87
-            when(manager.getOption("actions", entry.getKey())).thenReturn(entry.getValue());
88
-        }
89
-
90
-        final ActionController controller = mock(ActionController.class);
91
-        when(controller.getComponent("STRING_STRING")).thenReturn(CoreActionComponent.STRING_STRING);
92
-        when(controller.getComponent("STRING_LENGTH")).thenReturn(CoreActionComponent.STRING_LENGTH);
93
-        when(controller.getComponent("SERVER_NETWORK")).thenReturn(CoreActionComponent.SERVER_NETWORK);
94
-        when(controller.getComponent("SERVER_PROTOCOL")).thenReturn(CoreActionComponent.SERVER_PROTOCOL);
95
-        when(controller.getComponent("SERVER_MYAWAYREASON")).thenReturn(CoreActionComponent.SERVER_MYAWAYREASON);
96
-
97
-        substitutor = new ActionSubstitutor(controller, mock(CommandController.class),
98
-                mock(AggregateConfigProvider.class), CoreActionType.CHANNEL_MESSAGE);
99
-
100
-        args = new Object[]{
101
-            channel,
102
-            clientInfo,
103
-            "1 2 3 fourth_word_here 5 6 7"
104
-        };
105
-    }
106
-
107
-    @Test
108
-    public void testSubstitution() {
109
-        assertEquals(expected, substitutor.doSubstitution(input, args));
110
-    }
111
-
112
-    @Parameterized.Parameters
113
-    public static List<String[]> data() {
114
-        final String[][] tests = {
115
-            // -- Existing behaviour -------------------------------------------
116
-            // ---- No subs at all ---------------------------------------------
117
-            {"no subs here!", "no subs here!"},
118
-            // ---- Config subs ------------------------------------------------
119
-            {"$alpha", "A"},
120
-            {"--$alpha--", "--A--"},
121
-            // ---- Word subs --------------------------------------------------
122
-            {"$1", "1"},
123
-            {"$4", "fourth_word_here"},
124
-            {"$5-", "5 6 7"},
125
-            // ---- Component subs ---------------------------------------------
126
-            {"${2.STRING_LENGTH}", "28"},
127
-            {"${2.STRING_STRING}", "1 2 3 fourth_word_here 5 6 7"},
128
-            // ---- Server subs ------------------------------------------------
129
-            {"${SERVER_MYAWAYREASON}", "foo"},
130
-            // ---- Combinations -----------------------------------------------
131
-            {"${1}${2.STRING_LENGTH}$alpha", "128A"},
132
-            {"$alpha$4${SERVER_MYAWAYREASON}", "Afourth_word_herefoo"},
133
-
134
-            // -- New behaviour ------------------------------------------------
135
-            // ---- Config subs ------------------------------------------------
136
-            {"${alpha}", "A"},
137
-            {"\\$alpha", "$alpha"},
138
-            {"$bravo", "A"},
139
-            {"$charlie", "A"},
140
-            {"$delta", "win!"},
141
-            {"$sigma", "not_defined"},
142
-            // ---- Word subs --------------------------------------------------
143
-            {"$5-6", "5 6"},
144
-            {"${5-6}", "5 6"},
145
-            {"${5-$6}", "5 6"},
146
-            {"${5-${${6}}}", "5 6"},
147
-            // ---- Component subs ---------------------------------------------
148
-            {"${2.STRING_STRING.STRING_LENGTH}", "28"},
149
-            {"${2.STRING_FLUB.STRING_LENGTH}", "illegal_component"},
150
-            {"${SERVER_NETWORKFOO}", "illegal_component"},
151
-            {"${SERVER_NETWORK}", "not_connected"},
152
-            {"${SERVER_PROTOCOL}", "$alpha"},
153
-            // ---- Escaping ---------------------------------------------------
154
-            {"\\$1", "$1"},
155
-            {"\\$alpha $alpha", "$alpha A"},
156
-            {"\\$$1", "$1"},
157
-            {"\\\\$4", "\\fourth_word_here"},
158
-            {"\\\\${4}", "\\fourth_word_here"},
159
-            {"\\\\\\$4", "\\$4"},
160
-        };
161
-
162
-        return Arrays.asList(tests);
163
-    }
164
-
165
-}

+ 0
- 201
test/com/dmdirc/actions/ActionTest.java View File

@@ -1,201 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.GlobalWindow;
27
-import com.dmdirc.config.prefs.PreferencesSetting;
28
-import com.dmdirc.config.prefs.PreferencesType;
29
-import com.dmdirc.interfaces.ActionController;
30
-import com.dmdirc.interfaces.actions.ActionType;
31
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
32
-import com.dmdirc.interfaces.config.ConfigProvider;
33
-import com.dmdirc.interfaces.config.IdentityController;
34
-import com.dmdirc.util.io.ConfigFile;
35
-import com.dmdirc.util.io.InvalidConfigFileException;
36
-
37
-import com.google.common.jimfs.Configuration;
38
-import com.google.common.jimfs.Jimfs;
39
-
40
-import java.io.IOException;
41
-import java.nio.file.FileSystem;
42
-import java.nio.file.Files;
43
-import java.nio.file.Path;
44
-import java.util.ArrayList;
45
-import java.util.Arrays;
46
-import java.util.HashMap;
47
-import java.util.Map;
48
-
49
-import javax.inject.Provider;
50
-
51
-import org.junit.Before;
52
-import org.junit.Test;
53
-import org.junit.runner.RunWith;
54
-import org.mockito.Mock;
55
-import org.mockito.runners.MockitoJUnitRunner;
56
-
57
-import static org.junit.Assert.assertEquals;
58
-import static org.junit.Assert.assertFalse;
59
-import static org.junit.Assert.assertTrue;
60
-import static org.mockito.Matchers.anyString;
61
-import static org.mockito.Mockito.atLeast;
62
-import static org.mockito.Mockito.verify;
63
-import static org.mockito.Mockito.when;
64
-
65
-@RunWith(MockitoJUnitRunner.class)
66
-public class ActionTest {
67
-
68
-    @Mock private DMDircMBassador eventBus;
69
-    @Mock private Provider<GlobalWindow> gwProvider;
70
-    @Mock private ActionSubstitutorFactory substitutorFactory;
71
-    @Mock private ActionController actionController;
72
-    @Mock private ActionGroup actionGroup;
73
-    @Mock private IdentityController identityController;
74
-    @Mock private ConfigProvider configProvider;
75
-    @Mock private AggregateConfigProvider aggregateConfigProvider;
76
-    private Map<String, PreferencesSetting> prefs;
77
-    private FileSystem filesystem;
78
-
79
-    @Before
80
-    public void setupActionController() {
81
-        prefs = new HashMap<>();
82
-        when(actionController.getOrCreateGroup(anyString())).thenReturn(actionGroup);
83
-        when(actionGroup.getSettings()).thenReturn(prefs);
84
-        when(actionController.getType("SERVER_AWAY")).thenReturn(CoreActionType.SERVER_AWAY);
85
-        when(actionController.getComponent("STRING_LENGTH")).thenReturn(
86
-                CoreActionComponent.STRING_LENGTH);
87
-        when(actionController.getComparison("STRING_CONTAINS")).thenReturn(
88
-                CoreActionComparison.STRING_CONTAINS);
89
-        when(actionController.getComparison("INT_EQUALS")).thenReturn(
90
-                CoreActionComparison.INT_EQUALS);
91
-    }
92
-
93
-    @Before
94
-    public void setupIdentityController() {
95
-        when(identityController.getGlobalConfiguration()).thenReturn(aggregateConfigProvider);
96
-        when(identityController.getUserSettings()).thenReturn(configProvider);
97
-    }
98
-
99
-    @Before
100
-    public void setupFileSystem() {
101
-        filesystem = Jimfs.newFileSystem(Configuration.unix());
102
-    }
103
-
104
-    @Test
105
-    public void testSave() throws IOException {
106
-        new Action(eventBus, gwProvider, substitutorFactory,
107
-                actionController, identityController, getTempDirectory(), "unit-test", "test1",
108
-                new ActionType[0], new String[0], new ArrayList<>(),
109
-                ConditionTree.createConjunction(0), null);
110
-        assertTrue("Action constructor must create new file",
111
-                Files.exists(getTempDirectory().resolve("unit-test").resolve("test1")));
112
-
113
-    }
114
-
115
-    @Test
116
-    public void testSetGroup() throws IOException {
117
-        final Action action = new Action(eventBus, gwProvider,
118
-                substitutorFactory, actionController, identityController, getTempDirectory(),
119
-                "unit-test", "test1", new ActionType[0],
120
-                new String[0], new ArrayList<>(),
121
-                ConditionTree.createConjunction(0), null);
122
-        action.setGroup("unit-test-two");
123
-
124
-        assertFalse("setGroup must remove old file",
125
-                Files.exists(getTempDirectory().resolve("unit-test").resolve("test1")));
126
-        assertTrue("setGroup must create new file",
127
-                Files.exists(getTempDirectory().resolve("unit-test-two").resolve("test1")));
128
-    }
129
-
130
-    @Test
131
-    public void testSetName() throws IOException {
132
-        final Action action = new Action(eventBus, gwProvider,
133
-                substitutorFactory, actionController, identityController, getTempDirectory(),
134
-                "unit-test", "test1", new ActionType[0], new String[0],
135
-                new ArrayList<>(), ConditionTree.createConjunction(0), null);
136
-        action.setName("test2");
137
-
138
-        assertFalse("setName must remove old file",
139
-                Files.exists(getTempDirectory().resolve("unit-test").resolve("test1")));
140
-        assertTrue("setName must create new file",
141
-                Files.exists(getTempDirectory().resolve("unit-test").resolve("test2")));
142
-    }
143
-
144
-    @Test
145
-    public void testDelete() throws IOException {
146
-        final Action action = new Action(eventBus, gwProvider,
147
-                substitutorFactory, actionController, identityController, getTempDirectory(),
148
-                "unit-test", "test1", new ActionType[0],
149
-                new String[0], new ArrayList<>(),
150
-                ConditionTree.createConjunction(0), null);
151
-        action.delete();
152
-
153
-        assertFalse("delete must remove file",
154
-                Files.exists(getTempDirectory().resolve("unit-test").resolve("test1")));
155
-    }
156
-
157
-    @Test
158
-    public void testRead() throws IOException, InvalidConfigFileException {
159
-        final Action action = new Action(eventBus, gwProvider,
160
-                substitutorFactory, actionController, identityController, getTempDirectory(),
161
-                "unit-test", "doesn't_exist");
162
-        action.config = new ConfigFile(getClass().getResourceAsStream("action1"));
163
-        action.config.read();
164
-        action.loadActionFromConfig();
165
-
166
-        assertTrue(Arrays.equals(action.getTriggers(),
167
-                new ActionType[]{CoreActionType.SERVER_AWAY}));
168
-        assertEquals("(0&1)", action.getConditionTree().toString());
169
-        assertTrue(Arrays.equals(action.getResponse(), new String[]{"/away"}));
170
-        assertEquals(new ActionCondition(1, CoreActionComponent.STRING_LENGTH,
171
-                CoreActionComparison.INT_EQUALS, "0"), action.getConditions().get(0));
172
-        assertEquals(new ActionCondition("foo", CoreActionComparison.STRING_CONTAINS,
173
-                "bar"), action.getConditions().get(1));
174
-    }
175
-
176
-    @Test
177
-    public void testMultipleGroups() throws IOException, InvalidConfigFileException {
178
-        final Action action = new Action(eventBus, gwProvider,
179
-                substitutorFactory, actionController, identityController, getTempDirectory(),
180
-                "unit-test", "doesn't_exist");
181
-        action.config = new ConfigFile(getClass().getResourceAsStream("action_multisettings"));
182
-        action.config.read();
183
-        action.loadActionFromConfig();
184
-
185
-        assertEquals(1, prefs.size());
186
-
187
-        final PreferencesSetting setting = prefs.values().iterator().next();
188
-        assertEquals(PreferencesType.TEXT, setting.getType());
189
-        assertEquals("Highlight Regex", setting.getTitle());
190
-        assertEquals("Regex to use to detect a highlight", setting.getHelptext());
191
-
192
-        verify(actionController, atLeast(1)).registerSetting("highlightregex",
193
-                "(?i).*(shane|dataforce|Q${SERVER_MYNICKNAME}E|(?<![#A-Z])DF).*");
194
-    }
195
-
196
-    private Path getTempDirectory() throws IOException {
197
-        Files.createDirectories(filesystem.getPath("/temp"));
198
-        return filesystem.getPath("/temp/");
199
-    }
200
-
201
-}

+ 0
- 39
test/com/dmdirc/actions/ActionTypeComparatorTest.java View File

@@ -1,39 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-package com.dmdirc.actions;
23
-
24
-import org.junit.Test;
25
-
26
-import static org.junit.Assert.*;
27
-
28
-public class ActionTypeComparatorTest {
29
-
30
-    @Test
31
-    public void testCompare() {
32
-        final ActionTypeComparator atc = new ActionTypeComparator();
33
-
34
-        assertTrue(atc.compare(CoreActionType.CHANNEL_ACTION, CoreActionType.QUERY_ACTION) < 0);
35
-        assertTrue(atc.compare(CoreActionType.CHANNEL_ACTION, CoreActionType.CHANNEL_ACTION) == 0);
36
-        assertTrue(atc.compare(CoreActionType.QUERY_ACTION, CoreActionType.CHANNEL_ACTION) > 0);
37
-    }
38
-
39
-}

+ 0
- 95
test/com/dmdirc/actions/ConditionTreeEvaluatorTest.java View File

@@ -1,95 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import java.util.Arrays;
26
-import java.util.List;
27
-
28
-import org.junit.Test;
29
-import org.junit.runner.RunWith;
30
-import org.junit.runners.Parameterized;
31
-
32
-import static org.junit.Assert.*;
33
-
34
-@RunWith(Parameterized.class)
35
-public class ConditionTreeEvaluatorTest {
36
-
37
-    private final Boolean[] data;
38
-
39
-    public ConditionTreeEvaluatorTest(final Boolean[] data) {
40
-        this.data = data;
41
-    }
42
-
43
-    @Test
44
-    public void testEvaluate() {
45
-        final String target = "((0&1&2)|3)&(!4)";
46
-        final ConditionTree tree = ConditionTree.parseString(target);
47
-        assertNotNull(tree);
48
-
49
-        final boolean expected =
50
-                    ((data[0] && data[1] && data[2]) || data[3])
51
-                    && !data[4];
52
-        final boolean actual = tree.evaluate(new boolean[]{data[0], data[1],
53
-                data[2], data[3], data[4]});
54
-
55
-        assertEquals(expected, actual);
56
-    }
57
-
58
-    @Parameterized.Parameters
59
-    public static List<Boolean[][]> getData() {
60
-        return Arrays.asList(new Boolean[][][]{
61
-            {{true, true, true, true, true}},
62
-            {{true, true, true, true, false}},
63
-            {{true, true, true, false, true}},
64
-            {{true, true, true, false, false}},
65
-            {{true, true, false, true, true}},
66
-            {{true, true, false, true, false}},
67
-            {{true, true, false, false, true}},
68
-            {{true, true, false, false, false}},
69
-            {{true, false, true, true, true}},
70
-            {{true, false, true, true, false}},
71
-            {{true, false, true, false, true}},
72
-            {{true, false, true, false, false}},
73
-            {{true, false, false, true, true}},
74
-            {{true, false, false, true, false}},
75
-            {{true, false, false, false, true}},
76
-            {{true, false, false, false, false}},
77
-            {{false, true, true, true, true}},
78
-            {{false, true, true, true, false}},
79
-            {{false, true, true, false, true}},
80
-            {{false, true, true, false, false}},
81
-            {{false, true, false, true, true}},
82
-            {{false, true, false, true, false}},
83
-            {{false, true, false, false, true}},
84
-            {{false, true, false, false, false}},
85
-            {{false, false, true, true, true}},
86
-            {{false, false, true, true, false}},
87
-            {{false, false, true, false, true}},
88
-            {{false, false, true, false, false}},
89
-            {{false, false, false, true, true}},
90
-            {{false, false, false, true, false}},
91
-            {{false, false, false, false, true}},
92
-            {{false, false, false, false, false}},
93
-        });
94
-    }
95
-}

+ 0
- 73
test/com/dmdirc/actions/ConditionTreeParserTest.java View File

@@ -1,73 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import java.util.Arrays;
26
-import java.util.List;
27
-
28
-import org.junit.Test;
29
-import org.junit.runner.RunWith;
30
-import org.junit.runners.Parameterized;
31
-
32
-import static org.junit.Assert.*;
33
-
34
-@RunWith(Parameterized.class)
35
-public class ConditionTreeParserTest {
36
-
37
-    private final String input, expected;
38
-
39
-    public ConditionTreeParserTest(final String input, final String expected) {
40
-        this.input = input;
41
-        this.expected = expected;
42
-    }
43
-
44
-    @Test
45
-    public void testParseString() {
46
-        final ConditionTree res = ConditionTree.parseString(input);
47
-        assertNotNull(res);
48
-
49
-        assertEquals(expected, res.toString());
50
-    }
51
-
52
-    @Parameterized.Parameters
53
-    public static List<String[]> getData() {
54
-        return Arrays.asList(new String[][]{
55
-            {"1", "1"},
56
-            {"50", "50"},
57
-            {"!50", "!50"},
58
-            {"1&1", "(1&1)"},
59
-            {"1&!1", "(1&!1)"},
60
-            {"!1&1", "(!1&1)"},
61
-            {"(1)", "1"},
62
-            {"((((1))))", "1"},
63
-            {"(1&1)&1", "((1&1)&1)"},
64
-            {"1&2&3", "((1&2)&3)"},
65
-            {"(1&2&3)|4", "(((1&2)&3)|4)"},
66
-            {"!(1|!1)", "!(1|!1)"},
67
-            {"!!1", "!!1"},
68
-            {"1 & !(2 | (3 & !4))", "(1&!(2|(3&!4)))"},
69
-            {"", ""},
70
-            {"((1|((2&!3)&(!4))|6)&7)|!8", "((((1|((2&!3)&!4))|6)&7)|!8)"},
71
-        });
72
-    }
73
-}

+ 0
- 150
test/com/dmdirc/actions/ConditionTreeTest.java View File

@@ -1,150 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import org.junit.Test;
26
-
27
-import static org.junit.Assert.*;
28
-
29
-public class ConditionTreeTest {
30
-
31
-    @Test
32
-    public void testGetNumArgs() {
33
-        final String target = "((0&1&2)|3)&(!4)";
34
-        final ConditionTree tree = ConditionTree.parseString(target);
35
-        assertNotNull(tree);
36
-
37
-        assertEquals(4, tree.getMaximumArgument());
38
-
39
-        final String target2 = "";
40
-        assertEquals(0, ConditionTree.parseString(target2).getMaximumArgument());
41
-    }
42
-
43
-    @Test
44
-    public void testCreateConjunction() {
45
-        final String expected = "(((0&1)&2)&3)";
46
-        final ConditionTree tree = ConditionTree.createConjunction(4);
47
-
48
-        assertNotNull(tree);
49
-        assertEquals(expected, tree.toString());
50
-    }
51
-
52
-    @Test
53
-    public void testCreateDisjunction() {
54
-        final String expected = "(((0|1)|2)|3)";
55
-        final ConditionTree tree = ConditionTree.createDisjunction(4);
56
-
57
-        assertNotNull(tree);
58
-        assertEquals(expected, tree.toString());
59
-    }
60
-
61
-    @Test
62
-    public void testMismatchedBrackets() {
63
-        final ConditionTree tree = ConditionTree.parseString("(0");
64
-
65
-        assertNull(tree);
66
-    }
67
-
68
-    @Test
69
-    public void testMismatchedBrackets2() {
70
-        final ConditionTree tree = ConditionTree.parseString("0)");
71
-
72
-        assertNull(tree);
73
-    }
74
-
75
-    @Test
76
-    public void testMissingUnaryArg() {
77
-        final ConditionTree tree = ConditionTree.parseString("!");
78
-
79
-        assertNull(tree);
80
-    }
81
-
82
-    @Test
83
-    public void testGarbageUnaryArg() {
84
-        final ConditionTree tree = ConditionTree.parseString("!xy");
85
-
86
-        assertNull(tree);
87
-    }
88
-
89
-    @Test
90
-    public void testMissingBinaryArg() {
91
-        final ConditionTree tree = ConditionTree.parseString("0|");
92
-
93
-        assertNull(tree);
94
-    }
95
-
96
-    @Test
97
-    public void testMissingBinaryArg2() {
98
-        final ConditionTree tree = ConditionTree.parseString("0|!");
99
-
100
-        assertNull(tree);
101
-    }
102
-
103
-    @Test
104
-    public void testNonExistantOp() {
105
-        final ConditionTree tree = ConditionTree.parseString("0/1");
106
-
107
-        assertNull(tree);
108
-    }
109
-
110
-    @Test
111
-    public void testHugeNumber() {
112
-        final ConditionTree tree = ConditionTree.parseString("9999999999999999");
113
-
114
-        assertNull(tree);
115
-    }
116
-
117
-    @Test
118
-    public void testNoopEvaluation() {
119
-        final ConditionTree tree = ConditionTree.parseString("");
120
-
121
-        assertTrue(tree.evaluate(new boolean[]{true, false, true}));
122
-    }
123
-
124
-    @Test
125
-    public void testBracketedUnary() {
126
-        final ConditionTree tree = ConditionTree.parseString("(+)");
127
-
128
-        assertNull(tree);
129
-    }
130
-
131
-    @Test
132
-    public void testEquals() {
133
-        final ConditionTree tree1 = ConditionTree.parseString("(1&3)");
134
-        final ConditionTree tree2 = ConditionTree.parseString("((1&(3)))");
135
-
136
-        assertTrue(tree1.equals(tree2));
137
-        assertTrue(tree2.equals(tree1));
138
-        assertEquals(tree1.hashCode(), tree2.hashCode());
139
-    }
140
-
141
-    @Test
142
-    public void testNotEquals() {
143
-        final ConditionTree tree1 = ConditionTree.parseString("(1&3)");
144
-        final ConditionTree tree2 = ConditionTree.parseString("((1&(2)))");
145
-
146
-        assertFalse(tree1.equals(tree2));
147
-        assertFalse(tree2.equals(tree1));
148
-    }
149
-
150
-}

+ 0
- 104
test/com/dmdirc/actions/CoreActionComparisonTest.java View File

@@ -1,104 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-package com.dmdirc.actions;
23
-
24
-import org.junit.Test;
25
-
26
-import static org.junit.Assert.*;
27
-
28
-public class CoreActionComparisonTest {
29
-
30
-    @Test
31
-    public void testStringRegex() {
32
-        assertEquals(String.class, CoreActionComparison.STRING_REGEX.appliesTo());
33
-        assertTrue(CoreActionComparison.STRING_REGEX.getName().toLowerCase().contains("reg"));
34
-        assertTrue(CoreActionComparison.STRING_REGEX.test("hello", "h.*?o"));
35
-        assertFalse(CoreActionComparison.STRING_REGEX.test("hello", "h.{8}o"));
36
-        assertFalse(CoreActionComparison.STRING_REGEX.test("hello", "?!!?!{}"));
37
-    }
38
-
39
-    @Test
40
-    public void testStringEquals() {
41
-        assertEquals(String.class, CoreActionComparison.STRING_EQUALS.appliesTo());
42
-        assertTrue(CoreActionComparison.STRING_EQUALS.getName().toLowerCase().contains("equal"));
43
-        assertTrue(CoreActionComparison.STRING_EQUALS.test("hello", "hello"));
44
-        assertTrue(CoreActionComparison.STRING_EQUALS.test("hello", "HELLO"));
45
-        assertFalse(CoreActionComparison.STRING_EQUALS.test("hello", "h.{8}o"));
46
-        assertFalse(CoreActionComparison.STRING_EQUALS.test("hello", "?!!?!{}"));
47
-    }
48
-
49
-    @Test
50
-    public void testStringNEquals() {
51
-        assertEquals(String.class, CoreActionComparison.STRING_NEQUALS.appliesTo());
52
-        assertTrue(CoreActionComparison.STRING_NEQUALS.getName().toLowerCase().contains("equal"));
53
-        assertTrue(CoreActionComparison.STRING_NEQUALS.getName().toLowerCase().contains("not")
54
-                || CoreActionComparison.STRING_NEQUALS.getName().toLowerCase().contains("n't"));
55
-        assertFalse(CoreActionComparison.STRING_NEQUALS.test("hello", "hello"));
56
-        assertFalse(CoreActionComparison.STRING_NEQUALS.test("hello", "HELLO"));
57
-        assertTrue(CoreActionComparison.STRING_NEQUALS.test("hello", "h.{8}o"));
58
-        assertTrue(CoreActionComparison.STRING_NEQUALS.test("hello", "?!!?!{}"));
59
-    }
60
-
61
-    @Test
62
-    public void testStringStartsWith() {
63
-        assertEquals(String.class, CoreActionComparison.STRING_STARTSWITH.appliesTo());
64
-        assertTrue(CoreActionComparison.STRING_STARTSWITH.getName().toLowerCase().contains("start"));
65
-        assertTrue(CoreActionComparison.STRING_STARTSWITH.test("hello", "hello"));
66
-        assertTrue(CoreActionComparison.STRING_STARTSWITH.test("hello", "he"));
67
-        assertFalse(CoreActionComparison.STRING_STARTSWITH.test("hello", "h.{8}o"));
68
-        assertFalse(CoreActionComparison.STRING_STARTSWITH.test("hello", "?!!?!{}"));
69
-    }
70
-
71
-    @Test
72
-    public void testStringContains() {
73
-        assertEquals(String.class, CoreActionComparison.STRING_CONTAINS.appliesTo());
74
-        assertTrue(CoreActionComparison.STRING_CONTAINS.getName().toLowerCase().contains("contain"));
75
-        assertTrue(CoreActionComparison.STRING_CONTAINS.test("hello", "hello"));
76
-        assertTrue(CoreActionComparison.STRING_CONTAINS.test("hello", "lo"));
77
-        assertFalse(CoreActionComparison.STRING_CONTAINS.test("hello", "h.{8}o"));
78
-        assertFalse(CoreActionComparison.STRING_CONTAINS.test("hello", "?!!?!{}"));
79
-    }
80
-
81
-    @Test
82
-    public void testStringNContains() {
83
-        assertEquals(String.class, CoreActionComparison.STRING_NCONTAINS.appliesTo());
84
-        assertTrue(
85
-                CoreActionComparison.STRING_NCONTAINS.getName().toLowerCase().contains("contain"));
86
-        assertTrue(CoreActionComparison.STRING_NCONTAINS.getName().toLowerCase().contains("not")
87
-                || CoreActionComparison.STRING_NCONTAINS.getName().toLowerCase().contains("n't"));
88
-        assertFalse(CoreActionComparison.STRING_NCONTAINS.test("hello", "hello"));
89
-        assertFalse(CoreActionComparison.STRING_NCONTAINS.test("hello", "lo"));
90
-        assertTrue(CoreActionComparison.STRING_NCONTAINS.test("hello", "h.{8}o"));
91
-        assertTrue(CoreActionComparison.STRING_NCONTAINS.test("hello", "?!!?!{}"));
92
-    }
93
-
94
-    @Test
95
-    public void testBoolIs() {
96
-        assertEquals(Boolean.class, CoreActionComparison.BOOL_IS.appliesTo());
97
-        assertTrue(CoreActionComparison.BOOL_IS.getName().toLowerCase().contains("is"));
98
-        assertTrue(CoreActionComparison.BOOL_IS.test(Boolean.TRUE, "true"));
99
-        assertTrue(CoreActionComparison.BOOL_IS.test(Boolean.FALSE, "false"));
100
-        assertFalse(CoreActionComparison.BOOL_IS.test(Boolean.FALSE, "true"));
101
-        assertFalse(CoreActionComparison.BOOL_IS.test(Boolean.TRUE, "false"));
102
-    }
103
-
104
-}

+ 0
- 77
test/com/dmdirc/actions/CoreActionExtractorTest.java View File

@@ -1,77 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.interfaces.ActionController;
27
-
28
-import com.google.common.jimfs.Configuration;
29
-import com.google.common.jimfs.Jimfs;
30
-
31
-import java.nio.file.FileSystem;
32
-import java.nio.file.Files;
33
-import java.nio.file.Path;
34
-
35
-import org.junit.After;
36
-import org.junit.Before;
37
-import org.junit.Test;
38
-import org.junit.runner.RunWith;
39
-import org.mockito.Mock;
40
-import org.mockito.runners.MockitoJUnitRunner;
41
-
42
-import static junit.framework.TestCase.assertFalse;
43
-import static junit.framework.TestCase.assertTrue;
44
-import static org.mockito.Mockito.verify;
45
-
46
-@RunWith(MockitoJUnitRunner.class)
47
-public class CoreActionExtractorTest {
48
-
49
-    @Mock private ActionController actionController;
50
-    @Mock private DMDircMBassador eventBus;
51
-
52
-    private FileSystem fileSystem;
53
-    private Path actionsDir;
54
-    private CoreActionExtractor instance;
55
-
56
-    @Before
57
-    public void setUp() throws Exception {
58
-        fileSystem = Jimfs.newFileSystem(Configuration.unix());
59
-        actionsDir = fileSystem.getPath("/").resolve("actions");
60
-        Files.createDirectory(actionsDir);
61
-        instance = new CoreActionExtractor(actionController, actionsDir, eventBus);
62
-    }
63
-
64
-    @After
65
-    public void tearDown() throws Exception {
66
-        fileSystem.close();
67
-    }
68
-
69
-    @Test
70
-    public void testExtractCoreActions() throws Exception {
71
-        assertFalse(Files.list(actionsDir).findAny().isPresent());
72
-        instance.extractCoreActions();
73
-        assertTrue(Files.exists(actionsDir.resolve("action1")));
74
-        assertTrue(Files.exists(actionsDir.resolve("action2")));
75
-        verify(actionController).loadUserActions();
76
-    }
77
-}

+ 0
- 42
test/com/dmdirc/actions/CoreActionTypeTest.java View File

@@ -1,42 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-package com.dmdirc.actions;
23
-
24
-import com.dmdirc.actions.metatypes.PluginEvents;
25
-
26
-import org.junit.Test;
27
-
28
-import static org.junit.Assert.*;
29
-
30
-public class CoreActionTypeTest {
31
-
32
-    @Test
33
-    public void testGetName() {
34
-        assertEquals("Plugin loaded", CoreActionType.PLUGIN_LOADED.getName());
35
-    }
36
-
37
-    @Test
38
-    public void testMetaType() {
39
-        assertEquals(PluginEvents.PLUGIN_EVENT, CoreActionType.PLUGIN_LOADED.getType());
40
-    }
41
-
42
-}

+ 0
- 86
test/com/dmdirc/actions/StringComponentsTest.java View File

@@ -1,86 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions;
24
-
25
-import java.util.Arrays;
26
-import java.util.List;
27
-
28
-import org.junit.Test;
29
-import org.junit.runner.RunWith;
30
-import org.junit.runners.Parameterized;
31
-
32
-import static org.junit.Assert.*;
33
-
34
-@RunWith(Parameterized.class)
35
-public class StringComponentsTest {
36
-
37
-    private final String string1;
38
-    private final String string2;
39
-
40
-    public StringComponentsTest(final String string1, final String string2) {
41
-        this.string1 = string1;
42
-        this.string2 = string2;
43
-    }
44
-
45
-    @Test
46
-    public void testEquals() {
47
-        assertEquals(string1.equalsIgnoreCase(string2),
48
-                CoreActionComparison.STRING_EQUALS.test(string1, string2));
49
-    }
50
-
51
-    @Test
52
-    public void testNotEquals() {
53
-        assertEquals(!string1.equalsIgnoreCase(string2),
54
-                CoreActionComparison.STRING_NEQUALS.test(string1, string2));
55
-    }
56
-
57
-    @Test
58
-    public void testStartsWith() {
59
-        assertEquals(string1.startsWith(string2),
60
-                CoreActionComparison.STRING_STARTSWITH.test(string1, string2));
61
-    }
62
-
63
-    @Test
64
-    public void testContains() {
65
-        assertEquals(string1.contains(string2),
66
-                CoreActionComparison.STRING_CONTAINS.test(string1, string2));
67
-    }
68
-
69
-    @Test
70
-    public void testNotContains() {
71
-        assertEquals(!string1.contains(string2),
72
-                CoreActionComparison.STRING_NCONTAINS.test(string1, string2));
73
-    }
74
-
75
-    @Parameterized.Parameters
76
-    public static List<Object[]> data() {
77
-        return Arrays.asList(new Object[][]{
78
-            {"foo", "foo"},
79
-            {"FOO", "foo"},
80
-            {"", "foo"},
81
-            {"foo", ""},
82
-            {"abc foo def", "foo"}
83
-        });
84
-    }
85
-
86
-}

+ 0
- 42
test/com/dmdirc/actions/metatypes/ActionEventsTest.java View File

@@ -1,42 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-package com.dmdirc.actions.metatypes;
23
-
24
-import com.dmdirc.interfaces.actions.ActionMetaType;
25
-
26
-import org.junit.Test;
27
-
28
-import static org.junit.Assert.*;
29
-
30
-public class ActionEventsTest {
31
-
32
-    @Test
33
-    public void testArity() {
34
-        for (ActionMetaType event : ActionEvents.values()) {
35
-            assertEquals("Arity and number of arg names must be equal",
36
-                    event.getArity(), event.getArgNames().length);
37
-            assertEquals("Arity and number of arg types must be equal",
38
-                    event.getArity(), event.getArgTypes().length);
39
-        }
40
-    }
41
-
42
-}

+ 0
- 38
test/com/dmdirc/actions/metatypes/ChannelEventsTest.java View File

@@ -1,38 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-package com.dmdirc.actions.metatypes;
23
-
24
-import org.junit.Test;
25
-
26
-import static org.junit.Assert.*;
27
-
28
-public class ChannelEventsTest {
29
-
30
-    @Test
31
-    public void testArity() {
32
-        for (ChannelEvents event : ChannelEvents.values()) {
33
-            assertEquals(event.getArity(), event.getArgNames().length);
34
-            assertEquals(event.getArity(), event.getArgTypes().length);
35
-        }
36
-    }
37
-
38
-}

+ 0
- 38
test/com/dmdirc/actions/metatypes/ClientEventsTest.java View File

@@ -1,38 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-package com.dmdirc.actions.metatypes;
23
-
24
-import org.junit.Test;
25
-
26
-import static org.junit.Assert.*;
27
-
28
-public class ClientEventsTest {
29
-
30
-    @Test
31
-    public void testArity() {
32
-        for (ClientEvents event : ClientEvents.values()) {
33
-            assertEquals(event.getArity(), event.getArgNames().length);
34
-            assertEquals(event.getArity(), event.getArgTypes().length);
35
-        }
36
-    }
37
-
38
-}

+ 0
- 42
test/com/dmdirc/actions/metatypes/LinkEventsTest.java View File

@@ -1,42 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-package com.dmdirc.actions.metatypes;
23
-
24
-import com.dmdirc.interfaces.actions.ActionMetaType;
25
-
26
-import org.junit.Test;
27
-
28
-import static org.junit.Assert.*;
29
-
30
-public class LinkEventsTest {
31
-
32
-    @Test
33
-    public void testArity() {
34
-        for (ActionMetaType event : LinkEvents.values()) {
35
-            assertEquals("Arity and number of arg names must be equal",
36
-                    event.getArity(), event.getArgNames().length);
37
-            assertEquals("Arity and number of arg types must be equal",
38
-                    event.getArity(), event.getArgTypes().length);
39
-        }
40
-    }
41
-
42
-}

+ 0
- 38
test/com/dmdirc/actions/metatypes/PluginEventsTest.java View File

@@ -1,38 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-package com.dmdirc.actions.metatypes;
23
-
24
-import org.junit.Test;
25
-
26
-import static org.junit.Assert.*;
27
-
28
-public class PluginEventsTest {
29
-
30
-    @Test
31
-    public void testArity() {
32
-        for (PluginEvents event : PluginEvents.values()) {
33
-            assertEquals(event.getArity(), event.getArgNames().length);
34
-            assertEquals(event.getArity(), event.getArgTypes().length);
35
-        }
36
-    }
37
-
38
-}

+ 0
- 38
test/com/dmdirc/actions/metatypes/QueryEventsTest.java View File

@@ -1,38 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-package com.dmdirc.actions.metatypes;
23
-
24
-import org.junit.Test;
25
-
26
-import static org.junit.Assert.*;
27
-
28
-public class QueryEventsTest {
29
-
30
-    @Test
31
-    public void testArity() {
32
-        for (QueryEvents event : QueryEvents.values()) {
33
-            assertEquals(event.getArity(), event.getArgNames().length);
34
-            assertEquals(event.getArity(), event.getArgTypes().length);
35
-        }
36
-    }
37
-
38
-}

+ 0
- 38
test/com/dmdirc/actions/metatypes/ServerEventsTest.java View File

@@ -1,38 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
-package com.dmdirc.actions.metatypes;
23
-
24
-import org.junit.Test;
25
-
26
-import static org.junit.Assert.*;
27
-
28
-public class ServerEventsTest {
29
-
30
-    @Test
31
-    public void testArity() {
32
-        for (ServerEvents event : ServerEvents.values()) {
33
-            assertEquals(event.getArity(), event.getArgNames().length);
34
-            assertEquals(event.getArity(), event.getArgTypes().length);
35
-        }
36
-    }
37
-
38
-}

+ 0
- 72
test/com/dmdirc/actions/validators/ActionNameValidatorTest.java View File

@@ -1,72 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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
20
- * THE SOFTWARE.
21
- */
22
-package com.dmdirc.actions.validators;
23
-
24
-import com.dmdirc.actions.Action;
25
-import com.dmdirc.actions.ActionGroup;
26
-
27
-import java.util.ArrayList;
28
-import java.util.List;
29
-
30
-import org.junit.Test;
31
-
32
-import static org.junit.Assert.*;
33
-import static org.mockito.Mockito.*;
34
-
35
-public class ActionNameValidatorTest {
36
-
37
-    private ActionGroup getGroup() {
38
-        final List<Action> actions = new ArrayList<>();
39
-        final Action action1 = mock(Action.class);
40
-        final Action action2 = mock(Action.class);
41
-        final ActionGroup group = mock(ActionGroup.class);
42
-        actions.add(action1);
43
-        actions.add(action2);
44
-
45
-        when(group.getActions()).thenReturn(actions);
46
-        when(action1.getName()).thenReturn("test1");
47
-        when(action2.getName()).thenReturn("test2");
48
-
49
-        return group;
50
-    }
51
-
52
-    @Test
53
-    public void testConflicting() {
54
-        final ActionNameValidator instance = new ActionNameValidator(getGroup(), "blah");
55
-
56
-        assertTrue(instance.validate("test1").isFailure());
57
-    }
58
-
59
-    @Test
60
-    public void testRename() {
61
-        final ActionNameValidator instance = new ActionNameValidator(getGroup(), "test1");
62
-
63
-        assertFalse(instance.validate("test").isFailure());
64
-    }
65
-
66
-    @Test
67
-    public void testNoChange() {
68
-        final ActionNameValidator instance = new ActionNameValidator(getGroup(), "test");
69
-
70
-        assertFalse(instance.validate("test").isFailure());
71
-    }
72
-}

+ 0
- 59
test/com/dmdirc/actions/validators/ConditionRuleValidatorTest.java View File

@@ -1,59 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
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.actions.validators;
24
-
25
-import com.dmdirc.util.validators.ValidationResponse;
26
-
27
-import org.junit.Test;
28
-
29
-import static org.junit.Assert.*;
30
-
31
-public class ConditionRuleValidatorTest {
32
-
33
-    @Test
34
-    public void testIllegal() {
35
-        final ValidationResponse res = new ConditionRuleValidator(10).validate("|||");
36
-        assertTrue(res.isFailure());
37
-    }
38
-
39
-    @Test
40
-    public void testTooMany() {
41
-        final ValidationResponse res = new ConditionRuleValidator(1).validate("0|1|2");
42
-        assertTrue(res.isFailure());
43
-    }
44
-
45
-    @Test
46
-    public void testGood() {
47
-        final ValidationResponse res = new ConditionRuleValidator(3).validate("0|1|2");
48
-        assertFalse(res.isFailure());
49
-    }
50
-
51
-    @Test
52
-    public void testChangeArgs() {
53
-        final ConditionRuleValidator validator = new ConditionRuleValidator(1);
54
-        assertTrue(validator.validate("1|0").isFailure());
55
-        validator.setArgs(2);
56
-        assertFalse(validator.validate("1|0").isFailure());
57
-    }
58
-
59
-}

Loading…
Cancel
Save