001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle.
005 *
006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019
020package pt.ua.dicoogle.plugins;
021
022import java.io.File;
023import java.util.Collection;
024
025import net.xeoh.plugins.base.PluginManager;
026import net.xeoh.plugins.base.impl.PluginManagerFactory;
027import net.xeoh.plugins.base.util.PluginManagerUtil;
028import org.slf4j.Logger;
029import org.slf4j.LoggerFactory;
030import pt.ua.dicoogle.sdk.PluginSet;
031
032/** A collection of factory methods for retrieving Dicoogle plugins from a directory.
033 * 
034 * @author psytek
035 * @author Eduardo Pinho <eduardopinho@ua.pt>
036 */
037
038public class PluginFactory {
039    private static final Logger logger = LoggerFactory.getLogger(PluginFactory.class);
040    
041    public static Collection<PluginSet> getPlugins(File pluginDirectory){
042        if (pluginDirectory == null) {
043            throw new NullPointerException("pluginDirectory");
044        }
045        if (!pluginDirectory.isDirectory()) {
046            throw new IllegalArgumentException("Plugin base must be a directory");
047        }
048        PluginManager pm = PluginManagerFactory.createPluginManager();
049        logger.debug("Plugin Directory: {}", pluginDirectory.getAbsolutePath());
050        pm.addPluginsFrom(pluginDirectory.toURI());
051        PluginManagerUtil pmu = new PluginManagerUtil(pm);
052        return pmu.getPlugins(PluginSet.class);
053    }
054    
055     public static Collection<PluginSet> getPlugins(){
056        return getPlugins(new File("Plugins"));
057    }
058}