Search in sources :

Example 16 with ModuleDependencyInfo

use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.

the class JSUtils method readModuleInfo.

@SuppressWarnings("unchecked")
@Override
public ModuleVersionDetails readModuleInfo(String moduleName, String moduleVersion, File moduleArchive, boolean includeMembers, Overrides overrides) {
    Map<String, Object> model = loadJsonModel(moduleArchive);
    String name = asString(metaModelProperty(model, "$mod-name"));
    if (!moduleName.equals(name)) {
        throw new RuntimeException("Incorrect module");
    }
    String version = asString(metaModelProperty(model, "$mod-version"));
    Set<ModuleDependencyInfo> dependencies = getModuleInfo(model, moduleName, version, overrides).getDependencies();
    String type = ArtifactContext.getSuffixFromFilename(moduleArchive.getName());
    Integer major = null, minor = null;
    String bin = asString(metaModelProperty(model, "$mod-bin"));
    if (bin != null) {
        int p = bin.indexOf('.');
        if (p >= 0) {
            major = Integer.parseInt(bin.substring(0, p));
            minor = Integer.parseInt(bin.substring(p + 1));
        } else {
            major = Integer.parseInt(bin);
        }
    }
    ModuleVersionDetails mvd = new ModuleVersionDetails(moduleName, version, null, null);
    mvd.getArtifactTypes().add(new ModuleVersionArtifact(type, major, minor));
    mvd.getDependencies().addAll(dependencies);
    Object anns = metaModelProperty(model, "$mod-anns");
    List<Map<String, Object>> annotations = null;
    if (anns instanceof Map) {
        // Pre-10.0 style annotations
        annotations = new ArrayList<Map<String, Object>>(1);
        annotations.add((Map<String, Object>) anns);
    } else if (anns instanceof List) {
        // 10.0+ style annotations
        annotations = (List<Map<String, Object>>) anns;
    }
    if (annotations != null) {
        for (Map<String, Object> annot : annotations) {
            if (annot.containsKey("doc")) {
                mvd.setDoc(asString(annot.get("doc")));
            }
            if (annot.containsKey("label")) {
                mvd.setLabel(asString(annot.get("label")));
            }
            if (annot.containsKey("license")) {
                mvd.setLicense(asString(annot.get("license")));
            }
            if (annot.containsKey("by")) {
                Iterable<String> by = (Iterable<String>) annot.get("by");
                if (by != null) {
                    for (String author : by) {
                        mvd.getAuthors().add(author);
                    }
                }
            }
        }
    }
    if (includeMembers) {
        mvd.setMembers(getMembers(moduleName, moduleArchive));
    }
    return mvd;
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 17 with ModuleDependencyInfo

use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.

the class PropertiesDependencyResolver method resolveFromInputStream.

@Override
public ModuleInfo resolveFromInputStream(InputStream stream, String moduleName, String moduleVersion, Overrides overrides) {
    try {
        final Properties properties = new Properties();
        properties.load(stream);
        Set<ModuleDependencyInfo> infos = new LinkedHashSet<>();
        for (Map.Entry<?, ?> entry : properties.entrySet()) {
            String depUri = entry.getKey().toString();
            String version = entry.getValue().toString();
            boolean optional = false;
            boolean shared = false;
            if (depUri.startsWith("+")) {
                depUri = depUri.substring(1);
                shared = true;
            }
            if (depUri.endsWith("?")) {
                depUri = depUri.substring(0, depUri.length() - 1);
                optional = true;
            }
            String namespace = ModuleUtil.getNamespaceFromUri(depUri);
            String modName = ModuleUtil.getModuleNameFromUri(depUri);
            infos.add(new ModuleDependencyInfo(namespace, modName, version, optional, shared, Backends.JAVA));
        }
        ModuleInfo ret = new ModuleInfo(null, moduleName, moduleVersion, // FIXME: store this
        ModuleUtil.getMavenGroupIdIfMavenModule(moduleName), ModuleUtil.getMavenArtifactIdIfMavenModule(moduleName), ModuleUtil.getMavenClassifierIfMavenModule(moduleName), null, infos);
        if (overrides != null)
            ret = overrides.applyOverrides(moduleName, moduleVersion, ret);
        return ret;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) Properties(java.util.Properties) Map(java.util.Map)

Example 18 with ModuleDependencyInfo

use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.

the class ModuleSourceMapper method overrideModuleImports.

protected void overrideModuleImports(Module module, ArtifactResult artifact) {
    Overrides overrides = getContext().getRepositoryManager().getOverrides();
    if (overrides != null) {
        Set<ModuleDependencyInfo> existingModuleDependencies = new HashSet<>();
        for (ModuleImport i : module.getImports()) {
            Module m = i.getModule();
            if (m != null) {
                existingModuleDependencies.add(new ModuleDependencyInfo(i.getNamespace(), m.getNameAsString(), m.getVersion(), i.isOptional(), i.isExport(), i.getNativeBackends()));
            }
        }
        ModuleInfo sourceModuleInfo = new ModuleInfo(artifact.namespace(), artifact.name(), artifact.version(), artifact.groupId(), artifact.artifactId(), artifact.classifier(), null, existingModuleDependencies);
        ModuleInfo newModuleInfo = overrides.applyOverrides(artifact.name(), artifact.version(), sourceModuleInfo);
        List<ModuleImport> newModuleImports = new ArrayList<>();
        for (ModuleDependencyInfo dep : newModuleInfo.getDependencies()) {
            Module dependency = getModuleManager().getOrCreateModule(ModuleManager.splitModuleName(dep.getName()), dep.getVersion());
            Backends backends = dependency.getNativeBackends();
            ModuleImport newImport = new ModuleImport(dep.getNamespace(), dependency, dep.isOptional(), dep.isExport(), backends);
            newModuleImports.add(newImport);
        }
        module.overrideImports(newModuleImports);
    }
}
Also used : Backends(org.eclipse.ceylon.common.Backends) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) ArrayList(java.util.ArrayList) Overrides(org.eclipse.ceylon.cmr.api.Overrides) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) Module(org.eclipse.ceylon.model.typechecker.model.Module) HashSet(java.util.HashSet)

Example 19 with ModuleDependencyInfo

use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.

the class AbstractTestTool method findTestVersionInDependecies.

private String findTestVersionInDependecies(String moduleAndVersion) {
    String moduleName = ModuleUtil.moduleName(moduleAndVersion);
    String moduleVersion = ModuleUtil.moduleVersion(moduleAndVersion);
    ModuleDependencyInfo root = new ModuleDependencyInfo(null, moduleName, moduleVersion, false, false);
    Queue<ModuleDependencyInfo> queue = new LinkedList<ModuleDependencyInfo>();
    queue.add(root);
    while (!queue.isEmpty()) {
        String foundVersion = findTestVersionInDependecies(queue.poll(), queue);
        if (foundVersion != null) {
            return foundVersion;
        }
    }
    return null;
}
Also used : ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) LinkedList(java.util.LinkedList)

Example 20 with ModuleDependencyInfo

use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.

the class XmlDependencyResolver method resolveFromInputStream.

@Override
public ModuleInfo resolveFromInputStream(InputStream stream, String name, String version, Overrides overrides) {
    try {
        final Module module = parse(stream);
        final Set<ModuleDependencyInfo> infos = new LinkedHashSet<>();
        for (ModuleIdentifier mi : module.getDependencies()) {
            infos.add(new ModuleDependencyInfo(null, mi.getName(), mi.getSlot(), mi.isOptional(), mi.isExport(), Backends.JAVA));
        }
        ModuleInfo ret = new ModuleInfo(null, name, version, module.getGroupId(), module.getArtifactId(), null, module.getFilter(), infos);
        if (overrides != null)
            ret = overrides.applyOverrides(name, version, ret);
        return ret;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)29 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)12 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)10 HashSet (java.util.HashSet)9 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)5 IOException (java.io.IOException)3 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)3 Backends (org.eclipse.ceylon.common.Backends)3 Annotation (org.eclipse.ceylon.langtools.classfile.Annotation)3 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)3 File (java.io.File)2 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2 Properties (java.util.Properties)2 TreeSet (java.util.TreeSet)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 DependencyDescriptor (org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor)2 ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)2