Example usage for java.util.jar JarFile getJarEntry

List of usage examples for java.util.jar JarFile getJarEntry

Introduction

In this page you can find the example usage for java.util.jar JarFile getJarEntry.

Prototype

public JarEntry getJarEntry(String name) 

Source Link

Document

Returns the JarEntry for the given base entry name or null if not found.

Usage

From source file:tk.jomp16.plugin.PluginManager.java

public boolean reloadPlugin(String pluginName) throws Exception {
    File f = new File("plugins/" + pluginName + ".jar");

    if (f.exists()) {
        JarFile jarFile = new JarFile(f);
        JarEntry entry = jarFile.getJarEntry("plugin.json");

        if (entry != null) {
            PluginInfo pluginInfo = gson.fromJson(getPluginInfoInputStream(f), PluginInfo.class);
            Plugin plugin = new Plugin(pluginInfo, DigestUtils.md5Hex(new FileInputStream(f)),
                    pluginLoader.loadPluginEvent(f), MainUI.isGui() ? pluginLoader.loadPluginUI(f) : null);

            if (plugins.parallelStream()
                    .filter(plugin1 -> plugin1.getPluginInfo().getName()
                            .equals(plugin.getPluginInfo().getName()))
                    .count() != 0// ww  w .j  a v a2 s .  c  o  m
                    && plugins.parallelStream()
                            .filter(plugin1 -> plugin1.getMd5sums().equals(plugin.getMd5sums())).count() == 0) {
                for (Plugin plugin1 : plugins.parallelStream().filter(
                        plugin2 -> plugin2.getPluginInfo().getName().equals(plugin.getPluginInfo().getName()))
                        .collect(Collectors.toList())) {
                    pluginLoader.closePluginClassLoader(pluginName);

                    plugins.remove(plugin1);
                    plugins.add(plugin);

                    ircManager.unregisterPluginEvent(plugin1);
                    ircManager.registerPluginEvent(plugin);
                }

                return true;
            }
        }
    }

    return false;
}

From source file:tk.tomby.tedit.plugins.PluginDriver.java

private static JarEntry getDescriptor(JarFile jar) throws IOException {
    JarEntry entry = null;//from ww w .ja  v  a 2  s  . c om

    Manifest manifest = jar.getManifest();
    Attributes attrs = manifest.getMainAttributes();
    String pluginAttr = attrs.getValue("Plugin-Descriptor");

    if (pluginAttr != null) {
        entry = jar.getJarEntry(pluginAttr);
    } else {
        entry = jar.getJarEntry("META-INF/plugin.xml");
    }

    return entry;
}