use of org.eclipse.ceylon.compiler.java.loader.CompilerModuleLoader in project ceylon by eclipse.
the class LazyModuleSourceMapper method preResolveDependenciesIfRequired.
@Override
public void preResolveDependenciesIfRequired(RepositoryManager repositoryManager) {
AbstractModelLoader modelLoader = getModuleManager().getModelLoader();
if (!modelLoader.isFullyExportMavenDependencies())
return;
if (statusPrinter != null) {
statusPrinter.clearLine();
statusPrinter.log("Pre-resolving dependencies");
}
if (verbose) {
log.printRawLines(WriterKind.NOTICE, "[Pre-resolving dependencies]");
}
Set<Module> compiledModules = getCompiledModules();
Map<String, String> modules = new HashMap<>();
ModuleImport anyImport = null;
for (Module module : compiledModules) {
for (ModuleImport imp : module.getImports()) {
if (imp.getModule() == null || !compiledModules.contains(imp.getModule())) {
if (anyImport == null)
anyImport = imp;
String name = imp.getModule().getNameAsString();
if (imp.getNamespace() != null)
name = imp.getNamespace() + ":" + name;
modules.put(name, imp.getModule().getVersion());
}
}
}
if (statusPrinter != null) {
statusPrinter.clearLine();
statusPrinter.log("Pre-resolving found " + modules.size() + " to pre-resolve");
}
if (verbose) {
log.printRawLines(WriterKind.NOTICE, "[Pre-resolving " + modules.size() + " modules]");
}
if (modules.isEmpty())
return;
Entry<String, String> first = modules.entrySet().iterator().next();
CompilerModuleLoader ml = new CompilerModuleLoader(repositoryManager, null, modules, verbose, statusPrinter, log);
boolean giveup = false;
try {
ml.loadModule(first.getKey(), first.getValue(), ModuleScope.COMPILE);
} catch (ModuleNotFoundException e) {
attachErrorToDependencyDeclaration(anyImport, "Pre-resolving of module failed: " + e.getMessage(), true);
giveup = true;
}
if (statusPrinter != null) {
statusPrinter.clearLine();
// don't try to read the module count if pre-resolving failed
if (giveup)
statusPrinter.log("Pre-resolving failed");
else
statusPrinter.log("Pre-resolving resolved " + ml.getModuleCount());
}
if (verbose) {
// don't try to read the module count if pre-resolving failed
if (giveup)
log.printRawLines(WriterKind.NOTICE, "[Pre-resolved failed]");
else
log.printRawLines(WriterKind.NOTICE, "[Pre-resolved " + ml.getModuleCount() + " modules]");
}
if (giveup)
return;
Overrides overrides = repositoryManager.getOverrides();
if (overrides == null) {
overrides = Overrides.create();
repositoryManager.setOverrides(overrides);
}
ml.setupOverrides(overrides);
ml.cleanup();
}
Aggregations