Search in sources :

Example 1 with ModuleDependencyInfo

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

the class ModuleVersionReader method getModuleVersionDetailsFromSource.

/**
 * Reads a module descriptor and returns its information
 * @param moduleName The name of the module
 * @param srcDir The source directory where to find the descriptor
 * @return A <code>ModuleVersionsDetails</code> with the encountered information
 * @throws NoSuchModuleException if the module could not be found
 */
public static ModuleVersionDetails getModuleVersionDetailsFromSource(String moduleName, File srcDir) throws NoSuchModuleException {
    ModuleDescriptorReader mdr = new ModuleDescriptorReader(moduleName, srcDir);
    String module = mdr.getModuleName();
    String version = mdr.getModuleVersion();
    // PS In case the module descriptor was found but could not be parsed
    // we'll create an invalid details object
    ModuleVersionDetails mvd = new ModuleVersionDetails(module != null ? module : "", version != null ? version : "", mdr.getModuleGroupId(), mdr.getModuleArtifactId());
    mvd.setLabel(mdr.getModuleLabel());
    mvd.setLicense(mdr.getModuleLicense());
    List<String> by = mdr.getModuleAuthors();
    if (by != null) {
        mvd.getAuthors().addAll(by);
    }
    SortedSet<ModuleDependencyInfo> dependencies = new TreeSet<>();
    for (Object[] dep : mdr.getModuleImports()) {
        dependencies.add(new ModuleDependencyInfo((String) dep[0], (String) dep[1], (String) dep[2], (Boolean) dep[3], (Boolean) dep[4], (Backends) dep[5]));
    }
    mvd.setDependencies(dependencies);
    mvd.setRemote(false);
    mvd.setOrigin("Local source folder");
    return mvd;
}
Also used : ModuleDescriptorReader(org.eclipse.ceylon.common.ModuleDescriptorReader) Backends(org.eclipse.ceylon.common.Backends) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) TreeSet(java.util.TreeSet) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)

Example 2 with ModuleDependencyInfo

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

the class AbstractTestTool method findTestVersionInDependecies.

private String findTestVersionInDependecies(ModuleDependencyInfo module, Queue<ModuleDependencyInfo> queue) {
    Collection<ModuleVersionDetails> moduleDetailsCollection = getModuleVersions(module.getNamespace(), module.getName(), module.getVersion(), false, type, jvmBinaryMajor, jvmBinaryMinor, jsBinaryMajor, jsBinaryMinor);
    Iterator<ModuleVersionDetails> moduleDetailsIterator = moduleDetailsCollection.iterator();
    if (moduleDetailsIterator.hasNext()) {
        ModuleVersionDetails moduleDetails = moduleDetailsIterator.next();
        for (ModuleDependencyInfo dependency : moduleDetails.getDependencies()) {
            if (dependency.getName().equals("ceylon.test")) {
                return dependency.getVersion();
            }
            if (dependency.getName().equals("ceylon.language")) {
                continue;
            }
            queue.add(dependency);
        }
    }
    return null;
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)

Example 3 with ModuleDependencyInfo

use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo 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 4 with ModuleDependencyInfo

use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo 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 5 with ModuleDependencyInfo

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

the class BytecodeUtils method matchesModuleInfo.

public boolean matchesModuleInfo(String moduleName, String moduleVersion, File moduleArchive, String query, Overrides overrides) {
    ClassFile moduleInfo = readModuleInfo(moduleName, moduleArchive);
    if (moduleInfo == null)
        return false;
    Annotation moduleAnnotation = ClassFileUtil.findAnnotation(moduleInfo, MODULE_ANNOTATION);
    if (moduleAnnotation == null)
        return false;
    String groupId, artifactId;
    groupId = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "group");
    if (groupId == null || groupId.isEmpty()) {
        String[] coordinates = ModuleUtil.getMavenCoordinates(moduleName);
        groupId = coordinates[0];
        artifactId = coordinates[1];
    } else {
        artifactId = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "artifact");
        if (artifactId == null || artifactId.isEmpty())
            artifactId = moduleName;
    }
    String version = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "version");
    if (version == null)
        return false;
    String doc = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "doc");
    if (doc != null && matches(doc, query))
        return true;
    String label = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "label");
    if (label != null && matches(label, query))
        return true;
    String license = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "license");
    if (license != null && matches(license, query))
        return true;
    Object[] by = (Object[]) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "by");
    if (by != null) {
        for (Object author : by) {
            if (matches((String) author, query))
                return true;
        }
    }
    Object[] dependencies = (Object[]) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "dependencies");
    if (dependencies != null) {
        for (ModuleDependencyInfo dep : getDependencies(moduleInfo, dependencies, moduleName, version, groupId, artifactId, overrides)) {
            if (matches(dep.getModuleName(), query))
                return true;
        }
    }
    return false;
}
Also used : ClassFile(org.eclipse.ceylon.langtools.classfile.ClassFile) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) Annotation(org.eclipse.ceylon.langtools.classfile.Annotation)

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