All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.restheart.graal.ImageInfo Maven / Gradle / Ivy

There is a newer version: 8.1.7
Show newest version
/*-
 * ========================LICENSE_START=================================
 * restheart-core
 * %%
 * Copyright (C) 2014 - 2024 SoftInstigate
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 * =========================LICENSE_END==================================
 */
package org.restheart.graal;

public class ImageInfo {
    private static Class imageInfoClass = null;

    static {
        try {
            imageInfoClass = Class.forName("org.graalvm.nativeimage.ImageInfo");
        } catch(ClassNotFoundException cfe) {
            imageInfoClass = null;
        }
    }

    /**
     *
     * Returns true if (at the time of the call) code is executing in the
     * context of image building
     *
     * @return
     */
    @SuppressWarnings("unchecked")
    public static boolean inImageBuildtimeCode() {
        if (imageInfoClass == null) {
            return false;
        } else {
            try {
                return (boolean) imageInfoClass.getDeclaredMethod("inImageBuildtimeCode").invoke(null);
            } catch(Throwable ite) {
                return false;
            }
        }
    }

    /**
     * Returns true if (at the time of the call) code is executing in the
     * context of image building or during image runtime, else false.
     *
     * @return
     */
    @SuppressWarnings("unchecked")
    public static boolean inImageCode() {
        if (imageInfoClass == null) {
            return false;
        } else {
            try {
                return (boolean) imageInfoClass.getDeclaredMethod("inImageCode").invoke(null);
            } catch(Throwable ite) {
                return false;
            }
        }
    }

    /**
     * Returns true if (at the time of the call) code is executing at image
     * runtime.
     *
     * @return
     */
    @SuppressWarnings("unchecked")
    public static boolean inImageRuntimeCode() {
        if (imageInfoClass == null) {
            return false;
        } else {
            try {
                return (boolean) imageInfoClass.getDeclaredMethod("inImageRuntimeCode").invoke(null);
            } catch(Throwable ite) {
                return false;
            }
        }
    }

    /**
     * Returns true if the image is built as an executable.
     *
     * @return
     */
    @SuppressWarnings("unchecked")
    public static boolean isExecutable() {
        if (imageInfoClass == null) {
            return false;
        } else {
            try {
                return (boolean) imageInfoClass.getDeclaredMethod("isExecutable").invoke(null);
            } catch(Throwable ite) {
                return false;
            }
        }
    }

    /**
     * Returns true if the image is build as a shared library.
     */
    @SuppressWarnings("unchecked")
    public static boolean isSharedLibrary() {
        if (imageInfoClass == null) {
            return false;
        } else {
            try {
                return (boolean) imageInfoClass.getDeclaredMethod("isSharedLibrary").invoke(null);
            } catch(Throwable ite) {
                return false;
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy