Search in sources :

Example 21 with ModuleImport

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

the class RuntimeModuleManager method loadModuleImportsFromArtifact.

private void loadModuleImportsFromArtifact(Module module, ArtifactResult artifact) {
    for (ArtifactResult dep : artifact.dependencies()) {
        Module dependency = getOrCreateModule(splitModuleName(dep.name()), dep.version());
        ModuleImport depImport = findImport(module, dependency);
        // FIXME: exclude optionals and TEST deps?
        if (depImport == null) {
            ModuleImport moduleImport = new ModuleImport(dep.namespace(), dependency, dep.optional(), dep.exported(), Backend.Java);
            module.addImport(moduleImport);
        }
    }
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) ReflectionModule(org.eclipse.ceylon.model.loader.impl.reflect.model.ReflectionModule) Module(org.eclipse.ceylon.model.typechecker.model.Module) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 22 with ModuleImport

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

the class LazyModuleSourceMapper method setupJavaModule.

private void setupJavaModule(ModuleImport moduleImport, LazyModule module, AbstractModelLoader modelLoader, ModuleManager moduleManager, ArtifactResult artifact) {
    // we didn't find module.class so it must be a java module if it's not the default module
    module.setJava(true);
    module.setNativeBackends(Backend.Java.asSet());
    modelLoader.loadJava9Module(module, artifact.artifact());
    List<ArtifactResult> deps = artifact.dependencies();
    boolean forceExport = ModuleUtil.isMavenModule(module.getNameAsString()) && modelLoader.isFullyExportMavenDependencies();
    for (ArtifactResult dep : deps) {
        // forget runtime, test and even provided
        if (dep.moduleScope() != ModuleScope.COMPILE)
            continue;
        // re-export them anyway
        if (dep.optional())
            continue;
        Module dependency = moduleManager.getOrCreateModule(ModuleManager.splitModuleName(dep.name()), dep.version());
        ModuleImport depImport = moduleManager.findImport(module, dependency);
        if (depImport == null) {
            moduleImport = new ModuleImport(dep.namespace(), dependency, dep.optional(), // allow forcing export but not for optional modules
            dep.exported() || forceExport && !dep.optional(), Backend.Java);
            module.addImport(moduleImport);
        }
    }
}
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) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 23 with ModuleImport

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

the class AbstractModelLoader method loadCompiledModule.

private boolean loadCompiledModule(Module module, ClassMirror moduleClass, boolean loadModuleImports) {
    String moduleClassName = moduleClass.getQualifiedName();
    String name = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "name");
    String version = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "version");
    if (name == null || name.isEmpty()) {
        logWarning("Module class " + moduleClassName + " contains no name, ignoring it");
        return false;
    }
    if (!name.equals(module.getNameAsString())) {
        logWarning("Module class " + moduleClassName + " declares an invalid name: " + name + ". It should be: " + module.getNameAsString());
        return false;
    }
    if (version == null || version.isEmpty()) {
        logWarning("Module class " + moduleClassName + " contains no version, ignoring it");
        return false;
    }
    if (!version.equals(module.getVersion())) {
        logWarning("Module class " + moduleClassName + " declares an invalid version: " + version + ". It should be: " + module.getVersion());
        return false;
    }
    // String label = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "label");
    // module.setLabel(label);
    int major = getAnnotationIntegerValue(moduleClass, CEYLON_CEYLON_ANNOTATION, "major", 0);
    int minor = getAnnotationIntegerValue(moduleClass, CEYLON_CEYLON_ANNOTATION, "minor", 0);
    module.setJvmMajor(major);
    module.setJvmMinor(minor);
    // no need to load the "nativeBackends" annotation value, it's loaded from annotations
    setAnnotations(module, moduleClass, false);
    if (loadModuleImports) {
        List<AnnotationMirror> imports = getAnnotationArrayValue(moduleClass, CEYLON_MODULE_ANNOTATION, "dependencies");
        if (imports != null) {
            boolean supportsNamespaces = ModuleUtil.supportsImportsWithNamespaces(major, minor);
            for (AnnotationMirror importAttribute : imports) {
                String dependencyName = (String) importAttribute.getValue("name");
                if (dependencyName != null) {
                    String namespace;
                    if (supportsNamespaces) {
                        namespace = (String) importAttribute.getValue("namespace");
                        if (namespace != null && namespace.isEmpty()) {
                            namespace = null;
                        }
                    } else {
                        if (ModuleUtil.isMavenModule(dependencyName)) {
                            namespace = "maven";
                        } else {
                            namespace = null;
                        }
                    }
                    String dependencyVersion = (String) importAttribute.getValue("version");
                    Module dependency = moduleManager.getOrCreateModule(ModuleManager.splitModuleName(dependencyName), dependencyVersion);
                    Boolean optionalVal = (Boolean) importAttribute.getValue("optional");
                    Boolean exportVal = (Boolean) importAttribute.getValue("export");
                    List<String> nativeBackends = (List<String>) importAttribute.getValue("nativeBackends");
                    Backends backends = nativeBackends == null ? Backends.ANY : Backends.fromAnnotations(nativeBackends);
                    ModuleImport moduleImport = moduleManager.findImport(module, dependency);
                    if (moduleImport == null) {
                        boolean optional = optionalVal != null && optionalVal;
                        boolean export = exportVal != null && exportVal;
                        moduleImport = new ModuleImport(namespace, dependency, optional, export, backends);
                        module.addImport(moduleImport);
                    }
                }
            }
        }
    }
    module.setAvailable(true);
    modules.getListOfModules().add(module);
    Module languageModule = modules.getLanguageModule();
    module.setLanguageModule(languageModule);
    if (loadModuleImports) {
        if (!ModelUtil.equalModules(module, languageModule)) {
            boolean found = false;
            for (ModuleImport mi : module.getImports()) {
                if (mi.getModule().isLanguageModule()) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                // It's not really a LazyModule because we're not loading
                // it lazily. It's only here for module version analysis.
                // But other stuff expects non-source modules to be lazy.
                LazyModule oldLangMod = new LazyModule() {

                    @Override
                    protected AbstractModelLoader getModelLoader() {
                        return AbstractModelLoader.this;
                    }
                };
                oldLangMod.setLanguageModule(oldLangMod);
                oldLangMod.setName(Arrays.asList("ceylon", "language"));
                oldLangMod.setVersion(getJvmLanguageModuleVersion(major, minor));
                oldLangMod.setNativeBackends(Backends.JAVA);
                oldLangMod.setJvmMajor(major);
                oldLangMod.setJvmMinor(minor);
                ModuleImport moduleImport = new ModuleImport(null, oldLangMod, false, false);
                module.addImport(moduleImport);
            }
        }
    }
    return true;
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) Backends(org.eclipse.ceylon.common.Backends) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule)

Example 24 with ModuleImport

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

the class AbstractModelLoader method loadLanguageModuleAndPackage.

protected Module loadLanguageModuleAndPackage() {
    Module languageModule = findOrCreateModule(CEYLON_LANGUAGE, null);
    addModuleToClassPath(languageModule, null);
    Package languagePackage = findOrCreatePackage(languageModule, CEYLON_LANGUAGE);
    typeFactory.setPackage(languagePackage);
    // make sure the language module has its real dependencies added, because we need them in the classpath
    // otherwise we will get errors on the Util and Metamodel calls we insert
    // WARNING! Make sure this list is always the same as the one in /ceylon-runtime/dist/repo/ceylon/language/_version_/module.xml
    // Note that we lie about the module exports: we pretend they're not imported at compile-time
    // while they are at run-time (in the module.xml file), so that users don't get these imports
    // visible in all their modules.
    languageModule.addImport(new ModuleImport(null, findOrCreateModule("org.eclipse.ceylon.common", Versions.CEYLON_VERSION_NUMBER), false, false, Backend.Java));
    languageModule.addImport(new ModuleImport(null, findOrCreateModule("org.eclipse.ceylon.model", Versions.CEYLON_VERSION_NUMBER), false, false, Backend.Java));
    return languageModule;
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule)

Example 25 with ModuleImport

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

the class AbstractModelLoader method isImported.

public boolean isImported(Module moduleScope, Module importedModule) {
    if (ModelUtil.equalModules(moduleScope, importedModule))
        return true;
    if (isImportedSpecialRules(moduleScope, importedModule))
        return true;
    boolean isMavenAutoExport = // export to a Maven module
    (isAutoExportMavenDependencies() && isMavenModule(moduleScope)) || // export to any module
    isFullyExportMavenDependencies();
    // not check for imports
    if (isMavenAutoExport && isMavenModule(importedModule))
        return true;
    Set<Module> visited = new HashSet<Module>();
    visited.add(moduleScope);
    for (ModuleImport imp : moduleScope.getImports()) {
        if (ModelUtil.equalModules(imp.getModule(), importedModule))
            return true;
        if ((imp.isExport() || isMavenAutoExport) && isImportedTransitively(imp.getModule(), importedModule, visited))
            return true;
    }
    return false;
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) 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