// Path: src/main/java/net/openbyte/data/file/PluginDescriptionFile.java
// public class PluginDescriptionFile {
//     private String mainClassPath;
//     private String author;
//     private String logoURL;
//     private String iconURL;
//     private String description;
// 
//     private PluginDescriptionFile(String mainClassPath, String author, String logoURL, String iconURL, String description) {
//         this.mainClassPath = mainClassPath;
//         this.author = author;
//         this.logoURL = logoURL;
//         this.iconURL = iconURL;
//         this.description = description;
//     }
// 
//     public static PluginDescriptionFile getPluginDescription(InputStream file) throws Exception {
//         Properties properties = new Properties();
//         properties.load(file);
// 
//         final String main = properties.getProperty("main");
//         final String author = properties.getProperty("author");
//         final String description = properties.getProperty("description");
//         final String iconURL = properties.getProperty("iconurl");
//         final String logoURL = properties.getProperty("logourl");
// 
//         return new PluginDescriptionFile(main, author, logoURL, iconURL, description);
//     }
// 
//     public String getAuthor() {
//         return author;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// 
//     public String getIconURL() {
//         return iconURL;
//     }
// 
//     public String getLogoURL() {
//         return logoURL;
//     }
// 
//     public String getMainClassPath() {
//         return mainClassPath;
//     }
// }


import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import net.openbyte.data.file.PluginDescriptionFile;
import java.io.File;
import java.io.FilenameFilter;
import java.io.InputStream;
import java.net.URL;
/*
 * This file is part of OpenByte IDE, licensed under the MIT License (MIT).
 *
 * Copyright (c) TorchPowered 2016
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package net.openbyte.plugin;



/**
 * Represents the plugin manager that manages all plugins that are assignable as a AbstractPlugin.
 *
 * @since API Version 1.0
 */
public class PluginManager {
    /**
     * Represents the loaded abstract plugins.
     */
    private static ArrayList<AbstractPlugin> abstractPlugins = new ArrayList<AbstractPlugin>();
    private static HashMap<AbstractPlugin, PluginDescriptionFile> pluginToDescriptionMap = new HashMap<AbstractPlugin, PluginDescriptionFile>();

    /**
     * Retrieves the specified name representation of the plugin.
     *
     * @param pluginName the name representation of the plugin
     * @return the plugin from the name representation
     * @deprecated only for internal use
     */
    public static AbstractPlugin getPlugin(String pluginName) {
        for (AbstractPlugin plugin : abstractPlugins) {
            if(plugin.name().equals(pluginName)) {
                return plugin;
            }
        }
        return null;
    }

    /**
     * Registers and loads a plugin file.
     *
     * @param pluginFile the plugin file which will be loaded and registered.
     * @throws Exception if the plugin is not a valid OpenByte plugin
     * @deprecated only for internal use
     */
    public static void registerAndLoadPlugin(File pluginFile) throws Exception {
        JarFile jarFile = new JarFile(pluginFile);
        JarEntry pluginManifest = jarFile.getJarEntry("plugin.settings");
        InputStream manifestInputStream = jarFile.getInputStream(pluginManifest);

// Path: src/main/java/net/openbyte/data/file/PluginDescriptionFile.java
// public class PluginDescriptionFile {
//     private String mainClassPath;
//     private String author;
//     private String logoURL;
//     private String iconURL;
//     private String description;
// 
//     private PluginDescriptionFile(String mainClassPath, String author, String logoURL, String iconURL, String description) {
//         this.mainClassPath = mainClassPath;
//         this.author = author;
//         this.logoURL = logoURL;
//         this.iconURL = iconURL;
//         this.description = description;
//     }
// 
//     public static PluginDescriptionFile getPluginDescription(InputStream file) throws Exception {
//         Properties properties = new Properties();
//         properties.load(file);
// 
//         final String main = properties.getProperty("main");
//         final String author = properties.getProperty("author");
//         final String description = properties.getProperty("description");
//         final String iconURL = properties.getProperty("iconurl");
//         final String logoURL = properties.getProperty("logourl");
// 
//         return new PluginDescriptionFile(main, author, logoURL, iconURL, description);
//     }
// 
//     public String getAuthor() {
//         return author;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// 
//     public String getIconURL() {
//         return iconURL;
//     }
// 
//     public String getLogoURL() {
//         return logoURL;
//     }
// 
//     public String getMainClassPath() {
//         return mainClassPath;
//     }
// }


// Path: src/main/java/net/openbyte/plugin/PluginManager.java
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import net.openbyte.data.file.PluginDescriptionFile;
import java.io.File;
import java.io.FilenameFilter;
import java.io.InputStream;
import java.net.URL;

/*
 * This file is part of OpenByte IDE, licensed under the MIT License (MIT).
 *
 * Copyright (c) TorchPowered 2016
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package net.openbyte.plugin;



/**
 * Represents the plugin manager that manages all plugins that are assignable as a AbstractPlugin.
 *
 * @since API Version 1.0
 */
public class PluginManager {
    /**
     * Represents the loaded abstract plugins.
     */
    private static ArrayList<AbstractPlugin> abstractPlugins = new ArrayList<AbstractPlugin>();
    private static HashMap<AbstractPlugin, PluginDescriptionFile> pluginToDescriptionMap = new HashMap<AbstractPlugin, PluginDescriptionFile>();

    /**
     * Retrieves the specified name representation of the plugin.
     *
     * @param pluginName the name representation of the plugin
     * @return the plugin from the name representation
     * @deprecated only for internal use
     */
    public static AbstractPlugin getPlugin(String pluginName) {
        for (AbstractPlugin plugin : abstractPlugins) {
            if(plugin.name().equals(pluginName)) {
                return plugin;
            }
        }
        return null;
    }

    /**
     * Registers and loads a plugin file.
     *
     * @param pluginFile the plugin file which will be loaded and registered.
     * @throws Exception if the plugin is not a valid OpenByte plugin
     * @deprecated only for internal use
     */
    public static void registerAndLoadPlugin(File pluginFile) throws Exception {
        JarFile jarFile = new JarFile(pluginFile);
        JarEntry pluginManifest = jarFile.getJarEntry("plugin.settings");
        InputStream manifestInputStream = jarFile.getInputStream(pluginManifest);

        PluginDescriptionFile descriptionFile = PluginDescriptionFile.getPluginDescription(manifestInputStream);