use of com.redhat.ceylon.common.Backends in project ceylon-compiler by ceylon.
the class ModuleDoc method writeDependencyRow.
private void writeDependencyRow(ModuleImport moduleImport) throws IOException {
StringBuilder tooltip = new StringBuilder();
if (moduleImport.isExport()) {
tooltip.append("shared ");
}
if (moduleImport.isOptional()) {
tooltip.append("optional ");
}
tooltip.append("import of module ");
tooltip.append(moduleImport.getModule().getNameAsString());
tooltip.append(" ");
tooltip.append(moduleImport.getModule().getVersion());
open("tr");
open("td class='shrink'");
open("span title='" + tooltip + "'");
writeIcon(moduleImport);
close("span");
open("code class='decl-label'");
linkRenderer().to(moduleImport.getModule()).write();
Backends backends = moduleImport.getNativeBackends();
if (!backends.none()) {
write(" (");
write(backends.names());
write(")");
}
close("code");
close("td");
open("td class='shrink'");
open("code");
write(moduleImport.getModule().getVersion());
close("code");
close("td");
open("td");
open("div class='description import-description'");
write(getDoc(moduleImport, linkRenderer()));
close("div");
close("td");
close("tr");
}
use of com.redhat.ceylon.common.Backends 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);
}
}
Aggregations