瀏覽代碼

SLF4J some more plugins.

pull/420/head
Greg Holmes 9 年之前
父節點
當前提交
b73820f912

+ 8
- 8
mediasource_dbus/src/com/dmdirc/addons/mediasource_dbus/DBusMediaSourceManager.java 查看文件

22
 
22
 
23
 package com.dmdirc.addons.mediasource_dbus;
23
 package com.dmdirc.addons.mediasource_dbus;
24
 
24
 
25
-import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.addons.nowplaying.MediaSource;
25
 import com.dmdirc.addons.nowplaying.MediaSource;
27
-import com.dmdirc.events.UserErrorEvent;
28
-import com.dmdirc.logger.ErrorLevel;
29
 
26
 
30
 import java.io.BufferedReader;
27
 import java.io.BufferedReader;
31
 import java.io.File;
28
 import java.io.File;
39
 
36
 
40
 import javax.inject.Inject;
37
 import javax.inject.Inject;
41
 
38
 
39
+import org.slf4j.Logger;
40
+import org.slf4j.LoggerFactory;
41
+
42
+import static com.dmdirc.util.LogUtils.USER_ERROR;
43
+
42
 /**
44
 /**
43
  * Provides a media source for DBUS players.
45
  * Provides a media source for DBUS players.
44
  */
46
  */
45
 public class DBusMediaSourceManager {
47
 public class DBusMediaSourceManager {
46
 
48
 
49
+    private static final Logger LOG = LoggerFactory.getLogger(DBusMediaSourceManager.class);
47
     /** A map of discovered mpris sources. */
50
     /** A map of discovered mpris sources. */
48
     private final Map<String, MediaSource> mprisSources;
51
     private final Map<String, MediaSource> mprisSources;
49
-    /** The event bus to post errors to. */
50
-    private final DMDircMBassador eventBus;
51
     /** The sources used by this media source. */
52
     /** The sources used by this media source. */
52
     private final List<MediaSource> sources;
53
     private final List<MediaSource> sources;
53
     /** The path to qdbus. */
54
     /** The path to qdbus. */
54
     private String qdbus;
55
     private String qdbus;
55
 
56
 
56
     @Inject
57
     @Inject
57
-    public DBusMediaSourceManager(final DMDircMBassador eventBus) {
58
-        this.eventBus = eventBus;
58
+    public DBusMediaSourceManager() {
59
         sources = new ArrayList<>();
59
         sources = new ArrayList<>();
60
         mprisSources = new HashMap<>();
60
         mprisSources = new HashMap<>();
61
     }
61
     }
146
                 }
146
                 }
147
             }
147
             }
148
         } catch (IOException ex) {
148
         } catch (IOException ex) {
149
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.HIGH, ex, "Unable to get DBUS info", ""));
149
+            LOG.error(USER_ERROR, "Unable to get DBUS info", ex);
150
         } finally {
150
         } finally {
151
             if (process != null) {
151
             if (process != null) {
152
                 process.destroy();
152
                 process.destroy();

+ 10
- 14
mediasource_linux_title/src/com/dmdirc/addons/mediasource_linux_title/TitleMediaSource.java 查看文件

22
 
22
 
23
 package com.dmdirc.addons.mediasource_linux_title;
23
 package com.dmdirc.addons.mediasource_linux_title;
24
 
24
 
25
-import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.addons.nowplaying.MediaSource;
25
 import com.dmdirc.addons.nowplaying.MediaSource;
27
 import com.dmdirc.addons.nowplaying.MediaSourceState;
26
 import com.dmdirc.addons.nowplaying.MediaSourceState;
28
-import com.dmdirc.events.UserErrorEvent;
29
-import com.dmdirc.logger.ErrorLevel;
30
 
27
 
31
 import java.io.BufferedReader;
28
 import java.io.BufferedReader;
32
 import java.io.IOException;
29
 import java.io.IOException;
33
 import java.io.InputStreamReader;
30
 import java.io.InputStreamReader;
34
 
31
 
32
+import org.slf4j.Logger;
33
+import org.slf4j.LoggerFactory;
34
+
35
+import static com.dmdirc.util.LogUtils.USER_ERROR;
36
+
35
 /**
37
 /**
36
  * Provides a media source for Linux players using the `xwininfo` command.
38
  * Provides a media source for Linux players using the `xwininfo` command.
37
  */
39
  */
38
 public class TitleMediaSource implements MediaSource {
40
 public class TitleMediaSource implements MediaSource {
39
 
41
 
40
-    /** The event bus to post errors to. */
41
-    private final DMDircMBassador eventBus;
42
+    private static final Logger LOG = LoggerFactory.getLogger(TitleMediaSource.class);
42
     /** The command to use to get the title. */
43
     /** The command to use to get the title. */
43
     private final String command;
44
     private final String command;
44
     /** The name of the player we're retrieving. */
45
     /** The name of the player we're retrieving. */
47
     /**
48
     /**
48
      * Creates a new title media source.
49
      * Creates a new title media source.
49
      *
50
      *
50
-     * @param eventBus The event bus to post errors to
51
      * @param command  The command to be executed
51
      * @param command  The command to be executed
52
      * @param name     The name of the media source
52
      * @param name     The name of the media source
53
      */
53
      */
54
-    public TitleMediaSource(final DMDircMBassador eventBus, final String command, final String name) {
55
-        this.eventBus = eventBus;
54
+    public TitleMediaSource(final String command, final String name) {
56
         this.command = command;
55
         this.command = command;
57
         this.name = name;
56
         this.name = name;
58
     }
57
     }
115
     }
114
     }
116
 
115
 
117
     private String getInfo() {
116
     private String getInfo() {
118
-
119
-        final String[] args = new String[]{"/bin/bash", "-c", "xwininfo -root -tree | " + command};
117
+        final String[] args = {"/bin/bash", "-c", "xwininfo -root -tree | " + command};
120
         try {
118
         try {
121
             final Process process = Runtime.getRuntime().exec(args);
119
             final Process process = Runtime.getRuntime().exec(args);
122
             try (InputStreamReader reader = new InputStreamReader(process.getInputStream());
120
             try (InputStreamReader reader = new InputStreamReader(process.getInputStream());
126
                     return line;
124
                     return line;
127
                 }
125
                 }
128
             } catch (IOException ex) {
126
             } catch (IOException ex) {
129
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex,
130
-                        "Unable to retrieve media source info", ""));
127
+                LOG.info(USER_ERROR, "Unable to retrieve media source info", ex);
131
             }
128
             }
132
         } catch (IOException ex) {
129
         } catch (IOException ex) {
133
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex,
134
-                            "Unable to retrieve media source info", ""));
130
+            LOG.info(USER_ERROR, "Unable to retrieve media source info", ex);
135
         }
131
         }
136
 
132
 
137
         return "";
133
         return "";

+ 12
- 19
scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptEngineWrapper.java 查看文件

22
 
22
 
23
 package com.dmdirc.addons.scriptplugin;
23
 package com.dmdirc.addons.scriptplugin;
24
 
24
 
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.events.UserErrorEvent;
27
-import com.dmdirc.logger.ErrorLevel;
28
-
29
 import com.google.common.base.Preconditions;
25
 import com.google.common.base.Preconditions;
30
 
26
 
31
 import java.io.File;
27
 import java.io.File;
32
-import java.io.FileNotFoundException;
33
 import java.io.FileReader;
28
 import java.io.FileReader;
34
 import java.io.IOException;
29
 import java.io.IOException;
35
 
30
 
38
 import javax.script.ScriptEngineManager;
33
 import javax.script.ScriptEngineManager;
39
 import javax.script.ScriptException;
34
 import javax.script.ScriptException;
40
 
35
 
36
+import org.slf4j.Logger;
37
+import org.slf4j.LoggerFactory;
38
+
39
+import static com.dmdirc.util.LogUtils.USER_ERROR;
40
+
41
 /**
41
 /**
42
  * Class to create script engines!
42
  * Class to create script engines!
43
  */
43
  */
44
 public class ScriptEngineWrapper {
44
 public class ScriptEngineWrapper {
45
 
45
 
46
-    /** The event bus to post errors to. */
47
-    private final DMDircMBassador eventBus;
46
+    private static final Logger LOG = LoggerFactory.getLogger(ScriptEngineWrapper.class);
48
     /** The Script Engine this wrapper wraps */
47
     /** The Script Engine this wrapper wraps */
49
     private ScriptEngine engine;
48
     private ScriptEngine engine;
50
     /** The File this script is from */
49
     /** The File this script is from */
58
      * Create a new ScriptEngineWrapper
57
      * Create a new ScriptEngineWrapper
59
      *
58
      *
60
      * @param scriptEngineManager Manager to get script engines
59
      * @param scriptEngineManager Manager to get script engines
61
-     * @param eventBus            The event bus to post errors to
62
      * @param filename            Filename of script
60
      * @param filename            Filename of script
63
      *
61
      *
64
-     * @throws java.io.FileNotFoundException If file is not found
65
-     * @throws javax.script.ScriptException  If there was an error during creation
62
+     * @throws ScriptException  If there was an error during creation
66
      */
63
      */
67
     protected ScriptEngineWrapper(final ScriptEngineManager scriptEngineManager,
64
     protected ScriptEngineWrapper(final ScriptEngineManager scriptEngineManager,
68
-            final DMDircMBassador eventBus, final String filename)
69
-            throws FileNotFoundException, ScriptException {
65
+            final String filename) throws ScriptException {
70
         Preconditions.checkNotNull(filename, "File cannot be null");
66
         Preconditions.checkNotNull(filename, "File cannot be null");
71
-        this.eventBus = eventBus;
72
         this.scriptEngineManager = scriptEngineManager;
67
         this.scriptEngineManager = scriptEngineManager;
73
         file = new File(filename);
68
         file = new File(filename);
74
 
69
 
109
      *
104
      *
110
      * @return Created script engine
105
      * @return Created script engine
111
      *
106
      *
112
-     * @throws javax.script.ScriptException  If there was an error during creation
107
+     * @throws ScriptException  If there was an error during creation
113
      */
108
      */
114
     protected ScriptEngine createEngine() throws ScriptException {
109
     protected ScriptEngine createEngine() throws ScriptException {
115
         final ScriptEngine result = scriptEngineManager.getEngineByName("JavaScript");
110
         final ScriptEngine result = scriptEngineManager.getEngineByName("JavaScript");
141
             // and do nothing rather that add an error every time a method is called
136
             // and do nothing rather that add an error every time a method is called
142
             // that doesn't exist (such as the action_* methods)
137
             // that doesn't exist (such as the action_* methods)
143
         } catch (ScriptException e) {
138
         } catch (ScriptException e) {
144
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, e,
145
-                    "Error calling '" + functionName + "' in '" + file.getPath() + "': " +
146
-                            e.getMessage(), ""));
139
+            LOG.info(USER_ERROR, "Error calling '{}' in '{}': {}",
140
+                    functionName, file.getPath(), e.getMessage(), e);
147
         }
141
         }
148
     }
142
     }
149
 
143
 
162
             // Tell it that it has been rehashed
156
             // Tell it that it has been rehashed
163
             callFunction("onRehashSucess");
157
             callFunction("onRehashSucess");
164
         } catch (ScriptException e) {
158
         } catch (ScriptException e) {
165
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, e,
166
-                    "Reloading '" + file.getPath() + "' failed: " + e.getMessage(), ""));
159
+            LOG.info(USER_ERROR, "Reloading '{}' failed: {}", file.getPath(), e.getMessage(), e);
167
             // Tell it that its rehash failed
160
             // Tell it that its rehash failed
168
             callFunction("onRehashFailed", e);
161
             callFunction("onRehashFailed", e);
169
             return false;
162
             return false;

+ 10
- 13
scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptManager.java 查看文件

22
 
22
 
23
 package com.dmdirc.addons.scriptplugin;
23
 package com.dmdirc.addons.scriptplugin;
24
 
24
 
25
-import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
25
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
27
-import com.dmdirc.events.UserErrorEvent;
28
-import com.dmdirc.logger.ErrorLevel;
29
 
26
 
30
 import java.io.File;
27
 import java.io.File;
31
-import java.io.FileNotFoundException;
32
 import java.util.Arrays;
28
 import java.util.Arrays;
33
 import java.util.HashMap;
29
 import java.util.HashMap;
34
 import java.util.LinkedList;
30
 import java.util.LinkedList;
39
 import javax.script.ScriptEngineManager;
35
 import javax.script.ScriptEngineManager;
40
 import javax.script.ScriptException;
36
 import javax.script.ScriptException;
41
 
37
 
38
+import org.slf4j.Logger;
39
+import org.slf4j.LoggerFactory;
40
+
41
+import static com.dmdirc.util.LogUtils.USER_ERROR;
42
+
42
 public class ScriptManager {
43
 public class ScriptManager {
43
 
44
 
45
+    private static final Logger LOG = LoggerFactory.getLogger(ScriptManager.class);
44
     /** Script engine manager. */
46
     /** Script engine manager. */
45
     private final ScriptEngineManager scriptEngineManager;
47
     private final ScriptEngineManager scriptEngineManager;
46
     /** Script directory. */
48
     /** Script directory. */
47
     private final String scriptDirectory;
49
     private final String scriptDirectory;
48
     /** Store Script State Name,Engine */
50
     /** Store Script State Name,Engine */
49
     private final Map<String, ScriptEngineWrapper> scripts = new HashMap<>();
51
     private final Map<String, ScriptEngineWrapper> scripts = new HashMap<>();
50
-    /** The event bus to post events to. */
51
-    private final DMDircMBassador eventBus;
52
 
52
 
53
     @Inject
53
     @Inject
54
     public ScriptManager(final ScriptEngineManager scriptEngineManager,
54
     public ScriptManager(final ScriptEngineManager scriptEngineManager,
55
-            @Directory(ScriptModule.SCRIPTS) final String scriptDirectory,
56
-            final DMDircMBassador eventBus) {
55
+            @Directory(ScriptModule.SCRIPTS) final String scriptDirectory) {
57
         this.scriptEngineManager = scriptEngineManager;
56
         this.scriptEngineManager = scriptEngineManager;
58
         this.scriptDirectory = scriptDirectory;
57
         this.scriptDirectory = scriptDirectory;
59
-        this.eventBus = eventBus;
60
     }
58
     }
61
 
59
 
62
     /**
60
     /**
99
         if (!scripts.containsKey(scriptFilename)) {
97
         if (!scripts.containsKey(scriptFilename)) {
100
             try {
98
             try {
101
                 final ScriptEngineWrapper wrapper = new ScriptEngineWrapper(scriptEngineManager,
99
                 final ScriptEngineWrapper wrapper = new ScriptEngineWrapper(scriptEngineManager,
102
-                        eventBus, scriptFilename);
100
+                        scriptFilename);
103
                 scripts.put(scriptFilename, wrapper);
101
                 scripts.put(scriptFilename, wrapper);
104
-            } catch (FileNotFoundException | ScriptException e) {
105
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, e,
106
-                        "Error loading '" + scriptFilename + "': " + e.getMessage(), ""));
102
+            } catch (ScriptException e) {
103
+                LOG.info(USER_ERROR, "Error loading '{}': {}", scriptFilename, e.getMessage(), e);
107
                 return false;
104
                 return false;
108
             }
105
             }
109
         }
106
         }

+ 12
- 9
scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptPluginManager.java 查看文件

27
 import com.dmdirc.events.DMDircEvent;
27
 import com.dmdirc.events.DMDircEvent;
28
 import com.dmdirc.events.PluginLoadedEvent;
28
 import com.dmdirc.events.PluginLoadedEvent;
29
 import com.dmdirc.events.PluginUnloadedEvent;
29
 import com.dmdirc.events.PluginUnloadedEvent;
30
-import com.dmdirc.events.UserErrorEvent;
31
-import com.dmdirc.logger.ErrorLevel;
32
 
30
 
33
 import java.io.File;
31
 import java.io.File;
34
 import java.io.FileInputStream;
32
 import java.io.FileInputStream;
41
 import javax.inject.Inject;
39
 import javax.inject.Inject;
42
 import javax.script.ScriptEngineManager;
40
 import javax.script.ScriptEngineManager;
43
 
41
 
42
+import org.slf4j.Logger;
43
+import org.slf4j.LoggerFactory;
44
+
44
 import net.engio.mbassy.listener.Handler;
45
 import net.engio.mbassy.listener.Handler;
45
 
46
 
47
+import static com.dmdirc.util.LogUtils.USER_ERROR;
48
+
46
 public class ScriptPluginManager {
49
 public class ScriptPluginManager {
47
 
50
 
51
+    private static final Logger LOG = LoggerFactory.getLogger(ScriptPluginManager.class);
48
     private final DMDircMBassador eventBus;
52
     private final DMDircMBassador eventBus;
49
     private final String scriptDir;
53
     private final String scriptDir;
50
     private final ScriptManager scriptManager;
54
     private final ScriptManager scriptManager;
77
             try (FileInputStream fis = new FileInputStream(savedVariables)) {
81
             try (FileInputStream fis = new FileInputStream(savedVariables)) {
78
                 globalVariables.load(fis);
82
                 globalVariables.load(fis);
79
             } catch (IOException e) {
83
             } catch (IOException e) {
80
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, e,
81
-                        "Error reading savedVariables from '" + savedVariables.getPath() + "': "
82
-                                + e.getMessage(), ""));
84
+                LOG.info(USER_ERROR, "Error reading savedVariables from '{}': {}",
85
+                        savedVariables.getPath(), e.getMessage(), e);
83
             }
86
             }
84
         }
87
         }
85
     }
88
     }
91
         try (FileOutputStream fos = new FileOutputStream(savedVariables)) {
94
         try (FileOutputStream fos = new FileOutputStream(savedVariables)) {
92
             globalVariables.store(fos, "# DMDirc Script Plugin savedVariables");
95
             globalVariables.store(fos, "# DMDirc Script Plugin savedVariables");
93
         } catch (IOException e) {
96
         } catch (IOException e) {
94
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, e,"Error reading savedVariables to '"
95
-                    + savedVariables.getPath() + "': " + e.getMessage(), ""));
97
+            LOG.info(USER_ERROR, "Error writing savedVariables to '{}': {}",
98
+                    savedVariables.getPath(), e.getMessage(), e);
96
         }
99
         }
97
     }
100
     }
98
 
101
 
107
                 .toUpperCase();
110
                 .toUpperCase();
108
         final List<Object> arguments = new ArrayList<>();
111
         final List<Object> arguments = new ArrayList<>();
109
         for (Method method : event.getClass().getMethods()) {
112
         for (Method method : event.getClass().getMethods()) {
110
-            if ((method.getName().startsWith("get") && method.getParameterTypes().length == 0)
111
-                    && !method.getName().equals("getDisplayFormat")) {
113
+            if (method.getName().startsWith("get") && method.getParameterTypes().length == 0 &&
114
+                    !"getDisplayFormat".equals(method.getName())) {
112
                 arguments.add(method.invoke(event));
115
                 arguments.add(method.invoke(event));
113
             }
116
             }
114
         }
117
         }

Loading…
取消
儲存