7
$\begingroup$

For the Mathematica IntelliJ Plugin, I need to validate if a chosen directory is indeed a Mathematica installation and want to extract its version. The structure of the Mathematica installation is not consistent through the operating system and on OSX, the structure even changed in different versions. The goal is come up with a good way to extract version, the location of the Kernel, AddOns packages and the JLink.jar consistently for all Mathematica versions >=8 on all operating systems.

Requirements:

  • Find the kernel executable. Note that the location isn't constant relative to $InstallationDirectory.
  • Find the $InstallationDirectory
  • Find the version number, e.g. "10.0.2"
  • Should work on all operating systems for Mathematica 8.0 or later.
  • Must not launch the kernel, as this may fail if all licenses are already in use.

What is the simplest, most robust, future proof way of doing this?

After examining different Mathematica versions on all three operating systems, I believe I found a promising approach. Unfortunately, some distinction of cases is required. In short, here are the most important points:

  • Obviously, the Kernel is named MathKernel.exe on Windows, while it is only MathKernel on the other two systems.
  • On Linux, there is a .RevisionID file that contains both, the version and the built number. Unfortunately, this is not available on the other operating system so it can not be used.
  • On Windows and Linux there exist two files .VersionID and .CreationID which contain the version and built number. On OSX, these files are only available for versions < 10
  • On OSX there is an Info.plist "property list file" which is a sort of XML file typical for this operating system. This file can be used instead of the .VersionID and .CreationID files to extract version information.
  • On OSX until version 10, the installation folder contained an equivalent structure like on Windows or Linux. There was an additional Contents folder which is required on OSX for an application. From version 10.0.2 onwards the installation folder only contains the Contents folder, and everything else was moved inside it.

I have created a prototype version of this algorithm that can be downloaded from here. With this, one can test what I will later implement in Java for the plugin:

root = $InstallationDirectory
(* "/usr/local/Wolfram/Mathematica/11.0" *)

validateMathematicaInstallation[root] // Shallow
(* {"Version" -> "11.0.1.0", 
    "Build" -> "5597760", 
    "Kernel" -> "/usr/local/Wolfram/Mathematica/11.0/Executables/MathKernel", 
    "AddOnPackages" -> {<<102>>}, 
    "JLink"  -> "/usr/local/Wolfram/Mathematica/11.0/SystemFiles/Links/JLink/JLink.jar"} *)

Be careful not to use $InstallationDirectory on OSX for later versions of Mathematica, as it will contain the path up to the Contents folder.

I have tested this on Linux (8.0.4, 9.0.1, 10.3.1, 11.0.1), OSX (9.0.1, 11.0.1) and Windows (10.3.1). It would be fantastic if I had some more versions (>=8). Additionally, everyone is welcome to comment (not on the hacky coding, but) on the approach itself.

$\endgroup$
  • $\begingroup$ .plist files can in principle use several different storage formats. A more robust way to read from them is using the defaults read Info.plist CFBundleShortVersionString command. $\endgroup$ – Szabolcs Nov 22 '16 at 8:29
  • $\begingroup$ Works as expected for versions 10.4.1 and 11.0.1 on Windows $\endgroup$ – Simon Woods Nov 22 '16 at 8:54
  • 3
    $\begingroup$ A minor suggestion: The kernels are also called WolframKernel - maybe you want to take that into consideration as well. Who know what will happen to the MathKernel in the future.... $\endgroup$ – user21 Nov 22 '16 at 10:16
  • $\begingroup$ @Szabolcs The .plist parsing was the fastest way I could come up with. I'm sure there is some java library that does this when I implement it in the plugin. $\endgroup$ – halirutan Nov 22 '16 at 13:09
  • $\begingroup$ @user21 Yes, indeed! $\endgroup$ – halirutan Nov 22 '16 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.