Search in sources :

Example 6 with Annotation

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

Annotation (org.eclipse.ceylon.langtools.classfile.Annotation)6 ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)4 ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)3 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)2 File (java.io.File)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)1 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)1 Backends (org.eclipse.ceylon.common.Backends)1 RuntimeVisibleAnnotations_attribute (org.eclipse.ceylon.langtools.classfile.RuntimeVisibleAnnotations_attribute)1 Test (org.junit.Test)1