static List<String> orderPlugins(ClassLoader classLoader, Set<String> classNames) { Map<String, PluginDescriptor> descriptors = new HashMap<>(); try { for (String className : classNames) { PluginDescriptor descriptor = new PluginDescriptor(); descriptor.name = className; if (readDescriptor(classLoader, className, descriptor)) { descriptors.put(className, descriptor); } } } catch (IOException e) { throw new IllegalStateException("Error ordering plugins", e); } findReachableDescriptors(descriptors); processDescriptors(descriptors); List<String> plugins = new ArrayList<>(); Set<String> visited = new HashSet<>(); Set<String> emmited = new HashSet<>(); for (PluginDescriptor descriptor : descriptors.values()) { orderDescriptors(descriptor, descriptors, plugins, visited, emmited, new ArrayList<>()); } return plugins; }