Search in sources :

Example 11 with ClassFile

use of org.eclipse.ceylon.langtools.classfile.ClassFile 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)

Example 12 with ClassFile

use of org.eclipse.ceylon.langtools.classfile.ClassFile 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)

Aggregations

ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)12 Annotation (org.eclipse.ceylon.langtools.classfile.Annotation)4 Module_attribute (org.eclipse.ceylon.langtools.classfile.Module_attribute)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 ZipEntry (java.util.zip.ZipEntry)3 ZipFile (java.util.zip.ZipFile)3 File (java.io.File)2 ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)2 ClassWriter (org.eclipse.ceylon.langtools.classfile.ClassWriter)2 ConstantPoolException (org.eclipse.ceylon.langtools.classfile.ConstantPoolException)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)1 ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)1 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)1