Search in sources :

Example 6 with ModuleVersionArtifact

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

the class JSUtils method getBinaryVersions.

@Override
public int[] getBinaryVersions(String moduleName, String version, File moduleArchive) {
    int major = 0;
    int minor = 0;
    ModuleVersionDetails mvd = readModuleInfo(moduleName, version, moduleArchive, false, null);
    ModuleVersionArtifact mva = mvd.getArtifactTypes().first();
    if (mva.getMajorBinaryVersion() != null) {
        major = mva.getMajorBinaryVersion();
    }
    if (mva.getMinorBinaryVersion() != null) {
        minor = mva.getMinorBinaryVersion();
    }
    return new int[] { major, minor };
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)

Example 7 with ModuleVersionArtifact

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

the class NpmUtils 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, "name"));
    if (!moduleName.equals(name)) {
        throw new RuntimeException("Incorrect module");
    }
    String version = asString(metaModelProperty(model, "version"));
    Set<ModuleDependencyInfo> dependencies = getModuleInfo(model, moduleName, version, overrides).getDependencies();
    String type = ArtifactContext.getSuffixFromFilename(moduleArchive.getName());
    ModuleVersionDetails mvd = new ModuleVersionDetails(NpmRepository.NAMESPACE, moduleName, version, null, null);
    mvd.getArtifactTypes().add(new ModuleVersionArtifact(type, null, null));
    mvd.getDependencies().addAll(dependencies);
    mvd.setDoc(asString(model.get("description")));
    mvd.setLicense(asString(model.get("license")));
    String author = asString(model.get("author.name"));
    if (author != null) {
        mvd.getAuthors().add(author);
    }
    Iterable<Map<String, Object>> contributors = (Iterable<Map<String, Object>>) model.get("contributors");
    if (contributors != null) {
        for (Map<String, Object> contrib : contributors) {
            mvd.getAuthors().add(asString(contrib.get("name")));
        }
    }
    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) Map(java.util.Map)

Example 8 with ModuleVersionArtifact

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

the class NpmUtils method getBinaryVersions.

@Override
public int[] getBinaryVersions(String moduleName, String version, File moduleArchive) {
    int major = 0;
    int minor = 0;
    ModuleVersionDetails mvd = readModuleInfo(moduleName, version, moduleArchive, false, null);
    ModuleVersionArtifact mva = mvd.getArtifactTypes().first();
    if (mva.getMajorBinaryVersion() != null) {
        major = mva.getMajorBinaryVersion();
    }
    if (mva.getMinorBinaryVersion() != null) {
        minor = mva.getMinorBinaryVersion();
    }
    return new int[] { major, minor };
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)

Example 9 with ModuleVersionArtifact

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

the class AbstractRepository method addArtifactInfo.

private ArtifactInfoResult addArtifactInfo(Node artifact, String name, String version, String suffix, String memberName, ModuleVersionDetails mvd, ModuleQuery lookup) {
    // let's see if we can extract some information
    try {
        File file = artifact.getContent(File.class);
        if (file != null) {
            ModuleInfoReader reader = getModuleInfoReader(suffix);
            if (reader != null) {
                ModuleVersionDetails mvd2 = reader.readModuleInfo(name, version, file, memberName != null, getOverrides());
                Set<String> matchingMembers = null;
                if (memberName != null) {
                    matchingMembers = matchMembers(mvd2, lookup);
                    if (matchingMembers.isEmpty()) {
                        // just continue to the next suffix/artifact if any
                        return ArtifactInfoResult.NO_MATCH;
                    }
                    mvd.getMembers().addAll(matchingMembers);
                }
                if (mvd2.getGroupId() != null) {
                    mvd.setGroupId(mvd2.getGroupId());
                }
                if (mvd2.getArtifactId() != null) {
                    mvd.setArtifactId(mvd2.getArtifactId());
                }
                if (mvd2.getLabel() != null) {
                    mvd.setLabel(mvd2.getLabel());
                }
                if (mvd2.getDoc() != null) {
                    mvd.setDoc(mvd2.getDoc());
                }
                if (mvd2.getLicense() != null) {
                    mvd.setLicense(mvd2.getLicense());
                }
                mvd.getAuthors().addAll(mvd2.getAuthors());
                mvd.getDependencies().addAll(mvd2.getDependencies());
                mvd.getArtifactTypes().addAll(mvd2.getArtifactTypes());
                return ArtifactInfoResult.INFO_FOUND;
            } else {
                if (memberName == null) {
                    // We didn't get any information but we'll at least add the artifact type to the result
                    mvd.getArtifactTypes().add(new ModuleVersionArtifact(suffix, null, null));
                }
            }
        }
    } catch (Exception e) {
    // bah
    }
    return ArtifactInfoResult.OTHER;
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact) File(java.io.File) ModuleInfoReader(org.eclipse.ceylon.cmr.api.ModuleInfoReader)

Example 10 with ModuleVersionArtifact

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

the class BytecodeUtils method readModuleInfo.

@Override
public ModuleVersionDetails readModuleInfo(String moduleName, String moduleVersion, File moduleArchive, boolean includeMembers, Overrides overrides) {
    ClassFile moduleInfo = readModuleInfo(moduleName, moduleArchive);
    if (moduleInfo == null)
        return null;
    Annotation moduleAnnotation = ClassFileUtil.findAnnotation(moduleInfo, MODULE_ANNOTATION);
    if (moduleAnnotation == null)
        return null;
    String doc = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "doc");
    String license = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "license");
    String label = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "label");
    Object[] by = (Object[]) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "by");
    Object[] dependencies = (Object[]) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "dependencies");
    String type = ArtifactContext.getSuffixFromFilename(moduleArchive.getName());
    int[] binver = getBinaryVersions(moduleInfo);
    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;
    }
    ModuleVersionDetails mvd = new ModuleVersionDetails(moduleName, getVersionFromFilename(moduleName, moduleArchive.getName()), groupId, artifactId);
    mvd.setDoc(doc);
    mvd.setLabel(label);
    mvd.setLicense(license);
    if (by != null) {
        for (Object author : by) {
            mvd.getAuthors().add((String) author);
        }
    }
    mvd.getDependencies().addAll(getDependencies(moduleInfo, dependencies, moduleName, mvd.getVersion(), groupId, artifactId, overrides));
    ModuleVersionArtifact mva = new ModuleVersionArtifact(type, binver[0], binver[1]);
    mvd.getArtifactTypes().add(mva);
    if (includeMembers) {
        mvd.setMembers(getMembers(moduleArchive));
    }
    return mvd;
}
Also used : ClassFile(org.eclipse.ceylon.langtools.classfile.ClassFile) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact) Annotation(org.eclipse.ceylon.langtools.classfile.Annotation)

Aggregations

ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)11 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)10 ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)5 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)1 ArtifactOverrides (org.eclipse.ceylon.cmr.api.ArtifactOverrides)1 DependencyOverride (org.eclipse.ceylon.cmr.api.DependencyOverride)1 MavenArtifactContext (org.eclipse.ceylon.cmr.api.MavenArtifactContext)1 ModuleInfoReader (org.eclipse.ceylon.cmr.api.ModuleInfoReader)1 DependencyDescriptor (org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor)1 Annotation (org.eclipse.ceylon.langtools.classfile.Annotation)1 ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)1