Search in sources :

Example 1 with ModuleDependencyInfo

use of com.redhat.ceylon.cmr.api.ModuleDependencyInfo in project ceylon-compiler by ceylon.

the class CeylonInfoTool method outputVersions.

private void outputVersions(String moduleName, Collection<ModuleVersionDetails> versions, String prefix) throws IOException {
    String namePrefix = (formatting == Formatting.fancy) ? prefix + "    " : "";
    for (ModuleVersionDetails version : versions) {
        if (formatting == Formatting.fancy || (!showDependencies && !showNames)) {
            append(prefix);
            if (formatting == Formatting.simple) {
                append(moduleName).append("/");
            }
            append(version.getVersion());
            if (formatting == Formatting.fancy) {
                append(" - ").append(version.getOrigin());
                if (hasOnlyIncompatibleBinaries(version)) {
                    append(" ");
                    msg("label.incompatible.version");
                }
                if (version.isRemote()) {
                    append(" ");
                    msg("label.remote");
                }
            }
            newline();
        }
        if (showDependencies) {
            if (formatting == Formatting.fancy || !version.getDependencies().isEmpty()) {
                for (ModuleDependencyInfo dep : version.getDependencies()) {
                    if (formatting == Formatting.fancy) {
                        append(prefix).append("    ").append(dep);
                    } else {
                        append(moduleName).append("/").append(version.getVersion()).append(" ").append(dep.getModuleName());
                    }
                    newline();
                }
            } else {
                append(moduleName).append("/").append(version.getVersion()).newline();
            }
        }
        if (showNames) {
            outputNames(moduleName, version, namePrefix);
        }
    }
}
Also used : ModuleVersionDetails(com.redhat.ceylon.cmr.api.ModuleVersionDetails) ModuleDependencyInfo(com.redhat.ceylon.cmr.api.ModuleDependencyInfo)

Example 2 with ModuleDependencyInfo

use of com.redhat.ceylon.cmr.api.ModuleDependencyInfo in project ceylon-compiler by ceylon.

the class LazyModuleSourceMapper method resolveModule.

@Override
public void resolveModule(ArtifactResult artifact, Module module, ModuleImport moduleImport, LinkedList<Module> dependencyTree, List<PhasedUnits> phasedUnitsOfDependencies, boolean forCompiledModule) {
    String moduleName = module.getNameAsString();
    LazyModuleManager moduleManager = getModuleManager();
    boolean moduleLoadedFromSource = moduleManager.isModuleLoadedFromSource(moduleName);
    boolean isLanguageModule = module == module.getLanguageModule();
    // module in question will be in the classpath
    if (moduleLoadedFromSource || forCompiledModule) {
        String standardisedModuleName = ModuleUtil.toCeylonModuleName(moduleName);
        // check for an already loaded module with the same name but different version
        for (Module loadedModule : getContext().getModules().getListOfModules()) {
            String loadedModuleName = loadedModule.getNameAsString();
            String standardisedLoadedModuleName = ModuleUtil.toCeylonModuleName(loadedModuleName);
            boolean sameModule = loadedModuleName.equals(moduleName);
            boolean similarModule = standardisedLoadedModuleName.equals(standardisedModuleName);
            if ((sameModule || similarModule) && !loadedModule.getVersion().equals(module.getVersion()) && moduleManager.getModelLoader().isModuleInClassPath(loadedModule)) {
                if (sameModule) {
                    String[] versions = VersionComparator.orderVersions(module.getVersion(), loadedModule.getVersion());
                    String error = "source code imports two different versions of module '" + moduleName + "': " + "version '" + versions[0] + "' and version '" + versions[1] + "'";
                    addErrorToModule(dependencyTree.getFirst(), error);
                } else {
                    String moduleA;
                    String moduleB;
                    if (loadedModuleName.compareTo(moduleName) < 0) {
                        moduleA = ModuleUtil.makeModuleName(loadedModuleName, loadedModule.getVersion());
                        moduleB = ModuleUtil.makeModuleName(moduleName, module.getVersion());
                    } else {
                        moduleA = ModuleUtil.makeModuleName(moduleName, module.getVersion());
                        moduleB = ModuleUtil.makeModuleName(loadedModuleName, loadedModule.getVersion());
                    }
                    String error = "source code imports two different versions of similar modules '" + moduleA + "' and '" + moduleB + "'";
                    addWarningToModule(dependencyTree.getFirst(), Warning.similarModule, error);
                }
                return;
            }
        }
    }
    if (moduleLoadedFromSource) {
        super.resolveModule(artifact, module, moduleImport, dependencyTree, phasedUnitsOfDependencies, forCompiledModule);
    } else if (forCompiledModule || isLanguageModule || moduleManager.shouldLoadTransitiveDependencies()) {
        // we only add stuff to the classpath and load the modules if we need them to compile our modules
        // To be able to load it from the corresponding archive
        moduleManager.getModelLoader().addModuleToClassPath(module, artifact);
        if (!module.isDefault() && !moduleManager.getModelLoader().loadCompiledModule(module)) {
            // we didn't find module.class so it must be a java module if it's not the default module
            ((LazyModule) module).setJava(true);
            module.setNativeBackends(Backend.Java.asSet());
            List<ArtifactResult> deps = artifact.dependencies();
            for (ArtifactResult dep : deps) {
                Module dependency = moduleManager.getOrCreateModule(ModuleManager.splitModuleName(dep.name()), dep.version());
                ModuleImport depImport = moduleManager.findImport(module, dependency);
                if (depImport == null) {
                    moduleImport = new ModuleImport(dependency, dep.importType() == ImportType.OPTIONAL, dep.importType() == ImportType.EXPORT, Backend.Java);
                    module.addImport(moduleImport);
                }
            }
        }
        LazyModule lazyModule = (LazyModule) module;
        if (!lazyModule.isJava() && !module.isDefault()) {
            // it must be a Ceylon module
            // default modules don't have any module descriptors so we can't check them
            Overrides overrides = getContext().getRepositoryManager().getOverrides();
            if (overrides != null) {
                if (overrides.getArtifactOverrides(new ArtifactContext(artifact.name(), artifact.version())) != null) {
                    Set<ModuleDependencyInfo> existingModuleDependencies = new HashSet<>();
                    for (ModuleImport i : lazyModule.getImports()) {
                        Module m = i.getModule();
                        if (m != null) {
                            existingModuleDependencies.add(new ModuleDependencyInfo(m.getNameAsString(), m.getVersion(), i.isOptional(), i.isExport()));
                        }
                    }
                    ModuleInfo sourceModuleInfo = new ModuleInfo(null, existingModuleDependencies);
                    ModuleInfo newModuleInfo = overrides.applyOverrides(artifact.name(), artifact.version(), sourceModuleInfo);
                    List<ModuleImport> newModuleImports = new ArrayList<>();
                    for (ModuleDependencyInfo dep : newModuleInfo.getDependencies()) {
                        Module dependency = moduleManager.getOrCreateModule(ModuleManager.splitModuleName(dep.getName()), dep.getVersion());
                        Backends backends = dependency.getNativeBackends();
                        moduleImport = new ModuleImport(dependency, dep.isOptional(), dep.isExport(), backends);
                        newModuleImports.add(moduleImport);
                    }
                    module.overrideImports(newModuleImports);
                }
            }
            if (!Versions.isJvmBinaryVersionSupported(lazyModule.getMajor(), lazyModule.getMinor())) {
                attachErrorToDependencyDeclaration(moduleImport, dependencyTree, "version '" + lazyModule.getVersion() + "' of module '" + module.getNameAsString() + "' was compiled by an incompatible version of the compiler (binary version " + lazyModule.getMajor() + "." + lazyModule.getMinor() + " of module is not compatible with binary version " + Versions.JVM_BINARY_MAJOR_VERSION + "." + Versions.JVM_BINARY_MINOR_VERSION + " of this compiler)");
            }
        }
        // module is now available
        module.setAvailable(true);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) LazyModuleManager(com.redhat.ceylon.model.loader.model.LazyModuleManager) ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) LazyModule(com.redhat.ceylon.model.loader.model.LazyModule) ArtifactResult(com.redhat.ceylon.model.cmr.ArtifactResult) Backends(com.redhat.ceylon.common.Backends) ModuleInfo(com.redhat.ceylon.cmr.api.ModuleInfo) ModuleImport(com.redhat.ceylon.model.typechecker.model.ModuleImport) Overrides(com.redhat.ceylon.cmr.api.Overrides) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ModuleDependencyInfo(com.redhat.ceylon.cmr.api.ModuleDependencyInfo) LazyModule(com.redhat.ceylon.model.loader.model.LazyModule) Module(com.redhat.ceylon.model.typechecker.model.Module)

Aggregations

ModuleDependencyInfo (com.redhat.ceylon.cmr.api.ModuleDependencyInfo)2 ArtifactContext (com.redhat.ceylon.cmr.api.ArtifactContext)1 ModuleInfo (com.redhat.ceylon.cmr.api.ModuleInfo)1 ModuleVersionDetails (com.redhat.ceylon.cmr.api.ModuleVersionDetails)1 Overrides (com.redhat.ceylon.cmr.api.Overrides)1 Backends (com.redhat.ceylon.common.Backends)1 ArtifactResult (com.redhat.ceylon.model.cmr.ArtifactResult)1 LazyModule (com.redhat.ceylon.model.loader.model.LazyModule)1 LazyModuleManager (com.redhat.ceylon.model.loader.model.LazyModuleManager)1 Module (com.redhat.ceylon.model.typechecker.model.Module)1 ModuleImport (com.redhat.ceylon.model.typechecker.model.ModuleImport)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1