Search in sources :

Example 16 with ModuleInfo

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

the class OSGiDependencyResolver method parseRequireBundle.

private ModuleInfo parseRequireBundle(String requireBundle, String name, String version, Overrides overrides) {
    Set<ModuleDependencyInfo> infos = new HashSet<>();
    requireBundle = requireBundle.replaceAll(";bundle-version=\"\\[([^,]+),[^,]+(\\]|\\))\"", ";bundle-version=$1");
    String[] bundles = requireBundle.split(",");
    for (String bundle : bundles) {
        infos.add(parseModuleInfo(bundle));
    }
    ModuleInfo ret = new ModuleInfo(null, name, version, // FIXME: does OSGi store this?
    ModuleUtil.getMavenGroupIdIfMavenModule(name), ModuleUtil.getMavenArtifactIdIfMavenModule(name), ModuleUtil.getMavenClassifierIfMavenModule(name), null, infos);
    if (overrides != null)
        ret = overrides.applyOverrides(name, version, ret);
    return ret;
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) HashSet(java.util.HashSet)

Example 17 with ModuleInfo

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

the class BytecodeUtils method readModuleInformation.

/**
 * Read module info from bytecode.
 *
 * @param moduleName the module name
 * @param jarFile    the module jar file
 * @return module info list
 */
private static ModuleInfo readModuleInformation(final String moduleName, final File jarFile, Overrides overrides) {
    ClassFile moduleInfo = readModuleInfo(moduleName, jarFile);
    if (moduleInfo == null)
        return null;
    Annotation ai = ClassFileUtil.findAnnotation(moduleInfo, MODULE_ANNOTATION);
    if (ai == null)
        return null;
    final String version = (String) ClassFileUtil.getAnnotationValue(moduleInfo, ai, "version");
    if (version == null)
        return null;
    String groupId, artifactId;
    groupId = (String) ClassFileUtil.getAnnotationValue(moduleInfo, ai, "group");
    if (groupId == null || groupId.isEmpty()) {
        String[] coordinates = ModuleUtil.getMavenCoordinates(moduleName);
        groupId = coordinates[0];
        artifactId = coordinates[1];
    } else {
        artifactId = (String) ClassFileUtil.getAnnotationValue(moduleInfo, ai, "artifact");
        if (artifactId == null || artifactId.isEmpty())
            artifactId = moduleName;
    }
    final Object[] dependencies = (Object[]) ClassFileUtil.getAnnotationValue(moduleInfo, ai, "dependencies");
    final Set<ModuleDependencyInfo> infos = getDependencies(moduleInfo, dependencies, moduleName, version, groupId, artifactId, overrides);
    ModuleInfo ret = new ModuleInfo(null, moduleName, version, groupId, artifactId, null, null, infos);
    if (overrides != null)
        ret = overrides.applyOverrides(moduleName, version, ret);
    return ret;
}
Also used : ClassFile(org.eclipse.ceylon.langtools.classfile.ClassFile) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) Annotation(org.eclipse.ceylon.langtools.classfile.Annotation)

Example 18 with ModuleInfo

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

the class AbstractCeylonArtifactResult method artifactId.

@Override
public String artifactId() {
    ModuleInfo info = resolve();
    if (info != null) {
        String groupId = info.getGroupId();
        String artifactId = info.getArtifactId();
        if (groupId != null && !groupId.isEmpty()) {
            if (artifactId != null && !artifactId.isEmpty())
                return artifactId;
            // if we have a group but not artifact, default to the entire name
            return name();
        }
    }
    return ModuleUtil.getMavenCoordinates(name())[1];
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo)

Example 19 with ModuleInfo

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

the class JSUtils method getModuleInfo.

private ModuleInfo getModuleInfo(Object obj, String moduleName, String version, Overrides overrides) {
    if (obj == null) {
        return new ModuleInfo(null, moduleName, version, null, null, null, null, Collections.<ModuleDependencyInfo>emptySet());
    }
    if (!(obj instanceof Iterable)) {
        throw new RuntimeException("Expected something Iterable");
    }
    @SuppressWarnings("unchecked") Iterable<Object> array = (Iterable<Object>) obj;
    Set<ModuleDependencyInfo> deps = new HashSet<ModuleDependencyInfo>();
    for (Object o : array) {
        String module;
        boolean optional = false;
        boolean exported = false;
        if (o instanceof String) {
            module = asString(o);
        } else {
            @SuppressWarnings("unchecked") Map<String, Object> m = (Map<String, Object>) o;
            module = m.get("path").toString();
            optional = m.containsKey("opt");
            exported = m.containsKey("exp");
        }
        String depUri = ModuleUtil.moduleName(module);
        String namespace = ModuleUtil.getNamespaceFromUri(depUri);
        String modName = ModuleUtil.getModuleNameFromUri(depUri);
        deps.add(new ModuleDependencyInfo(namespace, modName, ModuleUtil.moduleVersion(module), optional, exported, Backends.JS));
    }
    ModuleInfo result = new ModuleInfo(null, moduleName, version, null, null, null, null, deps);
    if (overrides != null)
        result = overrides.applyOverrides(moduleName, version, result);
    return result;
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) Map(java.util.Map) HashSet(java.util.HashSet)

Example 20 with ModuleInfo

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

the class JarUtils method readModuleInfo.

@Override
public ModuleVersionDetails readModuleInfo(String moduleName, String version, File moduleArchive, boolean includeMembers, Overrides overrides) {
    ModuleInfo info = getDependencies(moduleArchive, moduleName, version, overrides);
    ModuleVersionDetails mvd = new ModuleVersionDetails(moduleName, version, info != null ? info.getGroupId() : null, info != null ? info.getArtifactId() : null);
    mvd.getArtifactTypes().add(new ModuleVersionArtifact(ArtifactContext.JAR, null, null));
    if (info != null) {
        mvd.getDependencies().addAll(info.getDependencies());
    }
    if (includeMembers) {
        mvd.setMembers(getMembers(moduleArchive));
    }
    return mvd;
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)

Aggregations

ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)20 ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)12 HashSet (java.util.HashSet)9 File (java.io.File)4 IOException (java.io.IOException)3 Map (java.util.Map)3 ZipEntry (java.util.zip.ZipEntry)3 ZipFile (java.util.zip.ZipFile)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 JarFile (java.util.jar.JarFile)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)2 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)2 MavenDependencyResolver (org.eclipse.ceylon.cmr.maven.MavenDependencyResolver)2 Backends (org.eclipse.ceylon.common.Backends)2 Annotation (org.eclipse.ceylon.langtools.classfile.Annotation)2 ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)2 Test (org.junit.Test)2