I am using this kind of code in plugin.xml in order to show/hide a menu item depending on OS type :
<menu label="Help">
<command commandId="org.eclipse.ui.help.aboutAction" style="push">
<visibleWhen checkEnabled="false">
<not>
<systemTest property="os.name" value="Mac OS X">
</systemTest>
</not>
</visibleWhen>
</command>
</menu>
The problem is that os.name, which is returned by System.getProperty("os.name")
, seems to not be very standardized. It can depends on OS version, specially for Microsoft Windows.
I was wondering if there was a best practice ?
The osgi.os
environment variable has a more defined value for the OS. Values for this are defined in org.eclipse.osgi.service.environment.Constants
:
public static final String OS_WIN32 = "win32";
public static final String OS_LINUX = "linux";
public static final String OS_AIX = "aix";
public static final String OS_SOLARIS = "solaris";
public static final String OS_HPUX = "hpux";
public static final String OS_QNX = "qnx";
public static final String OS_MACOSX = "macosx";
public static final String OS_EPOC32 = "epoc32";
public static final String OS_OS400 = "os/400";
public static final String OS_OS390 = "os/390";
public static final String OS_ZOS = "z/os";
public static final String OS_FREEBSD = "freebsd";
public static final String OS_UNKNOWN = "unknown";
Note: despite its name (and the comments in the Constants
class) win32
applies to 32 and 64 bit Windows.
There is also osgi.arch
for the processor architecture:
public static final String ARCH_X86 = "x86";
public static final String ARCH_X86_64 = "x86_64";
public static final String ARCH_PA_RISC = "PA_RISC";
public static final String ARCH_PPC = "ppc";
public static final String ARCH_PPC64 = "ppc64";
public static final String ARCH_SPARC = "sparc";
public static final String ARCH_IA64 = "ia64";
public static final String ARCH_IA64_32 = "ia64_32";
Finally osgi.ws
gives the Windowing System:
public static final String WS_WIN32 = "win32";
public static final String WS_WPF = "wpf";
public static final String WS_MOTIF = "motif";
public static final String WS_GTK = "gtk";
public static final String WS_PHOTON = "photon";
public static final String WS_CARBON = "carbon";
public static final String WS_COCOA = "cocoa";
public static final String WS_S60 = "s60";
public static final String WS_UNKNOWN = "unknown";