Search in sources :

Example 1 with ModuleInfo

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

the class AbstractCeylonArtifactResult method dependencies.

@Override
public List<ArtifactResult> dependencies() throws RepositoryException {
    ModuleInfo infos = resolve();
    // TODO -- perhaps null is not valid?
    if (infos == null || infos.getDependencies().isEmpty())
        return Collections.emptyList();
    final List<ArtifactResult> results = new ArrayList<ArtifactResult>();
    for (ModuleDependencyInfo mi : getOrderedDependencies(infos)) {
        results.add(new LazyArtifactResult(manager, mi.getNamespace(), mi.getName(), mi.getVersion(), mi.isExport(), mi.isOptional(), mi.getModuleScope()));
    }
    return results;
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ArrayList(java.util.ArrayList) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 2 with ModuleInfo

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

the class BytecodeUtils method getDependencies.

private static Set<ModuleDependencyInfo> getDependencies(ClassFile moduleInfo, Object[] dependencies, String module, String version, String groupId, String artifactId, Overrides overrides) {
    if (dependencies == null) {
        return Collections.<ModuleDependencyInfo>emptySet();
    }
    int[] binver = getBinaryVersions(moduleInfo);
    boolean supportsNamespaces = binver != null && ModuleUtil.supportsImportsWithNamespaces(binver[0], binver[1]);
    Set<ModuleDependencyInfo> result = new HashSet<ModuleDependencyInfo>(dependencies.length);
    for (Object depObject : dependencies) {
        Annotation dep = (Annotation) depObject;
        String namespace;
        String modName = (String) ClassFileUtil.getAnnotationValue(moduleInfo, dep, "name");
        if (supportsNamespaces) {
            namespace = (String) ClassFileUtil.getAnnotationValue(moduleInfo, dep, "namespace");
            if (namespace != null && namespace.isEmpty()) {
                namespace = null;
            }
        } else {
            if (ModuleUtil.isMavenModule(modName)) {
                namespace = MavenRepository.NAMESPACE;
            } else {
                namespace = null;
            }
        }
        String depVersion = (String) ClassFileUtil.getAnnotationValue(moduleInfo, dep, "version");
        boolean export = asBoolean(moduleInfo, dep, "export");
        boolean optional = asBoolean(moduleInfo, dep, "optional");
        Backends backends = Backends.ANY;
        Object[] backendNames = (Object[]) ClassFileUtil.getAnnotationValue(moduleInfo, dep, "dependencies");
        if (backendNames != null) {
            for (Object backend : backendNames) {
                backends = backends.merged(Backend.fromAnnotation((String) backend));
            }
        }
        result.add(new ModuleDependencyInfo(namespace, modName, depVersion, optional, export, backends));
    }
    if (overrides != null) {
        result = overrides.applyOverrides(module, version, new ModuleInfo(null, module, version, groupId, artifactId, null, null, result)).getDependencies();
    }
    return result;
}
Also used : Backends(org.eclipse.ceylon.common.Backends) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) Annotation(org.eclipse.ceylon.langtools.classfile.Annotation) HashSet(java.util.HashSet)

Example 3 with ModuleInfo

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

the class LegacyImporter method loadModuleDescriptor.

/**
 * The descriptor to use, this can either be a <code>module.xml</code> or
 * a <code>module.properties</code> file.
 * If it exists it will be parsed and its contents used to determine which external
 * classes are already covered by the defined dependencies.
 * Regardless of whether the file exists it will be remembered for use with the
 * <code>updateModuleDescripter()</code> method.
 * @param descriptorFile
 * @throws Exception
 */
public LegacyImporter loadModuleDescriptor() throws Exception {
    if (descriptorFile != null && !descriptorLoaded) {
        ModuleInfo moduleInfo = null;
        if (descriptorFile.exists()) {
            if (descriptorFile.toString().toLowerCase().endsWith(".xml")) {
                moduleInfo = XmlDependencyResolver.INSTANCE.resolveFromFile(descriptorFile, moduleName, moduleVersion, lookupRepoman.getOverrides());
            } else if (descriptorFile.toString().toLowerCase().endsWith(".properties")) {
                moduleInfo = PropertiesDependencyResolver.INSTANCE.resolveFromFile(descriptorFile, moduleName, moduleVersion, lookupRepoman.getOverrides());
            }
            descriptorLoaded = true;
        }
        gatherExternalClasses(moduleInfo);
        if (moduleInfo != null)
            checkModuleDescriptor(moduleInfo);
    }
    return this;
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo)

Example 4 with ModuleInfo

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

the class URLContentStore method parseCompleteVersionsResponse.

protected void parseCompleteVersionsResponse(Parser p, ModuleVersionResult result, Overrides overrides) {
    List<String> authors = new LinkedList<String>();
    Set<ModuleDependencyInfo> dependencies = new HashSet<ModuleDependencyInfo>();
    List<ModuleVersionArtifact> types = new LinkedList<ModuleVersionArtifact>();
    p.moveToOpenTag("results");
    while (p.moveToOptionalOpenTag("module-version")) {
        String module = null, version = null, doc = null, license = null, label = null, groupId = null, artifactId = null;
        authors.clear();
        dependencies.clear();
        types.clear();
        while (p.moveToOptionalOpenTag()) {
            if (p.isOpenTag("module")) {
                // ignored
                module = p.contents();
            } else if (p.isOpenTag("version")) {
                version = p.contents();
            } else if (p.isOpenTag("doc")) {
                doc = p.contents();
            } else if (p.isOpenTag("groupId")) {
                groupId = p.contents();
            } else if (p.isOpenTag("artifactId")) {
                artifactId = p.contents();
            } else if (p.isOpenTag("license")) {
                license = p.contents();
            } else if (p.isOpenTag("label")) {
                label = p.contents();
            } else if (p.isOpenTag("authors")) {
                authors.add(p.contents());
            } else if (p.isOpenTag("dependency")) {
                dependencies.add(parseDependency(p));
            } else if (p.isOpenTag("artifact")) {
                types.add(parseArtifact(p));
            } else {
                throw new RuntimeException("Unknown tag: " + p.tagName());
            }
        }
        if (version == null || version.isEmpty())
            throw new RuntimeException("Missing required version");
        ModuleVersionDetails newVersion = result.addVersion(null, module, version);
        if (newVersion != null) {
            if (groupId != null && !groupId.isEmpty())
                newVersion.setGroupId(groupId);
            if (artifactId != null && !artifactId.isEmpty())
                newVersion.setArtifactId(artifactId);
            if (doc != null && !doc.isEmpty())
                newVersion.setDoc(doc);
            if (license != null && !license.isEmpty())
                newVersion.setLicense(license);
            if (label != null && !label.isEmpty())
                newVersion.setLabel(label);
            if (!authors.isEmpty())
                newVersion.getAuthors().addAll(authors);
            if (overrides != null) {
                final ModuleInfo info = new ModuleInfo(null, module, version, groupId, artifactId, null, null, dependencies);
                dependencies = overrides.applyOverrides(module, version, info).getDependencies();
            }
            if (!dependencies.isEmpty())
                newVersion.getDependencies().addAll(dependencies);
            if (!types.isEmpty())
                newVersion.getArtifactTypes().addAll(types);
            newVersion.setRemote(true);
            if (isHerd()) {
                newVersion.setOrigin(HERD_ORIGIN + " (" + getDisplayString() + ")");
            } else {
                newVersion.setOrigin(getDisplayString());
            }
        }
        p.checkCloseTag();
    }
    p.checkCloseTag();
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 5 with ModuleInfo

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

the class MavenDependencyResolver method toModuleInfo.

private static ModuleInfo toModuleInfo(DependencyDescriptor descriptor, String name, String version, Overrides overrides) {
    Set<ModuleDependencyInfo> infos = new HashSet<>();
    for (DependencyDescriptor dep : descriptor.getDependencies()) {
        String depName = MavenUtils.moduleName(dep.getGroupId(), dep.getArtifactId(), null);
        infos.add(new ModuleDependencyInfo(MavenRepository.NAMESPACE, depName, dep.getVersion(), dep.isOptional(), false, Backends.JAVA, AetherUtils.toModuleScope(dep)));
    }
    String descrName = MavenUtils.moduleName(descriptor.getGroupId(), descriptor.getArtifactId(), null);
    // if it's not the descriptor we wanted, let's not return it
    if (name != null && !name.equals(descrName))
        return null;
    if (version != null && !version.equals(descriptor.getVersion()))
        return null;
    ModuleInfo ret = new ModuleInfo(MavenRepository.NAMESPACE, descrName, descriptor.getVersion(), descriptor.getGroupId(), descriptor.getArtifactId(), null, null, infos);
    if (overrides != null)
        ret = overrides.applyOverrides(descrName, descriptor.getVersion(), ret);
    return ret;
}
Also used : DependencyDescriptor(org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) HashSet(java.util.HashSet)

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