Search in sources :

Example 1 with CompilerModuleLoader

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();
}
Also used : AbstractModelLoader(org.eclipse.ceylon.model.loader.AbstractModelLoader) ModuleNotFoundException(org.eclipse.ceylon.cmr.ceylon.loader.ModuleNotFoundException) HashMap(java.util.HashMap) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Overrides(org.eclipse.ceylon.cmr.api.Overrides) CompilerModuleLoader(org.eclipse.ceylon.compiler.java.loader.CompilerModuleLoader) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) Module(org.eclipse.ceylon.model.typechecker.model.Module)

Aggregations

HashMap (java.util.HashMap)1 Overrides (org.eclipse.ceylon.cmr.api.Overrides)1 ModuleNotFoundException (org.eclipse.ceylon.cmr.ceylon.loader.ModuleNotFoundException)1 CompilerModuleLoader (org.eclipse.ceylon.compiler.java.loader.CompilerModuleLoader)1 AbstractModelLoader (org.eclipse.ceylon.model.loader.AbstractModelLoader)1 LazyModule (org.eclipse.ceylon.model.loader.model.LazyModule)1 Module (org.eclipse.ceylon.model.typechecker.model.Module)1 ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)1