Search in sources :

Example 1 with NativeIntegrationUnavailableException

use of net.rubygrapefruit.platform.NativeIntegrationUnavailableException in project gradle by gradle.

the class NativeServices method initialize.

/**
 * Initializes the native services to use the given user home directory to store native libs and other resources. Does nothing if already initialized.
 */
public static synchronized void initialize(File userHomeDir, boolean initializeJansi) {
    if (!initialized) {
        useNativeIntegrations = "true".equalsIgnoreCase(System.getProperty("org.gradle.native", "true"));
        if (useNativeIntegrations) {
            File nativeBaseDir = getNativeServicesDir(userHomeDir);
            try {
                net.rubygrapefruit.platform.Native.init(nativeBaseDir);
            } catch (NativeIntegrationUnavailableException ex) {
                LOGGER.debug("Native-platform is not available.");
                useNativeIntegrations = false;
            } catch (NativeException ex) {
                if (ex.getCause() instanceof UnsatisfiedLinkError && ex.getCause().getMessage().toLowerCase().contains("already loaded in another classloader")) {
                    LOGGER.debug("Unable to initialize native-platform. Failure: {}", format(ex));
                    useNativeIntegrations = false;
                } else if (ex.getMessage().equals("Could not extract native JNI library.") && ex.getCause().getMessage().contains("native-platform.dll (The process cannot access the file because it is being used by another process)")) {
                    // triggered through tooling API of Gradle <2.3 - native-platform.dll is shared by tooling client (<2.3) and daemon (current) and it is locked by the client (<2.3 issue)
                    LOGGER.debug("Unable to initialize native-platform. Failure: {}", format(ex));
                    useNativeIntegrations = false;
                } else {
                    throw ex;
                }
            }
            if (initializeJansi) {
                JANSI_BOOT_PATH_CONFIGURER.configure(nativeBaseDir);
            }
            LOGGER.info("Initialized native services in: " + nativeBaseDir);
        }
        initialized = true;
    }
}
Also used : NativeIntegrationUnavailableException(net.rubygrapefruit.platform.NativeIntegrationUnavailableException) File(java.io.File) NativeException(net.rubygrapefruit.platform.NativeException)

Aggregations

File (java.io.File)1 NativeException (net.rubygrapefruit.platform.NativeException)1 NativeIntegrationUnavailableException (net.rubygrapefruit.platform.NativeIntegrationUnavailableException)1