Selaa lähdekoodia

Merge pull request #575 from csmith/plugin-tidying

Minor tidying in plugins
pull/576/head
Greg Holmes 9 vuotta sitten
vanhempi
commit
9a2e4ef3ba

+ 1
- 1
src/com/dmdirc/plugins/CorePluginExtractor.java Näytä tiedosto

@@ -84,7 +84,7 @@ public class CorePluginExtractor {
84 84
                 }
85 85
 
86 86
                 final File newDir = new File(resourceName.substring(0,
87
-                        resourceName.lastIndexOf('/')) + "/");
87
+                        resourceName.lastIndexOf('/')) + '/');
88 88
 
89 89
                 if (!newDir.exists()) {
90 90
                     newDir.mkdirs();

+ 3
- 3
src/com/dmdirc/plugins/CorePluginHelper.java Näytä tiedosto

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.plugins;
24 24
 
25
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
25
+import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
26 26
 import com.dmdirc.updater.Version;
27 27
 
28 28
 import javax.inject.Inject;
@@ -55,7 +55,7 @@ public class CorePluginHelper {
55 55
             final PluginManager pm,
56 56
             final String serviceType) {
57 57
         if (serviceManager.getServicesByType(serviceType).isEmpty()) {
58
-            corePluginExtractor.extractCorePlugins(serviceType + "_");
58
+            corePluginExtractor.extractCorePlugins(serviceType + '_');
59 59
             pm.refreshPlugins();
60 60
         }
61 61
     }
@@ -72,7 +72,7 @@ public class CorePluginHelper {
72 72
     public void checkBundledPlugins(
73 73
             final CorePluginExtractor corePluginExtractor,
74 74
             final PluginManager pm,
75
-            final AggregateConfigProvider config) {
75
+            final ReadOnlyConfigProvider config) {
76 76
         pm.getAllPlugins().stream().filter(plugin -> config
77 77
                 .hasOptionString("bundledplugins_versions", plugin.getName())).forEach(plugin -> {
78 78
             final Version bundled =

+ 2
- 2
src/com/dmdirc/plugins/ExportInfo.java Näytä tiedosto

@@ -52,8 +52,8 @@ public class ExportInfo {
52 52
     public ExportedService getExportedService() {
53 53
         try {
54 54
             final Class<?> c = pluginInfo.getPluginClassLoader().loadClass(className, false);
55
-            final Plugin p = className.equals(pluginInfo.getMetaData().getMainClass()) ? pluginInfo.
56
-                    getPlugin() : null;
55
+            final Plugin p = className.equals(pluginInfo.getMetaData().getMainClass())
56
+                    ? pluginInfo.getPlugin() : null;
57 57
             return new ExportedService(c, methodName, p);
58 58
         } catch (ClassNotFoundException | IllegalArgumentException cnfe) {
59 59
             return null;

+ 2
- 11
src/com/dmdirc/plugins/ExportedService.java Näytä tiedosto

@@ -25,6 +25,7 @@ package com.dmdirc.plugins;
25 25
 import java.lang.reflect.InvocationTargetException;
26 26
 import java.lang.reflect.Method;
27 27
 
28
+import org.slf4j.Logger;
28 29
 import org.slf4j.LoggerFactory;
29 30
 
30 31
 /**
@@ -32,22 +33,12 @@ import org.slf4j.LoggerFactory;
32 33
  */
33 34
 public class ExportedService {
34 35
 
35
-    private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ExportedService.class);
36
+    private static final Logger LOG = LoggerFactory.getLogger(ExportedService.class);
36 37
     /** Method we will be executing today! */
37 38
     private final Method method;
38 39
     /** Object we will be executing this method on. */
39 40
     private final Object object;
40 41
 
41
-    /**
42
-     * Create a new ExportedService object.
43
-     *
44
-     * @param myClass    class method is in.
45
-     * @param methodName Name of method
46
-     */
47
-    public ExportedService(final Class<?> myClass, final String methodName) {
48
-        this(myClass, methodName, null);
49
-    }
50
-
51 42
     /**
52 43
      * Create a new ExportedService object.
53 44
      *

+ 7
- 5
src/com/dmdirc/plugins/Plugin.java Näytä tiedosto

@@ -22,8 +22,10 @@
22 22
 
23 23
 package com.dmdirc.plugins;
24 24
 
25
+import com.dmdirc.ClientModule;
25 26
 import com.dmdirc.util.validators.ValidationResponse;
26 27
 
28
+import dagger.Module;
27 29
 import dagger.ObjectGraph;
28 30
 
29 31
 /**
@@ -62,18 +64,18 @@ public interface Plugin {
62 64
      *
63 65
      * <p>
64 66
      * Plugins wishing to use this form of dependency injection should define a new
65
-     * {@link dagger.Module} which specifies an {@link dagger.Module#addsTo()} argument of either:
67
+     * {@link Module} which specifies an {@link Module#addsTo()} argument of either:
66 68
      *
67 69
      * <ul>
68 70
      * <li>For plugins with no parents, or plugins which do not have a dependency on their parent,
69
-     * {@link com.dmdirc.ClientModule}.</li>
70
-     * <li>For plugins with dependencies on a parent plugin, that plugin's own {@link dagger.Module}
71
+     * {@link ClientModule}.</li>
72
+     * <li>For plugins with dependencies on a parent plugin, that plugin's own {@link Module}
71 73
      * implementation.</li>
72 74
      * </ul>
73 75
      *
74 76
      * <p>
75 77
      * The implementation of this method should then call
76
-     * {@link ObjectGraph#plus(java.lang.Object[])} with an instance of the plugin's own module.
78
+     * {@link ObjectGraph#plus(Object[])} with an instance of the plugin's own module.
77 79
      *
78 80
      * <p>
79 81
      * To expose dependencies to child plugins, the relevant {@link ObjectGraph} should be returned
@@ -96,7 +98,7 @@ public interface Plugin {
96 98
      *
97 99
      * <p>
98 100
      * This should always be an extension of the {@link ObjectGraph} provided to the
99
-     * {@link #load(com.dmdirc.plugins.PluginInfo, dagger.ObjectGraph)} method. If the plugin has no
101
+     * {@link #load(PluginInfo, ObjectGraph)} method. If the plugin has no
100 102
      * dependencies it wishes to expose, it may return {@code null} and any subplugins will be given
101 103
      * the global {@link ObjectGraph}.
102 104
      *

+ 4
- 19
src/com/dmdirc/plugins/PluginClassLoader.java Näytä tiedosto

@@ -26,9 +26,9 @@ import java.io.IOException;
26 26
 import java.net.URL;
27 27
 import java.nio.file.Files;
28 28
 import java.util.ArrayList;
29
+import java.util.Collection;
29 30
 import java.util.Collections;
30 31
 import java.util.Enumeration;
31
-import java.util.List;
32 32
 
33 33
 public class PluginClassLoader extends ClassLoader {
34 34
 
@@ -53,17 +53,6 @@ public class PluginClassLoader extends ClassLoader {
53 53
         this.globalLoader = globalLoader;
54 54
     }
55 55
 
56
-    /**
57
-     * Get a PluginClassLoader that is a subclassloader of this one.
58
-     *
59
-     * @param info PluginInfo the new classloader will be for
60
-     *
61
-     * @return A classloader configured with this one as its parent
62
-     */
63
-    public PluginClassLoader getSubClassLoader(final PluginInfo info) {
64
-        return new PluginClassLoader(info, globalLoader, this);
65
-    }
66
-
67 56
     /**
68 57
      * Load the plugin with the given className.
69 58
      *
@@ -87,8 +76,7 @@ public class PluginClassLoader extends ClassLoader {
87 76
      * @return True if the specified class is loaded, false otherwise
88 77
      */
89 78
     public boolean isClassLoaded(final String name, final boolean checkGlobal) {
90
-        return findLoadedClass(name) != null || (checkGlobal
91
-                && globalLoader.isClassLoaded(name));
79
+        return findLoadedClass(name) != null || checkGlobal && globalLoader.isClassLoaded(name);
92 80
     }
93 81
 
94 82
     /**
@@ -178,10 +166,7 @@ public class PluginClassLoader extends ClassLoader {
178 166
     @Override
179 167
     protected URL findResource(final String name) {
180 168
         try {
181
-            final URL url = pluginInfo.getPath(name).toUri().toURL();
182
-            if (url != null) {
183
-                return url;
184
-            }
169
+            return pluginInfo.getPath(name).toUri().toURL();
185 170
         } catch (IOException ioe) {
186 171
             // Do nothing, fall through
187 172
         }
@@ -202,7 +187,7 @@ public class PluginClassLoader extends ClassLoader {
202 187
     protected Enumeration<URL> findResources(final String name)
203 188
             throws IOException {
204 189
         final URL resource = findResource(name);
205
-        final List<URL> resources = new ArrayList<>();
190
+        final Collection<URL> resources = new ArrayList<>();
206 191
 
207 192
         if (resource != null) {
208 193
             resources.add(resource);

+ 0
- 9
src/com/dmdirc/plugins/PluginInfo.java Näytä tiedosto

@@ -733,15 +733,6 @@ public class PluginInfo implements ServiceProvider {
733 733
         return metaData.getPersistentClasses().contains("*");
734 734
     }
735 735
 
736
-    /**
737
-     * Does this plugin contain any persistent classes?
738
-     *
739
-     * @return true if this plugin contains any persistent classes, else false
740
-     */
741
-    public boolean hasPersistent() {
742
-        return !metaData.getPersistentClasses().isEmpty();
743
-    }
744
-
745 736
     /**
746 737
      * Get a list of all persistent classes in this plugin
747 738
      *

+ 3
- 3
src/com/dmdirc/plugins/PluginManager.java Näytä tiedosto

@@ -158,9 +158,9 @@ public class PluginManager {
158 158
                 return false;
159 159
             }
160 160
 
161
-            if ((metadata.getUpdaterId() > 0 && metadata.getVersion().isValid())
162
-                    || (identityController.getGlobalConfiguration()
163
-                    .hasOptionInt("plugin-addonid", metadata.getName()))) {
161
+            if (metadata.getUpdaterId() > 0 && metadata.getVersion().isValid()
162
+                    || identityController.getGlobalConfiguration()
163
+                    .hasOptionInt("plugin-addonid", metadata.getName())) {
164 164
                 updateManager.addComponent(new PluginComponent(
165 165
                         identityController.getGlobalConfiguration(), pluginInfo));
166 166
             }

+ 2
- 2
src/com/dmdirc/plugins/PluginMetaDataValidator.java Näytä tiedosto

@@ -225,7 +225,7 @@ public class PluginMetaDataValidator {
225 225
                 if (target.getVersion().compareTo(new Version(data[1])) < 0) {
226 226
                     errors.add("Plugin '" + data[0]
227 227
                             + "' is too old (required version: " + data[1]
228
-                            + ", actual version: " + target.getVersion() + ")");
228
+                            + ", actual version: " + target.getVersion() + ')');
229 229
                 }
230 230
 
231 231
                 // Check plugin maximum version matches.
@@ -233,7 +233,7 @@ public class PluginMetaDataValidator {
233 233
                         new Version(data[2])) > 0) {
234 234
                     errors.add("Plugin '" + data[0]
235 235
                             + "' is too new (required version: " + data[2]
236
-                            + ", actual version: " + target.getVersion() + ")");
236
+                            + ", actual version: " + target.getVersion() + ')');
237 237
                 }
238 238
             }
239 239
         }

+ 1
- 1
src/com/dmdirc/plugins/Service.java Näytä tiedosto

@@ -150,7 +150,7 @@ public class Service {
150 150
 
151 151
     @Override
152 152
     public String toString() {
153
-        return "Service: " + type + "->" + name + " (Providers: " + serviceproviders.size() + ")";
153
+        return "Service: " + type + "->" + name + " (Providers: " + serviceproviders.size() + ')';
154 154
     }
155 155
 
156 156
 }

+ 7
- 7
src/com/dmdirc/plugins/ServiceManagerImpl.java Näytä tiedosto

@@ -77,16 +77,16 @@ public class ServiceManagerImpl implements ServiceManager {
77 77
             NoSuchProviderException {
78 78
         final Service service = getService(type, name);
79 79
         if (service != null) {
80
-            ServiceProvider provider = service.getActiveProvider();
81
-            if (provider != null) {
82
-                return provider;
83
-            } else {
80
+            final ServiceProvider provider = service.getActiveProvider();
81
+            if (provider == null) {
84 82
                 // Try to activate the service then try again.
85 83
                 service.activate();
86
-                provider = service.getActiveProvider();
87
-                if (provider != null) {
88
-                    return provider;
84
+                final ServiceProvider activeProvider = service.getActiveProvider();
85
+                if (activeProvider != null) {
86
+                    return activeProvider;
89 87
                 }
88
+            } else {
89
+                return provider;
90 90
             }
91 91
         }
92 92
 

+ 1
- 1
src/com/dmdirc/plugins/implementations/BaseCommandPlugin.java Näytä tiedosto

@@ -82,7 +82,7 @@ public abstract class BaseCommandPlugin extends BasePlugin {
82 82
      * <p>
83 83
      * This method will create a new instance of the specified command class using the
84 84
      * dependency-injection framework. It must only be called after
85
-     * {@link #setObjectGraph(dagger.ObjectGraph)}, and any command must be injectable using that
85
+     * {@link #setObjectGraph(ObjectGraph)}, and any command must be injectable using that
86 86
      * object graph.
87 87
      *
88 88
      * @param <T>         The type of the command that will be registered.

Loading…
Peruuta
Tallenna