ImportDepth importDepth,
Map<Module, ArtifactResult> alreadySearchedArtifacts) {
List<Module> visibleDependencies = new ArrayList<Module>();
visibleDependencies.add(dependencyTree.getLast()); //first addition => no possible conflict
for (ModuleImport moduleImport : moduleImports) {
Module module = moduleImport.getModule();
if (moduleManager.findModule(module, dependencyTree, true) != null) {
//circular dependency: stop right here
return;
}
Iterable<String> searchedArtifactExtensions = moduleManager.getSearchedArtifactExtensions();
ImportDepth newImportDepth = importDepth.forModuleImport(moduleImport);
boolean forCompiledModule = newImportDepth.isVisibleToCompiledModules();
if ( ! module.isAvailable()) {
ArtifactResult artifact = null;
if (alreadySearchedArtifacts.containsKey(module)) {
artifact = alreadySearchedArtifacts.get(module);
} else {
//try and load the module from the repository
RepositoryManager repositoryManager = context.getRepositoryManager();
Exception exceptionOnGetArtifact = null;
ArtifactContext artifactContext = new ArtifactContext(module.getNameAsString(), module.getVersion(), getArtifactSuffixes(searchedArtifactExtensions));
listener.retrievingModuleArtifact(module, artifactContext);
try {
artifact = repositoryManager.getArtifactResult(artifactContext);
} catch (Exception e) {
exceptionOnGetArtifact = catchIfPossible(e);
}
if (artifact == null) {
//not there => error
ModuleHelper.buildErrorOnMissingArtifact(artifactContext, module, moduleImport, dependencyTree, exceptionOnGetArtifact, moduleManager);
}
alreadySearchedArtifacts.put(module, artifact);
}
if (artifact != null) {
//parse module units and build module dependency and carry on
listener.resolvingModuleArtifact(module, artifact);
moduleManager.resolveModule(artifact, module, moduleImport, dependencyTree, phasedUnitsOfDependencies, forCompiledModule);
}
}
moduleManager.visitedModule(module, forCompiledModule);
dependencyTree.addLast(module);
List<Module> subModulePropagatedDependencies = new ArrayList<Module>();
verifyModuleDependencyTree( module.getImports(), dependencyTree, subModulePropagatedDependencies, newImportDepth, alreadySearchedArtifacts);
//visible dependency += subModule + subModulePropagatedDependencies
checkAndAddDependency(visibleDependencies, module, dependencyTree);
for (Module submodule : subModulePropagatedDependencies) {
checkAndAddDependency(visibleDependencies, submodule, dependencyTree);
}