Represents a Java plugin loader, allowing plugins in the form of .jar
| 49 | * Represents a Java plugin loader, allowing plugins in the form of .jar |
| 50 | */ |
| 51 | public final class JavaPluginLoader implements PluginLoader { |
| 52 | final Server server; |
| 53 | private final Pattern[] fileFilters = new Pattern[]{Pattern.compile("\\.jar$")}; |
| 54 | private final Map<String, Class<?>> classes = new ConcurrentHashMap<String, Class<?>>(); |
| 55 | private final List<PluginClassLoader> loaders = new CopyOnWriteArrayList<PluginClassLoader>(); |
| 56 | public static final CustomTimingsHandler pluginParentTimer = new CustomTimingsHandler("** Plugins"); // Spigot |
| 57 | |
| 58 | /** |
| 59 | * This class was not meant to be constructed explicitly |
| 60 | * |
| 61 | * @param instance the server instance |
| 62 | */ |
| 63 | @Deprecated |
| 64 | public JavaPluginLoader(@NotNull Server instance) { |
| 65 | Validate.notNull(instance, "Server cannot be null"); |
| 66 | server = instance; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | @NotNull |
| 71 | public Plugin loadPlugin(@NotNull final File file) throws InvalidPluginException { |
| 72 | Validate.notNull(file, "File cannot be null"); |
| 73 | |
| 74 | if (!file.exists()) { |
| 75 | throw new InvalidPluginException(new FileNotFoundException(file.getPath() + " does not exist")); |
| 76 | } |
| 77 | |
| 78 | final PluginDescriptionFile description; |
| 79 | try { |
| 80 | description = getPluginDescription(file); |
| 81 | } catch (InvalidDescriptionException ex) { |
| 82 | throw new InvalidPluginException(ex); |
| 83 | } |
| 84 | |
| 85 | final File parentFile = file.getParentFile(); |
| 86 | final File dataFolder = new File(parentFile, description.getName()); |
| 87 | @SuppressWarnings("deprecation") |
| 88 | final File oldDataFolder = new File(parentFile, description.getRawName()); |
| 89 | |
| 90 | // Found old data folder |
| 91 | if (dataFolder.equals(oldDataFolder)) { |
| 92 | // They are equal -- nothing needs to be done! |
| 93 | } else if (dataFolder.isDirectory() && oldDataFolder.isDirectory()) { |
| 94 | server.getLogger().warning(String.format( |
| 95 | "While loading %s (%s) found old-data folder: `%s' next to the new one `%s'", |
| 96 | description.getFullName(), |
| 97 | file, |
| 98 | oldDataFolder, |
| 99 | dataFolder |
| 100 | )); |
| 101 | } else if (oldDataFolder.isDirectory() && !dataFolder.exists()) { |
| 102 | if (!oldDataFolder.renameTo(dataFolder)) { |
| 103 | throw new InvalidPluginException("Unable to rename old data folder: `" + oldDataFolder + "' to: `" + dataFolder + "'"); |
| 104 | } |
| 105 | server.getLogger().log(Level.INFO, String.format( |
| 106 | "While loading %s (%s) renamed data folder: `%s' to `%s'", |
| 107 | description.getFullName(), |
| 108 | file, |
nothing calls this directly
no outgoing calls
no test coverage detected