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();
}
}
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();
}
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;
}
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());
}
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());
}
}
Aggregations