class Stagemonitor {

	static void initializePluginsInOrder(Collection<String> disabledPlugins, Iterable<StagemonitorPlugin> plugins) {
		Set<Class<? extends StagemonitorPlugin>> alreadyInitialized = new HashSet<Class<? extends StagemonitorPlugin>>();
		Set<StagemonitorPlugin> notYetInitialized = getPluginsToInit(disabledPlugins, plugins);
		while (!notYetInitialized.isEmpty()) {
			int countNotYetInitialized = notYetInitialized.size();
			// try to init plugins which are
			for (Iterator<StagemonitorPlugin> iterator = notYetInitialized.iterator(); iterator.hasNext(); ) {
				StagemonitorPlugin stagemonitorPlugin = iterator.next();
				{
					final List<Class<? extends StagemonitorPlugin>> dependencies = stagemonitorPlugin.dependsOn();
					if (dependencies.isEmpty() || alreadyInitialized.containsAll(dependencies)) {
						initializePlugin(stagemonitorPlugin);
						iterator.remove();
						alreadyInitialized.add(stagemonitorPlugin.getClass());
					}
				}
			}
			if (countNotYetInitialized == notYetInitialized.size()) {
				// no plugins could be initialized in this try. this probably means there is a cyclic dependency
				throw new IllegalStateException("Cyclic dependencies detected: " + notYetInitialized);
			}
		}
	}

	private  Stagemonitor();

}