From d71490fa46106b0502ee3b903793a16a3bb6f68b Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Wed, 23 Oct 2019 22:28:22 +0300 Subject: [PATCH] Report and log failure of Python DLL loading gitlab #2 Change-Id: I2e568ca49e0974cb4b7aedbdc14e00c594f991e8 --- org.simantics.pythonlink/META-INF/MANIFEST.MF | 1 + .../src/org/simantics/pythonlink/Activator.java | 16 +++++++++++++++- .../org/simantics/pythonlink/PythonContext.java | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/org.simantics.pythonlink/META-INF/MANIFEST.MF b/org.simantics.pythonlink/META-INF/MANIFEST.MF index 427f880..36a734c 100644 --- a/org.simantics.pythonlink/META-INF/MANIFEST.MF +++ b/org.simantics.pythonlink/META-INF/MANIFEST.MF @@ -20,3 +20,4 @@ Require-Bundle: org.junit, Export-Package: org.simantics.pythonlink Bundle-Activator: org.simantics.pythonlink.Activator Bundle-ActivationPolicy: lazy +Import-Package: org.slf4j diff --git a/org.simantics.pythonlink/src/org/simantics/pythonlink/Activator.java b/org.simantics.pythonlink/src/org/simantics/pythonlink/Activator.java index 83633a4..26798d6 100644 --- a/org.simantics.pythonlink/src/org/simantics/pythonlink/Activator.java +++ b/org.simantics.pythonlink/src/org/simantics/pythonlink/Activator.java @@ -2,11 +2,16 @@ package org.simantics.pythonlink; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class Activator implements BundleActivator { + private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class); private static BundleContext context; + private static boolean loaded = false; + static BundleContext getContext() { return context; } @@ -17,7 +22,16 @@ public class Activator implements BundleActivator { */ public void start(BundleContext bundleContext) throws Exception { Activator.context = bundleContext; - System.loadLibrary("jnipython"); + try { + System.loadLibrary("jnipython"); + loaded = true; + } catch (Exception e) { + LOGGER.error("Loading of jnipython.dll failed", e); + } + } + + public static boolean isPythonLoaded() { + return loaded; } /* diff --git a/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java b/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java index cceace3..77701ef 100644 --- a/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java +++ b/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java @@ -57,6 +57,10 @@ public class PythonContext implements Closeable { }; private static synchronized void ensurePythonInit() { + if (!Activator.isPythonLoaded()) { + throw new PythonException("Python interpreter has not been successfully loaded. Check availablility of python3.dll in path."); + } + if (!isPyInitialized) { execute(() -> initializePython(pythonWriter)); isPyInitialized = true; -- 2.47.1