Search in sources :

Example 1 with Platform

use of org.bytedeco.javacpp.annotation.Platform in project bigbluebutton by bigbluebutton.

the class Generator method checkPlatform.

boolean checkPlatform(Class<?> cls) {
    // check in priority this class for platform information, before the enclosing class
    Class<?> enclosingClass = Loader.getEnclosingClass(cls);
    while (!cls.isAnnotationPresent(org.bytedeco.javacpp.annotation.Properties.class) && !cls.isAnnotationPresent(Platform.class) && cls.getSuperclass() != null) {
        if (enclosingClass != null && cls.getSuperclass() == Object.class) {
            cls = enclosingClass;
            enclosingClass = null;
        } else {
            cls = cls.getSuperclass();
        }
    }
    org.bytedeco.javacpp.annotation.Properties classProperties = cls.getAnnotation(org.bytedeco.javacpp.annotation.Properties.class);
    if (classProperties != null) {
        Class[] classes = classProperties.inherit();
        // get default platform names, searching in inherited classes as well
        String[] defaultNames = classProperties.names();
        Deque<Class> queue = new ArrayDeque<Class>(Arrays.asList(classes));
        while (queue.size() > 0 && (defaultNames == null || defaultNames.length == 0)) {
            Class<?> c = queue.removeFirst();
            org.bytedeco.javacpp.annotation.Properties p = c.getAnnotation(org.bytedeco.javacpp.annotation.Properties.class);
            if (p != null) {
                defaultNames = p.names();
                queue.addAll(Arrays.asList(p.inherit()));
            }
        }
        // check in priority the platforms inside our properties annotation, before inherited ones
        Platform[] platforms = classProperties.value();
        if (platforms != null) {
            for (Platform p : platforms) {
                if (checkPlatform(p, defaultNames)) {
                    return true;
                }
            }
        } else if (classes != null) {
            for (Class c : classes) {
                if (checkPlatform(c)) {
                    return true;
                }
            }
        }
    } else if (checkPlatform(cls.getAnnotation(Platform.class), null)) {
        return true;
    }
    return false;
}
Also used : Platform(org.bytedeco.javacpp.annotation.Platform) ClassProperties(org.bytedeco.javacpp.ClassProperties) ArrayDeque(java.util.ArrayDeque)

Example 2 with Platform

use of org.bytedeco.javacpp.annotation.Platform in project bigbluebutton by bigbluebutton.

the class ClassProperties method load.

public void load(Class cls, boolean inherit) {
    Class<?> c = Loader.getEnclosingClass(cls);
    List<Class> classList = new ArrayList<Class>();
    classList.add(0, c);
    while (!c.isAnnotationPresent(org.bytedeco.javacpp.annotation.Properties.class) && !c.isAnnotationPresent(Platform.class) && c.getSuperclass() != null && c.getSuperclass() != Object.class) {
        // accumulate superclasses to process native methods from those as well
        classList.add(0, c = c.getSuperclass());
    }
    if (effectiveClasses == null) {
        effectiveClasses = classList;
    }
    org.bytedeco.javacpp.annotation.Properties classProperties = c.getAnnotation(org.bytedeco.javacpp.annotation.Properties.class);
    Platform[] platforms = null;
    if (classProperties == null) {
        Platform platform = c.getAnnotation(Platform.class);
        if (platform != null) {
            platforms = new Platform[] { platform };
        }
    } else {
        Class[] classes = classProperties.inherit();
        if (inherit && classes != null) {
            if (inheritedClasses == null) {
                inheritedClasses = new ArrayList<Class>();
            }
            for (Class c2 : classes) {
                load(c2, inherit);
                if (!inheritedClasses.contains(c2)) {
                    inheritedClasses.add(c2);
                }
            }
        }
        String target = classProperties.target();
        if (target.length() > 0) {
            addAll("target", target);
        }
        String helper = classProperties.helper();
        if (helper.length() > 0) {
            addAll("helper", helper);
        }
        String[] names = classProperties.names();
        if (names.length > 0) {
            defaultNames = names;
        }
        platforms = classProperties.value();
    }
    String[] pragma = {}, define = {}, include = {}, cinclude = {}, includepath = {}, compiler = {}, linkpath = {}, link = {}, frameworkpath = {}, framework = {}, preloadpath = {}, preload = {};
    String library = "jni" + c.getSimpleName();
    for (Platform p : platforms != null ? platforms : new Platform[0]) {
        String[][] names = { p.value().length > 0 ? p.value() : defaultNames, p.not() };
        boolean[] matches = { false, false };
        for (int i = 0; i < names.length; i++) {
            for (String s : names[i]) {
                if (platform.startsWith(s)) {
                    matches[i] = true;
                    break;
                }
            }
        }
        if ((names[0].length == 0 || matches[0]) && (names[1].length == 0 || !matches[1])) {
            if (p.pragma().length > 0) {
                pragma = p.pragma();
            }
            if (p.define().length > 0) {
                define = p.define();
            }
            if (p.include().length > 0) {
                include = p.include();
            }
            if (p.cinclude().length > 0) {
                cinclude = p.cinclude();
            }
            if (p.includepath().length > 0) {
                includepath = p.includepath();
            }
            if (p.compiler().length > 0) {
                compiler = p.compiler();
            }
            if (p.linkpath().length > 0) {
                linkpath = p.linkpath();
            }
            if (p.link().length > 0) {
                link = p.link();
            }
            if (p.frameworkpath().length > 0) {
                frameworkpath = p.frameworkpath();
            }
            if (p.framework().length > 0) {
                framework = p.framework();
            }
            if (p.preloadpath().length > 0) {
                preloadpath = p.preloadpath();
            }
            if (p.preload().length > 0) {
                preload = p.preload();
            }
            if (p.library().length() > 0) {
                library = p.library();
            }
        }
    }
    addAll("platform.pragma", pragma);
    addAll("platform.define", define);
    addAll("platform.include", include);
    addAll("platform.cinclude", cinclude);
    addAll("platform.includepath", includepath);
    addAll("platform.compiler.*", compiler);
    addAll("platform.linkpath", linkpath);
    addAll("platform.link", link);
    addAll("platform.frameworkpath", frameworkpath);
    addAll("platform.framework", framework);
    addAll("platform.preloadpath", preloadpath);
    addAll("platform.preload", preload);
    setProperty("platform.library", library);
    if (platforms != null && platforms.length > 0) {
        loaded = true;
    }
}
Also used : Platform(org.bytedeco.javacpp.annotation.Platform) ArrayList(java.util.ArrayList)

Example 3 with Platform

use of org.bytedeco.javacpp.annotation.Platform in project javacpp by bytedeco.

the class Loader method checkPlatform.

public static boolean checkPlatform(Class<?> cls, Properties properties) {
    // check in priority this class for platform information, before the enclosing class
    Class<?> enclosingClass = Loader.getEnclosingClass(cls);
    while (!cls.isAnnotationPresent(org.bytedeco.javacpp.annotation.Properties.class) && !cls.isAnnotationPresent(Platform.class) && cls.getSuperclass() != null) {
        if (enclosingClass != null && cls.getSuperclass() == Object.class) {
            cls = enclosingClass;
            enclosingClass = null;
        } else {
            cls = cls.getSuperclass();
        }
    }
    org.bytedeco.javacpp.annotation.Properties classProperties = cls.getAnnotation(org.bytedeco.javacpp.annotation.Properties.class);
    if (classProperties != null) {
        Class[] classes = classProperties.inherit();
        // get default platform names, searching in inherited classes as well
        String[] defaultNames = classProperties.names();
        Deque<Class> queue = new ArrayDeque<Class>(Arrays.asList(classes));
        while (queue.size() > 0 && (defaultNames == null || defaultNames.length == 0)) {
            Class<?> c = queue.removeFirst();
            org.bytedeco.javacpp.annotation.Properties p = c.getAnnotation(org.bytedeco.javacpp.annotation.Properties.class);
            if (p != null) {
                defaultNames = p.names();
                queue.addAll(Arrays.asList(p.inherit()));
            }
        }
        // check in priority the platforms inside our properties annotation, before inherited ones
        Platform[] platforms = classProperties.value();
        if (platforms != null) {
            for (Platform p : platforms) {
                if (checkPlatform(p, properties, defaultNames)) {
                    return true;
                }
            }
        } else if (classes != null) {
            for (Class c : classes) {
                if (checkPlatform(c, properties)) {
                    return true;
                }
            }
        }
    } else if (checkPlatform(cls.getAnnotation(Platform.class), properties)) {
        return true;
    }
    return false;
}
Also used : Platform(org.bytedeco.javacpp.annotation.Platform) Properties(java.util.Properties) ArrayDeque(java.util.ArrayDeque)

Example 4 with Platform

use of org.bytedeco.javacpp.annotation.Platform in project javacpp by bytedeco.

the class ClassProperties method load.

public void load(Class cls, boolean inherit) {
    Class<?> c = Loader.getEnclosingClass(cls);
    List<Class> classList = new ArrayList<Class>();
    classList.add(0, c);
    while (!c.isAnnotationPresent(org.bytedeco.javacpp.annotation.Properties.class) && !c.isAnnotationPresent(Platform.class) && c.getSuperclass() != null && c.getSuperclass() != Object.class) {
        // accumulate superclasses to process native methods from those as well
        classList.add(0, c = c.getSuperclass());
    }
    if (effectiveClasses == null) {
        effectiveClasses = classList;
    }
    org.bytedeco.javacpp.annotation.Properties classProperties = c.getAnnotation(org.bytedeco.javacpp.annotation.Properties.class);
    Platform[] platforms = null;
    if (classProperties == null) {
        Platform platform = c.getAnnotation(Platform.class);
        if (platform != null) {
            platforms = new Platform[] { platform };
        }
    } else {
        Class[] classes = classProperties.inherit();
        if (inherit && classes != null) {
            if (inheritedClasses == null) {
                inheritedClasses = new ArrayList<Class>();
            }
            for (Class c2 : classes) {
                load(c2, inherit);
                if (!inheritedClasses.contains(c2)) {
                    inheritedClasses.add(c2);
                }
            }
        }
        String target = classProperties.target();
        if (target.length() > 0) {
            addAll("target", target);
        }
        String helper = classProperties.helper();
        if (helper.length() > 0) {
            addAll("helper", helper);
        }
        String[] names = classProperties.names();
        if (names.length > 0) {
            defaultNames = names;
        }
        platforms = classProperties.value();
    }
    String[] pragma = {}, define = {}, exclude = {}, include = {}, cinclude = {}, includepath = {}, includeresource = {}, compiler = {}, linkpath = {}, linkresource = {}, link = {}, frameworkpath = {}, framework = {}, preloadpath = {}, preload = {}, resourcepath = {}, resource = {}, extension = {};
    String library = "jni" + c.getSimpleName();
    for (Platform p : platforms != null ? platforms : new Platform[0]) {
        String[][] names = { p.value().length > 0 ? p.value() : defaultNames, p.not() };
        boolean[] matches = { false, false };
        for (int i = 0; i < names.length; i++) {
            for (String s : names[i]) {
                if (platform.startsWith(s)) {
                    matches[i] = true;
                    break;
                }
            }
        }
        if ((names[0].length == 0 || matches[0]) && (names[1].length == 0 || !matches[1])) {
            // when no extensions are given by user, but we are in library loading mode, try to load extensions anyway
            boolean match = p.extension().length == 0 || (Loader.isLoadLibraries() && platformExtension.length() == 0);
            for (String s : p.extension()) {
                if (platformExtension.length() > 0 && platformExtension.endsWith(s)) {
                    match = true;
                    break;
                }
            }
            if (!match) {
                continue;
            }
            if (p.pragma().length > 0) {
                pragma = p.pragma();
            }
            if (p.define().length > 0) {
                define = p.define();
            }
            if (p.exclude().length > 0) {
                exclude = p.exclude();
            }
            if (p.include().length > 0) {
                include = p.include();
            }
            if (p.cinclude().length > 0) {
                cinclude = p.cinclude();
            }
            if (p.includepath().length > 0) {
                includepath = p.includepath();
            }
            if (p.includeresource().length > 0) {
                includeresource = p.includeresource();
            }
            if (p.compiler().length > 0) {
                compiler = p.compiler();
            }
            if (p.linkpath().length > 0) {
                linkpath = p.linkpath();
            }
            if (p.linkresource().length > 0) {
                linkresource = p.linkresource();
            }
            if (p.link().length > 0) {
                link = p.link();
            }
            if (p.frameworkpath().length > 0) {
                frameworkpath = p.frameworkpath();
            }
            if (p.framework().length > 0) {
                framework = p.framework();
            }
            if (p.preloadpath().length > 0) {
                preloadpath = p.preloadpath();
            }
            if (p.preload().length > 0) {
                preload = p.preload();
            }
            if (p.resourcepath().length > 0) {
                resourcepath = p.resourcepath();
            }
            if (p.resource().length > 0) {
                resource = p.resource();
            }
            if (p.extension().length > 0) {
                extension = p.extension();
            }
            if (p.library().length() > 0) {
                library = p.library();
            }
        }
    }
    for (int i = 0; i < includeresource.length; i++) {
        // turn resources into absolute names
        String name = includeresource[i];
        if (!name.startsWith("/")) {
            String s = cls.getName().replace('.', '/');
            int n = s.lastIndexOf('/');
            if (n >= 0) {
                name = s.substring(0, n + 1) + name;
            }
            includeresource[i] = "/" + name;
        }
    }
    for (int i = 0; i < linkresource.length; i++) {
        // turn resources into absolute names
        String name = linkresource[i];
        if (!name.startsWith("/")) {
            String s = cls.getName().replace('.', '/');
            int n = s.lastIndexOf('/');
            if (n >= 0) {
                name = s.substring(0, n + 1) + name;
            }
            linkresource[i] = "/" + name;
        }
    }
    addAll("platform.pragma", pragma);
    addAll("platform.define", define);
    addAll("platform.exclude", exclude);
    addAll("platform.include", include);
    addAll("platform.cinclude", cinclude);
    addAll("platform.includepath", includepath);
    addAll("platform.includeresource", includeresource);
    addAll("platform.compiler.*", compiler);
    addAll("platform.linkpath", linkpath);
    addAll("platform.linkresource", linkresource);
    addAll("platform.link", link);
    addAll("platform.frameworkpath", frameworkpath);
    addAll("platform.framework", framework);
    addAll("platform.preloadpath", preloadpath);
    addAll("platform.preload", preload);
    addAll("platform.resourcepath", resourcepath);
    addAll("platform.resource", resource);
    addAll("platform.extension", extension);
    setProperty("platform.library", library);
    try {
        if (LoadEnabled.class.isAssignableFrom(c)) {
            ((LoadEnabled) c.newInstance()).init(this);
        }
    } catch (ClassCastException | InstantiationException | IllegalAccessException e) {
    // fail silently as if the interface wasn't implemented
    }
    if (platforms != null && platforms.length > 0) {
        loaded = true;
    }
}
Also used : Platform(org.bytedeco.javacpp.annotation.Platform) ArrayList(java.util.ArrayList)

Aggregations

Platform (org.bytedeco.javacpp.annotation.Platform)4 ArrayDeque (java.util.ArrayDeque)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)1 ClassProperties (org.bytedeco.javacpp.ClassProperties)1