Search in sources :

Example 11 with ModuleImport

use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.

the class JsModuleManager method createModule.

@Override
protected Module createModule(List<String> moduleName, String version) {
    final Module module = new JsonModule();
    module.setName(moduleName);
    module.setVersion(version);
    Unit u = new Unit();
    u.setFilename(Constants.MODULE_DESCRIPTOR);
    u.setFullPath(moduleName + "/" + version);
    module.setUnit(u);
    JsonModule dep = (JsonModule) findLoadedModule(LANGUAGE_MODULE_NAME, null);
    // This can only happen during initCoreModules()
    if (!(module.isDefaultModule() || module.isLanguageModule())) {
        // Load the language module if we're not inside initCoreModules()
        if (dep == null) {
            dep = (JsonModule) getModules().getLanguageModule();
        }
        // Add language module as a dependency
        // This will cause the dependency to be loaded later
        ModuleImport imp = new ModuleImport(null, dep, false, false);
        module.addImport(imp);
        module.setLanguageModule(dep);
    // Fix 280 part 1 -- [Tako] I have the feeling this can't be correct
    // Backend backend = null; // TODO Figure out if this dependency is only for a specific backend
    // getContext().getModules().getDefaultModule().addImport(new ModuleImport(module, false, false, backend));
    }
    return module;
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Module(org.eclipse.ceylon.model.typechecker.model.Module) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 12 with ModuleImport

use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.

the class JsModuleSourceMapper method loadModuleFromMap.

protected void loadModuleFromMap(ArtifactResult artifact, Module module, LinkedList<Module> dependencyTree, List<PhasedUnits> phasedUnitsOfDependencies, boolean forCompiledModule, Map<String, Object> model) {
    @SuppressWarnings("unchecked") List<Object> deps = (List<Object>) model.get("$mod-deps");
    if (deps != null) {
        for (Object dep : deps) {
            final String s;
            boolean optional = false;
            boolean export = false;
            if (dep instanceof Map) {
                @SuppressWarnings("unchecked") final Map<String, Object> depmap = (Map<String, Object>) dep;
                s = (String) depmap.get("path");
                optional = depmap.containsKey("opt");
                export = depmap.containsKey("exp");
            } else {
                s = (String) dep;
            }
            int p = s.indexOf('/');
            String depuri = null;
            String depv = null;
            if (p > 0) {
                depuri = s.substring(0, p);
                depv = s.substring(p + 1);
                if (depv.isEmpty()) {
                    depv = null;
                }
                // TODO Remove this hack after next bin compat breaks
                if (LANGUAGE_MODULE_NAME.equals(depuri)) {
                    if ("1.1.0".equals(depv)) {
                        depv = "1.2.0";
                    } else if ("1.2.1".equals(depv)) {
                        depv = Versions.CEYLON_VERSION_NUMBER;
                    } else if ("1.2.2".equals(depv)) {
                        depv = Versions.CEYLON_VERSION_NUMBER;
                    } else if ("1.3.0".equals(depv)) {
                        depv = Versions.CEYLON_VERSION_NUMBER;
                    } else if ("1.3.1".equals(depv)) {
                        depv = Versions.CEYLON_VERSION_NUMBER;
                    } else if ("1.3.2".equals(depv)) {
                        depv = Versions.CEYLON_VERSION_NUMBER;
                    } else if ("1.3.3".equals(depv)) {
                        depv = Versions.CEYLON_VERSION_NUMBER;
                    }
                /*@NEW_VERSION@*/
                }
            } else {
                depuri = s;
            }
            String depnamespace = ModuleUtil.getNamespaceFromUri(depuri);
            String depname = ModuleUtil.getModuleNameFromUri(depuri);
            // This will cause the dependency to be loaded later
            JsonModule mod = (JsonModule) getModuleManager().getOrCreateModule(ModuleManager.splitModuleName(depname), depv);
            Backends backends = mod.getNativeBackends();
            ModuleImport imp = new ModuleImport(depnamespace, mod, optional, export, backends);
            module.addImport(imp);
        }
        model.remove("$mod-deps");
        overrideModuleImports(module, artifact);
    }
    ((JsonModule) module).setModel(model);
    ((JsonModule) module).loadDeclarations();
    return;
}
Also used : Backends(org.eclipse.ceylon.common.Backends) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map)

Example 13 with ModuleImport

use of org.eclipse.ceylon.model.typechecker.model.ModuleImport 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)

Example 14 with ModuleImport

use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.

the class RuntimeModelLoader method lazyLoadModuleForPackage.

private Module lazyLoadModuleForPackage(String pkgName) {
    if (lazyLoadedModulesByPackage.containsKey(pkgName)) {
        return lazyLoadedModulesByPackage.get(pkgName);
    }
    Module module;
    if (pkgName.isEmpty()) {
        module = modules.getDefaultModule();
    } else {
        // pretend it's the default module trying to load a new module? not sure what
        // to do here
        Module loadByModule = modules.getDefaultModule();
        ClassMirror moduleClass = findModuleClass(loadByModule, pkgName);
        if (moduleClass != null) {
            String name = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "name");
            String version = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "version");
            module = findOrCreateModule(name, version);
            loadCompiledModule(module);
            // damnit, make it import the default module, otherwise it won't be able to see non-ceylon modules
            module.addImport(new ModuleImport(null, modules.getDefaultModule(), false, false));
        // FIXME: do other things like what RuntimeModuleManager does?
        } else {
            // try parent package
            int lastDot = pkgName.lastIndexOf('.');
            String parentPackage;
            if (lastDot == -1)
                parentPackage = "";
            else
                parentPackage = pkgName.substring(0, lastDot);
            module = lazyLoadModuleForPackage(parentPackage);
        }
    }
    // cache module and return
    lazyLoadedModulesByPackage.put(pkgName, module);
    return module;
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) Module(org.eclipse.ceylon.model.typechecker.model.Module) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror)

Example 15 with ModuleImport

use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.

the class LazyModule method getPackage.

@Override
public Package getPackage(String name) {
    // try here first
    Package pkg = null;
    // unless we're the default module, in which case we have to check this at the end,
    // since every package can be part of the default module
    boolean defaultModule = isDefaultModule();
    if (!defaultModule) {
        pkg = findPackageInModule(this, name);
        if (pkg != null)
            return loadPackage(pkg);
    }
    // then try in dependencies
    Set<Module> visited = new HashSet<Module>();
    for (ModuleImport dependency : getImports()) {
        // we don't have to worry about the default module here since we can't depend on it
        pkg = findPackageInImport(name, dependency, visited);
        if (pkg != null)
            return loadPackage(pkg);
    }
    AbstractModelLoader modelLoader = getModelLoader();
    JdkProvider jdkProvider = modelLoader.getJdkProvider();
    // so we pretend the JDK imports the language module
    if (jdkProvider != null && jdkProvider.isJDKModule(getNameAsString())) {
        Module languageModule = getModelLoader().getLanguageModule();
        if (languageModule instanceof LazyModule) {
            pkg = findPackageInModule((LazyModule) languageModule, name);
            if (pkg != null)
                return loadPackage(pkg);
        }
    }
    // work and appear to come from there
    if (jdkProvider.isJDKPackage(name)) {
        return null;
    }
    // do the lookup of the default module last
    if (defaultModule)
        pkg = modelLoader.findExistingPackage(this, name);
    return pkg;
}
Also used : AbstractModelLoader(org.eclipse.ceylon.model.loader.AbstractModelLoader) JdkProvider(org.eclipse.ceylon.model.loader.JdkProvider) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) HashSet(java.util.HashSet)

Aggregations

ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)30 Module (org.eclipse.ceylon.model.typechecker.model.Module)25 HashSet (java.util.HashSet)8 ArrayList (java.util.ArrayList)7 LazyModule (org.eclipse.ceylon.model.loader.model.LazyModule)7 Package (org.eclipse.ceylon.model.typechecker.model.Package)7 Backends (org.eclipse.ceylon.common.Backends)6 LinkedList (java.util.LinkedList)3 List (java.util.List)3 HashMap (java.util.HashMap)2 Overrides (org.eclipse.ceylon.cmr.api.Overrides)2 ImportModule (org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportModule)2 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)2 AbstractModelLoader (org.eclipse.ceylon.model.loader.AbstractModelLoader)2 Annotation (org.eclipse.ceylon.model.typechecker.model.Annotation)2 Unit (org.eclipse.ceylon.model.typechecker.model.Unit)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1