Search in sources :

Example 6 with ModuleImport

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

the class ModuleValidator method verifyModuleDependencyTree.

private void verifyModuleDependencyTree(Collection<ModuleImport> moduleImports, LinkedList<Module> dependencyTree, List<Module> propagatedDependencies, ImportDepth importDepth, Map<Module, ArtifactResult> alreadySearchedArtifacts) {
    List<Module> visibleDependencies = new ArrayList<Module>();
    // first addition => no possible conflict
    visibleDependencies.add(dependencyTree.getLast());
    for (ModuleImport moduleImport : moduleImports) {
        if (moduleImport.isNative() && !isForBackend(moduleImport.getNativeBackends(), moduleManager.getSupportedBackends())) {
            // import is not for this backend
            continue;
        }
        Module module = moduleImport.getModule();
        if (moduleManager.findModule(module, dependencyTree, true) != null) {
            // circular dependency: stop right here
            continue;
        }
        ImportDepth newImportDepth = importDepth.forModuleImport(moduleImport);
        boolean forCompiledModule = newImportDepth.isVisibleToCompiledModules();
        resolveModuleIfRequired(module, forCompiledModule, moduleImport, importDepth, dependencyTree, alreadySearchedArtifacts);
        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);
        }
        // propagated dependency += if subModule.export then subModule + subModulePropagatedDependencies
        if (moduleImport.isExport()) {
            checkAndAddDependency(propagatedDependencies, module, dependencyTree);
            for (Module submodule : subModulePropagatedDependencies) {
                checkAndAddDependency(propagatedDependencies, submodule, dependencyTree);
            }
        }
        dependencyTree.pollLast();
    }
}
Also used : ArrayList(java.util.ArrayList) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) ImportModule(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportModule) Module(org.eclipse.ceylon.model.typechecker.model.Module)

Example 7 with ModuleImport

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

the class ModuleValidator method verifyModuleDependencyTree.

/**
 *  At this stage we need to
 *  - resolve all non local modules (recursively)
 *  - build the object model of these compiled modules
 *  - declare a missing module as an error
 *  - detect circular dependencies
 *  - detect module version conflicts
 */
public void verifyModuleDependencyTree() {
    TypeCache.doWithoutCaching(new Runnable() {

        @Override
        public void run() {
            phasedUnitsOfDependencies = new ArrayList<PhasedUnits>();
            LinkedList<Module> dependencyTree = new LinkedList<Module>();
            // only verify modules we compile (and default/language), as that makes us traverse their dependencies anyways
            Set<Module> compiledModules = moduleManagerUtil.getCompiledModules();
            moduleManagerUtil.preResolveDependenciesIfRequired(context.getRepositoryManager());
            Module jdkProviderModule = moduleManagerUtil.getJdkProviderModule();
            List<Module> modules = new ArrayList<Module>(compiledModules.size() + 2);
            if (jdkProviderModule != null) {
                ModuleImport synthimp = new ModuleImport(null, jdkProviderModule, false, false);
                resolveModuleIfRequired(jdkProviderModule, true, synthimp, ImportDepth.First, dependencyTree, searchedArtifacts);
            }
            // we must resolve the language module first because it contains definitions that must be in the classpath
            // before any other JVM class is loaded, including the module descriptor annotations themselves
            modules.add(context.getModules().getLanguageModule());
            modules.add(context.getModules().getDefaultModule());
            modules.addAll(compiledModules);
            for (Module module : modules) {
                dependencyTree.addLast(module);
                // we don't care about propagated dependency here as top modules are independent from one another
                verifyModuleDependencyTree(module.getImports(), dependencyTree, new ArrayList<Module>(), ImportDepth.First, searchedArtifacts);
                dependencyTree.pollLast();
            }
            for (Module module : compiledModules) {
                verifyNative(module);
            }
            moduleManager.addImplicitImports();
        }
    });
    executeExternalModulePhases();
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) ArrayList(java.util.ArrayList) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ImportModule(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportModule) Module(org.eclipse.ceylon.model.typechecker.model.Module) LinkedList(java.util.LinkedList)

Example 8 with ModuleImport

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

the class ExpressionVisitor method getModuleBackends.

private Backends getModuleBackends(Module decModule, Unit unit) {
    Backends bs = decModule.getNativeBackends();
    List<ModuleImport> imports = unit.getPackage().getModule().getImports();
    for (ModuleImport imp : imports) {
        if (imp.getModule().equals(decModule)) {
            if (!imp.getNativeBackends().none()) {
                bs = bs.none() ? imp.getNativeBackends() : bs.supported(imp.getNativeBackends());
            }
            break;
        }
    }
    return bs;
}
Also used : NativeUtil.getBackends(org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.getBackends) Backends(org.eclipse.ceylon.common.Backends) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport)

Example 9 with ModuleImport

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

the class CMRTests method testOverridesCeylonModuleShareImport.

@Test
public void testOverridesCeylonModuleShareImport() {
    setupBinaryModulesForOverridesCeylonModuleTests();
    ErrorCollector collector = new ErrorCollector();
    CeyloncTaskImpl compilerTask = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules", "-overrides", getPackagePath() + "modules/overridesCeylonModule/overrides-share-c-import.xml"), collector, "modules/overridesCeylonModule/module.ceylon");
    ModulesRetriever modulesRetriever = new ModulesRetriever(compilerTask.getContext());
    compilerTask.setTaskListener(modulesRetriever);
    Boolean result = compilerTask.call();
    Assert.assertEquals(Boolean.TRUE, result);
    Module a = modulesRetriever.modules.get("a");
    assert (a != null);
    ModuleImport cImport = getModuleImport(a, "c");
    assert (cImport != null);
    assertEquals("The 'c' module import should be seen as 'exported' after applying the overrides file", true, cImport.isExport());
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) Module(org.eclipse.ceylon.model.typechecker.model.Module) Test(org.junit.Test)

Example 10 with ModuleImport

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

the class Metamodel method loadModule.

private static void loadModule(String namespace, org.eclipse.ceylon.model.typechecker.model.Module declaration, Set<org.eclipse.ceylon.model.typechecker.model.Module> visitedModules, boolean optional) {
    // don't do if not running JBoss modules
    if (!isJBossModules()) {
        return;
    }
    // no loading required for these
    if (JDKUtils.isJDKModule(declaration.getNameAsString()) || JDKUtils.isOracleJDKModule(declaration.getNameAsString()))
        return;
    try {
        // Stef: this can fail, in particular is the TCCCL is that of a bootstrap module CL since we can't override those
        // if it does we have to resort to reflection to get around this
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        if (contextClassLoader instanceof CeylonModuleClassLoader) {
            // this will return null for bootstrap modules
            String modname = ModuleUtil.makeModuleName(namespace, declaration.getNameAsString(), null);
            CeylonModuleClassLoader newModuleClassLoader = ((CeylonModuleClassLoader) contextClassLoader).loadModule(modname, declaration.getVersion());
            // if we can force it loaded, let's do
            if (newModuleClassLoader != null) {
                // this can complete in another thread or this thread
                newModuleClassLoader.registerInMetaModel();
            }
            if (!declaration.isAvailable()) {
                // perhaps it is being loaded in another thread, wait for it
                Object lock = getLock();
                synchronized (lock) {
                    int tries = RuntimeModelLoader.MAX_JBOSS_MODULES_WAITS;
                    while (!declaration.isAvailable()) {
                        try {
                            lock.wait(RuntimeModelLoader.JBOSS_MODULES_TIMEOUT);
                        } catch (InterruptedException e) {
                            throw Metamodel.newModelError("Interrupted");
                        }
                        if (tries-- < 0)
                            throw Metamodel.newModelError("JBoss modules failed to make module available: " + declaration.getNameAsString() + "/" + declaration.getVersion());
                    }
                }
            }
        }
        if (visitedModules == null)
            visitedModules = new HashSet<org.eclipse.ceylon.model.typechecker.model.Module>();
        // do not visit this module again
        visitedModules.add(declaration);
        // make sure its imports are also loaded
        for (ModuleImport mi : declaration.getImports()) {
            org.eclipse.ceylon.model.typechecker.model.Module importedModule = mi.getModule();
            // don't try loading optional modules
            if (mi.isOptional())
                continue;
            // make sure we don't run in circles
            if (importedModule != null && !visitedModules.contains(importedModule)) {
                String ns = mi.getNamespace() != null ? mi.getNamespace() : namespace;
                getOrCreateMetamodel(ns, importedModule, visitedModules, mi.isOptional());
            }
        }
    } catch (ModuleLoadException e) {
        // present. Also not an issue for optional modules.
        if (!declaration.isDefaultModule() && !optional)
            throw Metamodel.newModelError(e.toString());
    } catch (SecurityException e) {
        throw Metamodel.newModelError(e.toString());
    } catch (IllegalArgumentException e) {
        throw Metamodel.newModelError(e.toString());
    }
}
Also used : ModuleLoadException(org.eclipse.ceylon.model.runtime.CeylonModuleClassLoader.ModuleLoadException) CeylonModuleClassLoader(org.eclipse.ceylon.model.runtime.CeylonModuleClassLoader) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) CeylonModuleClassLoader(org.eclipse.ceylon.model.runtime.CeylonModuleClassLoader) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) 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