Browse Source

Remove some more uses of ResourceManager.

Change-Id: I84af38e71783565410c5c24236ee8c74c0cf372e
Reviewed-on: http://gerrit.dmdirc.com/4031
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
pull/1/head
Greg Holmes 9 years ago
parent
commit
cd81f1fb0f
2 changed files with 37 additions and 15 deletions
  1. 10
    15
      src/com/dmdirc/plugins/PluginClassLoader.java
  2. 27
    0
      src/com/dmdirc/plugins/PluginInfo.java

+ 10
- 15
src/com/dmdirc/plugins/PluginClassLoader.java View File

@@ -22,10 +22,9 @@
22 22
 
23 23
 package com.dmdirc.plugins;
24 24
 
25
-import com.dmdirc.util.resourcemanager.ResourceManager;
26
-
27 25
 import java.io.IOException;
28 26
 import java.net.URL;
27
+import java.nio.file.Files;
29 28
 import java.util.ArrayList;
30 29
 import java.util.Collections;
31 30
 import java.util.Enumeration;
@@ -117,16 +116,10 @@ public class PluginClassLoader extends ClassLoader {
117 116
             }
118 117
         }
119 118
 
120
-        final ResourceManager res;
121
-        try {
122
-            res = pluginInfo.getResourceManager();
123
-        } catch (IOException ioe) {
124
-            throw new ClassNotFoundException("Error with resourcemanager", ioe);
125
-        }
126
-
127 119
         final String fileName = name.replace('.', '/') + ".class";
128 120
         try {
129
-            if (pluginInfo.isPersistent(name) || !res.resourceExists(fileName)) {
121
+            if (pluginInfo.isPersistent(name) || !Files.exists(
122
+                    pluginInfo.getPath(fileName))) {
130 123
                 if (!pluginInfo.isPersistent(name) && askGlobal) {
131 124
                     return globalLoader.loadClass(name);
132 125
                 } else {
@@ -152,8 +145,12 @@ public class PluginClassLoader extends ClassLoader {
152 145
 
153 146
         // We are meant to be loading this one!
154 147
         final byte[] data;
155
-        if (res.resourceExists(fileName)) {
156
-            data = res.getResourceBytes(fileName);
148
+        if (Files.exists(pluginInfo.getPath(fileName))) {
149
+            try {
150
+                data = Files.readAllBytes(pluginInfo.getPath(fileName));
151
+            } catch (IOException ex) {
152
+                throw new ClassNotFoundException(ex.getMessage(), ex);
153
+            }
157 154
         } else {
158 155
             throw new ClassNotFoundException("Resource '" + name + "' (wanted by " + pluginInfo.
159 156
                     getMetaData().getName() + ") does not exist.");
@@ -181,9 +178,7 @@ public class PluginClassLoader extends ClassLoader {
181 178
     @Override
182 179
     protected URL findResource(final String name) {
183 180
         try {
184
-            final ResourceManager res = pluginInfo.getResourceManager();
185
-            final URL url = res.getResourceURL(name);
186
-
181
+            final URL url = pluginInfo.getPath(name).toUri().toURL();
187 182
             if (url != null) {
188 183
                 return url;
189 184
             }

+ 27
- 0
src/com/dmdirc/plugins/PluginInfo.java View File

@@ -424,13 +424,37 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
424 424
         return !metaData.hasErrors();
425 425
     }
426 426
 
427
+    /**
428
+     * Returns the file system for this plugin's jar.
429
+     *
430
+     * @return Filesystem
431
+     */
432
+    public FileSystem getFileSystem() {
433
+        return pluginFilesystem;
434
+    }
435
+
436
+    /**
437
+     * Returns a path inside the plugin's jar for the given name.
438
+     *
439
+     * @param   first The path string or initial part of the path string
440
+     * @param   more Additional strings to be joined to form the full path
441
+     *
442
+     * @return The resulting path inside the plugin's jar
443
+     */
444
+    public Path getPath(final String first, final String... more) {
445
+        return pluginFilesystem.getPath(first, more);
446
+    }
447
+
427 448
     /**
428 449
      * Gets a resource manager for this plugin
429 450
      *
430 451
      * @return The resource manager for this plugin
431 452
      *
432 453
      * @throws IOException if there is any problem getting a ResourceManager for this plugin
454
+     *
455
+     * @deprecated @See getFileSystem()
433 456
      */
457
+    @Deprecated
434 458
     public ResourceManager getResourceManager() throws IOException {
435 459
         return getResourceManager(false);
436 460
     }
@@ -444,7 +468,10 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
444 468
      *
445 469
      * @throws IOException if there is any problem getting a ResourceManager for this plugin
446 470
      * @since 0.6
471
+     *
472
+     * @deprecated @See getFileSystem()
447 473
      */
474
+    @Deprecated
448 475
     public synchronized ResourceManager getResourceManager(final boolean forceNew) throws
449 476
             IOException {
450 477
         if (resourceManager == null || forceNew) {

Loading…
Cancel
Save