}
public GraphClassLoader newClassLoader(GraphClassLoaderRegistry classLoaderRegistry, DependencyManager dependencyManager, ModuleDefinition moduleDefinition) {
String moduleName = moduleDefinition.getName();
GraphClassLoader classLoader = classLoaderRegistry.getClassLoader(moduleName);
if (classLoader != null) {
return classLoader;
}
ClassRetriever resourceLoader = newResourceLoader(moduleDefinition);
List<ModuleDefinition> dependencies = dependencyManager.getOrderedModuleDependencies(moduleDefinition.getName());
List<GraphClassLoader> classLoaders = new ArrayList<GraphClassLoader>();
for (ModuleDefinition dependency : dependencies) {
if (dependency.getName().equals(moduleDefinition.getName())) continue;
classLoaders.add(newClassLoader(classLoaderRegistry, dependencyManager, dependency));
}
ClassLoader parentClassLoader = classLoaderRegistry.getApplicationClassLoader();
ClassLoader parentClassLoaderToUse = parentClassLoader != null ? parentClassLoader : GraphClassLoaderFactory.class.getClassLoader();
GraphClassLoader gcl = newGraphClassLoader(moduleDefinition, resourceLoader, classLoaders, parentClassLoaderToUse);
classLoaderRegistry.addClassLoader(moduleDefinition.getName(), gcl);
return gcl;
}