Browse Source

Merge pull request #577 from csmith/plugin-tidying

Remove silly URL usage in PluginMetaData.
pull/579/head
Greg Holmes 9 years ago
parent
commit
fce6fcde8b

+ 4
- 17
src/com/dmdirc/plugins/PluginFileHandler.java View File

@@ -32,8 +32,6 @@ import com.google.common.collect.ArrayListMultimap;
32 32
 import com.google.common.collect.Multimap;
33 33
 
34 34
 import java.io.IOException;
35
-import java.net.MalformedURLException;
36
-import java.net.URL;
37 35
 import java.nio.file.FileVisitOption;
38 36
 import java.nio.file.Files;
39 37
 import java.nio.file.Path;
@@ -41,12 +39,10 @@ import java.util.ArrayList;
41 39
 import java.util.Collection;
42 40
 import java.util.Collections;
43 41
 import java.util.Map;
44
-import java.util.Objects;
45 42
 import java.util.concurrent.CopyOnWriteArrayList;
46 43
 import java.util.function.Function;
47 44
 import java.util.stream.Collectors;
48 45
 
49
-import javax.annotation.Nullable;
50 46
 import javax.inject.Inject;
51 47
 import javax.inject.Singleton;
52 48
 
@@ -111,7 +107,6 @@ public class PluginFileHandler {
111 107
                     .filter(p -> p.getFileName().toString().endsWith(".jar"))
112 108
                     .map(Path::toAbsolutePath)
113 109
                     .map(path -> getMetaData(path, manager))
114
-                    .filter(Objects::nonNull)
115 110
                     .collect(Collectors.toList());
116 111
         } catch (IOException ex) {
117 112
             eventBus.publish(new UserErrorEvent(ErrorLevel.HIGH, ex,
@@ -125,20 +120,12 @@ public class PluginFileHandler {
125 120
      *
126 121
      * @param path The path of the plugin to get metadata from.
127 122
      * @param manager The plugin manager to pass to new metadata instances.
128
-     * @return The metadata if it could be created, {@code null} otherwise.
123
+     * @return The metadata for the given plugin.
129 124
      */
130
-    @Nullable
131 125
     private PluginMetaData getMetaData(final Path path, final PluginManager manager) {
132
-        try {
133
-            final PluginMetaData metaData = new PluginMetaData(
134
-                    manager, new URL("jar:file:" + path + "!/META-INF/plugin.config"), path);
135
-            metaData.load();
136
-            return metaData;
137
-        } catch (MalformedURLException ex) {
138
-            eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, ex,
139
-                    "Error creating URL for plugin " + path + ": " + ex.getMessage(), ""));
140
-            return null;
141
-        }
126
+        final PluginMetaData metaData = new PluginMetaData(manager, path);
127
+        metaData.load();
128
+        return metaData;
142 129
     }
143 130
 
144 131
     /**

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

@@ -31,8 +31,6 @@ import com.dmdirc.updater.components.PluginComponent;
31 31
 import com.dmdirc.updater.manager.UpdateManager;
32 32
 
33 33
 import java.io.File;
34
-import java.net.MalformedURLException;
35
-import java.net.URL;
36 34
 import java.nio.file.Paths;
37 35
 import java.util.ArrayList;
38 36
 import java.util.Arrays;
@@ -144,8 +142,6 @@ public class PluginManager {
144 142
 
145 143
         try {
146 144
             final PluginMetaData metadata = new PluginMetaData(this,
147
-                    new URL("jar:file:" + directory + filename
148
-                            + "!/META-INF/plugin.config"),
149 145
                     Paths.get(directory, filename));
150 146
             metadata.load();
151 147
             final PluginInfo pluginInfo = new PluginInfo(this, serviceManager, directory, metadata,
@@ -169,9 +165,6 @@ public class PluginManager {
169 165
 
170 166
             eventBus.publishAsync(new PluginRefreshEvent());
171 167
             return true;
172
-        } catch (MalformedURLException mue) {
173
-            eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, mue,
174
-                    "Error creating URL for plugin " + filename + ": " + mue.getMessage(), ""));
175 168
         } catch (PluginException e) {
176 169
             eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, e,
177 170
                     "Error loading plugin " + filename + ": " + e.getMessage(), ""));

+ 5
- 9
src/com/dmdirc/plugins/PluginMetaData.java View File

@@ -27,8 +27,8 @@ import com.dmdirc.util.io.ConfigFile;
27 27
 import com.dmdirc.util.io.InvalidConfigFileException;
28 28
 
29 29
 import java.io.IOException;
30
-import java.io.InputStream;
31
-import java.net.URL;
30
+import java.nio.file.FileSystem;
31
+import java.nio.file.FileSystems;
32 32
 import java.nio.file.Path;
33 33
 import java.nio.file.Paths;
34 34
 import java.util.ArrayList;
@@ -108,8 +108,6 @@ public class PluginMetaData {
108 108
     private boolean unloadable;
109 109
     /** The URL to the plugin. */
110 110
     private final Path pluginPath;
111
-    /** The URL to load the metadata from. */
112
-    private final URL url;
113 111
     /** The parent plugin manager. */
114 112
     private final PluginManager manager;
115 113
 
@@ -117,13 +115,11 @@ public class PluginMetaData {
117 115
      * Creates a new meta data reader for a config file at the specified URL.
118 116
      *
119 117
      * @param manager   Plugin manager
120
-     * @param url       The URL to load the config file from
121 118
      * @param pluginPath The path to the plugin that this data corresponds to
122 119
      */
123
-    public PluginMetaData(final PluginManager manager, final URL url, final Path pluginPath) {
120
+    public PluginMetaData(final PluginManager manager, final Path pluginPath) {
124 121
         this.manager = manager;
125 122
         this.pluginPath = pluginPath;
126
-        this.url = url;
127 123
     }
128 124
 
129 125
     /**
@@ -131,8 +127,8 @@ public class PluginMetaData {
131 127
      */
132 128
     public void load() {
133 129
         errors.clear();
134
-        try (final InputStream stream = url.openStream()) {
135
-            final ConfigFile configFile = new ConfigFile(stream);
130
+        try (FileSystem fs = FileSystems.newFileSystem(pluginPath, getClass().getClassLoader())) {
131
+            final ConfigFile configFile = new ConfigFile(fs.getPath("/META-INF/plugin.config"));
136 132
             configFile.read();
137 133
             readMetaData(configFile.getKeyDomain("metadata"));
138 134
             readVersion(configFile.getKeyDomain("version"));

Loading…
Cancel
Save