All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.highway2urhell.PluginUtils Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
package com.highway2urhell;

import org.reflections.Reflections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.Set;


public class PluginUtils {
    private static final Logger LOGGER = LoggerFactory.getLogger(PluginUtils.class);

    private PluginUtils() {
    }

    public static  Set autodiscoverPlugin(Class pluginClass) {
        Set pluginList = new HashSet<>();
        Reflections reflections = new Reflections("com.highway2urhell");
        Set> pluginsAvailable = reflections
                .getSubTypesOf(pluginClass);
        for (Class plugin : pluginsAvailable) {
            try {
                LOGGER.info("registering {} : {}", pluginClass.getName(),
                        plugin.getCanonicalName());
                T instance = plugin.newInstance();
                pluginList.add(instance);
            } catch (InstantiationException | IllegalAccessException e) {
                LOGGER.error("An error occurred while registering " + pluginClass.getName() + " : " + plugin.getCanonicalName(), e);
            }
        }
        return pluginList;

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy